1 //------------------------------------------------------------------------------
2 // emClockHandsPanel.cpp
3 //
4 // Copyright (C) 2006-2008,2016 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20 
21 #include <emClock/emClockHandsPanel.h>
22 
23 
emClockHandsPanel(ParentArg parent,const emString & name,emColor fgColor)24 emClockHandsPanel::emClockHandsPanel(
25 	ParentArg parent, const emString & name, emColor fgColor
26 )
27 	: emPanel(parent,name)
28 {
29 	FgColor=fgColor;
30 	Hour=0;
31 	Minute=0;
32 	Second=0;
33 	SetFocusable(false);
34 }
35 
36 
~emClockHandsPanel()37 emClockHandsPanel::~emClockHandsPanel()
38 {
39 }
40 
41 
SetFgColor(emColor fgColor)42 void emClockHandsPanel::SetFgColor(emColor fgColor)
43 {
44 	FgColor=fgColor;
45 	InvalidatePainting();
46 }
47 
48 
SetTime(int hour,int minute,int second)49 void emClockHandsPanel::SetTime(int hour, int minute, int second)
50 {
51 	if (Hour!=hour || Minute!=minute || Second!=second) {
52 		Hour=hour;
53 		Minute=minute;
54 		Second=second;
55 		InvalidatePainting();
56 	}
57 }
58 
59 
IsOpaque() const60 bool emClockHandsPanel::IsOpaque() const
61 {
62 	return false;
63 }
64 
65 
Paint(const emPainter & painter,emColor canvasColor) const66 void emClockHandsPanel::Paint(
67 	const emPainter & painter, emColor canvasColor
68 ) const
69 {
70 	double hxy[5*2];
71 	double mxy[5*2];
72 	double sxy[4*2];
73 	double u,v,a,cx,cy,r,dx,dy,shx,shy,smx,smy,ssx,ssy;
74 	emColor color,shadow;
75 	int i;
76 
77 	u=emMin(GetViewedWidth(),GetViewedHeight());
78 	v=emMin(GetView().GetCurrentWidth(),GetView().GetCurrentHeight());
79 	a=(v/u*0.75-0.08)*255.0;
80 	if (a<=0.0) return;
81 	if (a>255.0) a=255.0;
82 	shadow=emColor(0,0,0,(emByte)(a*0.2));
83 	color=FgColor;
84 	color.SetAlpha((emByte)a);
85 
86 	cx=0.5;
87 	cy=GetHeight()*0.5;
88 	r=emMin(cx,cy);
89 
90 	shx=r*0.010;
91 	shy=r*0.015;
92 	smx=r*0.016;
93 	smy=r*0.024;
94 	ssx=r*0.020;
95 	ssy=r*0.030;
96 
97 	dx=r*sin((Hour+Minute/60.0+Second/3600.0)*M_PI/6.0);
98 	dy=-r*cos((Hour+Minute/60.0+Second/3600.0)*M_PI/6.0);
99 	hxy[0]=cx+shx-0.100*dx+0.039*dy;
100 	hxy[1]=cy+shy-0.100*dy-0.039*dx;
101 	hxy[2]=cx+shx-0.100*dx-0.039*dy;
102 	hxy[3]=cy+shy-0.100*dy+0.039*dx;
103 	hxy[4]=cx+shx+0.530*dx-0.039*dy;
104 	hxy[5]=cy+shy+0.530*dy+0.039*dx;
105 	hxy[6]=cx+shx+0.610*dx;
106 	hxy[7]=cy+shy+0.610*dy;
107 	hxy[8]=cx+shx+0.530*dx+0.039*dy;
108 	hxy[9]=cy+shy+0.530*dy-0.039*dx;
109 
110 	dx=r*sin((Minute+Second/60.0)*M_PI/30.0);
111 	dy=-r*cos((Minute+Second/60.0)*M_PI/30.0);
112 	mxy[0]=cx+smx-0.100*dx+0.035*dy;
113 	mxy[1]=cy+smy-0.100*dy-0.035*dx;
114 	mxy[2]=cx+smx-0.100*dx-0.035*dy;
115 	mxy[3]=cy+smy-0.100*dy+0.035*dx;
116 	mxy[4]=cx+smx+0.910*dx-0.035*dy;
117 	mxy[5]=cy+smy+0.910*dy+0.035*dx;
118 	mxy[6]=cx+smx+0.960*dx;
119 	mxy[7]=cy+smy+0.960*dy;
120 	mxy[8]=cx+smx+0.910*dx+0.035*dy;
121 	mxy[9]=cy+smy+0.910*dy-0.035*dx;
122 
123 	dx=r*sin(Second*M_PI/30.0);
124 	dy=-r*cos(Second*M_PI/30.0);
125 	sxy[0]=cx+ssx-0.150*dx+0.008*dy;
126 	sxy[1]=cy+ssy-0.150*dy-0.008*dx;
127 	sxy[2]=cx+ssx-0.150*dx-0.008*dy;
128 	sxy[3]=cy+ssy-0.150*dy+0.008*dx;
129 	sxy[4]=cx+ssx+1.000*dx-0.008*dy;
130 	sxy[5]=cy+ssy+1.000*dy+0.008*dx;
131 	sxy[6]=cx+ssx+1.000*dx+0.008*dy;
132 	sxy[7]=cy+ssy+1.000*dy-0.008*dx;
133 
134 	painter.PaintPolygon(hxy,5,shadow);
135 	painter.PaintPolygon(mxy,5,shadow);
136 	painter.PaintPolygon(sxy,4,shadow);
137 
138 	for (i=0; i<5; i++) { hxy[i*2]-=shx; hxy[i*2+1]-=shy; }
139 	for (i=0; i<5; i++) { mxy[i*2]-=smx; mxy[i*2+1]-=smy; }
140 	for (i=0; i<4; i++) { sxy[i*2]-=ssx; sxy[i*2+1]-=ssy; }
141 
142 	painter.PaintPolygon(hxy,5,color);
143 	painter.PaintPolygon(mxy,5,color);
144 	painter.PaintPolygon(sxy,4,color);
145 }
146