KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bitmap_button.h
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) 2020 Ian McInerney <ian.s.mcinerney at ieee dot org>
5 * Copyright (C) 2020-2021 Kicad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef BITMAP_BUTTON_H_
26#define BITMAP_BUTTON_H_
27
28#include <wx/bmpbndl.h>
29#include <wx/panel.h>
30#include <wx/colour.h>
31
32
40class BITMAP_BUTTON : public wxPanel
41{
42public:
43 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos = wxDefaultPosition,
44 const wxSize& aSize = wxDefaultSize,
45 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
46
47 // For use with wxFormBuilder on a sub-classed wxBitmapButton
48 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxBitmap& aDummyBitmap,
49 const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize,
50 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
51
53
59 void SetPadding( int aPadding );
60
66 void SetBitmap( const wxBitmapBundle& aBmp );
67
73 void SetDisabledBitmap( const wxBitmapBundle& aBmp );
74
78 bool Enable( bool aEnable = true ) override;
79
83 void SetIsCheckButton();
84
85 void SetIsRadioButton();
86
90 void Check( bool aCheck = true );
91
92 bool IsChecked() const;
93
99 void SetIsSeparator();
100
106 void AcceptDragInAsClick( bool aAcceptDragIn = true );
107
108 void SetShowBadge( bool aShowBadge ) { m_showBadge = aShowBadge; }
109
110 void SetBadgeText( const wxString& aText ) { m_badgeText = aText; }
111
112 void SetBadgeColors( const wxColor& aBadgeColor, const wxColor& aBadgeTextColor )
113 {
114 m_badgeColor = aBadgeColor;
115 m_badgeTextColor = aBadgeTextColor;
116 }
117
118 void SetBitmapCentered( bool aCentered )
119 {
120 m_centerBitmap = aCentered;
121 }
122
123protected:
124 void setupEvents();
125
126 void OnMouseLeave( wxEvent& aEvent );
127 void OnMouseEnter( wxEvent& aEvent );
128 void OnKillFocus( wxEvent& aEvent );
129 void OnSetFocus( wxEvent& aEvent );
130 void OnLeftButtonUp( wxMouseEvent& aEvent );
131 void OnLeftButtonDown( wxMouseEvent& aEvent );
132 void OnPaint( wxPaintEvent& aEvent );
133
134 void setFlag( int aFlag )
135 {
136 m_buttonState |= aFlag;
137 }
138
139 void clearFlag( int aFlag )
140 {
141 m_buttonState &= ~aFlag;
142 }
143
144 bool hasFlag( int aFlag ) const
145 {
146 return m_buttonState & aFlag;
147 }
148
149private:
150 wxBitmapBundle m_normalBitmap;
151 wxBitmapBundle m_disabledBitmap;
152
155 wxString m_badgeText;
162
165
168};
169
170#endif /*BITMAP_BUTTON_H_*/
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void OnKillFocus(wxEvent &aEvent)
void SetBadgeText(const wxString &aText)
void SetIsRadioButton()
bool IsChecked() const
void OnSetFocus(wxEvent &aEvent)
void AcceptDragInAsClick(bool aAcceptDragIn=true)
Accept mouse-up as click even if mouse-down happened outside of the control.
wxFont m_badgeFont
void OnMouseLeave(wxEvent &aEvent)
bool Enable(bool aEnable=true) override
Enable the button.
void setFlag(int aFlag)
wxBitmapBundle m_disabledBitmap
void SetBitmapCentered(bool aCentered)
void SetBadgeColors(const wxColor &aBadgeColor, const wxColor &aBadgeTextColor)
void Check(bool aCheck=true)
Check the control.
bool hasFlag(int aFlag) const
void SetDisabledBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is disabled.
wxColor m_badgeTextColor
void OnLeftButtonDown(wxMouseEvent &aEvent)
wxString m_badgeText
void SetIsSeparator()
Render button as a toolbar separator.
wxSize m_unadjustedMinSize
Accept mouse-up as click even if mouse-down happened outside of the control.
void clearFlag(int aFlag)
bool m_acceptDraggedInClicks
Draws bitmap centered in the control.
wxBitmapBundle m_normalBitmap
void OnPaint(wxPaintEvent &aEvent)
void OnMouseEnter(wxEvent &aEvent)
void OnLeftButtonUp(wxMouseEvent &aEvent)
void SetIsCheckButton()
Setup the control as a two-state button (checked or unchecked).
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
void SetShowBadge(bool aShowBadge)
wxColor m_badgeColor
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.