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 * Original file header:
14 * > rolex.c: Windows clock application for WINE (by Jim Peterson)
16 * > This is a translation of a Turbo Pascal OWL application I made
17 * > once, so it's a little flaky (tons of globals, functions that
18 * > could have been in-lined, etc.). The source code should easily
19 * > compile with a standard Win32 C compiler.
21 * > To try it out, type 'make rolex'.
33 COLORREF FaceColor
= RGB(192,192,192);
34 COLORREF HandColor
= RGB(0,0,0);
35 COLORREF EtchColor
= RGB(0,0,0);
41 HandData OldSecond
,OldHour
,OldMinute
;
47 diff
= (Globals
.MaxX
-Globals
.MaxY
);
48 if (diff
>0) { X
= (X
-(diff
/2)); }
56 diff
= (Globals
.MaxX
-Globals
.MaxY
);
57 if (diff
<0) { Y
= Y
+(diff
/2); }
63 int MidX
, MidY
, t
, DiffX
, DiffY
;
67 DiffX
= (Globals
.MaxX
-MidX
*2)/2;
68 DiffY
= (Globals
.MaxY
-MidY
*2)/2;
70 SelectObject(dc
,CreateSolidBrush(FaceColor
));
71 SelectObject(dc
,CreatePen(PS_SOLID
,1,EtchColor
));
72 Ellipse(dc
,DiffX
,DiffY
,2*MidX
+DiffX
,2*MidY
+DiffY
);
76 MoveToEx(dc
,(MidX
+DiffX
)+sin(t
*Pi
/6)*0.9*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/6)*0.9*MidY
,NULL
);
77 LineTo(dc
,(MidY
+DiffX
)+sin(t
*Pi
/6)*0.8*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/6)*0.8*MidY
);
79 if(Globals
.MaxX
>64 && Globals
.MaxY
>64)
81 SetPixel(dc
,(MidX
+DiffX
)+sin(t
*Pi
/30)*0.9*MidX
,(MidY
+DiffY
)-cos(t
*Pi
/30)*0.9*MidY
83 DeleteObject(SelectObject(dc
,GetStockObject(NULL_BRUSH
)));
84 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
85 memset(&OldSecond
,0,sizeof(OldSecond
));
86 memset(&OldMinute
,0,sizeof(OldMinute
));
87 memset(&OldHour
,0,sizeof(OldHour
));
90 void DrawHourHand(HDC dc
)
92 if (OldHour
.DontRedraw
) return;
93 MoveToEx(dc
, OldHour
.StartX
, OldHour
.StartY
, NULL
);
94 LineTo(dc
, OldHour
.EndX
, OldHour
.EndY
);
97 void DrawMinuteHand(HDC dc
)
99 if (OldMinute
.DontRedraw
) return;
100 MoveToEx(dc
, OldMinute
.StartX
, OldMinute
.StartY
, NULL
);
101 LineTo(dc
, OldMinute
.EndX
, OldMinute
.EndY
);
104 void DrawSecondHand(HDC dc
)
106 if (OldSecond
.DontRedraw
) return;
107 MoveToEx(dc
, OldSecond
.StartX
, OldSecond
.StartY
, NULL
);
108 LineTo(dc
, OldSecond
.EndX
, OldSecond
.EndY
);
111 BOOL
UpdateHourHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
117 Sx
= MidX
; Sy
= MidY
;
118 Ex
= MidX
+sin(Pos
*Pi
/6000)*XExt
;
119 Ey
= MidY
-cos(Pos
*Pi
/6000)*YExt
;
120 rv
= ( Sx
!=OldHour
.StartX
|| Ex
!=OldHour
.EndX
||
121 Sy
!=OldHour
.StartY
|| Ey
!=OldHour
.EndY
);
122 if (Globals
.bAnalog
&& rv
)DrawHourHand(dc
);
123 OldHour
.StartX
= Sx
; OldHour
.EndX
= Ex
;
124 OldHour
.StartY
= Sy
; OldHour
.EndY
= Ey
;
125 OldHour
.DontRedraw
=FALSE
;
129 BOOL
UpdateMinuteHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
135 Sx
= MidX
; Sy
= MidY
;
136 Ex
= MidX
+sin(Pos
*Pi
/30000)*XExt
;
137 Ey
= MidY
-cos(Pos
*Pi
/30000)*YExt
;
138 rv
= ( Sx
!=OldMinute
.StartX
|| Ex
!=OldMinute
.EndX
||
139 Sy
!=OldMinute
.StartY
|| Ey
!=OldMinute
.EndY
);
140 if (Globals
.bAnalog
&& rv
)DrawMinuteHand(dc
);
141 OldMinute
.StartX
= Sx
; OldMinute
.EndX
= Ex
;
142 OldMinute
.StartY
= Sy
; OldMinute
.EndY
= Ey
;
143 OldMinute
.DontRedraw
=FALSE
;
147 BOOL
UpdateSecondHand(HDC dc
,int MidX
,int MidY
,int XExt
,int YExt
,WORD Pos
)
154 if (Globals
.bSeconds
) {
155 Sx
= MidX
; Sy
= MidY
;
156 Ex
= MidX
+sin(Pos
*Pi
/3000)*XExt
;
157 Ey
= MidY
-cos(Pos
*Pi
/3000)*YExt
;
158 rv
= ( Sx
!=OldSecond
.StartX
|| Ex
!=OldSecond
.EndX
||
159 Sy
!=OldSecond
.StartY
|| Ey
!=OldSecond
.EndY
);
160 if (Globals
.bAnalog
&& rv
) DrawSecondHand(dc
);
161 OldSecond
.StartX
= Sx
; OldSecond
.EndX
= Ex
;
162 OldSecond
.StartY
= Sy
; OldSecond
.EndY
= Ey
;
163 OldSecond
.DontRedraw
=FALSE
;
169 void DigitalClock(HDC dc
) {
171 CHAR szTime
[MAX_STRING_LEN
];
173 static short xChar
, yChar
;
177 LPSYSTEMTIME lpst
= &st
;
180 GetTimeFormat(LOCALE_USER_DEFAULT
, LOCALE_STIMEFORMAT
, lpst
, NULL
, time
,
183 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
184 xChar
= tm
.tmAveCharWidth
;
189 TextOut (dc
, xChar
, yChar
, szTime
, strlen (szTime
));
190 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
196 void AnalogClock(HDC dc
) {
200 int MidX
, MidY
, DiffX
, DiffY
;
206 if (nLastSecond
==S
) { exit
; }
210 F
= st
.wMilliseconds
/ 10;
216 DiffX
= (Globals
.MaxX
-MidX
*2)/2;
217 DiffY
= (Globals
.MaxY
-MidY
*2)/2;
219 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
221 if(UpdateHourHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.5,MidY
*0.5,H
)) Redraw
= TRUE
;
222 if(UpdateMinuteHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.65,MidY
*0.65,M
)) Redraw
= TRUE
;
223 if(UpdateSecondHand(dc
,MidX
+DiffX
,MidY
+DiffY
,MidX
*0.79,MidY
*0.79,F
)) Redraw
= TRUE
;
225 DeleteObject(SelectObject(dc
,CreatePen(PS_SOLID
,1,HandColor
)));
232 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
243 context
=GetDC(Globals
.hMainWnd
);
245 if (!context
) return;
249 AnalogClock(context
);
253 DigitalClock(context
);
255 if(!idc
) ReleaseDC(Globals
.hMainWnd
, context
);