/* * Here we do the actual rendering. I put it in a separate * method so that it can work no matter what type of DC * (e.g. wxPaintDC or wxClientDC) is used. */ void BasicDrawPane::Render(wxDC& dc) { int width, height; this->GetSize(&width, &height); if ( m_bgColor.IsOk() ) { dc.SetBrush(wxBrush(m_bgColor)); dc.DrawRectangle(0, 0, width, height); } if ( m_textForeGround.IsOk() ) { dc.SetTextForeground( m_textForeGround ); } if ( !m_text.IsEmpty() ) { dc.SetBackgroundMode(wxTRANSPARENT); dc.SetFont( m_font ); /* * ちょうど中央表示できるよう調整 */ const int cHeight = dc.GetCharHeight(); const int cWidth = dc.GetCharWidth(); const int textLen = m_text.Len(); const int textHalfSize = textLen * cWidth / 2; dc.DrawText( m_text, width / 2 - textHalfSize, height / 2 - cHeight / 2 ); } }
void wxStaticBox::PaintForeground(wxDC& dc, const RECT& WXUNUSED(rc)) { MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(dc), 0); // when using XP themes, neither setting the text colour nor transparent // background mode doesn't change anything: the static box def window proc // still draws the label in its own colours, so we need to redraw the text // ourselves if we have a non default fg colour if ( m_hasFgCol && wxUxThemeEngine::GetIfActive() ) { // draw over the text in default colour in our colour dc.SetFont(GetFont()); HDC hdc = GetHdcOf(dc); ::SetTextColor(hdc, GetForegroundColour().GetPixel()); // FIXME: value of x is hardcoded as this is what it is on my system, // no idea if it's true everywhere const int y = dc.GetCharHeight(); const int x = 9; // TODO: RTL? RECT rc = { x, 0, GetSize().x - x, y }; const wxString label = GetLabel(); ::DrawText(hdc, label, label.length(), &rc, DT_SINGLELINE | DT_VCENTER); } }
void ODIconCombo::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { int offset_x = bmpArray.Item(item).GetWidth(); int bmpHeight = bmpArray.Item(item).GetHeight(); dc.DrawBitmap(bmpArray.Item(item), rect.x, rect.y + (rect.height - bmpHeight)/2, true); if ( flags & wxODCB_PAINTING_CONTROL ) { wxString text = GetValue(); int margin_x = 2; #if wxCHECK_VERSION(2, 9, 0) if ( ShouldUseHintText() ) { text = GetHint(); wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); dc.SetTextForeground(col); } margin_x = GetMargins().x; #endif dc.DrawText( text, rect.x + margin_x + offset_x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } else { dc.DrawText( GetVListBoxComboPopup()->GetString(item), rect.x + 2 + offset_x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } }
int wxGridCellAutoWrapStringRenderer::GetBestWidth(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col, int height) { const int lineHeight = dc.GetCharHeight(); // Maximal number of lines that fully fit but at least 1. const size_t maxLines = height - AUTOWRAP_Y_MARGIN < lineHeight ? 1 : (height - AUTOWRAP_Y_MARGIN)/lineHeight; // Increase width until all the text fits. // // TODO: this is not the most efficient to do it for the long strings. const int charWidth = dc.GetCharWidth(); int width = 2*charWidth; while ( GetTextLines(grid, dc, attr, wxSize(width, height), row, col).size() > maxLines ) width += charWidth; return width; }
void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { if ( flags & wxODCB_PAINTING_CONTROL ) { wxString text; if ( !ShouldUseHintText() ) { text = GetValue(); } else { text = GetHint(); wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); dc.SetTextForeground(col); } dc.DrawText( text, rect.x + GetMargins().x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } else { dc.DrawText( GetVListBoxComboPopup()->GetString(item), rect.x + 2, rect.y ); } }
virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { if ( item == wxNOT_FOUND ) return; wxRect r(rect); r.Deflate(3); r.height -= 2; wxPenStyle penStyle = wxPENSTYLE_SOLID; if ( item == 1 ) penStyle = wxPENSTYLE_TRANSPARENT; else if ( item == 2 ) penStyle = wxPENSTYLE_DOT; else if ( item == 3 ) penStyle = wxPENSTYLE_LONG_DASH; else if ( item == 4 ) penStyle = wxPENSTYLE_SHORT_DASH; else if ( item == 5 ) penStyle = wxPENSTYLE_DOT_DASH; else if ( item == 6 ) penStyle = wxPENSTYLE_BDIAGONAL_HATCH; else if ( item == 7 ) penStyle = wxPENSTYLE_CROSSDIAG_HATCH; else if ( item == 8 ) penStyle = wxPENSTYLE_FDIAGONAL_HATCH; else if ( item == 9 ) penStyle = wxPENSTYLE_CROSS_HATCH; else if ( item == 10 ) penStyle = wxPENSTYLE_HORIZONTAL_HATCH; else if ( item == 11 ) penStyle = wxPENSTYLE_VERTICAL_HATCH; wxPen pen( dc.GetTextForeground(), 3, penStyle ); // Get text colour as pen colour dc.SetPen( pen ); if ( !(flags & wxODCB_PAINTING_CONTROL) ) { dc.DrawText(GetString( item ), r.x + 3, (r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2 ); dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) ); } else { dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 ); } }
void PenStyleComboBox::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { if ( item == wxNOT_FOUND ) return; wxRect r(rect); r.Deflate(3); r.height -= 2; int penStyle = wxSOLID; // if ( item == 1 ) // penStyle = wxTRANSPARENT; // else if ( item == 2 ) // penStyle = wxDOT; // else if ( item == 3 ) // penStyle = wxLONG_DASH; // else if ( item == 4 ) // penStyle = wxSHORT_DASH; if ( item == 0 ) penStyle = wxDOT_DASH; else if ( item == 1 ) penStyle = wxBDIAGONAL_HATCH; else if ( item == 2 ) penStyle = wxCROSSDIAG_HATCH; // else if ( item == 8 ) // penStyle = wxFDIAGONAL_HATCH; // else if ( item == 9 ) // penStyle = wxCROSS_HATCH; // else if ( item == 10 ) // penStyle = wxHORIZONTAL_HATCH; // else if ( item == 11 ) // penStyle = wxVERTICAL_HATCH; wxPen pen( dc.GetTextForeground(), 3, penStyle ); // Get text colour as pen colour dc.SetPen( pen ); if ( !(flags & wxODCB_PAINTING_CONTROL) ) { dc.DrawText(GetString( item ), r.x + 3, (r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2 ); dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) ); } else { dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 ); } }
static void AdjustFontSize(wxFont& font, wxDC& dc, const wxSize& pixelSize) { int currentSize = 0; int largestGood = 0; int smallestBad = 0; bool initialGoodFound = false; bool initialBadFound = false; // NB: this assignment was separated from the variable definition // in order to fix a gcc v3.3.3 compiler crash currentSize = font.GetPointSize(); while (currentSize > 0) { dc.SetFont(font); // if currentSize (in points) results in a font that is smaller // than required by pixelSize it is considered a good size if (dc.GetCharHeight() <= pixelSize.GetHeight() && (!pixelSize.GetWidth() || dc.GetCharWidth() <= pixelSize.GetWidth())) { largestGood = currentSize; initialGoodFound = true; } else { smallestBad = currentSize; initialBadFound = true; } if (!initialGoodFound) { currentSize /= 2; } else if (!initialBadFound) { currentSize *= 2; } else { int distance = smallestBad - largestGood; if (distance == 1) break; currentSize = largestGood + distance / 2; } font.SetPointSize(currentSize); } if (currentSize != largestGood) font.SetPointSize(largestGood); }
void StateEvaluationTreePanel::render(wxDC &dc) { if (Settings.m_ColourScheme == nullptr) return; PrepareDC(dc); auto const &Scheme = *(Settings.m_ColourScheme); dc.SetBackground(wxBrush{Scheme.getDefault().GetBackground()}); dc.Clear(); if (Statement.empty()) return; auto const ActiveStmt = ActiveFn->getActiveStmt(); if (!ActiveStmt) return; dc.SetFont(CodeFont); // Draw the sub-Stmts' nodes. for (auto const &Node : Nodes) { // Don't draw hovered nodes, they will be drawn later. if (&*HoverNodeIt == &Node || &*ReplayHoverNodeIt == &Node) continue; auto const DoHighlight = (HighlightedStmt && Node.Statement == HighlightedStmt) || (HighlightedValue && Node.Value.get() == HighlightedValue); if (DoHighlight) drawNode(dc, Scheme, Node, NodeDecoration::Highlighted); else if (Node.Statement == ActiveStmt) drawNode(dc, Scheme, Node, NodeDecoration::Active); else drawNode(dc, Scheme, Node, NodeDecoration::None); } // Redraw the hovered nodes, so that they outrank active node highlighting. if (HoverNodeIt != Nodes.end()) drawNode(dc, Scheme, *HoverNodeIt, NodeDecoration::Highlighted); if (ReplayHoverNodeIt != Nodes.end()) drawNode(dc, Scheme, *ReplayHoverNodeIt, NodeDecoration::Highlighted); // Draw the pretty-printed Stmt's string. dc.SetTextForeground(Scheme.getDefault().GetForeground()); wxCoord const PageBorderH = dc.GetCharWidth() * Settings.PageBorderHorizontal; wxCoord const PageBorderV = dc.GetCharHeight() * Settings.PageBorderVertical; dc.DrawText(Statement, PageBorderH, PageBorderV); }
int wxGridCellAutoWrapStringRenderer::GetBestHeight(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col, int width) { const int lineHeight = dc.GetCharHeight(); // Use as many lines as we need for this width and add a small border to // improve the appearance. return GetTextLines(grid, dc, attr, wxSize(width, lineHeight), row, col).size() * lineHeight + AUTOWRAP_Y_MARGIN; }
wxSize wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) { // We have to make a choice here and fix either width or height because we // don't have any naturally best size. This choice is mostly arbitrary, but // we need to be consistent about it, otherwise wxGrid auto-sizing code // would get confused. For now we decide to use a single line of text and // compute the width needed to fully display everything. const int height = dc.GetCharHeight(); return wxSize(GetBestWidth(grid, attr, dc, row, col, height), height); }
void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { if ( flags & wxODCB_PAINTING_CONTROL ) { dc.DrawText( GetValue(), rect.x + GetTextIndent(), (rect.height-dc.GetCharHeight())/2 + rect.y ); } else { dc.DrawText( GetVListBoxComboPopup()->GetString(item), rect.x + 2, rect.y ); } }
void wxBitmapComboBox::OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const { wxString text; int imgAreaWidth = m_imgAreaWidth; bool drawText; if ( imgAreaWidth == 0 ) { wxOwnerDrawnComboBox::OnDrawItem(dc, rect, item, flags); return; } if ( flags & wxODCB_PAINTING_CONTROL ) { text = GetValue(); if ( HasFlag(wxCB_READONLY) ) drawText = true; else drawText = false; } else { text = GetString(item); drawText = true; } const wxBitmap& bmp = *GetBitmapPtr(item); if ( bmp.Ok() ) { wxCoord w = bmp.GetWidth(); wxCoord h = bmp.GetHeight(); // Draw the image centered dc.DrawBitmap(bmp, rect.x + (m_usedImgSize.x-w)/2 + IMAGE_SPACING_LEFT, rect.y + (rect.height-h)/2, true); } if ( drawText ) dc.DrawText(GetString(item), rect.x + imgAreaWidth + 1, rect.y + (rect.height-dc.GetCharHeight())/2); }
wxSize DropDown::DrawText(void * ItemData, wxDC& dc, wxRect& TextRect, INT32 item, INT32 flags, BOOL Draw) { if (Draw) { if ( (m_pPopup->wxVListBox::GetSelection() == (INT32)item) && !(flags & wxODCB_PAINTING_CONTROL) ) dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); else dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); } wxString Text = GetText(ItemData, item); wxCoord w, h; dc.GetTextExtent(Text, &w, &h); wxSize size(w,dc.GetCharHeight()); if (Draw) dc.DrawText( Text, TextRect.x, TextRect.y ); return size; }
void wxBitmapComboBoxBase::DrawItem(wxDC& dc, const wxRect& rect, int item, const wxString& text, int WXUNUSED(flags)) const { const wxBitmap& bmp = *GetBitmapPtr(item); if ( bmp.IsOk() ) { wxCoord w = bmp.GetWidth(); wxCoord h = bmp.GetHeight(); // Draw the image centered dc.DrawBitmap(bmp, rect.x + (m_usedImgSize.x-w)/2 + IMAGE_SPACING_LEFT, rect.y + (rect.height-h)/2, true); } if ( text.length() ) dc.DrawText(text, rect.x + m_imgAreaWidth + 1, rect.y + (rect.height-dc.GetCharHeight())/2); }
void StateEvaluationTreePanel::drawNode(wxDC &DC, ColourScheme const &Scheme, NodeInfo const &Node, NodeDecoration const Decoration) { auto const CharWidth = DC.GetCharWidth(); auto const CharHeight = DC.GetCharHeight(); wxCoord const PageBorderV = CharHeight * Settings.PageBorderVertical; // Determine the indicator (if any). IndicatorStyle const *Indicator = nullptr; switch (Decoration) { case NodeDecoration::None: break; case NodeDecoration::Active: Indicator = &(Scheme.getActiveCode()); break; case NodeDecoration::Highlighted: Indicator = &(Scheme.getHighlightCode()); break; } // Set the background colour. DC.SetPen(wxPen{Scheme.getDefault().GetForeground(), Settings.PenWidth}); DC.SetBrush(wxBrush{Scheme.getDefault().GetBackground()}); DC.SetTextForeground(Scheme.getDefault().GetForeground()); // Also highlight this node's area in the pretty-printed Stmt. if (Indicator) { drawIndicatorAtArea(DC, *Indicator, Node.XStart, PageBorderV, Node.XEnd - Node.XStart, CharHeight); } // Draw the background. wxPen const PrevPen = DC.GetPen(); DC.SetPen(wxPen{DC.GetBrush().GetColour()}); DC.DrawRectangle(Node.XStart, Node.YStart, Node.XEnd - Node.XStart, Node.YEnd - Node.YStart); DC.SetPen(PrevPen); // Draw the line over the node. DC.DrawLine(Node.XStart, Node.YStart, Node.XEnd + 1, Node.YStart); // Draw the base indicator on the node (if any). if (Indicator) { drawIndicatorAtArea(DC, *Indicator, Node.XStart, Node.YStart, Node.XEnd - Node.XStart, Node.YEnd - Node.YStart); } // Draw the error indicator if the node has an error. if (Node.Error == NodeError::Error) { drawIndicatorAtArea(DC, Scheme.getErrorCode(), Node.XStart, Node.YStart, Node.XEnd - Node.XStart, Node.YEnd - Node.YStart); } // Draw the node's value string. if (Node.Value) { auto const ValText = Node.ValueStringShort; auto const TextWidth = CharWidth * ValText.size(); auto const NodeWidth = CharWidth * Node.RangeLength; auto const Offset = (NodeWidth - TextWidth) / 2; DC.DrawText(ValText, Node.XStart + Offset, Node.YStart); } }
void ChipPackage::DrawPins(wxDC& dc, const wxPoint& pt, unsigned int PackageLen, unsigned int FirstPin, unsigned int LastPin, int flags, wxDirection dir) { wxASSERT_MSG(LastPin>FirstPin, "invalid pin indexes"); // NOTE: inside this function context // pin number == the index of the pin (e.g. "1", "2", etc) // pin name == pin label == the name of the pin signal (e.g. "VCC", "GND" etc) // pin == pin rectangle // some drawing constants: const unsigned int PinCount = LastPin - FirstPin; // pin height is calculated imposing that // 1) PinCount*PinH + (PinCount+1)*PinSpacing = PackageLen // 2) PinSpacing = PinH/2 // solving for PinH yields: unsigned int PinH = (unsigned int)floor(2*PackageLen/(3.0*PinCount+1)); unsigned int PinW = (unsigned int)1.5*PinH; const unsigned int PinSpacing = (const unsigned int)floor(PinH/2.0); // the error which force us to have a "pin y offset" is caused by rounding // in the calculation of PinH: const int PinOffset = (PackageLen - (PinCount*PinH + (PinCount+1)*PinSpacing))/2; wxASSERT(PinOffset>=0); if (int(PinH*0.8) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor // select a font suitable for the PinH we have computed above: int fSize = int(PinH*0.8); if(fSize>12)fSize=12; wxFont fnt(wxSize(0,fSize), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); dc.SetFont(fnt); const unsigned int PinNumberW = 2*dc.GetCharWidth(); const unsigned int PinNumberH = dc.GetCharHeight(); bool invertOrder = (flags & DRAWPIN_INVERTED_ORDER) != 0; unsigned int start = invertOrder ? LastPin-1 : FirstPin; unsigned int end = invertOrder ? FirstPin-1 : LastPin; int inc = invertOrder ? -1 : +1; if (dir == wxLEFT || dir == wxRIGHT) { unsigned int PinX = (dir == wxLEFT) ? pt.x-PinW+1 : pt.x-1; unsigned int PinY = pt.y + PinOffset + PinSpacing; unsigned int PinNumberX = (dir == wxLEFT) ? pt.x+PinSpacing : pt.x-PinNumberW-PinSpacing; if (flags & DRAWPIN_NUMBERS_INSIDE_PINS) PinNumberX = PinX + (PinW-PinNumberW)/2; // draw the pins organizing them in a vertical column for (unsigned int i=start; i != end; i+=inc) { unsigned int PinNumberY = PinY + (PinH-PinNumberH)/2; unsigned int pinLabelX = (dir == wxLEFT) ? PinX-PinSpacing-dc.GetTextExtent(PinNames[i]).GetWidth() : PinX+PinW+PinSpacing; unsigned int pinLabelY = PinNumberY; // draw the pin rect dc.DrawRectangle(PinX, PinY, PinW, PinH); // print the pin number dc.SetTextForeground(IsICSPPin(i) ? *wxRED : *wxBLACK); dc.DrawText(wxString::Format(("%d"), i+1), PinNumberX, PinNumberY); // print the pin name dc.DrawText(PinNames[i], pinLabelX, pinLabelY); PinY += PinH+PinSpacing; } } else if (dir == wxTOP || dir == wxBOTTOM) { SWAP(PinH, PinW, unsigned int); // in this case the PackageLen is the number of horizontal pixels available // for drawing the pin strip; thus we want to compute PinW and set PinH // VERY IMPORTANT: the code below is the dual of the code for wxLEFT|wxRIGHT case! // If you change something here, you may want to change it also // above, with the appropriate differences // NOTE: remember however that the text is drawn rotated by 90 degrees unsigned int PinX = pt.x + PinOffset + PinSpacing; unsigned int PinY = (dir == wxTOP) ? pt.y-PinH+1 : pt.y-1; unsigned int PinNumberY = (dir == wxTOP) ? pt.y+PinSpacing : pt.y-PinNumberH-PinSpacing; if (flags & DRAWPIN_NUMBERS_INSIDE_PINS) PinNumberY = PinY + (PinH-PinNumberW)/2; // draw the pins organizing them in a horizontal column for (unsigned int i=start; i != end; i+=inc) { unsigned int PinNumberX = PinX + PinNumberH + (PinW-PinNumberH)/2; unsigned int pinLabelX = PinNumberX; unsigned int pinLabelY = (dir == wxTOP) ? PinY-PinSpacing-dc.GetTextExtent(PinNames[i]).GetWidth() : PinY+PinH+PinSpacing; // draw the pin rect dc.DrawRectangle(PinX, PinY, PinW, PinH); // print the pin number dc.SetTextForeground(IsICSPPin(i) ? *wxRED : *wxBLACK); dc.DrawRotatedText(wxString::Format(("%d"), i+1), PinNumberX, PinNumberY, -90); // print the pin name dc.DrawRotatedText(PinNames[i], pinLabelX, pinLabelY, -90); PinX += PinW+PinSpacing; } } else wxLogWarning(_("Invalid direction")); }
int SurfaceImpl::Height(Font &font) { SetFont(font); return hdc->GetCharHeight() + 1; }