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 
31 
39 class BITMAP_BUTTON : public wxPanel
40 {
41 public:
42  BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos = wxDefaultPosition,
43  const wxSize& aSize = wxDefaultSize,
44  int aStyles = wxBORDER_NONE | wxTAB_TRAVERSAL );
45 
47 
53  void SetPadding( int aPadding );
54 
60  void SetBitmap( const wxBitmap& aBmp );
61 
67  void SetDisabledBitmap( const wxBitmap& aBmp );
68 
74  bool Enable( bool aEnable = true ) override;
75 
81  void Check( bool aCheck = true );
82 
88  void AcceptDragInAsClick( bool aAcceptDragIn = true );
89 
90 protected:
91  void OnMouseLeave( wxEvent& aEvent );
92  void OnMouseEnter( wxEvent& aEvent );
93  void OnKillFocus( wxEvent& aEvent );
94  void OnSetFocus( wxEvent& aEvent );
95  void OnLeftButtonUp( wxMouseEvent& aEvent );
96  void OnLeftButtonDown( wxMouseEvent& aEvent );
97  void OnPaint( wxPaintEvent& aEvent );
98 
99  void setFlag( int aFlag )
100  {
101  m_buttonState |= aFlag;
102  }
103 
104  void clearFlag( int aFlag )
105  {
106  m_buttonState &= ~aFlag;
107  }
108 
109  bool hasFlag( int aFlag )
110  {
111  return m_buttonState & aFlag;
112  }
113 
114 private:
116  wxBitmap m_normalBitmap;
117 
120 
123 
126 
129 
132 };
133 
134 #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:39
void OnLeftButtonUp(wxMouseEvent &aEvent)
void OnMouseLeave(wxEvent &aEvent)
wxSize m_unadjustedMinSize
Accept mouse-up as click even if mouse-down happened outside of the control.
void OnMouseEnter(wxEvent &aEvent)
bool m_acceptDraggedInClicks
bool Enable(bool aEnable=true) override
Enable the button.
void OnSetFocus(wxEvent &aEvent)
void setFlag(int aFlag)
Definition: bitmap_button.h:99
int m_padding
Size without the padding.
void Check(bool aCheck=true)
Check the control.
void clearFlag(int aFlag)
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
wxBitmap m_disabledBitmap
Current state of the button.
int m_buttonState
Padding on each side of the bitmap.
void OnKillFocus(wxEvent &aEvent)
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
wxBitmap m_normalBitmap
< Bitmap shown when button is enabled
void AcceptDragInAsClick(bool aAcceptDragIn=true)
Accept mouse-up as click even if mouse-down happened outside of the control.
BITMAP_BUTTON(wxWindow *aParent, wxWindowID aId, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyles=wxBORDER_NONE|wxTAB_TRAVERSAL)
void OnPaint(wxPaintEvent &aEvent)
void SetDisabledBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is disabled.
bool hasFlag(int aFlag)
void OnLeftButtonDown(wxMouseEvent &aEvent)