KiCad PCB EDA Suite
STD_BITMAP_BUTTON Class Reference

A bitmap button widget that behaves like a standard dialog button except with an icon. More...

#include <std_bitmap_button.h>

Inheritance diagram for STD_BITMAP_BUTTON:

Public Member Functions

 STD_BITMAP_BUTTON (wxWindow *aParent, wxWindowID aId, const wxBitmap &aDummyBitmap, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyle=0)
 
 ~STD_BITMAP_BUTTON ()
 
void SetBitmap (const wxBitmap &aBmp)
 
bool Enable (bool aEnable=true) override
 

Protected Member Functions

void OnKillFocus (wxFocusEvent &aEvent)
 
void OnMouseLeave (wxMouseEvent &aEvent)
 
void OnMouseEnter (wxMouseEvent &aEvent)
 
void OnLeftButtonUp (wxMouseEvent &aEvent)
 
void OnLeftButtonDown (wxMouseEvent &aEvent)
 
void OnPaint (wxPaintEvent &WXUNUSED(aEvent))
 
void onThemeChanged (wxSysColourChangedEvent &aEvent)
 

Private Attributes

int m_stateButton = 0
 
bool m_bIsEnable = true
 
wxBitmap m_bitmap
 

Detailed Description

A bitmap button widget that behaves like a standard dialog button except with an icon.

Specifically:

  • It has a border
  • It has no hover/focused state

In wxWidgets 3.2 the native button control is used on Mac for wxBitmapButton with or without text. Said widget has margins that are more than twice what previous versions had. This class allows our bitmap buttons to match the layout of our SPLIT_BUTTON.

Definition at line 44 of file std_bitmap_button.h.

Constructor & Destructor Documentation

◆ STD_BITMAP_BUTTON()

STD_BITMAP_BUTTON::STD_BITMAP_BUTTON ( wxWindow *  aParent,
wxWindowID  aId,
const wxBitmap &  aDummyBitmap,
const wxPoint &  aPos = wxDefaultPosition,
const wxSize &  aSize = wxDefaultSize,
int  aStyle = 0 
)

Definition at line 36 of file std_bitmap_button.cpp.

38 :
39 wxPanel( aParent, aId, aPos, aSize, aStyle, wxS( "StdBitmapButton" ) )
40{
41 if( aSize == wxDefaultSize )
42 {
43 #if wxCHECK_VERSION( 3, 1, 3 )
44 wxSize defaultSize = wxButton::GetDefaultSize( aParent );
45 #else
46 wxSize defaultSize = wxButton::GetDefaultSize();
47 #endif
48
49 SetMinSize( wxSize( defaultSize.GetWidth() + 1, defaultSize.GetHeight() + 1 ) );
50 }
51
52 Bind( wxEVT_PAINT, &STD_BITMAP_BUTTON::OnPaint, this );
53 Bind( wxEVT_LEFT_UP, &STD_BITMAP_BUTTON::OnLeftButtonUp, this );
54 Bind( wxEVT_LEFT_DOWN, &STD_BITMAP_BUTTON::OnLeftButtonDown, this );
55 Bind( wxEVT_KILL_FOCUS, &STD_BITMAP_BUTTON::OnKillFocus, this );
56 Bind( wxEVT_LEAVE_WINDOW, &STD_BITMAP_BUTTON::OnMouseLeave, this );
57 Bind( wxEVT_ENTER_WINDOW, &STD_BITMAP_BUTTON::OnMouseEnter, this );
58
59 Bind( wxEVT_SYS_COLOUR_CHANGED,
60 wxSysColourChangedEventHandler( STD_BITMAP_BUTTON::onThemeChanged ),
61 this );
62}
void OnPaint(wxPaintEvent &WXUNUSED(aEvent))
void OnKillFocus(wxFocusEvent &aEvent)
void OnLeftButtonDown(wxMouseEvent &aEvent)
void OnMouseEnter(wxMouseEvent &aEvent)
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void OnLeftButtonUp(wxMouseEvent &aEvent)
void OnMouseLeave(wxMouseEvent &aEvent)
static const wxSize defaultSize(FRAME_T aFrameType)

References defaultSize(), OnKillFocus(), OnLeftButtonDown(), OnLeftButtonUp(), OnMouseEnter(), OnMouseLeave(), OnPaint(), and onThemeChanged().

◆ ~STD_BITMAP_BUTTON()

STD_BITMAP_BUTTON::~STD_BITMAP_BUTTON ( )

Definition at line 65 of file std_bitmap_button.cpp.

