void wxFlatButtonBar::OnPaint(wxPaintEvent& event) { wxBufferedPaintDC dc(this); dc.SetBrush(GetBgColour()); dc.SetPen(GetBgColour()); dc.DrawRectangle(GetClientRect()); }
void wxFlatButton::OnPaint(wxPaintEvent& event) { wxUnusedVar(event); wxAutoBufferedPaintDC paintDC(this); wxGCDC gdc; GetGCDC(paintDC, gdc); wxRect clientRect = GetClientRect(); // Draw the background gdc.SetPen(GetBarBgColour(m_theme)); gdc.SetBrush(GetBarBgColour(m_theme)); gdc.DrawRectangle(clientRect); switch(m_state) { case kStateHover: { if(!IsChecked()) { // Hover gdc.SetBrush(GetBgHoverColour()); gdc.SetPen(m_penHoverOuterColour); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); clientRect.Deflate(1); gdc.SetBrush(*wxTRANSPARENT_BRUSH); gdc.SetPen(m_penHoverColourInner); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); // gdc.SetPen(m_penHoverColourInner); // gdc.DrawLine(clientRect.GetBottomLeft(), clientRect.GetTopLeft()); // gdc.DrawLine(clientRect.GetTopLeft(), clientRect.GetTopRight()); // // gdc.SetPen(m_penHoverOuterColour); // gdc.DrawLine(clientRect.GetTopRight(), clientRect.GetBottomRight()); // gdc.DrawLine(clientRect.GetBottomRight(), clientRect.GetBottomLeft()); } break; } case kStateNormal: { // do nothing gdc.SetBrush(GetBgColour()); gdc.SetPen(GetPenNormalColour()); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); break; } case kStatePressed: { // Pressed gdc.SetBrush(GetBgPressedColour()); gdc.SetPen(GetPenPressedColour()); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); // gdc.SetBrush(GetBgPressedColour()); // gdc.DrawRectangle(clientRect); // // gdc.SetPen(m_penHoverOuterColour); // gdc.DrawLine(clientRect.GetBottomLeft(), clientRect.GetTopLeft()); // gdc.DrawLine(clientRect.GetTopLeft(), clientRect.GetTopRight()); // // gdc.SetPen(m_penHoverColourInner); // gdc.DrawLine(clientRect.GetTopRight(), clientRect.GetBottomRight()); // gdc.DrawLine(clientRect.GetBottomRight(), clientRect.GetBottomLeft()); break; } } // Draw text gdc.SetFont(GetTextFont()); if(!IsEnabled()) { gdc.SetTextForeground(GetTextColourDisabled()); gdc.DrawLabel( m_text, m_bmpDisabled, clientRect, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL, m_accelIndex); } else { gdc.SetTextForeground(GetTextColour()); gdc.DrawLabel(m_text, m_bmp, clientRect, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL, m_accelIndex); } }
void clRowEntry::Render(wxWindow* win, wxDC& dc, const clColours& c, int row_index, clSearchText* searcher) { wxUnusedVar(searcher); wxRect rowRect = GetItemRect(); bool zebraColouring = (m_tree->HasStyle(wxTR_ROW_LINES) || m_tree->HasStyle(wxDV_ROW_LINES)); bool even_row = ((row_index % 2) == 0); // Define the clipping region bool hasHeader = (m_tree->GetHeader() && !m_tree->GetHeader()->empty()); // Not cell related clColours colours = c; if(zebraColouring) { // Set Zebra colouring, only if no user colour was provided for the given line colours.SetItemBgColour(even_row ? c.GetAlternateColour() : c.GetBgColour()); } // Override default item bg colour with the user's one if(GetBgColour().IsOk()) { colours.SetItemBgColour(GetBgColour()); } wxRect selectionRect = rowRect; wxPoint deviceOrigin = dc.GetDeviceOrigin(); selectionRect.SetX(-deviceOrigin.x); if(IsSelected()) { DrawSimpleSelection(win, dc, selectionRect, colours); } else if(IsHovered()) { dc.SetPen(colours.GetHoverBgColour()); dc.SetBrush(colours.GetHoverBgColour()); dc.DrawRectangle(selectionRect); } else if(colours.GetItemBgColour().IsOk()) { dc.SetBrush(colours.GetItemBgColour()); dc.SetPen(colours.GetItemBgColour()); dc.DrawRectangle(selectionRect); } // Per cell drawings for(size_t i = 0; i < m_cells.size(); ++i) { bool last_cell = (i == (m_cells.size() - 1)); colours = c; // reset the colours wxFont f = clScrolledPanel::GetDefaultFont(); clCellValue& cell = GetColumn(i); if(cell.GetFont().IsOk()) { f = cell.GetFont(); } if(cell.GetTextColour().IsOk()) { colours.SetItemTextColour(cell.GetTextColour()); } if(cell.GetBgColour().IsOk()) { colours.SetItemBgColour(cell.GetBgColour()); } dc.SetFont(f); wxColour buttonColour = IsSelected() ? colours.GetSelbuttonColour() : colours.GetButtonColour(); wxRect cellRect = GetCellRect(i); // We use a helper class to clip the drawings this ensures that if we exit the scope // the clipping region is restored properly clClipperHelper clipper(dc); if(hasHeader) { clipper.Clip(cellRect); } int textXOffset = cellRect.GetX(); if((i == 0) && !IsListItem()) { // The expand button is only make sense for the first cell if(HasChildren()) { wxRect buttonRect = GetButtonRect(); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(m_tree->IsNativeTheme() && !IS_OSX) { int flags = wxCONTROL_CURRENT; if(IsExpanded()) { flags |= wxCONTROL_EXPANDED; } int button_width = wxSystemSettings::GetMetric(wxSYS_SMALLICON_X); wxRect modButtonRect = buttonRect; modButtonRect.SetWidth(button_width); modButtonRect.SetHeight(button_width); modButtonRect = modButtonRect.CenterIn(buttonRect); wxRendererNative::Get().DrawTreeItemButton(win, dc, modButtonRect, flags); } else { wxRect buttonRect = GetButtonRect(); if(textXOffset >= cellRect.GetWidth()) { // if we cant draw the button (off screen etc) SetRects(GetItemRect(), wxRect()); continue; } buttonRect.Deflate((buttonRect.GetWidth() / 3), (buttonRect.GetHeight() / 3)); wxRect tribtn = buttonRect; dc.SetPen(wxPen(buttonColour, 2)); if(IsExpanded()) { tribtn.SetHeight(tribtn.GetHeight() - tribtn.GetHeight() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint((tribtn.GetLeft() + tribtn.GetWidth() / 2), tribtn.GetBottom()); dc.DrawLine(tribtn.GetTopLeft(), middleLeft); dc.DrawLine(tribtn.GetTopRight(), middleLeft); } else { tribtn.SetWidth(tribtn.GetWidth() - tribtn.GetWidth() / 2); tribtn = tribtn.CenterIn(buttonRect); wxPoint middleLeft = wxPoint(tribtn.GetRight(), (tribtn.GetY() + (tribtn.GetHeight() / 2))); wxPoint p1 = tribtn.GetTopLeft(); wxPoint p2 = tribtn.GetBottomLeft(); dc.DrawLine(p1, middleLeft); dc.DrawLine(middleLeft, p2); } } } else { wxRect buttonRect(rowRect); buttonRect.SetWidth(rowRect.GetHeight()); buttonRect.Deflate(1); textXOffset += buttonRect.GetWidth(); if(textXOffset >= cellRect.GetWidth()) { SetRects(GetItemRect(), wxRect()); continue; } } } int itemIndent = IsListItem() ? clHeaderItem::X_SPACER : (GetIndentsCount() * m_tree->GetIndent()); int bitmapIndex = cell.GetBitmapIndex(); if(IsExpanded() && HasChildren() && cell.GetBitmapSelectedIndex() != wxNOT_FOUND) { bitmapIndex = cell.GetBitmapSelectedIndex(); } // Draw checkbox if(cell.IsBool()) { // Render the checkbox textXOffset += X_SPACER; int checkboxSize = GetCheckBoxWidth(win); wxRect checkboxRect = wxRect(textXOffset, rowRect.GetY(), checkboxSize, checkboxSize); checkboxRect = checkboxRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(colours.GetItemTextColour()); RenderCheckBox(win, dc, colours, checkboxRect, cell.GetValueBool()); cell.SetCheckboxRect(checkboxRect); textXOffset += checkboxRect.GetWidth(); textXOffset += X_SPACER; } else { cell.SetCheckboxRect(wxRect()); // clear the checkbox rect } // Draw the bitmap if(bitmapIndex != wxNOT_FOUND) { const wxBitmap& bmp = m_tree->GetBitmap(bitmapIndex); if(bmp.IsOk()) { textXOffset += IsListItem() ? 0 : X_SPACER; int bitmapY = rowRect.GetY() + ((rowRect.GetHeight() - bmp.GetScaledHeight()) / 2); // if((textXOffset + bmp.GetScaledWidth()) >= cellRect.GetWidth()) { continue; } dc.DrawBitmap(bmp, itemIndent + textXOffset, bitmapY, true); textXOffset += bmp.GetScaledWidth(); textXOffset += X_SPACER; } } // Draw the text wxRect textRect(dc.GetTextExtent(cell.GetValueString())); textRect = textRect.CenterIn(rowRect, wxVERTICAL); int textY = textRect.GetY(); int textX = (i == 0 ? itemIndent : clHeaderItem::X_SPACER) + textXOffset; RenderText(win, dc, colours, cell.GetValueString(), textX, textY, i); textXOffset += textRect.GetWidth(); textXOffset += X_SPACER; if(cell.IsChoice()) { // draw the drop down arrow. Make it aligned to the right wxRect dropDownRect(cellRect.GetTopRight().x - rowRect.GetHeight(), rowRect.GetY(), rowRect.GetHeight(), rowRect.GetHeight()); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); DrawingUtils::DrawDropDownArrow(win, dc, dropDownRect, wxNullColour); // Keep the rect to test clicks cell.SetDropDownRect(dropDownRect); textXOffset += dropDownRect.GetWidth(); textXOffset += X_SPACER; // Draw a separator line between the drop down arrow and the rest of the cell content dropDownRect.Deflate(3); dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(dropDownRect.GetTopLeft(), dropDownRect.GetBottomLeft()); } else { cell.SetDropDownRect(wxRect()); } if(!last_cell) { cellRect.SetHeight(rowRect.GetHeight()); dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE)); dc.DrawLine(cellRect.GetTopRight(), cellRect.GetBottomRight()); } } }
void wxFlatButton::OnPaint(wxPaintEvent& event) { wxUnusedVar(event); wxAutoBufferedPaintDC paintDC(this); PrepareDC(paintDC); wxGCDC gdc; GetGCDC(paintDC, gdc); wxRect clientRect = GetClientRect(); // Draw the background gdc.SetPen(GetBarBgColour(m_theme)); gdc.SetBrush(GetBarBgColour(m_theme)); gdc.DrawRectangle(clientRect); switch(m_state) { case kStateHover: { // do nothing gdc.SetBrush(GetBgColour()); gdc.SetPen(GetPenNormalColour()); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); break; } case kStateNormal: { break; } case kStatePressed: { // Pressed gdc.SetBrush(GetBgPressedColour()); gdc.SetPen(GetPenPressedColour()); gdc.DrawRoundedRectangle(clientRect, BTN_RADIUS); break; } } // Draw text gdc.SetFont(GetTextFont()); wxColour textColour = IsEnabled() ? GetTextColour() : GetTextColourDisabled(); wxBitmap bmp = IsEnabled() ? m_bmp : m_bmpDisabled; wxCoord textY; wxCoord bmpY; wxCoord totalLen = 0; const int spacer = 2; if(bmp.IsOk()) { // we got a bitmap totalLen += bmp.GetScaledWidth(); } wxSize textSize; if(!m_text.IsEmpty()) { textSize = gdc.GetTextExtent(m_text); totalLen += spacer; totalLen += textSize.x; } wxCoord offset = (clientRect.GetWidth() - totalLen) / 2; bmpY = (clientRect.GetHeight() - bmp.GetScaledHeight()) / 2; textY = (clientRect.GetHeight() - textSize.y) / 2; if(bmp.IsOk()) { gdc.DrawBitmap(bmp, offset, bmpY); offset += bmp.GetScaledWidth(); offset += spacer; } if(!m_text.IsEmpty()) { gdc.DrawText(m_text, offset, textY); offset += textSize.x; offset += spacer; } }