void TimeLogChart::DrawAxis(wxPaintDC &dc) { const int MARKER_OFFSET = 5; dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(m_axisBounds); dc.SetPen(wxPen(wxColour(*wxBLACK), 1, wxPENSTYLE_DOT)); int topBound = m_axisBounds.GetTop(); int leftBound = m_axisBounds.GetLeft(); int rightBound = m_axisBounds.GetRight(); int bottomBound = m_axisBounds.GetBottom(); int dx = leftBound; wxFont savedFont = dc.GetFont(); dc.SetFont(*m_valueFont); int n = m_logDuration -1; for (int i = 0; i <= n; i++) { dx = leftBound + (int)floor(i*m_axisBounds.GetWidth() / (double)n); if (i % m_logTickFrequency == 0) { dc.DrawLine(dx, topBound, dx, bottomBound); if (i % (m_logTickFrequency*2) == 0) { // draw axis marker wxString s = wxString::Format(wxT("%d secs"), (m_logDuration-i)); wxSize ext = dc.GetTextExtent(s); dc.DrawText(s, dx - ext.GetWidth()/2, bottomBound + MARKER_OFFSET); } } } dc.DrawLine(dx, topBound, dx, bottomBound); int yValue = m_maxValue; int yValueSteps = (m_minValue-m_maxValue)/m_valueDivisions; int ySteps = ValueToPixel((m_maxValue - m_minValue)/m_valueDivisions); int dy = topBound; for (int n = 0; n < m_valueDivisions; n++) { dc.DrawLine(leftBound, dy, rightBound, dy); wxString s = wxString::Format(m_valueAxisFormat, (double)yValue/m_valueAxisScale); wxSize ext = dc.GetTextExtent(s); dc.DrawText(s, m_axisBounds.GetLeft()-ext.GetWidth() - MARKER_OFFSET, dy - ext.GetHeight()/2); dy += ySteps; yValue += yValueSteps; } dc.DrawLine(leftBound, bottomBound, rightBound, bottomBound); dc.SetFont(savedFont); }
void THISCLASS::DrawTicks(wxPaintDC &dc, const SwisTrackCoreEventRecorder::Timeline *timeline) { wxSize dcsize = dc.GetSize(); int dw = dcsize.GetWidth(); //int dh=dcsize.GetHeight(); // Not needed dc.SetFont(GetFont()); dc.SetPen(wxPen(wxColour(0xcc, 0xcc, 0xcc))); dc.SetTextForeground(wxColour(0xcc, 0xcc, 0xcc)); // Calculate how many ticks to display double mintickdistance = 5; double mintickdistancetime = mintickdistance / mViewScale; double tickdistancetime = pow(10, ceil(log(mintickdistancetime) / log((double)10))); // Draw ticks double endtime = mSwisTrack->mSwisTrackCore->mEventRecorder->CalculateDuration(&(timeline->mBegin), &(timeline->mEnd)); int ticknumber = (int)ceil(-mViewOffset / mViewScale / tickdistancetime); while (true) { double xtime = ticknumber * tickdistancetime; if (xtime >= endtime) { break; } int x = (int)floor(xtime * mViewScale + mViewOffset); if (x > dw) { break; } if (ticknumber % 10 == 0) { dc.DrawLine(x, 0, x, 4); wxString label = wxString::Format(wxT("%d"), (int)(xtime * 1000)); int textwidth, textheight; GetTextExtent(label, &textwidth, &textheight) ; textwidth >>= 1; dc.DrawText(label, x - textwidth, 2); } else {
void TimeLogChart::DrawLegends(wxPaintDC &dc) { const int LEGEND_LENGTH = 10; if (m_chartCollection == NULL && m_chartCollection->GetCount() == 0) return; dc.SetFont(*m_valueFont); wxSize ext = dc.GetTextExtent("H"); int dy = GetClientRect().GetBottom() - ext.GetHeight(); int dx = m_axisBounds.GetLeft(); for (int i = 0; i < m_chartCollection->GetCount(); i++) { ChartValueList *list = m_chartCollection->Item(i)->GetData(); dc.SetPen(wxPen(list->GetColour(), 5)); // draw legend with latest value wxString label = list->GetTitle(); if (list->GetCount() > 0) { // get the latest value double value = *list->GetLast()->GetData()/m_valueAxisScale; label += " (" + wxString::Format(m_valueAxisFormat, value) + ")"; } ext = dc.GetTextExtent(label); dc.DrawLine(dx, dy, dx + LEGEND_LENGTH, dy); dx += LEGEND_LENGTH + 5; dc.DrawText(label, dx, dy - ext.GetHeight()/2); dx += ext.GetWidth() + 20; } }
void TimeLogChart::DrawTitle(wxPaintDC &dc) { wxRect titleRect = GetClientRect(); titleRect.SetHeight(m_axisBounds.GetTop()); titleRect.Deflate(m_axisBounds.GetLeft(), 5); dc.SetFont(*m_titleFont); dc.DrawText(m_title, titleRect.GetTopLeft()); }
static int DrawText(wxPaintDC& arDC, const wxString& arString, int aStartPosition, wxFont& arFont) { int Width = 0; int Height = 0; if (arString.Length() > 0) { arDC.SetFont(arFont); arDC.GetTextExtent(arString, &Width, &Height); arDC.DrawText(arString, aStartPosition, 0); } return aStartPosition+Width; }
void SudokuSolverFrame::DrawBoardNumbers(wxPaintDC &dc) { unsigned int spSq = 0; unsigned int smallSide; unsigned int i,j,k, pVal; wxString debugString; wxString pString; wxColour redC, greenC, blackC; redC.Set(200,0,0); greenC.Set(0,200,0); blackC.Set(0,0,0); wxSize sz = GameBoardPanel->GetClientSize(); if (sz.x < sz.y) smallSide = sz.x; else smallSide = sz.y; spSq = smallSide / 9; smallSide -= 10; // Create a 16 point, serif font, that is not bold, // not italic, and not underlined. dc.SetPen(*wxBLACK_PEN ); wxFont BigFont(spSq/2,wxFONTFAMILY_ROMAN,wxNORMAL,wxNORMAL,false); wxFont SmallFont(spSq/8,wxFONTFAMILY_ROMAN,wxNORMAL,wxNORMAL,false); // Tell dc to use this font dc.SetFont(BigFont); for(i=0;i < 9;i++) { for(j=0;j<9;j++) { if (mGuessGB->GetVal(i, j) != 0) // Show if there's a value { dc.SetFont(BigFont); debugString.clear(); debugString << _("i = ") << i << _(" j = ") << j; debugString << _("\nVal = ") << mGuessGB->GetVal(i, j); //wxMessageBox(debugString); pVal = 0; pVal = mGuessGB->GetVal(i, j); if(mGuessGB->GetShown(i, j)) dc.SetTextForeground(blackC); else if(mGuessGB->GetVal(i, j) == mMainGB->GetVal(i, j)) dc.SetTextForeground(greenC); else dc.SetTextForeground(redC); pString.clear(); pString << pVal; dc.DrawText(pString, 6 * spSq / 20 + ((j) * spSq), spSq / 6 + ((i) * spSq)); } else // Draw all possibles { for(k=1;k<=9;k++) { dc.SetFont(SmallFont); pString.clear(); pString << k; if(mGuessGB->GetPossibles(i, j, k)) switch (k) { case 1: dc.DrawText(pString, spSq*j + spSq/12, spSq*i + spSq/12); break; case 2: dc.DrawText(pString, spSq*j + spSq*5/12, spSq*i + spSq/12); break; case 3: dc.DrawText(pString, spSq*j + spSq*9/12, spSq*i + spSq/12); break; case 4: dc.DrawText(pString, spSq*j + spSq/12, spSq*i + spSq*9/24); break; case 5: dc.DrawText(pString, spSq*j + spSq*5/12, spSq*i + spSq*9/24); break; case 6: dc.DrawText(pString, spSq*j + spSq*9/12, spSq*i + spSq*9/24); break; case 7: dc.DrawText(pString, spSq*j + spSq*1/12, spSq*i + spSq*8/12); break; case 8: dc.DrawText(pString, spSq*j + spSq*5/12, spSq*i + spSq*8/12); break; case 9: dc.DrawText(pString, spSq*j + spSq*9/12, spSq*i + spSq*8/12); break; default: break; } } } } } }