KiCad PCB EDA Suite
wx_aui_art_providers.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <wx/aui/aui.h>
21 #include <wx/aui/framemanager.h>
22 #include <wx/bitmap.h>
23 #include <wx/dc.h>
24 #include <wx/settings.h>
25 
26 #include <kiplatform/ui.h>
28 
29 
30 void WX_AUI_TOOLBAR_ART::DrawButton( wxDC& aDc, wxWindow* aWindow, const wxAuiToolBarItem& aItem,
31  const wxRect& aRect )
32 {
33  bool darkMode = KIPLATFORM::UI::IsDarkTheme();
34  int textWidth = 0;
35  int textHeight = 0;
36 
37  if( m_flags & wxAUI_TB_TEXT )
38  {
39  aDc.SetFont( m_font );
40 
41  int tx, ty;
42 
43  aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &textHeight );
44  textWidth = 0;
45  aDc.GetTextExtent( aItem.GetLabel(), &textWidth, &ty );
46  }
47 
48  int bmpX = 0, bmpY = 0;
49  int textX = 0, textY = 0;
50 
51  if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
52  {
53  bmpX = aRect.x + ( aRect.width / 2 ) - ( aItem.GetBitmap().GetWidth() / 2 );
54 
55  bmpY = aRect.y + ( ( aRect.height - textHeight ) / 2 ) -
56  ( aItem.GetBitmap().GetHeight() / 2 );
57 
58  textX = aRect.x + ( aRect.width / 2 ) - ( textWidth / 2 ) + 1;
59  textY = aRect.y + aRect.height - textHeight - 1;
60  }
61  else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
62  {
63  bmpX = aRect.x + 3;
64 
65  bmpY = aRect.y + ( aRect.height / 2 ) - ( aItem.GetBitmap().GetHeight() / 2 );
66 
67  textX = bmpX + 3 + aItem.GetBitmap().GetWidth();
68  textY = aRect.y + ( aRect.height / 2 ) - ( textHeight / 2 );
69  }
70 
71  if( !( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED ) )
72  {
73  if( aItem.GetState() & wxAUI_BUTTON_STATE_PRESSED )
74  {
75  aDc.SetPen( wxPen( m_highlightColour ) );
76  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 20 : 150 ) ) );
77  aDc.DrawRectangle( aRect );
78  }
79  else if( ( aItem.GetState() & wxAUI_BUTTON_STATE_HOVER ) || aItem.IsSticky() )
80  {
81  aDc.SetPen( wxPen( m_highlightColour ) );
82  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 40 : 170 ) ) );
83 
84  // draw an even lighter background for checked aItem hovers (since
85  // the hover background is the same color as the check background)
86  if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
87  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 50 : 180 ) ) );
88 
89  aDc.DrawRectangle( aRect );
90  }
91  else if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
92  {
93  // it's important to put this code in an else statement after the
94  // hover, otherwise hovers won't draw properly for checked aItems
95  aDc.SetPen( wxPen( m_highlightColour ) );
96  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 40 : 170 ) ) );
97  aDc.DrawRectangle( aRect );
98  }
99  }
100 
101  wxBitmap bmp;
102 
103  if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
104  bmp = aItem.GetDisabledBitmap();
105  else
106  bmp = aItem.GetBitmap();
107 
108  if( bmp.IsOk() )
109  aDc.DrawBitmap( bmp, bmpX, bmpY, true );
110 
111  // set the aItem's text color based on if it is disabled
112  aDc.SetTextForeground( *wxBLACK );
113 
114  if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
115  aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
116 
117  if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
118  {
119  aDc.DrawText( aItem.GetLabel(), textX, textY );
120  }
121 }
122 
123 
124 WX_AUI_DOCK_ART::WX_AUI_DOCK_ART() : wxAuiDefaultDockArt()
125 {
126 #if defined( _WIN32 )
127  #if wxCHECK_VERSION( 3, 1, 0 )
128  // Use normal control font, wx likes to use "small"
129  m_captionFont = *wxNORMAL_FONT;
130 
131  // Increase the box the caption rests in size a bit
132  m_captionSize = wxWindow::FromDIP( 20, nullptr );
133 #endif
134 #endif
135 
136  SetColour( wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR,
137  wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
138  SetColour( wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
139  wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
140 
141  // Turn off the ridiculous looking gradient
142  m_gradientType = wxAUI_GRADIENT_NONE;
143 }
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
void DrawButton(wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
The same as wxAuiDefaultToolBarArt::DrawButton except with dark-mode awareness based on BITMAP_BUTTON...