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
28 #include "wine/port.h"
37 #define MIN(a,b) (((a)<(b))?(a):(b))
39 COLORREF FaceColor
= RGB(192,192,192);
40 COLORREF HandColor
= RGB(0,0,0);
41 COLORREF EtchColor
= RGB(0,0,0);
49 HandData HourHand
, MinuteHand
, SecondHand
;
51 static void DrawFace(HDC dc
, const POINT
* centre
, int radius
)
55 SelectObject(dc
,CreateSolidBrush(FaceColor
));
56 SelectObject(dc
,CreatePen(PS_SOLID
,1,EtchColor
));
58 centre
->x
- radius
, centre
->y
- radius
,
59 centre
->x
+ radius
, centre
->y
+ radius
);
63 centre
->x
+ sin(t
*M_PI
/6)*0.9*radius
,
64 centre
->y
- cos(t
*M_PI
/6)*0.9*radius
,
67 centre
->x
+ sin(t
*M_PI
/6)*0.8*radius
,
68 centre
->y
- cos(t
*M_PI
/6)*0.8*radius
);
73 centre
->x
+ sin(t
*M_PI
/30)*0.9*radius
,
74 centre
->y
- cos(t
*M_PI
/30)*0.9*radius
,
76 DeleteObject(SelectObject(dc
,GetStockObject(NULL_BRUSH
)));
77 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
80 static void DrawHand(HDC dc
,HandData
* hand
)
82 MoveToEx(dc
, hand
->Start
.x
, hand
->Start
.y
, NULL
);
83 LineTo(dc
, hand
->End
.x
, hand
->End
.y
);
86 static void DrawHands(HDC dc
)
88 SelectObject(dc
,CreatePen(PS_SOLID
,1,HandColor
));
89 DrawHand(dc
, &SecondHand
);
90 DrawHand(dc
, &MinuteHand
);
91 DrawHand(dc
, &HourHand
);
92 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));
95 static void PositionHand(const POINT
* centre
, double length
, double angle
, HandData
* hand
)
97 hand
->Start
= *centre
;
98 hand
->End
.x
= centre
->x
+ sin(angle
)*length
;
99 hand
->End
.y
= centre
->y
- cos(angle
)*length
;
102 static void PositionHands(const POINT
* centre
, int radius
)
105 double hour
, minute
, second
;
107 /* 0 <= hour,minute,second < 2pi */
108 /* Adding the millisecond count makes the second hand move more smoothly */
111 second
= st
.wSecond
+ st
.wMilliseconds
/1000.0;
112 minute
= st
.wMinute
+ second
/60.0;
113 hour
= st
.wHour
% 12 + minute
/60.0;
115 PositionHand(centre
, radius
* 0.5, hour
/12 * 2*M_PI
, &HourHand
);
116 PositionHand(centre
, radius
* 0.65, minute
/60 * 2*M_PI
, &MinuteHand
);
117 PositionHand(centre
, radius
* 0.79, second
/60 * 2*M_PI
, &SecondHand
);
120 void AnalogClock(HDC dc
, int x
, int y
)
124 radius
= MIN(x
, y
)/2;
129 DrawFace(dc
, ¢re
, radius
);
130 PositionHands(¢re
, radius
);
134 void DigitalClock(HDC dc
, int X
, int Y
)
136 /* FIXME - this doesn't work very well */
138 static short xChar
, yChar
;
143 GetTimeFormat(LOCALE_USER_DEFAULT
, LOCALE_STIMEFORMAT
, &st
, NULL
,
144 szTime
, sizeof szTime
);
145 xChar
= tm
.tmAveCharWidth
;
150 SelectObject(dc
,CreatePen(PS_SOLID
,1,FaceColor
));
151 TextOut (dc
, xChar
, yChar
, szTime
, strlen (szTime
));
152 DeleteObject(SelectObject(dc
,GetStockObject(NULL_PEN
)));