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