KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_color_swatch_helpers.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GRID_COLOR_SWATCH_HELPERS
21#define GRID_COLOR_SWATCH_HELPERS
22
23#include <wx/generic/gridctrl.h>
24#include <wx/generic/grideditors.h>
25#include <gal/color4d.h>
27
28
29class wxGrid;
30
31//-------- Custom wxGridCellRenderers --------------------------------------------------
32
33class GRID_CELL_COLOR_RENDERER : public wxGridCellRenderer
34{
35public:
36 GRID_CELL_COLOR_RENDERER( wxWindow* aParent = nullptr, SWATCH_SIZE aSize = SWATCH_EXPAND,
37 const KIGFX::COLOR4D& aBackground = KIGFX::COLOR4D::UNSPECIFIED );
40
41 wxGridCellRenderer* Clone() const override;
42 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
43
44 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
45 int aCol, bool isSelected ) override;
46
47 void OnDarkModeToggle();
48
49private:
50 wxWindow* m_parent;
51
53
54 wxSize m_size;
57};
58
59
60//-------- Custom wxGridCellEditors ----------------------------------------------------
61//
62// Note: this implementation is an adaptation of wxGridCellChoiceEditor
63
64class GRID_CELL_COLOR_SELECTOR : public wxGridCellEditor
65{
66public:
67 GRID_CELL_COLOR_SELECTOR( wxWindow* aParent, wxGrid* aGrid );
68
69 wxGridCellEditor* Clone() const override;
70 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
71
72 wxString GetValue() const override;
73
74 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
75 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override;
76 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
77 void Reset() override;
78
79protected:
80 wxWindow* m_parent;
81 wxGrid* m_grid;
83
85};
86
87#endif // GRID_COLOR_SWATCH_HELPERS
GRID_CELL_COLOR_RENDERER(wxWindow *aParent=nullptr, SWATCH_SIZE aSize=SWATCH_EXPAND, const KIGFX::COLOR4D &aBackground=KIGFX::COLOR4D::UNSPECIFIED)
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxGridCellRenderer * Clone() const override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_COLOR_SELECTOR(wxWindow *aParent, wxGrid *aGrid)
void ApplyEdit(int aRow, int aCol, wxGrid *aGrid) override
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
bool EndEdit(int, int, const wxGrid *, const wxString &, wxString *newval) override
wxGridCellEditor * Clone() const override
wxString GetValue() const override
wxDECLARE_NO_COPY_CLASS(GRID_CELL_COLOR_SELECTOR)
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
SWATCH_SIZE
@ SWATCH_EXPAND