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'.
34 COLORREF FaceColor = RGB(192,192,192);
35 COLORREF HandColor = RGB(0,0,0);
36 COLORREF EtchColor = RGB(0,0,0);
42 HandData OldSecond,OldHour,OldMinute;
48 diff = (Globals.MaxX-Globals.MaxY);
49 if (diff>0) { X = (X-(diff/2)); }
57 diff = (Globals.MaxX-Globals.MaxY);
58 if (diff<0) { Y = Y+(diff/2); }
64 int MidX, MidY, t, DiffX, DiffY;
68 DiffX = (Globals.MaxX-MidX*2)/2;
69 DiffY = (Globals.MaxY-MidY*2)/2;
71 SelectObject(dc,CreateSolidBrush(FaceColor));
72 SelectObject(dc,CreatePen(PS_SOLID,1,EtchColor));
73 Ellipse(dc,DiffX,DiffY,2*MidX+DiffX,2*MidY+DiffY);
77 MoveToEx(dc,(MidX+DiffX)+sin(t*Pi/6)*0.9*MidX,(MidY+DiffY)-cos(t*Pi/6)*0.9*MidY,NULL);
78 LineTo(dc,(MidY+DiffX)+sin(t*Pi/6)*0.8*MidX,(MidY+DiffY)-cos(t*Pi/6)*0.8*MidY);
80 if(Globals.MaxX>64 && Globals.MaxY>64)
82 SetPixel(dc,(MidX+DiffX)+sin(t*Pi/30)*0.9*MidX,(MidY+DiffY)-cos(t*Pi/30)*0.9*MidY
84 DeleteObject(SelectObject(dc,GetStockObject(NULL_BRUSH)));
85 DeleteObject(SelectObject(dc,GetStockObject(NULL_PEN)));
86 memset(&OldSecond,0,sizeof(OldSecond));
87 memset(&OldMinute,0,sizeof(OldMinute));
88 memset(&OldHour,0,sizeof(OldHour));
91 void DrawHourHand(HDC dc)
93 if (OldHour.DontRedraw) return;
94 MoveToEx(dc, OldHour.StartX, OldHour.StartY, NULL);
95 LineTo(dc, OldHour.EndX, OldHour.EndY);
98 void DrawMinuteHand(HDC dc)
100 if (OldMinute.DontRedraw) return;
101 MoveToEx(dc, OldMinute.StartX, OldMinute.StartY, NULL);
102 LineTo(dc, OldMinute.EndX, OldMinute.EndY);
105 void DrawSecondHand(HDC dc)
107 if (OldSecond.DontRedraw) return;
108 MoveToEx(dc, OldSecond.StartX, OldSecond.StartY, NULL);
109 LineTo(dc, OldSecond.EndX, OldSecond.EndY);
112 BOOL UpdateHourHand(HDC dc,int MidX,int MidY,int XExt,int YExt,WORD Pos)
118 Sx = MidX; Sy = MidY;
119 Ex = MidX+sin(Pos*Pi/6000)*XExt;
120 Ey = MidY-cos(Pos*Pi/6000)*YExt;
121 rv = ( Sx!=OldHour.StartX || Ex!=OldHour.EndX ||
122 Sy!=OldHour.StartY || Ey!=OldHour.EndY );
123 if (Globals.bAnalog && rv)DrawHourHand(dc);
124 OldHour.StartX = Sx; OldHour.EndX = Ex;
125 OldHour.StartY = Sy; OldHour.EndY = Ey;
126 OldHour.DontRedraw=FALSE;
130 BOOL UpdateMinuteHand(HDC dc,int MidX,int MidY,int XExt,int YExt,WORD Pos)
136 Sx = MidX; Sy = MidY;
137 Ex = MidX+sin(Pos*Pi/30000)*XExt;
138 Ey = MidY-cos(Pos*Pi/30000)*YExt;
139 rv = ( Sx!=OldMinute.StartX || Ex!=OldMinute.EndX ||
140 Sy!=OldMinute.StartY || Ey!=OldMinute.EndY );
141 if (Globals.bAnalog && rv)DrawMinuteHand(dc);
142 OldMinute.StartX = Sx; OldMinute.EndX = Ex;
143 OldMinute.StartY = Sy; OldMinute.EndY = Ey;
144 OldMinute.DontRedraw=FALSE;
148 BOOL UpdateSecondHand(HDC dc,int MidX,int MidY,int XExt,int YExt,WORD Pos)
155 if (Globals.bSeconds) {
156 Sx = MidX; Sy = MidY;
157 Ex = MidX+sin(Pos*Pi/3000)*XExt;
158 Ey = MidY-cos(Pos*Pi/3000)*YExt;
159 rv = ( Sx!=OldSecond.StartX || Ex!=OldSecond.EndX ||
160 Sy!=OldSecond.StartY || Ey!=OldSecond.EndY );
161 if (Globals.bAnalog && rv) DrawSecondHand(dc);
162 OldSecond.StartX = Sx; OldSecond.EndX = Ex;
163 OldSecond.StartY = Sy; OldSecond.EndY = Ey;
164 OldSecond.DontRedraw=FALSE;
170 void DigitalClock(HDC dc) {
172 CHAR szTime[MAX_STRING_LEN];
174 static short xChar, yChar;
178 LPSYSTEMTIME lpst = &st;
181 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, time,
184 SelectObject(dc,CreatePen(PS_SOLID,1,FaceColor));
185 xChar = tm.tmAveCharWidth;
190 TextOut (dc, xChar, yChar, szTime, strlen (szTime));
191 DeleteObject(SelectObject(dc,GetStockObject(NULL_PEN)));
197 void AnalogClock(HDC dc) {
201 int MidX, MidY, DiffX, DiffY;
207 if (nLastSecond==S) { exit; }
211 F = st.wMilliseconds / 10;
217 DiffX = (Globals.MaxX-MidX*2)/2;
218 DiffY = (Globals.MaxY-MidY*2)/2;
220 SelectObject(dc,CreatePen(PS_SOLID,1,FaceColor));
222 if(UpdateHourHand(dc,MidX+DiffX,MidY+DiffY,MidX*0.5,MidY*0.5,H)) Redraw = TRUE;
223 if(UpdateMinuteHand(dc,MidX+DiffX,MidY+DiffY,MidX*0.65,MidY*0.65,M)) Redraw = TRUE;
224 if(UpdateSecondHand(dc,MidX+DiffX,MidY+DiffY,MidX*0.79,MidY*0.79,F)) Redraw = TRUE;
226 DeleteObject(SelectObject(dc,CreatePen(PS_SOLID,1,HandColor)));
233 DeleteObject(SelectObject(dc,GetStockObject(NULL_PEN)));
244 context=GetDC(Globals.hMainWnd);
246 if (!context) return;
250 AnalogClock(context);
254 DigitalClock(context);
256 if(!idc) ReleaseDC(Globals.hMainWnd, context);