66{
67}

Member Function Documentation

◆ Enable()

bool STD_BITMAP_BUTTON::Enable ( bool  aEnable = true)
override

Definition at line 220 of file std_bitmap_button.cpp.

221{
222 m_bIsEnable = aEnable;
223 wxPanel::Enable( m_bIsEnable );
224
225 if( m_bIsEnable && m_stateButton == wxCONTROL_DISABLED )
226 {
227 m_stateButton = 0;
228 Refresh();
229 }
230
231 if( !m_bIsEnable && m_stateButton != wxCONTROL_DISABLED )
232 {
233 m_stateButton = wxCONTROL_DISABLED;
234 Refresh();
235 }
236
237 return aEnable;
238}
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_bIsEnable, m_stateButton, and Refresh().

Referenced by DIALOG_PAGES_SETTINGS::EnableWksFileNamePicker(), DIALOG_MIGRATE_SETTINGS::OnPrevVerSelected(), DIALOG_NET_INSPECTOR::onSelChanged(), PANEL_FP_PROPERTIES_3D_MODEL::OnUpdateUI(), PANEL_COMMON_SETTINGS::setPdfViewerPathState(), and PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow().

◆ OnKillFocus()

void STD_BITMAP_BUTTON::OnKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 84 of file std_bitmap_button.cpp.

85{
86 if( m_stateButton != 0 )
87 {
88 m_stateButton = 0;
89 Refresh();
90 }
91
92 aEvent.Skip();
93}

References m_stateButton, and Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ OnLeftButtonDown()

void STD_BITMAP_BUTTON::OnLeftButtonDown ( wxMouseEvent &  aEvent)
protected

Definition at line 141 of file std_bitmap_button.cpp.

142{
143 m_stateButton = wxCONTROL_PRESSED;
144 Refresh();
145
146 aEvent.Skip();
147}

References m_stateButton, and Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ OnLeftButtonUp()

void STD_BITMAP_BUTTON::OnLeftButtonUp ( wxMouseEvent &  aEvent)
protected

Definition at line 120 of file std_bitmap_button.cpp.

121{
122 m_stateButton = 0;
123
124 Refresh();
125
126 wxEvtHandler* pEventHandler = GetEventHandler();
127 wxASSERT( pEventHandler );
128
129 pEventHandler->CallAfter(
130 [=]()
131 {
132 wxCommandEvent evt( wxEVT_BUTTON, GetId() );
133 evt.SetEventObject( this );
134 GetEventHandler()->ProcessEvent( evt );
135 } );
136
137 aEvent.Skip();
138}

References m_stateButton, and Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ OnMouseEnter()

void STD_BITMAP_BUTTON::OnMouseEnter ( wxMouseEvent &  aEvent)
protected

Definition at line 108 of file std_bitmap_button.cpp.

109{
110 if( m_stateButton != wxCONTROL_CURRENT )
111 {
112 m_stateButton = wxCONTROL_CURRENT;
113 Refresh();
114 }
115
116 aEvent.Skip();
117}

References m_stateButton, and Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ OnMouseLeave()

void STD_BITMAP_BUTTON::OnMouseLeave ( wxMouseEvent &  aEvent)
protected

Definition at line 96 of file std_bitmap_button.cpp.

97{
98 if( m_stateButton != 0 )
99 {
100 m_stateButton = 0;
101 Refresh();
102 }
103
104 aEvent.Skip();
105}

References m_stateButton, and Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ OnPaint()

void STD_BITMAP_BUTTON::OnPaint ( wxPaintEvent &  WXUNUSEDaEvent)
protected

Definition at line 150 of file std_bitmap_button.cpp.

