~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/clock/winclock.c

Version: ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  *  Clock (winclock.c)
  3  *
  4  *  Copyright 1998 by Marcel Baur <mbaur@g26.ethz.ch>
  5  *
  6  *  This file is based on  rolex.c  by Jim Peterson.
  7  *
  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.
 11  *
 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.
 16  *
 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.
 21  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 25  */
 26 #include "config.h"
 27 #include "wine/port.h"
 28 
 29 #include <math.h>
 30 #include <stdlib.h>
 31 #include <string.h>
 32 #include "windows.h"
 33 #include "winclock.h"
 34 
 35 #define FaceColor (GetSysColor(COLOR_3DFACE))
 36 #define HandColor (GetSysColor(COLOR_3DHIGHLIGHT))
 37 #define TickColor (GetSysColor(COLOR_3DHIGHLIGHT))
 38 #define ShadowColor (GetSysColor(COLOR_3DDKSHADOW))
 39 #define BackgroundColor (GetSysColor(COLOR_3DFACE))
 40 
 41 static const int SHADOW_DEPTH = 2;
 42  
 43 typedef struct
 44 {
 45     POINT Start;
 46     POINT End;
 47 } HandData;
 48 
 49 HandData HourHand, MinuteHand, SecondHand;
 50 
 51 static void DrawTicks(HDC dc, const POINT* centre, int radius)
 52 {
 53     int t;
 54 
 55     /* Minute divisions */
 56     if (radius>64)
 57         for(t=0; t<60; t++) {
 58             MoveToEx(dc,
 59                      centre->x + sin(t*M_PI/30)*0.9*radius,
 60                      centre->y - cos(t*M_PI/30)*0.9*radius,
 61                      NULL);
 62             LineTo(dc,
 63                    centre->x + sin(t*M_PI/30)*0.89*radius,
 64                    centre->y - cos(t*M_PI/30)*0.89*radius);
 65         }
 66 
 67     /* Hour divisions */
 68     for(t=0; t<12; t++) {
 69 
 70         MoveToEx(dc,
 71                  centre->x + sin(t*M_PI/6)*0.9*radius,
 72                  centre->y - cos(t*M_PI/6)*0.9*radius,
 73                  NULL);
 74         LineTo(dc,
 75                centre->x + sin(t*M_PI/6)*0.8*radius,
 76                centre->y - cos(t*M_PI/6)*0.8*radius);
 77     }
 78 }
 79 
 80 static void DrawFace(HDC dc, const POINT* centre, int radius, int border)
 81 {
 82     /* Ticks */
 83     SelectObject(dc, CreatePen(PS_SOLID, 2, ShadowColor));
 84     OffsetWindowOrgEx(dc, -SHADOW_DEPTH, -SHADOW_DEPTH, NULL);
 85     DrawTicks(dc, centre, radius);
 86     DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 2, TickColor)));
 87     OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL);
 88     DrawTicks(dc, centre, radius);
 89     if (border)
 90     {
 91         SelectObject(dc, GetStockObject(NULL_BRUSH));
 92         DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 5, ShadowColor)));
 93         Ellipse(dc, centre->x - radius, centre->y - radius, centre->x + radius, centre->y + radius);
 94     }
 95     DeleteObject(SelectObject(dc, GetStockObject(NULL_PEN)));
 96 }
 97 
 98 static void DrawHand(HDC dc,HandData* hand)
 99 {
100     MoveToEx(dc, hand->Start.x, hand->Start.y, NULL);
101     LineTo(dc, hand->End.x, hand->End.y);
102 }
103 
104 static void DrawHands(HDC dc, BOOL bSeconds)
105 {
106     if (bSeconds) {
107 #if 0
108         SelectObject(dc, CreatePen(PS_SOLID, 1, ShadowColor));
109         OffsetWindowOrgEx(dc, -SHADOW_DEPTH, -SHADOW_DEPTH, NULL);
110         DrawHand(dc, &SecondHand);
111         DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 1, HandColor)));
112         OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL);
113 #else
114         SelectObject(dc, CreatePen(PS_SOLID, 1, HandColor));
115 #endif
116         DrawHand(dc, &SecondHand);
117         DeleteObject(SelectObject(dc, GetStockObject(NULL_PEN)));
118     }
119 
120     SelectObject(dc, CreatePen(PS_SOLID, 4, ShadowColor));
121 
122     OffsetWindowOrgEx(dc, -SHADOW_DEPTH, -SHADOW_DEPTH, NULL);
123     DrawHand(dc, &MinuteHand);
124     DrawHand(dc, &HourHand);
125 
126     DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 4, HandColor)));
127     OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL);
128     DrawHand(dc, &MinuteHand);
129     DrawHand(dc, &HourHand);
130 
131     DeleteObject(SelectObject(dc, GetStockObject(NULL_PEN)));
132 }
133 
134 static void PositionHand(const POINT* centre, double length, double angle, HandData* hand)
135 {
136     hand->Start = *centre;
137     hand->End.x = centre->x + sin(angle)*length;
138     hand->End.y = centre->y - cos(angle)*length;
139 }
140 
141 static void PositionHands(const POINT* centre, int radius, BOOL bSeconds)
142 {
143     SYSTEMTIME st;
144     double hour, minute, second;
145 
146     /* 0 <= hour,minute,second < 2pi */
147     /* Adding the millisecond count makes the second hand move more smoothly */
148 
149     GetLocalTime(&st);
150 
151     second = st.wSecond + st.wMilliseconds/1000.0;
152     minute = st.wMinute + second/60.0;
153     hour   = st.wHour % 12 + minute/60.0;
154 
155     PositionHand(centre, radius * 0.5,  hour/12   * 2*M_PI, &HourHand);
156     PositionHand(centre, radius * 0.65, minute/60 * 2*M_PI, &MinuteHand);
157     if (bSeconds)
158         PositionHand(centre, radius * 0.79, second/60 * 2*M_PI, &SecondHand);  
159 }
160 
161 void AnalogClock(HDC dc, int x, int y, BOOL bSeconds, BOOL border)
162 {
163     POINT centre;
164     int radius;
165     
166     radius = min(x, y)/2 - SHADOW_DEPTH;
167     if (radius < 0)
168         return;
169 
170     centre.x = x/2;
171     centre.y = y/2;
172 
173     DrawFace(dc, &centre, radius, border);
174 
175     PositionHands(&centre, radius, bSeconds);
176     DrawHands(dc, bSeconds);
177 }
178 
179 
180 HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font)
181 {
182     SIZE extent;
183     LOGFONT lf;
184     double xscale, yscale;
185     HFONT oldFont, newFont;
186     CHAR szTime[255];
187     int chars;
188 
189     chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL,
190                           NULL, szTime, sizeof (szTime));
191     if (!chars)
192         return 0;
193 
194     --chars;
195 
196     lf = *font;
197     lf.lfHeight = -20;
198 
199     x -= 2 * SHADOW_DEPTH;
200     y -= 2 * SHADOW_DEPTH;
201 
202     oldFont = SelectObject(dc, CreateFontIndirect(&lf));
203     GetTextExtentPoint(dc, szTime, chars, &extent);
204     DeleteObject(SelectObject(dc, oldFont));
205 
206     xscale = (double)x/extent.cx;
207     yscale = (double)y/extent.cy;
208     lf.lfHeight *= min(xscale, yscale);    
209     newFont = CreateFontIndirect(&lf);
210 
211     return newFont;
212 }
213 
214 void DigitalClock(HDC dc, int x, int y, BOOL bSeconds, HFONT font)
215 {
216     SIZE extent;
217     HFONT oldFont;
218     CHAR szTime[255];
219     int chars;
220 
221     chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL,
222                   NULL, szTime, sizeof (szTime));
223     if (!chars)
224         return;
225     --chars;
226 
227     oldFont = SelectObject(dc, font);
228     GetTextExtentPoint(dc, szTime, chars, &extent);
229 
230     SetBkColor(dc, BackgroundColor);
231     SetTextColor(dc, ShadowColor);
232     TextOut(dc, (x - extent.cx)/2 + SHADOW_DEPTH, (y - extent.cy)/2 + SHADOW_DEPTH,
233             szTime, chars);
234     SetBkMode(dc, TRANSPARENT);
235 
236     SetTextColor(dc, HandColor);
237     TextOut(dc, (x - extent.cx)/2, (y - extent.cy)/2, szTime, chars);
238 
239     SelectObject(dc, oldFont);
240 }
241 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.