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); } }
wxFlatButton::wxFlatButton(wxWindow* parent, const wxString& label, const wxFlatButton::eTheme theme, const wxBitmap& bmp, const wxSize& size, int style) : wxFlatButtonBase(parent) , m_theme(theme) , m_state(kStateNormal) , m_text(label) , m_bmp(bmp) , m_accelIndex(wxNOT_FOUND) , m_kind(kKindNormal) , m_isChecked(false) , m_contextMenu(NULL) , m_isDisabled(false) , m_style(style) { SetBackgroundStyle(wxBG_STYLE_PAINT); // Parse the label wxString tmpLabel; m_text.Replace("&&", "@@"); // Parse the label for(size_t i = 0; i < m_text.length(); ++i) { if(m_accelIndex == wxNOT_FOUND && m_text.GetChar(i) == '&') { m_accelIndex = i; continue; } else { tmpLabel << m_text.GetChar(i); } } tmpLabel.Replace("@@", "&"); m_text.swap(tmpLabel); // Colours - dark theme if(m_theme == kThemeDark) { SetPenNormalColour("rgb(48, 48, 48)"); SetPenPressedColour("rgb(125, 125, 125)"); SetBgPressedColour("rgb(48, 48, 48)"); SetBgHoverColour("rgb(80, 80, 80)"); SetBgColour("rgb(65, 65, 65)"); m_penHoverColourInner = "rgb(160, 160, 160)"; m_penHoverOuterColour = GetPenNormalColour(); SetTextColour("rgb(248, 248, 242)"); SetTextColourDisabled("rgb(109, 109, 109)"); if(m_bmp.IsOk()) { m_bmpDisabled = m_bmp.ConvertToDisabled(100); } } else { wxColour paneColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColour bgColour = paneColour.ChangeLightness(150); wxColour penColour = paneColour.ChangeLightness(90); SetPenNormalColour(penColour); SetBgColour(bgColour); SetPenPressedColour("rgb(90, 90, 90)"); SetBgPressedColour("rgb(120, 120, 120)"); SetBgHoverColour(bgColour); m_penHoverColourInner = "WHITE"; m_penHoverOuterColour = "TURQUOISE"; SetTextColour("rgb(15, 15, 15)"); SetTextColourDisabled(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); if(m_bmp.IsOk()) { m_bmpDisabled = m_bmp.ConvertToDisabled(); } } SetTextFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); if(size != wxDefaultSize) { SetMinSize(size); } else { SetMinSize(GetBestSize()); } }
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; } }