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-2021 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>
29#include "../../common/dialogs/dialog_color_picker_base.h"
30
31class COLOR_SWATCH;
32
33
38{
40 wxString m_ColorName;
41
42 CUSTOM_COLOR_ITEM( double red, double green, double blue, const wxString& aName )
43 {
44 m_Color.r = red;
45 m_Color.g = green;
46 m_Color.b = blue;
47 m_ColorName = aName;
48 }
49
50 CUSTOM_COLOR_ITEM( double red, double green, double blue, double alpha, const wxString& aName )
51 {
52 m_Color.r = red;
53 m_Color.g = green;
54 m_Color.b = blue;
55 m_Color.a = alpha;
56 m_ColorName = aName;
57 }
58
59 CUSTOM_COLOR_ITEM( const KIGFX::COLOR4D& aColor, const wxString& aName )
60 : m_Color( aColor ), m_ColorName( aName)
61 {}
62};
63
64
65typedef std::vector<CUSTOM_COLOR_ITEM> CUSTOM_COLORS_LIST;
66
67
69{
79};
80
82{
83public:
93 DIALOG_COLOR_PICKER( wxWindow* aParent, const KIGFX::COLOR4D& aCurrentColor,
94 bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr,
95 const KIGFX::COLOR4D& aDefaultColor = KIGFX::COLOR4D::UNSPECIFIED );
97
99
100private:
101 /* When the dialog is created, the mouse cursor can be on the RGB or HSV palette selector
102 * Because this dialog is created by clicking double clicking on a widget, the left mouse
103 * button is down, thus creating a not wanted mouse event inside this dialog
104 * m_allowMouseEvents is first set to false, and then set to true on the first left mouse
105 * clicking inside this dialog to prevent not wanted mouse drag event
106 */
113
115 std::vector<KIGFX::COLOR4D> m_Color4DList;
117
123
124 double m_hue;
125 double m_sat;
126 double m_val;
127
128 wxBitmap* m_bitmapRGB;
129 wxBitmap* m_bitmapHSV;
130
131 std::vector<wxStaticBitmap*> m_colorSwatches;
132
133 void SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransparency );
134 void drawAll();
135
136 void createHSVBitmap();
137 void drawHSVPalette();
138 void createRGBBitmap();
139 void drawRGBPalette();
140
142 void updatePreview( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D );
143
145 void OnChangeBrightness( wxScrollEvent& event ) override;
146
148 void OnChangeAlpha( wxScrollEvent& event ) override;
149
151 void OnChangeEditRed( wxSpinEvent& event ) override;
152 void OnChangeEditGreen( wxSpinEvent& event ) override;
153 void OnChangeEditBlue( wxSpinEvent& event ) override;
154 void OnChangeEditHue( wxSpinEvent& event ) override;
155 void OnChangeEditSat( wxSpinEvent& event ) override;
156
158 void onRGBMouseClick( wxMouseEvent& event ) override;
159 void onRGBMouseDrag( wxMouseEvent& event ) override;
160 void onHSVMouseClick( wxMouseEvent& event ) override;
161 void onHSVMouseDrag( wxMouseEvent& event ) override;
162
163 void OnColorValueText( wxCommandEvent& event ) override;
164
166 void OnResetButton( wxCommandEvent& aEvent ) override;
167
176 bool setHSvaluesFromCursor( const wxPoint& aMouseCursor );
177
179 void buttColorClick( wxMouseEvent& event );
180
182 void colorDClick( wxMouseEvent& event );
183
185 bool TransferDataToWindow() override;
186
192 void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
193
194 // convert double value 0 ... 1 to int 0 ... aValMax
195 int normalizeToInt( double aValue, int aValMax = 255 )
196 {
197 return ( aValue * aValMax ) + 0.5;
198 }
199
200};
201
202#endif // #define DIALOG_COLOR_PICKER_H
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:57
Class DIALOG_COLOR_PICKER_BASE.
KIGFX::COLOR4D m_previousColor4D
the initial color4d
void buttColorClick(wxMouseEvent &event)
Event handler for double click on color buttons.
void OnResetButton(wxCommandEvent &aEvent) override
void initDefinedColors(CUSTOM_COLORS_LIST *aPredefinedColors)
Create the bitmap buttons for each defined colors.
void colorDClick(wxMouseEvent &event)
called when creating the dialog
void OnChangeAlpha(wxScrollEvent &event) override
Event handlers from wxSpinControl.
void onRGBMouseDrag(wxMouseEvent &event) override
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
KIGFX::COLOR4D m_newColor4D
the current color4d
double m_val
the current value (0 ... 1.0)
void OnChangeEditGreen(wxSpinEvent &event) override
void createRGBBitmap()
generate the bitmap that shows the RVB color space
DIALOG_COLOR_PICKER(wxWindow *aParent, const KIGFX::COLOR4D &aCurrentColor, bool aAllowOpacityControl, CUSTOM_COLORS_LIST *aUserColors=nullptr, const KIGFX::COLOR4D &aDefaultColor=KIGFX::COLOR4D::UNSPECIFIED)
Dialog constructor.
KIGFX::COLOR4D GetColor()
std::vector< wxStaticBitmap * > m_colorSwatches
list of defined colors buttons
wxBitmap * m_bitmapRGB
the basic RGB palette
void OnChangeEditBlue(wxSpinEvent &event) override
wxPoint m_cursorBitmapBlue
the blue cursor on the RGB bitmap palette.
wxBitmap * m_bitmapHSV
the basic HUV palette
void OnColorValueText(wxCommandEvent &event) override
Event handler for the reset button press.
void createHSVBitmap()
generate the bitmap that shows the HSV color circle
std::vector< KIGFX::COLOR4D > m_Color4DList
the list of color4d ordered by button ID, for predefined colors
void onRGBMouseClick(wxMouseEvent &event) override
wxPoint m_cursorBitmapRed
the red cursor on the RGB bitmap palette.
double m_hue
the current hue, in degrees (0 ... 360)
bool setHSvaluesFromCursor(const wxPoint &aMouseCursor)
Manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
void OnChangeEditSat(wxSpinEvent &event) override
mouse handlers, when clicking on a palette bitmap
double m_sat
the current saturation (0 ... 1.0)
bool m_allowOpacityCtrl
true to show the widget, false to keep alpha channel = 1.0
bool TransferDataToWindow() override
void drawHSVPalette()
draws the HSV color circle
void onHSVMouseClick(wxMouseEvent &event) override
void onHSVMouseDrag(wxMouseEvent &event) override
void updatePreview(wxStaticBitmap *aStaticBitmap, KIGFX::COLOR4D &aColor4D)
Event handler from wxSlider: brightness (value) control.
KIGFX::COLOR4D m_defaultColor
The default color4d.
void OnChangeEditRed(wxSpinEvent &event) override
void OnChangeEditHue(wxSpinEvent &event) override
int normalizeToInt(double aValue, int aValMax=255)
void SetEditVals(CHANGED_COLOR aChanged, bool aCheckTransparency)
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
void drawRGBPalette()
draws the RVB color space
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
wxPoint * m_selectedCursor
the ref cursor to the selected cursor, if any, or null.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double r
Red component.
Definition: color4d.h:390
double g
Green component.
Definition: color4d.h:391
double a
Alpha component.
Definition: color4d.h:393
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:396
double b
Blue component.
Definition: color4d.h:392
CHANGED_COLOR
@ VAL_CHANGED
@ HUE_CHANGED
@ HEX_CHANGED
@ RED_CHANGED
@ ALL_CHANGED
@ ALPHA_CHANGED
@ GREEN_CHANGED
@ SAT_CHANGED
@ BLUE_CHANGED
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
A class to handle a custom color (predefined color) for the color picker dialog.
KIGFX::COLOR4D m_Color
CUSTOM_COLOR_ITEM(double red, double green, double blue, double alpha, const wxString &aName)
CUSTOM_COLOR_ITEM(double red, double green, double blue, const wxString &aName)
CUSTOM_COLOR_ITEM(const KIGFX::COLOR4D &aColor, const wxString &aName)