KiCad PCB EDA Suite
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/bitmap.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 wxBitmap& aBmp );
67
73 void SetDisabledBitmap( const wxBitmap& 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
118protected:
119 void setupEvents();
120
121 void OnMouseLeave( wxEvent& aEvent );
122 void OnMouseEnter( wxEvent& aEvent );
123 void OnKillFocus( wxEvent& aEvent );
124 void OnSetFocus( wxEvent& aEvent );
125 void OnLeftButtonUp( wxMouseEvent& aEvent );
126 void OnLeftButtonDown( wxMouseEvent& aEvent );
127 void OnPaint( wxPaintEvent& aEvent );
128
129 void setFlag( int aFlag )
130 {
131 m_buttonState |= aFlag;
132 }
133
134 void clearFlag( int aFlag )
135 {
136 m_buttonState &= ~aFlag;
137 }
138
139 bool hasFlag( int aFlag ) const
140 {
141 return m_buttonState & aFlag;
142 }
143
144private:
147
150 wxString m_badgeText;
157
160};
161
162#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)
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
bool Enable(bool aEnable=true) override
Enable the button.
void setFlag(int aFlag)
void SetBadgeColors(const wxColor &aBadgeColor, const wxColor &aBadgeTextColor)
void Check(bool aCheck=true)
Check the control.
bool hasFlag(int aFlag) const
BITMAP_BUTTON(wxWindow *aParent, wxWindowID aId, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyles=wxBORDER_NONE|wxTAB_TRAVERSAL)
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
wxBitmap m_disabledBitmap
wxBitmap 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 SetShowBadge(bool aShowBadge)
wxColor m_badgeColor
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
void SetDisabledBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is disabled.