void wxStdRenderer::DrawCheckOrRadioButton(wxDC& dc, const wxString& label, const wxBitmap& bitmap, const wxRect& rect, int flags, wxAlignment align, int indexAccel) { // calculate the position of the bitmap and of the label wxCoord heightBmp = bitmap.GetHeight(); wxCoord xBmp, yBmp = rect.y + (rect.height - heightBmp) / 2; wxRect rectLabel; dc.GetMultiLineTextExtent(label, NULL, &rectLabel.height); rectLabel.y = rect.y + (rect.height - rectLabel.height) / 2; // align label vertically with the bitmap - looks nicer like this rectLabel.y -= (rectLabel.height - heightBmp) % 2; // calc horz position if ( align == wxALIGN_RIGHT ) { xBmp = rect.GetRight() - bitmap.GetWidth(); rectLabel.x = rect.x + 3; rectLabel.SetRight(xBmp); } else // normal (checkbox to the left of the text) case { xBmp = rect.x; rectLabel.x = xBmp + bitmap.GetWidth() + 5; rectLabel.SetRight(rect.GetRight()); } dc.DrawBitmap(bitmap, xBmp, yBmp, true /* use mask */); DrawLabel(dc, label, rectLabel, flags, wxALIGN_LEFT | wxALIGN_TOP, indexAccel); }
/// Draw the item bool InstanceVisual::Draw(wxDC& dc, InstanceCtrl* ctrl, const wxRect& rect, int style) { wxColour backgroundColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); wxColour textColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); wxColour highlightTextColor = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); wxColour focus_color = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); wxColour focussedSelection = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); wxRect imageRect(rect.x + (rect.width - 32) / 2, rect.y, 32, 32); if (style & wxINST_SELECTED) { wxBrush brush(focus_color); wxPen pen(focus_color); dc.SetBrush(brush); dc.SetPen(pen); } else { wxBrush brush(backgroundColor); wxPen pen(backgroundColor); dc.SetBrush(brush); dc.SetPen(pen); } // Draw the label wxString name = m_inst->GetName(); if (!name.IsEmpty()) { int margin = ctrl->GetItemMargin(); wxRect textRect; textRect.x = rect.x + margin; textRect.y = rect.y + imageRect.height + 2 * margin; textRect.width = rect.width - 2 * margin; dc.SetFont(ctrl->GetFont()); if (style & wxINST_SELECTED) dc.SetTextForeground(highlightTextColor); else dc.SetTextForeground(textColor); dc.SetBackgroundMode(wxTRANSPARENT); int yoffset = 0; wxSize textsize = dc.GetMultiLineTextExtent(name_wrapped); textRect.height = textsize.GetHeight(); if (style & wxINST_SELECTED) { wxRect hiRect; hiRect.x = rect.x + (rect.width - textsize.x) / 2 - margin; hiRect.y = textRect.y - margin; hiRect.SetSize(textsize + wxSize(2 * margin, 2 * margin)); dc.DrawRectangle(hiRect); } dc.DrawLabel(name_wrapped, textRect, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL); } // Draw the icon auto list = InstIconList::Instance(); wxImage icon; if (style & wxINST_SELECTED) icon = list->getHLImageForKey(m_inst->GetIconKey()); else icon = list->getImageForKey(m_inst->GetIconKey()); wxBitmap bmap = wxBitmap(icon); int x = imageRect.x + (imageRect.width - bmap.GetWidth()) / 2; int y = imageRect.y + (imageRect.height - bmap.GetHeight()) / 2; dc.DrawBitmap(bmap , x, y, true); return true; }