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 = true )
119 {
120 m_centerBitmap = aCentered;
121 }
122
123 void SetIsToolbarButton( bool aIsToolbar = true ) { m_isToolbarButton = aIsToolbar; }
124 bool IsToolbarButton() const { return m_isToolbarButton; }
125
126protected:
127 void setupEvents();
128
129 void OnMouseLeave( wxEvent& aEvent );
130 void OnMouseEnter( wxEvent& aEvent );
131 void OnKillFocus( wxEvent& aEvent );
132 void OnSetFocus( wxEvent& aEvent );
133 void OnLeftButtonUp( wxMouseEvent& aEvent );
134 void OnLeftButtonDown( wxMouseEvent& aEvent );
135 void OnPaint( wxPaintEvent& aEvent );
136
137 void setFlag( int aFlag )
138 {
139 m_buttonState |= aFlag;
140 }
141
142 void clearFlag( int aFlag )
143 {
144 m_buttonState &= ~aFlag;
145 }
146
147 bool hasFlag( int aFlag ) const
148 {
149 return m_buttonState & aFlag;
150 }
151
152private:
153 wxBitmapBundle m_normalBitmap;
154 wxBitmapBundle m_disabledBitmap;
155
158 wxString m_badgeText;
166
169
172};
173
174#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
bool IsToolbarButton() const
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)
void SetBitmapCentered(bool aCentered=true)
wxString m_badgeText
void SetIsSeparator()
Render button as a toolbar separator.
wxSize m_unadjustedMinSize
void clearFlag(int aFlag)
bool m_acceptDraggedInClicks
Draws bitmap centered in the control.
wxBitmapBundle m_normalBitmap
void SetIsToolbarButton(bool aIsToolbar=true)
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.
bool m_isToolbarButton
Accept mouse-up as click even if mouse-down happened outside of the control.
void SetShowBadge(bool aShowBadge)
wxColor m_badgeColor
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.