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 {
66 };
67 
69 {
70 public:
79  DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
80  bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr,
81  const KIGFX::COLOR4D& aDefaultColor = KIGFX::COLOR4D::UNSPECIFIED );
83 
85 
86  static int m_ActivePage;
87 
88 private:
89  /* When the dialog is created, the mouse cursor can be on the RGB or HSV palette selector
90  * Because this dialog is created by clicking double clicking on a widget, the left mouse
91  * button is down, thus creating a not wanted mouse event inside this dialog
92  * m_allowMouseEvents is first set to false, and then set to true on the first left mouse
93  * clicking inside this dialog to prevent not wanted mouse drag event
94  */
101 
103  std::vector<KIGFX::COLOR4D> m_Color4DList;
105 
111 
112  double m_hue;
113  double m_sat;
114  double m_val;
115 
116  wxBitmap* m_bitmapRGB;
117  wxBitmap* m_bitmapHSV;
118 
119  std::vector<wxBitmapButton*> m_buttonsColor;
120 
121  void SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransparency );
122  void drawAll();
123 
124  void createHSVBitmap();
125  void drawHSVPalette();
126  void createRGBBitmap();
127  void drawRGBPalette();
128  void drawRGBCursors();
129 
131  void setIconColor( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D );
132 
134  void OnChangeBrightness( wxScrollEvent& event ) override;
135 
137  void OnChangeAlpha( wxScrollEvent& event ) override;
138 
140  void OnChangeEditRed( wxSpinEvent& event ) override;
141  void OnChangeEditGreen( wxSpinEvent& event ) override;
142  void OnChangeEditBlue( wxSpinEvent& event ) override;
143  void OnChangeEditHue( wxSpinEvent& event ) override;
144  void OnChangeEditSat( wxSpinEvent& event ) override;
145 
147  void onRGBMouseClick( wxMouseEvent& event ) override;
148  void onRGBMouseDrag( wxMouseEvent& event ) override;
149  void onHSVMouseClick( wxMouseEvent& event ) override;
150  void onHSVMouseDrag( wxMouseEvent& event ) override;
151 
152  void OnColorValueText( wxCommandEvent& event ) override;
153 
155  void OnResetButton( wxCommandEvent& aEvent ) override;
156 
164  bool setHSvaluesFromCursor( wxPoint aMouseCursor );
165 
167  void buttColorClick( wxCommandEvent& event );
168 
170  bool TransferDataToWindow() override;
171 
175  void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
176 
177  // convert double value 0 ... 1 to int 0 ... aValMax
178  int normalizeToInt( double aValue, int aValMax = 255 )
179  {
180  return ( aValue * aValMax ) + 0.5;
181  }
182 
183 };
184 
185 #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 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
void OnColorValueText(wxCommandEvent &event) override
Event handler for the reset button press.
double g
Green component.
Definition: color4d.h:303
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:308
double b
Blue component.
Definition: color4d.h:304
void SetEditVals(CHANGED_COLOR aChanged, bool aCheckTransparency)
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:302
void OnChangeEditSat(wxSpinEvent &event) override
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
wxPoint * m_selectedCursor
the ref cursor to the selected curor, if any, or null.