K
Hallo,
ich versuche von einer anderen Methode ein Teilstück meines Panels zu malen. Unter Linux (wxWidgets 2.8.7, Debian Lenny) funktioniert es nicht. Manchmal zeichnet es nicht den Hintergrund oder fängt erst nach dem vergrössern des Programms mit dem Zeichnen an. Teilweise stürzt es sogar ab.
Unter Windows (wxWidgets 2.8.7) funktioniert dieser Code und macht, was er soll.
Der gesamte Quelltext ist unter http://fbi.hooster.de/download/sonstiges/wxwidgets/pyro.zip
Mache ich etwas grundsätzliches falsch?
Gruß Klaus
void GraphPanel::setTemperature(double Temperature)
{
//Refresh ();
wxClientDC dc(this);
wxPen pen(wxColour(0,0,255),4);;
pen.SetStyle(wxSOLID);
pen.SetWidth(1);
dc.SetPen(pen);
width=GetSize().GetWidth()-margin_left-margin_right;
height = GetSize().GetHeight()-margin_top-margin_bottom;
//dc.DrawText(wxString::Format(wxT("%6.1f C"),Temperature ),width,5);
dc.DrawLine(xAxis+m_pointDistance,getTemperatureInPix(Temperature),xAxis,getTemperatureInPix(lastTemperature));
xAxis+= m_pointDistance;
lastTemperature=Temperature;
Update();
}
void GraphPanel::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
int dif= 0;
dc.DrawRectangle(dif,dif,GetSize().GetWidth()-dif*2,GetSize().GetHeight()-dif*2);
int charHeight = (GetCharHeight()/2);
width=GetSize().GetWidth()-margin_left-margin_right;
height = GetSize().GetHeight()-margin_top-margin_bottom;
dc.DrawRectangle(margin_left,margin_top,width,height);
//draw min and max
dc.DrawText(wxString::Format(wxT("%d"),(int)max ),5, margin_top-charHeight);
dc.DrawText(wxString::Format(wxT("%d"),(int)min ),5, height+margin_top -charHeight);
//dc.DrawText(wxString::Format(wxT("%6.1f C"),lastTemperature ),width,5);
dc.SetPen(wxPen(col1, 1, wxLONG_DASH));
int count = ((int)(height/80))+1;
int diff = height/count;
int i =0, j=0;
for (i = 1 ; i < count; i++) {
int temp = (((max-min)/count))*(count-i)+min;
int hTemp = diff*i+margin_top;
dc.DrawLine(margin_left, hTemp, width+margin_left,hTemp );
dc.DrawText(wxString::Format(wxT("%d"),temp) ,5, hTemp-charHeight);
}
if (!m_controller)
return;
m_controller->setMeasuringPoints(width/m_pointDistance);
wxPen pen(wxColour(0,0,255),4);;
pen.SetStyle(wxSOLID);
pen.SetWidth(1);
dc.SetPen(pen);
wxCoord x = 0;
wxCoord y = 0;
wxSize size = this->GetSize();
wxCoord xold =margin_left;
wxCoord yold =size.GetY()-margin_bottom;
for (xAxis=margin_left+m_pointDistance, j =1; xAxis< width+margin_right && j<m_controller->m_points.size();j++) {
y = getTemperatureInPix((m_controller->m_points.at(j).temperature));
yold = getTemperatureInPix((m_controller->m_points.at(j-1).temperature));
dc.DrawLine(xAxis,y,xold,yold);
xold = xAxis;
xAxis+=m_pointDistance;
lastTemperature=(m_controller->m_points.at(j).temperature);
}
xAxis-=m_pointDistance;
}
int GraphPanel::getTemperatureInPix(double Temperature)
{
return (height-((Temperature-min)/(max-min))*height)+margin_bottom;
}