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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef BITMAP_BUTTON_H_
22#define BITMAP_BUTTON_H_
23
24#include <kicommon.h>
25#include <wx/bmpbndl.h>
26#include <wx/panel.h>
27#include <wx/colour.h>
28
29
37class KICOMMON_API BITMAP_BUTTON : public wxPanel
38{
39public:
40 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos = wxDefaultPosition,
41 const wxSize& aSize = wxDefaultSize,
42 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
43
44 // For use with wxFormBuilder on a sub-classed wxBitmapButton
45 BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxBitmap& aDummyBitmap,
46 const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize,
47 int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
48
50
56 void SetPadding( int aPaddingDIP );
57
63 void SetBitmap( const wxBitmapBundle& aBmp );
64
70 void SetDisabledBitmap( const wxBitmapBundle& aBmp );
71
75 bool Enable( bool aEnable = true ) override;
76
80 void SetIsCheckButton();
81
82 void SetIsRadioButton();
83
87 void Check( bool aCheck = true );
88
89 bool IsChecked() const;
90
96 void SetIsSeparator();
97
103 void AcceptDragInAsClick( bool aAcceptDragIn = true );
104
105 void SetShowBadge( bool aShowBadge ) { m_showBadge = aShowBadge; }
106
107 void SetBadgeText( const wxString& aText ) { m_badgeText = aText; }
108
109 void SetBadgeColors( const wxColor& aBadgeColor, const wxColor& aBadgeTextColor )
110 {
111 m_badgeColor = aBadgeColor;
112 m_badgeTextColor = aBadgeTextColor;
113 }
114
115 void SetBitmapCentered( bool aCentered = true )
116 {
117 m_centerBitmap = aCentered;
118 }
119
120 void SetIsToolbarButton( bool aIsToolbar = true ) { m_isToolbarButton = aIsToolbar; }
121 bool IsToolbarButton() const { return m_isToolbarButton; }
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 void OnDPIChanged( wxDPIChangedEvent& aEvent );
134
135 virtual wxSize DoGetBestSize() const override;
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
152 void invalidateBestSize();
153
154private:
155 wxBitmapBundle m_normalBitmap;
156 wxBitmapBundle m_disabledBitmap;
157
160 wxString m_badgeText;
166 wxSize m_dipSize;
168
171
174};
175
176#endif /*BITMAP_BUTTON_H_*/
void SetBadgeText(const wxString &aText)
bool m_centerBitmap
Draw bitmap centered in the control.
bool IsChecked() const
void AcceptDragInAsClick(bool aAcceptDragIn=true)
Accept mouse-up as click even if mouse-down happened outside of the control.
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.
BITMAP_BUTTON(wxWindow *aParent, wxWindowID aId, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyles=wxBORDER_NONE|wxTAB_TRAVERSAL)
wxColor m_badgeTextColor
void SetBitmapCentered(bool aCentered=true)
wxString m_badgeText
void SetIsSeparator()
Render button as a toolbar separator.
void clearFlag(int aFlag)
bool m_acceptDraggedInClicks
Accept mouse-up as click even if mouse-down happened outside of the control.
wxBitmapBundle m_normalBitmap
void SetIsToolbarButton(bool aIsToolbar=true)
void SetPadding(int aPaddingDIP)
Set the amount of padding present on each side of the bitmap.
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
#define KICOMMON_API
Definition kicommon.h:27