KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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/aui/auibook.h>
23#include <wx/bitmap.h>
24#include <wx/dc.h>
25#include <wx/settings.h>
26
27#include <kiplatform/ui.h>
28#include <pgm_base.h>
32
33#if wxCHECK_VERSION( 3, 3, 0 )
34wxSize WX_AUI_TOOLBAR_ART::GetToolSize( wxReadOnlyDC& aDc, wxWindow* aWindow,
35 const wxAuiToolBarItem& aItem )
36#else
37wxSize WX_AUI_TOOLBAR_ART::GetToolSize( wxDC& aDc, wxWindow* aWindow,
38 const wxAuiToolBarItem& aItem )
39#endif
40{
41 // Based on the upstream wxWidgets implementation, but simplified for our application
43
44#ifdef __WXMSW__
46#endif
47
48 int width = size;
49 int height = size;
50
51 if( m_flags & wxAUI_TB_TEXT )
52 {
53 aDc.SetFont( m_font );
54 int tx, ty;
55
56 if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
57 {
58 aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &ty );
59 height += ty;
60
61 if( !aItem.GetLabel().empty() )
62 {
63 aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
64 width = wxMax( width, tx + aWindow->FromDIP( 6 ) );
65 }
66 }
67 else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT && !aItem.GetLabel().empty() )
68 {
69 width += aWindow->FromDIP( 3 ); // space between left border and bitmap
70 width += aWindow->FromDIP( 3 ); // space between bitmap and text
71
72 if( !aItem.GetLabel().empty() )
73 {
74 aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
75 width += tx;
76 height = wxMax( height, ty );
77 }
78 }
79 }
80
81 if( aItem.HasDropDown() )
82 {
83 int dropdownWidth = GetElementSize( wxAUI_TBART_DROPDOWN_SIZE );
84 width += dropdownWidth + aWindow->FromDIP( 4 );
85 }
86
87 return wxSize( width, height );
88}
89
90
91void WX_AUI_TOOLBAR_ART::DrawButton( wxDC& aDc, wxWindow* aWindow, const wxAuiToolBarItem& aItem,
92 const wxRect& aRect )
93{
94 // Taken from upstream implementation; modified to respect tool size
95 wxSize bmpSize = GetToolSize( aDc, aWindow, aItem );
96
97 int textWidth = 0, textHeight = 0;
98
99 if( m_flags & wxAUI_TB_TEXT )
100 {
101 aDc.SetFont( m_font );
102
103 int tx, ty;
104
105 aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &textHeight );
106 textWidth = 0;
107 aDc.GetTextExtent( aItem.GetLabel(), &textWidth, &ty );
108 }
109
110 int bmpX = 0, bmpY = 0;
111 int textX = 0, textY = 0;
112
113 double scale = KIPLATFORM::UI::GetPixelScaleFactor( aWindow );
114 const wxBitmapBundle& bundle = ( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
115 ? aItem.GetDisabledBitmapBundle()
116 : aItem.GetBitmapBundle();
117 wxBitmap bmp = bundle.GetBitmap( bmpSize * scale );
118
119 // wxBitmapBundle::GetBitmap thinks we need this rescaled to match the base size, which we don't
120 if( bmp.IsOk() )
121 bmp.SetScaleFactor( scale );
122
123 if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
124 {
125 bmpX = aRect.x + ( aRect.width / 2 ) - ( bmpSize.x / 2 );
126
127 bmpY = aRect.y + ( ( aRect.height - textHeight ) / 2 ) - ( bmpSize.y / 2 );
128
129 textX = aRect.x + ( aRect.width / 2 ) - ( textWidth / 2 ) + 1;
130 textY = aRect.y + aRect.height - textHeight - 1;
131 }
132 else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
133 {
134 bmpX = aRect.x + aWindow->FromDIP( 3 );
135
136 bmpY = aRect.y + ( aRect.height / 2 ) - ( bmpSize.y / 2 );
137
138 textX = bmpX + aWindow->FromDIP( 3 ) + bmpSize.x;
139 textY = aRect.y + ( aRect.height / 2 ) - ( textHeight / 2 );
140 }
141
142 bool isThemeDark = KIPLATFORM::UI::IsDarkTheme();
143
144 if( !( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED ) )
145 {
146 if( aItem.GetState() & wxAUI_BUTTON_STATE_PRESSED )
147 {
148 aDc.SetPen( wxPen( m_highlightColour ) );
149 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 20 : 150 ) ) );
150 aDc.DrawRectangle( aRect );
151 }
152 else if( ( aItem.GetState() & wxAUI_BUTTON_STATE_HOVER ) || aItem.IsSticky() )
153 {
154 aDc.SetPen( wxPen( m_highlightColour ) );
155 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
156
157 // draw an even lighter background for checked item hovers (since
158 // the hover background is the same color as the check background)
159 if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
160 aDc.SetBrush(
161 wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 50 : 180 ) ) );
162
163 aDc.DrawRectangle( aRect );
164 }
165 else if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
166 {
167 // it's important to put this code in an else statement after the
168 // hover, otherwise hovers won't draw properly for checked items
169 aDc.SetPen( wxPen( m_highlightColour ) );
170 aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
171 aDc.DrawRectangle( aRect );
172 }
173 }
174
175 if( bmp.IsOk() )
176 aDc.DrawBitmap( bmp, bmpX, bmpY, true );
177
178 // set the item's text color based on if it is disabled
179 aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
180
181 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
182 {
183 aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
184 }
185
186 if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
187 {
188 aDc.DrawText( aItem.GetLabel(), textX, textY );
189 }
190}
191
192
194 wxAuiDefaultDockArt()
195{
196#if defined( _WIN32 )
197 // Use normal control font, wx likes to use "small"
198 m_captionFont = *wxNORMAL_FONT;
199
200 // Increase the box the caption rests in size a bit
201 m_captionSize = ( wxNORMAL_FONT->GetPointSize() * 7 ) / 4 + 6;
202#endif
203
204 SetColour( wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR,
205 wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
206 SetColour( wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
207 wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
208
209 // Turn off the ridiculous looking gradient
210 m_gradientType = wxAUI_GRADIENT_NONE;
211}
212
213
214void WX_AUI_TAB_ART::DrawTab( wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect,
215 int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect,
216 int* x_extent )
217{
218 PANEL_NOTEBOOK_BASE* panel = dynamic_cast<PANEL_NOTEBOOK_BASE*>( page.window );
219
220 if( panel && !panel->GetClosable() )
221 close_button_state = wxAUI_BUTTON_STATE_HIDDEN;
222
223 return wxAuiGenericTabArt::DrawTab( dc, wnd, page, in_rect, close_button_state, out_tab_rect,
224 out_button_rect, x_extent );
225}
APPEARANCE m_Appearance
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:537
void DrawTab(wxDC &dc, wxWindow *wnd, const wxAuiNotebookPage &page, const wxRect &in_rect, int close_button_state, wxRect *out_tab_rect, wxRect *out_button_rect, int *x_extent) override
wxSize GetToolSize(wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem) override
void DrawButton(wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
Unfortunately we need to re-implement this to actually be able to control the size.
double GetPixelScaleFactor(const wxWindow *aWindow)
Tries to determine the pixel scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:244
double GetContentScaleFactor(const wxWindow *aWindow)
Tries to determine the content scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:257
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:48
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE
const int scale