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