1 /*
2 Copyright (C) 2011-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: DkWxColorView.cpt
12 */
13 
14 /**	@file DkWxColorView.cpp The DkWxColorView module.
15 */
16 
17 
18 #include "dk3conf.h"
19 #include <libdk3wx/DkWxColorView.h>
20 
21 #include <wx/dcbuffer.h>
22 #include <wx/colordlg.h>
23 
24 
25 
26 
27 
28 
29 
30 #if	wxCHECK_VERSION(3,0,0)
31 wxBEGIN_EVENT_TABLE(DkWxColorView, wxControl)
32 #else
33 BEGIN_EVENT_TABLE(DkWxColorView, wxControl)
34 #endif
35   EVT_ERASE_BACKGROUND(DkWxColorView::OnErase)
36   EVT_PAINT(DkWxColorView::OnPaint)
37   EVT_LEFT_DOWN(DkWxColorView::OnLeftMouseButtonDown)
38 #if	wxCHECK_VERSION(3,0,0)
39 wxEND_EVENT_TABLE()
40 #else
41 END_EVENT_TABLE()
42 #endif
43 
44 
45 #if	wxCHECK_VERSION(3,0,0)
46 wxIMPLEMENT_DYNAMIC_CLASS(DkWxColorView, wxControl);
47 #else
48 IMPLEMENT_DYNAMIC_CLASS(DkWxColorView, wxControl)
49 #endif
50 
51 
52 
53 
54 wxChar const DkWxColorView::DkWxColorViewName[] = { wxT("DkWxColorView") } ;
55 
56 
57 
DkWxColorView()58 DkWxColorView::DkWxColorView()
59 {
60   pParentWindow = NULL;
61   pHelper = NULL;
62   w = -1;
63   h = -1;
64   r = 255;
65   g = 255;
66   b = 255;
67   ccdx = -1;
68   ccdy = -1;
69 }
70 
71 
72 
DkWxColorView(wxWindow * pParent,wxWindowID wxid,DkWxAppHelper * appHelper,int red,int green,int blue,wxPoint const & pos,wxSize const & size,long style,wxChar const * name)73 DkWxColorView::DkWxColorView(
74       wxWindow		*pParent,
75       wxWindowID	 wxid,
76       DkWxAppHelper	*appHelper,
77       int		 red,
78       int		 green,
79       int		 blue,
80       wxPoint const &	 pos,
81       wxSize  const &	 size,
82       long		 style,
83       wxChar const	*name
84 )
85 : wxControl(
86     pParent, wxid, pos, size, style, wxDefaultValidator,
87     wxString(name)
88 )
89 {
90   pParentWindow = pParent;
91   pHelper = appHelper;
92   w = size.x;
93   h = size.y;
94   r = red;
95   g = green;
96   b = blue;
97   ccdx = -1;
98   ccdy = -1;
99 }
100 
101 
102 
103 bool
Create(wxWindow * pParent,wxWindowID wxid,DkWxAppHelper * appHelper,int red,int green,int blue,wxPoint const & pos,wxSize const & size,long style,wxChar const * name)104 DkWxColorView::Create(
105       wxWindow		*pParent,
106       wxWindowID	 wxid,
107       DkWxAppHelper	*appHelper,
108       int		 red,
109       int		 green,
110       int		 blue,
111       wxPoint const &	 pos,
112       wxSize  const &	 size,
113       long		 style,
114       wxChar const	*name
115 )
116 {
117   bool back;
118   back = wxControl::Create(
119     pParent, wxid, pos, size, style, wxDefaultValidator,
120     wxString(name)
121   );
122   pParentWindow = pParent;
123   pHelper = appHelper;
124   w = size.x;
125   h = size.y;
126   r = red;
127   g = green;
128   b = blue;
129   return back;
130 }
131 
132 
133 
134 wxSize
DoGetBestSize() const135 DkWxColorView::DoGetBestSize() const
136 {
137   wxSize back(((-1 < w) ? w : 20), ((-1 < h) ? h : 20));
138   return back;
139 }
140 
141 
142 
143 void
OnErase(wxEraseEvent & WXUNUSED (event))144 DkWxColorView::OnErase(wxEraseEvent & WXUNUSED(event))
145 {
146 }
147 
148 
149 
150 void
OnPaint(wxPaintEvent & WXUNUSED (event))151 DkWxColorView::OnPaint(wxPaintEvent & WXUNUSED(event))
152 {
153   wxBufferedPaintDC	useDC(this);
154   wxSize		sz = GetClientSize();
155   wxColour		mycolor(
156   					(unsigned char)r,
157 					(unsigned char)g,
158 					(unsigned char)b
159   );
160 #if	wxCHECK_VERSION(3,0,0)
161   wxBrush		myBrush(mycolor, wxBRUSHSTYLE_SOLID);
162 #else
163   wxBrush		myBrush(mycolor, wxSOLID);
164 #endif
165   const wxBrush		oldBrush = useDC.GetBrush();
166   useDC.SetBrush(myBrush);
167   useDC.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight());
168   useDC.SetBrush(wxNullBrush);
169 }
170 
171 
172 
173 void
OnLeftMouseButtonDown(wxMouseEvent & WXUNUSED (event))174 DkWxColorView::OnLeftMouseButtonDown(wxMouseEvent & WXUNUSED(event))
175 {
176 
177   wxColourDialog	dlg(this);
178   if(pParentWindow) {
179     if(pHelper) {
180       pHelper->setRelatedPosition(pParentWindow, &dlg, &ccdx, &ccdy);
181     }
182   }
183   if(dlg.ShowModal() == wxID_OK) {
184     wxColour col = dlg.GetColourData().GetColour();
185     r = col.Red();
186     g = col.Green();
187     b = col.Blue();
188     dlg.GetPosition(&ccdx, &ccdy);
189     Refresh();
190     Update();
191   } else {
192     dlg.GetPosition(&ccdx, &ccdy);
193   }
194 
195 }
196 
197 
198 
199 int
getRed() const200 DkWxColorView::getRed() const
201 {
202   return r;
203 }
204 
205 
206 
207 
208 int
getGreen() const209 DkWxColorView::getGreen() const
210 {
211   return g;
212 }
213 
214 
215 
216 int
getBlue() const217 DkWxColorView::getBlue() const
218 {
219   return b;
220 }
221 
222 
223 
224 void
setRGB(int red,int green,int blue)225 DkWxColorView::setRGB(int red, int green, int blue)
226 {
227   r = red;
228   g = green;
229   b = blue;
230   if(r < 0) r = 0;
231   if(g < 0) g = 0;
232   if(b < 0) b = 0;
233   if(r > 255) r = 255;
234   if(g > 255) g = 255;
235   if(b > 255) b = 255;
236 }
237 
238