VOID CColorPage::OnPaint() { CRect rcBack, rcGrid; CPaintDC dc(this); CPaintDC dcBack(&BackColor()); CPaintDC dcGrid(&GridColor()); rcBack.CopyRect(&(dcBack.m_ps.rcPaint)); rcGrid.CopyRect(&(dcGrid.m_ps.rcPaint)); dcBack.FillSolidRect(&rcBack, m_lBackColor); dcGrid.FillSolidRect(&rcGrid, m_lGridColor); CPropertyPage::OnPaint(); }
void COScopeCtrl::RecreateGrid() { // There is a lot of drawing going on here - particularly in terms of // drawing the grid. Don't panic, this is all being drawn (only once) // to a bitmap. The result is then BitBlt'd to the control whenever needed. bRecreateGrid = false; if (m_rectClient.GetWidth() == 0 || m_rectClient.GetHeight() == 0) { return; } wxMemoryDC dcGrid(m_bmapGrid); wxPen solidPen = *(wxThePenList->FindOrCreatePen(m_gridColour, 1, wxSOLID)); wxString strTemp; // fill the grid background dcGrid.SetBrush(brushBack); dcGrid.SetPen(*wxTRANSPARENT_PEN); dcGrid.DrawRectangle(m_rectClient); // adjust the plot rectangle dimensions // assume 6 pixels per character (this may need to be adjusted) m_rectPlot.x = m_rectClient.GetLeft() + 6*7+4; // draw the plot rectangle dcGrid.SetPen(solidPen); dcGrid.DrawRectangle(m_rectPlot.x - 1, m_rectPlot.y - 1, m_rectPlot.GetWidth() + 2, m_rectPlot.GetHeight() + 2); dcGrid.SetPen(wxNullPen); // create some fonts (horizontal and vertical) wxFont axisFont(10, wxSWISS, wxNORMAL, wxNORMAL, false); dcGrid.SetFont(axisFont); // y max dcGrid.SetTextForeground(m_gridColour); if( strYMax.IsEmpty() ) { strTemp = wxString::Format(wxT("%.*f"), nYDecimals, pdsTrends[ 0 ].fUpperLimit); } else { strTemp = strYMax; } wxCoord sizX,sizY; dcGrid.GetTextExtent(strTemp,&sizX,&sizY); dcGrid.DrawText(strTemp,m_rectPlot.GetLeft()-4-sizX,m_rectPlot.GetTop()-7); // y min if( strYMin.IsEmpty() ) { strTemp = wxString::Format(wxT("%.*f"), nYDecimals, pdsTrends[ 0 ].fLowerLimit) ; } else { strTemp = strYMin; } dcGrid.GetTextExtent(strTemp,&sizX,&sizY); dcGrid.DrawText(strTemp,m_rectPlot.GetLeft()-4-sizX, m_rectPlot.GetBottom()); // x units strTemp = CastSecondsToHM((m_rectPlot.GetWidth()/nShiftPixels) * (int)floor(sLastPeriod+0.5)); // floor(x + 0.5) is a way of doing round(x) that works with gcc < 3 ... if (bStopped) { strXUnits = CFormat( _("Disabled [%s]") ) % strTemp; } else { strXUnits = strTemp; } dcGrid.GetTextExtent(strXUnits,&sizX,&sizY); dcGrid.DrawText(strXUnits,(m_rectPlot.GetLeft() + m_rectPlot.GetRight())/2-sizX/2,m_rectPlot.GetBottom()+4); // y units if (!strYUnits.IsEmpty()) { dcGrid.GetTextExtent(strYUnits,&sizX,&sizY); dcGrid.DrawText(strYUnits, m_rectPlot.GetLeft()-4-sizX, (m_rectPlot.GetTop()+m_rectPlot.GetBottom())/2-sizY/2); } // no more drawing to this bitmap is needed until the setting are changed if (bRecreateGraph) { RecreateGraph(false); } // finally, force the plot area to redraw Refresh(false); }