KiCad PCB EDA Suite
color_swatch.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) 2017 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef COLOR_SWATCH__H_
25 #define COLOR_SWATCH__H_
26 
27 #include <wx/bitmap.h>
28 #include <wx/gdicmn.h>
29 #include <wx/panel.h>
30 #include <wx/statbmp.h>
31 #include <wx/window.h>
32 
33 #include <functional>
34 
35 #include <gal/color4d.h>
36 
37 
39 {
44 };
45 
46 
47 const static wxSize SWATCH_SIZE_SMALL_DU( 8, 6 );
48 const static wxSize SWATCH_SIZE_MEDIUM_DU( 24, 10 );
49 const static wxSize SWATCH_SIZE_LARGE_DU( 24, 16 );
50 const static wxSize CHECKERBOARD_SIZE_DU( 3, 3 );
51 
52 
57 class COLOR_SWATCH: public wxPanel
58 {
59 public:
60 
68  COLOR_SWATCH( wxWindow* aParent, KIGFX::COLOR4D aColor, int aID, KIGFX::COLOR4D aBackground,
69  const KIGFX::COLOR4D aDefault, SWATCH_SIZE aSwatchType );
70 
74  COLOR_SWATCH( wxWindow *aParent, wxWindowID aId, const wxPoint &aPos = wxDefaultPosition,
75  const wxSize &aSize = wxDefaultSize, long aStyle = 0 );
76 
80  void SetSwatchColor( KIGFX::COLOR4D aColor, bool sendEvent );
81 
85  void SetDefaultColor( KIGFX::COLOR4D aColor );
86 
90  void SetSwatchBackground( KIGFX::COLOR4D aBackground );
91 
96 
102  void GetNewSwatchColor();
103 
104  void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
105  bool IsReadOnly() const { return m_readOnly; }
106 
108  void SetReadOnlyCallback( std::function<void()> aCallback ) { m_readOnlyCallback = aCallback; }
109 
110  static wxBitmap MakeBitmap( KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize,
111  wxSize aCheckerboardSize, KIGFX::COLOR4D aCheckerboardBackground );
112 
113 private:
114  void setupEvents();
115 
119  void rePostEvent( wxEvent& aEvt );
120 
124 
125  wxStaticBitmap* m_swatch;
126 
127  wxSize m_size;
130 
133  std::function<void()> m_readOnlyCallback;
134 };
135 
136 
140 wxDECLARE_EVENT(COLOR_SWATCH_CHANGED, wxCommandEvent);
141 
142 #endif // COLOR_SWATCH__H_
KIGFX::COLOR4D GetSwatchColor() const
void SetSwatchColor(KIGFX::COLOR4D aColor, bool sendEvent)
Set the current swatch color directly.
wxDECLARE_EVENT(COLOR_SWATCH_CHANGED, wxCommandEvent)
Event signalling a swatch has changed color.
COLOR_SWATCH(wxWindow *aParent, KIGFX::COLOR4D aColor, int aID, KIGFX::COLOR4D aBackground, const KIGFX::COLOR4D aDefault, SWATCH_SIZE aSwatchType)
Construct a COLOR_SWATCH.
void setupEvents()
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize, wxSize aCheckerboardSize, KIGFX::COLOR4D aCheckerboardBackground)
Make a simple color swatch bitmap.
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
void SetSwatchBackground(KIGFX::COLOR4D aBackground)
Set the swatch background color.
void SetReadOnly(bool aReadOnly=true)
Definition: color_swatch.h:104
void SetReadOnlyCallback(std::function< void()> aCallback)
Registers a handler for when the user tries to interact with a read-only swatch.
Definition: color_swatch.h:108
bool IsReadOnly() const
Definition: color_swatch.h:105
KIGFX::COLOR4D m_default
Definition: color_swatch.h:123
wxSize m_checkerboardSize
Definition: color_swatch.h:128
void rePostEvent(wxEvent &aEvt)
Pass unwanted events on to listeners of this object.
KIGFX::COLOR4D m_background
Definition: color_swatch.h:122
static const wxSize SWATCH_SIZE_MEDIUM_DU(24, 10)
std::function< void()> m_readOnlyCallback
Definition: color_swatch.h:133
wxStaticBitmap * m_swatch
Definition: color_swatch.h:125
KIGFX::COLOR4D m_checkerboardBg
Definition: color_swatch.h:129
bool m_readOnly
A read-only swatch won't show the color chooser dialog but otherwise works normally.
Definition: color_swatch.h:132
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:57
static const wxSize SWATCH_SIZE_SMALL_DU(8, 6)
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
KIGFX::COLOR4D m_color
Definition: color_swatch.h:121
SWATCH_SIZE
Definition: color_swatch.h:38
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100