151{
152 wxPaintDC dc( this );
153 wxSize size = GetSize();
154
155#ifdef __WXMAC__
156 auto drawBackground =
157 [&]( wxRect aRect )
158 {
159 // wxWidgets doesn't have much support for dark mode on OSX; none of the
160 // system colours return the right values, nor does wxRendererNative draw
161 // the borders correctly. So we add some empirically chosen hacks here.
162
163 // NOTE: KEEP THESE HACKS IN SYNC WITH SPLIT_BUTTON
164
165 wxColor fg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
166 wxColor bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
167
168 aRect.width += 1;
169 aRect.height += 1;
170
172 {
173 bg = bg.ChangeLightness( m_bIsEnable ? 130 : 120 );
174 dc.SetBrush( bg );
175 dc.SetPen( bg );
176 }
177 else
178 {
179 bg = bg.ChangeLightness( m_bIsEnable ? 200 : 160 );
180 dc.SetBrush( bg );
181 fg = fg.ChangeLightness( 180 );
182 dc.SetPen( fg );
183 }
184
185 dc.DrawRoundedRectangle( aRect, aRect.height / 4.0 );
186 };
187#endif
188
189 wxRect r1;
190 r1.x = 0;
191 r1.y = 0;
192 r1.width = size.GetWidth();
193 r1.height = size.GetHeight();
194
195#ifdef __WXMAC__
196 // wxRendereNative doesn't handle dark mode on OSX.
197 drawBackground( r1 );
198#else
199 #ifdef __WXMSW__
200 r1.width += 1;
201 #endif
202
203 wxRendererNative::Get().DrawPushButton( this, dc, r1, m_stateButton );
204#endif
205
206 if( m_bitmap.IsOk() )
207 {
208 r1.x = ( size.GetWidth() - m_bitmap.GetWidth() ) / 2;
209
210 if( r1.x < 0 )
211 r1.x = 0;
212
213 r1.y += ( size.GetHeight() - m_bitmap.GetHeight() ) / 2;
214
215 dc.DrawBitmap( m_bIsEnable ? m_bitmap : m_bitmap.ConvertToDisabled(), r1.x, r1.y, true );
216 }
217}
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31

References KIPLATFORM::UI::IsDarkTheme(), m_bIsEnable, m_bitmap, and m_stateButton.

Referenced by STD_BITMAP_BUTTON().

◆ onThemeChanged()

void STD_BITMAP_BUTTON::onThemeChanged ( wxSysColourChangedEvent &  aEvent)
protected

Definition at line 70 of file std_bitmap_button.cpp.

71{
72 Refresh();
73}

References Refresh().

Referenced by STD_BITMAP_BUTTON().

◆ SetBitmap()

void STD_BITMAP_BUTTON::SetBitmap ( const wxBitmap &  aBmp)

Definition at line 76 of file std_bitmap_button.cpp.

77{
78 m_bitmap = aBmp;
79
80 SetMinSize( wxSize( m_bitmap.GetWidth() + 8, m_bitmap.GetHeight() + 8 ) );
81}

References m_bitmap.

Referenced by DIALOG_BOM::DIALOG_BOM(), DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS(), DIALOG_EXPORT_SVG::DIALOG_EXPORT_SVG(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), DIALOG_GROUP_PROPERTIES::DIALOG_GROUP_PROPERTIES(), DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_IMPORT_NETLIST::DIALOG_IMPORT_NETLIST(), DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS(), DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_MANAGE_REPOSITORIES::DIALOG_MANAGE_REPOSITORIES(), DIALOG_MIGRATE_SETTINGS::DIALOG_MIGRATE_SETTINGS(), DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS(), DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS(), DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES(), DIALOG_PLOT_SCHEMATIC::DIALOG_PLOT_SCHEMATIC(), DIALOG_SCH_IMPORT_SETTINGS::DIALOG_SCH_IMPORT_SETTINGS(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_SIM_MODEL< T_symbol, T_field >::DIALOG_SIM_MODEL(), DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES(), DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR(), DIALOG_USER_DEFINED_SIGNALS::DIALOG_USER_DEFINED_SIGNALS(), DIALOG_PLOT::init_Dialog(), DIALOG_GEN_FOOTPRINT_POSITION::initDialog(), DIALOG_GENDRILL::InitDisplayParams(), PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS(), PANEL_RF_ATTENUATORS::PANEL_RF_ATTENUATORS(), PANEL_SETUP_BUSES::PANEL_SETUP_BUSES(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES(), PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES(), PANEL_TRANSLINE::PANEL_TRANSLINE(), PANEL_FP_EDITOR_DEFAULTS::Show(), PANEL_RF_ATTENUATORS::ThemeChanged(), PANEL_TRANSLINE::ThemeChanged(), and TUNER_SLIDER::TUNER_SLIDER().

Member Data Documentation

◆ m_bIsEnable

bool STD_BITMAP_BUTTON::m_bIsEnable = true
private

Definition at line 68 of file std_bitmap_button.h.

Referenced by Enable(), and OnPaint().

◆ m_bitmap

wxBitmap STD_BITMAP_BUTTON::m_bitmap
private

Definition at line 69 of file std_bitmap_button.h.

Referenced by OnPaint(), and SetBitmap().

◆ m_stateButton

int STD_BITMAP_BUTTON::m_stateButton = 0
private

The documentation for this class was generated from the following files: