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 );
81 
82  KIGFX::COLOR4D GetColor() { return m_newColor4D; };
83 
84  static int m_ActivePage;
85 
86 private:
87  /* When the dialog is created, the mouse cursor can be on the RGB or HSV palette selector
88  * Because this dialog is created by clicking double clicking on a widget, the left mouse
89  * button is down, thus creating a not wanted mouse event inside this dialog
90  * m_allowMouseEvents is first set to false, and then set to true on the first left mouse
91  * clicking inside this dialog to prevent not wanted mouse drag event
92  */
95  KIGFX::COLOR4D m_previousColor4D;
98  std::vector<KIGFX::COLOR4D> m_Color4DList;
101 
107 
108  double m_hue;
109  double m_sat;
110  double m_val;
111 
112  wxBitmap* m_bitmapRGB;
113  wxBitmap* m_bitmapHSV;
114 
115  std::vector<wxBitmapButton*> m_buttonsColor;
116 
117  void SetEditVals( CHANGED_COLOR aChanged );
118  void drawAll();
119 
120  void createHSVBitmap();
121  void drawHSVPalette();
122  void createRGBBitmap();
123  void drawRGBPalette();
124  void drawRGBCursors();
125 
127  void setIconColor( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D );
128 
130  void OnChangeBrightness( wxScrollEvent& event ) override;
131 
133  void OnChangeAlpha( wxScrollEvent& event ) override;
134 
136  void OnChangeEditRed( wxSpinEvent& event ) override;
137  void OnChangeEditGreen( wxSpinEvent& event ) override;
138  void OnChangeEditBlue( wxSpinEvent& event ) override;
139  void OnChangeEditHue( wxSpinEvent& event ) override;
140  void OnChangeEditSat( wxSpinEvent& event ) override;
141 
143  void onRGBMouseClick( wxMouseEvent& event ) override;
144  void onRGBMouseDrag( wxMouseEvent& event ) override;
145  void onHSVMouseClick( wxMouseEvent& event ) override;
146  void onHSVMouseDrag( wxMouseEvent& event ) override;
147 
155  bool setHSvaluesFromCursor( wxPoint aMouseCursor );
156 
158  void buttColorClick( wxCommandEvent& event );
159 
161  bool TransferDataToWindow() override;
162 
166  void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
167 
168  // convert double value 0 ... 1 to int 0 ... aValMax
169  int normalizeToInt( double aValue, int aValMax = 255 )
170  {
171  return ( aValue * aValMax ) + 0.5;
172  }
173 
174 };
175 
176 #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)
CUSTOM_COLOR_ITEM(const KIGFX::COLOR4D &aColor, const wxString &aName)
CHANGED_COLOR
int normalizeToInt(double aValue, int aValMax=255)
double g
Green component.
Definition: color4d.h:288
a class to handle a custom color (predefined color) for the color picker dialog
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
KIGFX::COLOR4D m_newColor4D
the current color4d
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
double b
Blue component.
Definition: color4d.h:289
static int m_ActivePage
the active notebook page, stored during a session
wxBitmap * m_bitmapHSV
the basic HUV palette
Class DIALOG_COLOR_PICKER_BASE.
double m_val
the current value (0 ... 1.0)
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.
std::vector< wxBitmapButton * > m_buttonsColor
list of defined colors buttons
KIGFX::COLOR4D m_Color
wxBitmap * m_bitmapRGB
the basic RGB palette
double r
Red component.
Definition: color4d.h:287
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.