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 (C) 2018-2022 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef GRID_COLOR_SWATCH_HELPERS
25#define GRID_COLOR_SWATCH_HELPERS
26
27#include <wx/generic/gridctrl.h>
28#include <wx/generic/grideditors.h>
29#include <gal/color4d.h>
31
32
33class wxGrid;
34
35//-------- Custom wxGridCellRenderers --------------------------------------------------
36
37class GRID_CELL_COLOR_RENDERER : public wxGridCellRenderer
38{
39public:
40 GRID_CELL_COLOR_RENDERER( wxWindow* aParent = nullptr, SWATCH_SIZE aSize = SWATCH_EXPAND,
41 const KIGFX::COLOR4D& aBackground = KIGFX::COLOR4D::UNSPECIFIED );
44
45 wxGridCellRenderer* Clone() const override;
46 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
47
48 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
49 int aCol, bool isSelected ) override;
50
51 void OnDarkModeToggle();
52
53private:
54 wxWindow* m_parent;
55
57
58 wxSize m_size;
61};
62
63
64//-------- Custom wxGridCellEditors ----------------------------------------------------
65//
66// Note: this implementation is an adaptation of wxGridCellChoiceEditor
67
68class GRID_CELL_COLOR_SELECTOR : public wxGridCellEditor
69{
70public:
71 GRID_CELL_COLOR_SELECTOR( wxWindow* aParent, wxGrid* aGrid );
72
73 wxGridCellEditor* Clone() const override;
74 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
75
76 wxString GetValue() const override;
77
78 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
79 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override;
80 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
81 void Reset() override;
82
83protected:
84 wxWindow* m_parent;
85 wxGrid* m_grid;
87
89};
90
91#endif // GRID_COLOR_SWATCH_HELPERS
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
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:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:382
SWATCH_SIZE
Definition: color_swatch.h:39
@ SWATCH_EXPAND
Definition: color_swatch.h:43