1 /*
2 Copyright (C) 2013-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: DkClockView.cpt
12 */
13 
14 /**	@file DkClockView.cpp The DkClockView module.
15 */
16 
17 
18 #include "dk3conf.h"
19 #include <wxdkclock/wxdkclock.h>
20 
21 
22 
23 
24 
25 #if	wxCHECK_VERSION(3,0,0)
26 wxIMPLEMENT_DYNAMIC_CLASS(DkClockView, DkWxBufferedControl);
27 #else
28 IMPLEMENT_DYNAMIC_CLASS(DkClockView, DkWxBufferedControl)
29 #endif
30 
31 
32 /**	Event handler table.
33 */
34 #if	wxCHECK_VERSION(3,0,0)
35 wxBEGIN_EVENT_TABLE(DkClockView,DkWxBufferedControl)
36 #else
37 BEGIN_EVENT_TABLE(DkClockView,DkWxBufferedControl)
38 #endif
39 	EVT_LEFT_DOWN(DkClockView::OnLeftDown)
40 #if	wxCHECK_VERSION(3,0,0)
41 wxEND_EVENT_TABLE()
42 #else
43 END_EVENT_TABLE()
44 #endif
45 
46 
47 wxChar const DkClockView::windowtypename[] = { wxT("DkClockView") };
48 
49 
50 
DkClockView()51 DkClockView::DkClockView()
52 :
53 cBlack(0, 0, 0),
54 #if defined(__WXMSW__)
55 cRed(127, 0, 0)
56 #else
57 cRed(191, 0, 0)
58 #endif
59 {
60   bUseRed = false;
61   cld = NULL;
62 }
63 
64 
65 
DkClockView(wxWindow * wParent,wxWindowID wid,DkClockData * clockData,const wxPoint & pos,const wxSize & size,long style)66 DkClockView::DkClockView(
67   wxWindow		*wParent,
68   wxWindowID		 wid,
69   DkClockData		*clockData,
70   const wxPoint &	 pos,
71   const wxSize  &	 size,
72   long		 	 style
73 ) : DkWxBufferedControl(
74   wParent,
75   wid,
76   pos,
77   size,
78   (style | wxFULL_REPAINT_ON_RESIZE),
79   wxDefaultValidator,
80   wxString(windowtypename)
81 ),
82 cBlack(0, 0, 0),
83 #if defined(__WXMSW__)
84 cRed(127, 0, 0)
85 #else
86 cRed(191, 0, 0)
87 #endif
88 {
89 
90   bUseRed = false;
91   cld = clockData;
92 
93 }
94 
95 
96 
97 bool
Create(wxWindow * wParent,wxWindowID wid,DkClockData * clockData,const wxPoint & pos,const wxSize & size,long style)98 DkClockView::Create(
99   wxWindow		*wParent,
100   wxWindowID		 wid,
101   DkClockData		*clockData,
102   const wxPoint &	 pos,
103   const wxSize  &	 size,
104   long		 	 style
105 )
106 {
107   bool back;
108   back = DkWxBufferedControl::Create(
109     wParent, wid, pos, size, (style | wxFULL_REPAINT_ON_RESIZE),
110     wxDefaultValidator, wxString(windowtypename)
111   );
112   bUseRed = false;
113   cld = clockData;
114   return back;
115 }
116 
117 
118 
119 void
PaintOperation(wxDC & pdc,wxPaintEvent & WXUNUSED (event),bool WXUNUSED (buffered),int clWidth,int clHeight)120 DkClockView::PaintOperation(
121   wxDC & pdc, wxPaintEvent & WXUNUSED(event),
122   bool WXUNUSED(buffered), int clWidth, int clHeight
123 )
124 {
125   clockview_data_t	clvdata;		/* Clock data. */
126   double		alpha;			/* Current angle in radians. */
127   int			cx;			/* Center x. */
128   int			cy;			/* Center y. */
129   int			ro;			/* Outer radius. */
130   int			rd;			/* Radius 5-minutes dot. */
131   int			rc;			/* Center points radius. */
132   int			ri;			/* Inner radius. */
133   int			lw;			/* Line width of minute dots. */
134   int			r1;			/* Inner radius minute dots. */
135   int			r2;			/* Outer radius minute dots. */
136   int			rs;			/* Radius seconds arrow. */
137   int			rm;			/* Radius minuts arrow. */
138   int			rh;			/* Radius hours arrow. */
139   int			aw;			/* Width minutes and hours. */
140   int			i;			/* Current index. */
141   int			x;			/* Current x. */
142   int			y;			/* Current y. */
143 
144   pdc.SetBackground(*wxWHITE_BRUSH);
145   pdc.Clear();
146   cld->getData(&clvdata);
147   if(clvdata.a) {
148     bUseRed = ((bUseRed) ? false : true);
149   } else {
150     bUseRed = false;
151   }
152   cx = clWidth / 2;
153   cy = clHeight / 2;
154   ro = cx; if(cy < ro) { ro = cy; }
155   ro = (int)(0.95 * (double)ro);
156   rd = (int)(0.0497331 * (double)ro);
157   if(rd < 1) { rd = 1; }
158   rc = ro - rd;
159   if(rc < 0) { rc = 0; }
160   ri = ro - (2 * rd);
161   if(ri < 0) { ri = 0; }
162   lw = rd / 2;
163   if(lw < 1) { lw = 1; }
164   r1 = ri + (lw / 2);
165   r2 = ro - (lw / 2);
166   rs = ri - rd - (lw / 2);
167   if(rs < 1) { rs = 1; }
168   aw = rd;
169   rm = ri - (2 * rd) - (aw / 2);
170   if(rm < 1) { rm = 1; }
171   rh = (int)(0.75 * (double)rm);
172   if(rm < 1) { rh = 1; }
173   /*
174   	5-minute dots.
175   */
176   pdc.SetPen(*wxTRANSPARENT_PEN);
177   if(bUseRed) {
178     pdc.SetBrush(cRed);
179   } else {
180     pdc.SetBrush(cBlack);
181   }
182   for(i = 0; i < 12; i++) {
183     alpha = (2.0 * M_PI * (double)i) / 12.0;
184     x = cx + (int)((double)rc * cos(alpha));
185     y = cy + (int)((double)rc * sin(alpha));
186     pdc.DrawCircle(x, y, rd);
187   }
188   /*
189   	Other minute ticks.
190   */
191   pdc.SetBrush(wxNullBrush);
192   if(bUseRed) {
193     pdc.SetPen(wxPen(cRed, lw));
194   } else{
195     pdc.SetPen(wxPen(cBlack, lw));
196   }
197   for(i = 0; i < 60; i++) {
198     if(i % 5) {
199       alpha = (2.0 * M_PI * (double)i) / 60.0;
200       pdc.DrawLine(
201         (cx + (int)((double)r1 * cos(alpha))),
202 	(cy + (int)((double)r1 * sin(alpha))),
203 	(cx + (int)((double)r2 * cos(alpha))),
204 	(cy + (int)((double)r2 * sin(alpha)))
205       );
206     }
207   }
208   /*
209   	Hours arrow.
210   */
211   pdc.SetBrush(wxNullBrush);
212   if(bUseRed) {
213     pdc.SetPen(wxPen(cRed, aw));
214   } else{
215     pdc.SetPen(wxPen(cBlack, aw));
216   }
217   alpha = M_PI_2 - ((4.0 * M_PI * (double)(clvdata.h)) / 24.0);
218   alpha = alpha - ((M_PI * (double)(clvdata.m)) / 360.0);
219   pdc.DrawLine(
220     cx, cy,
221     (cx + (int)((double)rh * cos(alpha))),
222     (cy - (int)((double)rh * sin(alpha)))
223   );
224   /*
225   	Minutes arrow.
226   */
227   alpha = M_PI_2 - ((2.0 * M_PI * (double)(clvdata.m)) / 60.0);
228   pdc.DrawLine(
229     cx, cy,
230     (cx + (int)((double)rm * cos(alpha))),
231     (cy - (int)((double)rm * sin(alpha)))
232   );
233   /*
234   	Seconds arrow.
235   */
236   pdc.SetBrush(wxNullBrush);
237   if(bUseRed) {
238     pdc.SetPen(wxPen(cRed, lw));
239   } else{
240     pdc.SetPen(wxPen(cBlack, lw));
241   }
242   alpha = M_PI_2 - ((2.0 * M_PI * (int)(clvdata.s)) / 60.0);
243   pdc.DrawLine(
244     cx, cy,
245     (cx + (int)((double)rs * cos(alpha))),
246     (cy - (int)((double)rs * sin(alpha)))
247   );
248   /*
249   	Before leaving the function choose stock objects.
250   */
251   pdc.SetBrush(wxNullBrush);
252   pdc.SetBackground(wxNullBrush);
253   pdc.SetPen(wxNullPen);
254 
255 }
256 
257 
258 
259 void
OnLeftDown(wxMouseEvent & WXUNUSED (event))260 DkClockView::OnLeftDown(wxMouseEvent & WXUNUSED(event))
261 {
262 
263   if(cld) {
264     cld->endAlert();
265     SetMustUpdate();
266     Refresh();
267     Update();
268   }
269 }
270 
271 
272 
273 int
getNormalRed(void) const274 DkClockView::getNormalRed(void) const
275 {
276   int back;
277   back = cBlack.Red();
278   if(back < 0) { back = back + 256; }
279   return back;
280 }
281 
282 
283 
284 int
getNormalGreen(void) const285 DkClockView::getNormalGreen(void) const
286 {
287   int back;
288   back = cBlack.Green();
289   if(back < 0) { back = back + 256; }
290   return back;
291 }
292 
293 
294 
295 int
getNormalBlue(void) const296 DkClockView::getNormalBlue(void) const
297 {
298   int back;
299   back = cBlack.Blue();
300   if(back < 0) { back = back + 256; }
301   return back;
302 }
303 
304 
305 
306 int
getAlertRed(void) const307 DkClockView::getAlertRed(void) const
308 {
309   int back;
310   back = cRed.Red();
311   if(back < 0) { back = back + 256; }
312   return back;
313 }
314 
315 
316 
317 int
getAlertGreen(void) const318 DkClockView::getAlertGreen(void) const
319 {
320   int back;
321   back = cRed.Green();
322   if(back < 0) { back = back + 256; }
323   return back;
324 }
325 
326 
327 
328 int
getAlertBlue(void) const329 DkClockView::getAlertBlue(void) const
330 {
331   int back;
332   back = cRed.Blue();
333   if(back < 0) { back = back + 256; }
334   return back;
335 }
336 
337 
338 
339 void
setNormal(int r,int g,int b)340 DkClockView::setNormal(int r, int g, int b)
341 {
342   cBlack.Set((unsigned char)r, (unsigned char)g, (unsigned char)b);
343 }
344 
345 
346 
347 void
setAlert(int r,int g,int b)348 DkClockView::setAlert(int r, int g, int b)
349 {
350   cRed.Set((unsigned char)r, (unsigned char)g, (unsigned char)b);
351 }
352 
353