KiCad PCB EDA Suite
dialog_color_picker.h
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software: you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the
12  * Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef DIALOG_COLOR_PICKER_H
25 #define DIALOG_COLOR_PICKER_H
26 
27 
28 #include <gal/color4d.h>
30 
35 {
37  wxString m_ColorName;
38 
39  CUSTOM_COLOR_ITEM( double red, double green, double blue, const wxString& aName )
40  {
41  m_Color.r = red;
42  m_Color.g = green;
43  m_Color.b = blue;
44  m_ColorName = aName;
45  }
46 
47  CUSTOM_COLOR_ITEM( const KIGFX::COLOR4D& aColor, const wxString& aName )
48  : m_Color( aColor ), m_ColorName( aName)
49  {}
50 };
51 
52 
53 typedef std::vector<CUSTOM_COLOR_ITEM> CUSTOM_COLORS_LIST;
54 
55 
57 {
65 };
66 
68 {
69 public:
78  DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
79  bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr,
80  const KIGFX::COLOR4D& aDefaultColor = KIGFX::COLOR4D::UNSPECIFIED );
82 
84 
85  static int m_ActivePage;
86 
87 private:
88  /* When the dialog is created, the mouse cursor can be on the RGB or HSV palette selector
89  * Because this dialog is created by clicking double clicking on a widget, the left mouse
90  * button is down, thus creating a not wanted mouse event inside this dialog
91  * m_allowMouseEvents is first set to false, and then set to true on the first left mouse
92  * clicking inside this dialog to prevent not wanted mouse drag event
93  */
100 
102  std::vector<KIGFX::COLOR4D> m_Color4DList;
104 
109  wxPoint* m_selectedCursor;
110 
111  double m_hue;
112  double m_sat;
113  double m_val;
114 
115  wxBitmap* m_bitmapRGB;
116  wxBitmap* m_bitmapHSV;
117 
118  std::vector<wxBitmapButton*> m_buttonsColor;
119 
120  void SetEditVals( CHANGED_COLOR aChanged );
121  void drawAll();
122 
123  void createHSVBitmap();
124  void drawHSVPalette();
125  void createRGBBitmap();
126  void drawRGBPalette();
127  void drawRGBCursors();
128 
130  void setIconColor( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D );
131 
133  void OnChangeBrightness( wxScrollEvent& event ) override;
134 
136  void OnChangeAlpha( wxScrollEvent& event ) override;
137 
139  void OnChangeEditRed( wxSpinEvent& event ) override;
140  void OnChangeEditGreen( wxSpinEvent& event ) override;
141  void OnChangeEditBlue( wxSpinEvent& event ) override;
142  void OnChangeEditHue( wxSpinEvent& event ) override;
143  void OnChangeEditSat( wxSpinEvent& event ) override;
144 
146  void onRGBMouseClick( wxMouseEvent& event ) override;
147  void onRGBMouseDrag( wxMouseEvent& event ) override;
148  void onHSVMouseClick( wxMouseEvent& event ) override;
149  void onHSVMouseDrag( wxMouseEvent& event ) override;
150 
152  void OnResetButton( wxCommandEvent& aEvent ) override;
153 
161  bool setHSvaluesFromCursor( wxPoint aMouseCursor );
162 
164  void buttColorClick( wxCommandEvent& event );
165 
167  bool TransferDataToWindow() override;
168 
172  void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
173 
174  // convert double value 0 ... 1 to int 0 ... aValMax
175  int normalizeToInt( double aValue, int aValMax = 255 )
176  {
177  return ( aValue * aValMax ) + 0.5;
178  }
179 
180 };
181 
182 #endif // #define DIALOG_COLOR_PICKER_H
double m_hue
the current hue, in degrees (0 ... 360)
bool m_allowOpacityCtrl
true to show the widget, false to keep alpha channel = 1.0
double m_sat
the current saturation (0 ... 1.0)
void SetEditVals(CHANGED_COLOR aChanged)
void drawRGBPalette()
draws the RVB color space
CUSTOM_COLOR_ITEM(const KIGFX::COLOR4D &aColor, const wxString &aName)
void OnChangeEditGreen(wxSpinEvent &event) override
std::vector< KIGFX::COLOR4D > m_Color4DList
the list of color4d ordered by button ID, for predefined colors
CHANGED_COLOR
void OnChangeAlpha(wxScrollEvent &event) override
Event handlers from wxSpinControl.
int normalizeToInt(double aValue, int aValMax=255)
void onHSVMouseDrag(wxMouseEvent &event) override
Event handler for the reset button press.
double g
Green component.
Definition: color4d.h:302
void drawHSVPalette()
draws the HSV color circle
a class to handle a custom color (predefined color) for the color picker dialog
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
void createHSVBitmap()
generate the bitmap that shows the HSV color circle
void setIconColor(wxStaticBitmap *aStaticBitmap, KIGFX::COLOR4D &aColor4D)
repaint a static bitmap with the aColor4D color
bool setHSvaluesFromCursor(wxPoint aMouseCursor)
manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
KIGFX::COLOR4D m_newColor4D
the current color4d
void onHSVMouseClick(wxMouseEvent &event) override
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:307
double b
Blue component.
Definition: color4d.h:303
void onRGBMouseClick(wxMouseEvent &event) override
mouse handlers, when clicking on a palette bitmap
KIGFX::COLOR4D m_previousColor4D
the inital color4d
void createRGBBitmap()
generate the bitmap that shows the RVB color space
static int m_ActivePage
the active notebook page, stored during a session
wxBitmap * m_bitmapHSV
the basic HUV palette
void OnChangeEditHue(wxSpinEvent &event) override
void buttColorClick(wxCommandEvent &event)
Event handler for defined color buttons
Class DIALOG_COLOR_PICKER_BASE.
DIALOG_COLOR_PICKER(wxWindow *aParent, KIGFX::COLOR4D &aCurrentColor, bool aAllowOpacityControl, CUSTOM_COLORS_LIST *aUserColors=nullptr, const KIGFX::COLOR4D &aDefaultColor=KIGFX::COLOR4D::UNSPECIFIED)
Dialog constructor.
void onRGBMouseDrag(wxMouseEvent &event) override
void OnResetButton(wxCommandEvent &aEvent) override
double m_val
the current value (0 ... 1.0)
KIGFX::COLOR4D m_defaultColor
The default color4d.
CUSTOM_COLOR_ITEM(double red, double green, double blue, const wxString &aName)
wxPoint m_cursorBitmapRed
the red cursor on the RGB bitmap palette.
wxPoint m_cursorBitmapBlue
the blue cursor on the RGB bitmap palette.
void OnChangeEditBlue(wxSpinEvent &event) override
bool TransferDataToWindow() override
called when creating the dialog
void initDefinedColors(CUSTOM_COLORS_LIST *aPredefinedColors)
creates the bitmap buttons for each defined colors if aPredefinedColors is nullptr,...
KIGFX::COLOR4D GetColor()
std::vector< wxBitmapButton * > m_buttonsColor
list of defined colors buttons
KIGFX::COLOR4D m_Color
void OnChangeEditRed(wxSpinEvent &event) override
wxBitmap * m_bitmapRGB
the basic RGB palette
double r
Red component.
Definition: color4d.h:301
void OnChangeEditSat(wxSpinEvent &event) override
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxPoint * m_selectedCursor
the ref cursor to the selected curor, if any, or null.