4 * Copyright 1998 by Marcel Baur <mbaur@g26.ethz.ch>
6 * This file is based on rolex.c by Jim Peterson.
8 * I just managed to move the relevant parts into the Clock application
9 * and made it look like the original Windows one. You can find the original
10 * rolex.c in the wine /libtest directory.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 COLORREF FaceColor
= RGB(192,192,192);
36 COLORREF HandColor
= RGB(0,0,0);
37 COLORREF EtchColor
= RGB(0,0,0);
43 HandData OldSecond
,OldHour
,OldMinute
;
49 diff
= (Globals
.MaxX
-Globals
.MaxY
);
50 if (diff
>0) { X
= (X
-(diff
/2)); }
58 diff
= (Globals
.MaxX
-Globals
.MaxY
);
59 if (diff
<0) { Y
= Y
+(diff
/2); }
65 int MidX
, MidY
, t
, DiffX
, DiffY
;
69 DiffX
= (Globals
.MaxX
-MidX
*2)/2;
70 DiffY
= (Globals
.MaxY
-MidY
*2)/2;
72 SelectObject(dc
,CreateSolidBrush(FaceColor
));
73 SelectObject(dc
,CreatePen(PS_SOLID
,1,EtchColor
));
74 Ellipse(dc
,DiffX
,DiffY
,2*MidX
+DiffX
,2*MidY
+DiffY
);
78 MoveToEx(dc
,(MidX
+DiffX
)+sin(t
*Pi
/6)*0.9*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/6)*0.9*MidY
,NULL
);
79 LineTo(dc
,(MidY
+DiffX
)+sin(t
*Pi
/6)*0.8*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/6)*0.8*MidY
);
81 if(Globals
.MaxX
>64 && Globals
.MaxY
>64)
83 SetPixel(dc
,(MidX
+DiffX
)+sin(t
*Pi
/30)*0.9*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/30)*0.9*MidY
85 DeleteObject(SelectObject(dc
,GetStockObject(NULL_BRUSH
)));
86 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
87 memset(&OldSecond
,0,sizeof(OldSecond
));
88 memset(&OldMinute
,0,sizeof(OldMinute
));
89 memset(&OldHour
,0,sizeof(OldHour
));
92 void DrawHourHand(HDC dc
)
94 if (OldHour
.DontRedraw
) return;
95 MoveToEx(dc
, OldHour
.StartX
, OldHour
.StartY
, NULL
);
96 LineTo(dc
, OldHour
.EndX
, OldHour
.EndY
);
99 void DrawMinuteHand(HDC dc
)
101 if (OldMinute
.DontRedraw
) return;
102 MoveToEx(dc
, OldMinute
.StartX
, OldMinute
.StartY
, NULL
);
103 LineTo(dc
, OldMinute
.EndX
, OldMinute
.EndY
);
106 void DrawSecondHand(HDC dc
)
108 if (OldSecond
.DontRedraw
) return;
109 MoveToEx(dc
, OldSecond
.StartX
, OldSecond
.StartY
, NULL
);
110 LineTo(dc
, OldSecond
.EndX
, OldSecond
.EndY
);
113 BOOL
UpdateHourHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
119 Sx
= MidX
; Sy
= MidY
;
120 Ex
= MidX
+sin(Pos
*Pi
/6000)*XExt
;
121 Ey
= MidY
-cos(Pos
*Pi
/6000)*YExt
;
122 rv
= ( Sx
!=OldHour
.StartX
|| Ex
!=OldHour
.EndX
||
123 Sy
!=OldHour
.StartY
|| Ey
!=OldHour
.EndY
);
124 if (Globals
.bAnalog
&& rv
)DrawHourHand(dc
);
125 OldHour
.StartX
= Sx
; OldHour
.EndX
= Ex
;
126 OldHour
.StartY
= Sy
; OldHour
.EndY
= Ey
;
127 OldHour
.DontRedraw
=FALSE
;
131 BOOL
UpdateMinuteHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
137 Sx
= MidX
; Sy
= MidY
;
138 Ex
= MidX
+sin(Pos
*Pi
/30000)*XExt
;
139 Ey
= MidY
-cos(Pos
*Pi
/30000)*YExt
;
140 rv
= ( Sx
!=OldMinute
.StartX
|| Ex
!=OldMinute
.EndX
||
141 Sy
!=OldMinute
.StartY
|| Ey
!=OldMinute
.EndY
);
142 if (Globals
.bAnalog
&& rv
)DrawMinuteHand(dc
);
143 OldMinute
.StartX
= Sx
; OldMinute
.EndX
= Ex
;
144 OldMinute
.StartY
= Sy
; OldMinute
.EndY
= Ey
;
145 OldMinute
.DontRedraw
=FALSE
;
149 BOOL
UpdateSecondHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
156 if (Globals
.bSeconds
) {
157 Sx
= MidX
; Sy
= MidY
;
158 Ex
= MidX
+sin(Pos
*Pi
/3000)*XExt
;
159 Ey
= MidY
-cos(Pos
*Pi
/3000)*YExt
;
160 rv
= ( Sx
!=OldSecond
.StartX
|| Ex
!=OldSecond
.EndX
||
161 Sy
!=OldSecond
.StartY
|| Ey
!=OldSecond
.EndY
);
162 if (Globals
.bAnalog
&& rv
) DrawSecondHand(dc
);
163 OldSecond
.StartX
= Sx
; OldSecond
.EndX
= Ex
;
164 OldSecond
.StartY
= Sy
; OldSecond
.EndY
= Ey
;
165 OldSecond
.DontRedraw
=FALSE
;
171 void DigitalClock(HDC dc
) {
173 CHAR szTime
[MAX_STRING_LEN
];
175 static short xChar
, yChar
;
179 LPSYSTEMTIME lpst
= &st
;
182 GetTimeFormat(LOCALE_USER_DEFAULT
, LOCALE_STIMEFORMAT
, lpst
, NULL
, time
,
185 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
186 xChar
= tm
.tmAveCharWidth
;
191 TextOut (dc
, xChar
, yChar
, szTime
, strlen (szTime
));
192 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
198 void AnalogClock(HDC dc
) {
202 int MidX
, MidY
, DiffX
, DiffY
;
208 if (nLastSecond
==S
) { exit
; }
212 F
= st
.wMilliseconds
/ 10;
218 DiffX
= (Globals
.MaxX
-MidX
*2)/2;
219 DiffY
= (Globals
.MaxY
-MidY
*2)/2;
221 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
223 if(UpdateHourHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.5,MidY
*0.5,H
)) Redraw
= TRUE
;
224 if(UpdateMinuteHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.65,MidY
*0.65,M
)) Redraw
= TRUE
;
225 if(UpdateSecondHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.79,MidY
*0.79,F
)) Redraw
= TRUE
;
227 DeleteObject(SelectObject(dc
,CreatePen(PS_SOLID
,1,HandColor
)));
234 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
245 context
=GetDC(Globals
.hMainWnd
);
247 if (!context
) return;
251 AnalogClock(context
);
255 DigitalClock(context
);
257 if(!idc
) ReleaseDC(Globals
.hMainWnd
, context
);