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 <kicommon.h>
29#include <wx/bmpbndl.h>
30#include <wx/panel.h>
31#include <wx/colour.h>
32
33
41class KICOMMON_API BITMAP_BUTTON : public wxPanel
42{
43public:
44 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos = wxDefaultPosition,
45 const wxSize& aSize = wxDefaultSize,
46 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
47
48 // For use with wxFormBuilder on a sub-classed wxBitmapButton
49 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxBitmap& aDummyBitmap,
50 const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize,
51 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
52
54
60 void SetPadding( int aPadding );
61
67 void SetBitmap( const wxBitmapBundle& aBmp );
68
74 void SetDisabledBitmap( const wxBitmapBundle& aBmp );
75
79 bool Enable( bool aEnable = true ) override;
80
84 void SetIsCheckButton();
85
86 void SetIsRadioButton();
87
91 void Check( bool aCheck = true );
92
93 bool IsChecked() const;
94
100 void SetIsSeparator();
101
107 void AcceptDragInAsClick( bool aAcceptDragIn = true );
108
109 void SetShowBadge( bool aShowBadge ) { m_showBadge = aShowBadge; }
110
111 void SetBadgeText( const wxString& aText ) { m_badgeText = aText; }
112
113 void SetBadgeColors( const wxColor& aBadgeColor, const wxColor& aBadgeTextColor )
114 {
115 m_badgeColor = aBadgeColor;
116 m_badgeTextColor = aBadgeTextColor;
117 }
118
119 void SetBitmapCentered( bool aCentered = true )
120 {
121 m_centerBitmap = aCentered;
122 }
123
124 void SetIsToolbarButton( bool aIsToolbar = true ) { m_isToolbarButton = aIsToolbar; }
125 bool IsToolbarButton() const { return m_isToolbarButton; }
126
127protected:
128 void setupEvents();
129
130 void OnMouseLeave( wxEvent& aEvent );
131 void OnMouseEnter( wxEvent& aEvent );
132 void OnKillFocus( wxEvent& aEvent );
133 void OnSetFocus( wxEvent& aEvent );
134 void OnLeftButtonUp( wxMouseEvent& aEvent );
135 void OnLeftButtonDown( wxMouseEvent& aEvent );
136 void OnPaint( wxPaintEvent& aEvent );
137
138 void setFlag( int aFlag )
139 {
140 m_buttonState |= aFlag;
141 }
142
143 void clearFlag( int aFlag )
144 {
145 m_buttonState &= ~aFlag;
146 }
147
148 bool hasFlag( int aFlag ) const
149 {
150 return m_buttonState & aFlag;
151 }
152
153private:
154 wxBitmapBundle m_normalBitmap;
155 wxBitmapBundle m_disabledBitmap;
156
159 wxString m_badgeText;
167
170
173};
174
175#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:42
void SetBadgeText(const wxString &aText)
wxFont m_badgeFont
void setFlag(int aFlag)
wxBitmapBundle m_disabledBitmap
bool IsToolbarButton() const
void SetBadgeColors(const wxColor &aBadgeColor, const wxColor &aBadgeTextColor)
bool hasFlag(int aFlag) const
wxColor m_badgeTextColor
void SetBitmapCentered(bool aCentered=true)
wxString m_badgeText
wxSize m_unadjustedMinSize
void clearFlag(int aFlag)
bool m_acceptDraggedInClicks
Draws bitmap centered in the control.
wxBitmapBundle m_normalBitmap
void SetIsToolbarButton(bool aIsToolbar=true)
bool m_isToolbarButton
Accept mouse-up as click even if mouse-down happened outside of the control.
void SetShowBadge(bool aShowBadge)
wxColor m_badgeColor
#define KICOMMON_API
Definition: kicommon.h:28