KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_color_picker.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) 2018-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef DIALOG_COLOR_PICKER_H
21#define DIALOG_COLOR_PICKER_H
22
23
24#include <gal/color4d.h>
25#include "../../common/dialogs/dialog_color_picker_base.h"
26
27class COLOR_SWATCH;
28
29
34{
36 wxString m_ColorName;
37
38 CUSTOM_COLOR_ITEM( double red, double green, double blue, const wxString& aName )
39 {
40 m_Color.r = red;
41 m_Color.g = green;
42 m_Color.b = blue;
43 m_ColorName = aName;
44 }
45
46 CUSTOM_COLOR_ITEM( double red, double green, double blue, double alpha, const wxString& aName )
47 {
48 m_Color.r = red;
49 m_Color.g = green;
50 m_Color.b = blue;
51 m_Color.a = alpha;
52 m_ColorName = aName;
53 }
54
55 CUSTOM_COLOR_ITEM( const KIGFX::COLOR4D& aColor, const wxString& aName )
56 : m_Color( aColor ), m_ColorName( aName)
57 {}
58};
59
60
61typedef std::vector<CUSTOM_COLOR_ITEM> CUSTOM_COLORS_LIST;
62
63
65{
75};
76
78{
79public:
89 DIALOG_COLOR_PICKER( wxWindow* aParent, const KIGFX::COLOR4D& aCurrentColor,
90 bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr,
91 const KIGFX::COLOR4D& aDefaultColor = KIGFX::COLOR4D::UNSPECIFIED );
93
95
96private:
97 /* When the dialog is created, the mouse cursor can be on the RGB or HSV palette selector
98 * Because this dialog is created by clicking double clicking on a widget, the left mouse
99 * button is down, thus creating a not wanted mouse event inside this dialog
100 * m_allowMouseEvents is first set to false, and then set to true on the first left mouse
101 * clicking inside this dialog to prevent not wanted mouse drag event
102 */
109
111 std::vector<KIGFX::COLOR4D> m_Color4DList;
113
119
120 double m_hue;
121 double m_sat;
122 double m_val;
123
124 wxBitmap* m_bitmapRGB;
125 wxBitmap* m_bitmapHSV;
126
127 std::vector<wxStaticBitmap*> m_colorSwatches;
128
129 void SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransparency );
130 void drawAll();
131
132 void createHSVBitmap();
133 void drawHSVPalette();
134 void createRGBBitmap();
135 void drawRGBPalette();
136
138 void updatePreview( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D );
139
141 void OnChangeBrightness( wxScrollEvent& event ) override;
142
144 void OnChangeAlpha( wxScrollEvent& event ) override;
145
147 void OnChangeEditRed( wxSpinEvent& event ) override;
148 void OnChangeEditGreen( wxSpinEvent& event ) override;
149 void OnChangeEditBlue( wxSpinEvent& event ) override;
150 void OnChangeEditHue( wxSpinEvent& event ) override;
151 void OnChangeEditSat( wxSpinEvent& event ) override;
152
154 void onRGBMouseClick( wxMouseEvent& event ) override;
155 void onRGBMouseDrag( wxMouseEvent& event ) override;
156 void onHSVMouseClick( wxMouseEvent& event ) override;
157 void onHSVMouseDrag( wxMouseEvent& event ) override;
158
159 void onSize( wxSizeEvent& event ) override;
160
161 void OnColorValueText( wxCommandEvent& event ) override;
162
164 void OnResetButton( wxCommandEvent& aEvent ) override;
165
174 bool setHSvaluesFromCursor( const wxPoint& aMouseCursor );
175
177 void buttColorClick( wxMouseEvent& event );
178
180 void colorDClick( wxMouseEvent& event );
181
183 bool TransferDataToWindow() override;
184
190 void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
191
192 void updateHandleSize();
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
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.
void onSize(wxSizeEvent &event) override
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:392
double g
Green component.
Definition: color4d.h:393
double a
Alpha component.
Definition: color4d.h:395
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
double b
Blue component.
Definition: color4d.h:394
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)