-1
我有一些关于wxpaintDC绘图的代码。我在wxPaintDC绘图中得到了一个奇怪的东西
我有这样一些相关的绘图类:
IMPLEMENT_CLASS(MapView, wxWindow)
BEGIN_EVENT_TABLE(MapView, wxWindow)
EVT_PAINT(MapView::OnPaint)
END_EVENT_TABLE()
void MapView::OnPaint(wxPaintEvent & event)
{
wxPaintDC dc(this);
wxRect m_Rect = this->GetRect(); //get the rect
wxCoord x1 = 50, y1 = 60;
wxCoord x2 = 190, y2 = 60;
dc.DrawLine(x1, y1, x2, y2);
//draw line
//draw point
//draw polygon
if(m_ly->lineSVector.size()>0)
{
wxString tmp = wxString::Format(_T("%d"), m_ly->lineSVector.size());
for(int i =0 ; i < m_ly->lineSVector.size(); i++)
{
wxArrayString strArrTmp = m_ly->lineSVector.at(i);
wxPoint *pts = new wxPoint;
wxPoint p1;
wxPoint p2;
wxPaintDC dc_k(this);
wxRect m_Rect = this->GetRect();
wxCoord xx1 = 40, yy1 = 50;
wxCoord xx2 = 180, yy2 = 70;
dc_k.DrawLine(xx1, yy1,xx2,yy2);
for(int j = 0; j < strArrTmp.size(); j++)
{
wxString strPt = strArrTmp.Item(j);
int p = strPt.Find(" ");
wxString strX = strPt.substr(0,p);
wxString strY = strPt.substr(p+1,strPt.Length()-p);
double a = atof(strX);
double b = atof(strY);
a = a - m_ly->m_rect->GetLeft();
b = b - m_ly->m_rect->GetBottom();
a = m_Rect.GetLeft() + ((double)m_Rect.GetWidth()/(double)m_ly->m_rect->GetWidth()) * (double)a;
b = m_Rect.GetBottom() + ((double)m_Rect.GetHeight()/(double)m_ly->m_rect->GetHeight())* (double)b;
(pts + j)->x = a;
(pts + j)->y = b;
if(j==0)
{
//xx1 = a;
//yy1 = b;
}
else if(j==1)
{
//xx2 = a;
//yy2 = b;
}
}
//dc.DrawLines(strArrTmp.size(), pts);
//dc.DrawLine(p1, p2);
/* dc.DrawLine(xx1, yy1,xx2,yy2);*/
}
//wxMessageBox(tmp);
}
else
{
}
}
我尝试各种方法,但我发现,只有
wxPaintDC dc(this);
wxRect m_Rect = this->GetRect(); //get the rect
wxCoord x1 = 50, y1 = 60;
wxCoord x2 = 190, y2 = 60;
dc.DrawLine(x1, y1, x2, y2);
生效。
它借鉴(50,60)一行(190,60)
我调试代码,并发现该代码可以进入
if(m_ly->lineSVector.size()>0)
{....
....
}
而且它可以进入该代码 [code] wxPaintDC dc_k(this); wxRect m_Rect = this-> GetRect();
wxCoord xx1 = 40, yy1 = 50;
wxCoord xx2 = 180, yy2 = 70;
dc_k.DrawLine(xx1, yy1,xx2,yy2);
我调试,并观看他们的价值毫无疑问,他们有正确的价值,并运行它们,
,但我真的不明白,为什么在我如果{}块不会生效我的绘制代码。