@@ -64,6 +64,7 @@ GdiPlusInit::~GdiPlusInit() {
6464
6565TimerGraphic::TimerGraphic (const std::string& id) :
6666 id_(id),
67+ repeatMode(TRM_ON_THE_HOUR ),
6768 maxSecIndex(TM_60 ),
6869 restartSec(restartDefaultSec[maxSecIndex]),
6970 remainSec(restartDefaultSec[maxSecIndex]),
@@ -75,8 +76,8 @@ TimerGraphic::TimerGraphic(const std::string& id) :
7576 pieEnd(0 .95f ),
7677 scaleColor(alpha, 96 , 96 , 96 ),
7778 smallScaleThickness(0 .01f ),
78- smallScaleBegin(0 .975f ),
79- smallScaleEnd(1 . 0f ),
79+ smallScaleBegin(0 .925f ),
80+ smallScaleEnd(0 . 975f ),
8081 bigScaleThickness(0 .02f ),
8182 bigScaleBegin(0 .90f ),
8283 bigScaleEnd(1 .0f ),
@@ -176,6 +177,7 @@ static void fillCircle(Graphics& G, Brush* brush, REAL r)
176177 G.FillEllipse (brush, -r, -r, 2 *r, 2 *r);
177178}
178179
180+ // CCW s ~ e
179181static void fillDonut (Graphics& G, Brush* brush, REAL r1, REAL r2, REAL s, REAL e)
180182{
181183 GraphicsPath gp (Gdiplus::FillModeAlternate);
@@ -328,17 +330,47 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
328330 SolidBrush greenPieBrush (sparePieColor);
329331 SolidBrush faintGreenBrush (faintColor (sparePieColor, faintDiv));
330332
333+ int spareSec = maxSec () - restartSec;
331334 REAL remainDegree = secToDegree (remainSec);
332335 REAL restartDegree = secToDegree (restartSec);
336+ // REAL remainDegreeReverse = 360.0f - remainDegree;
337+ REAL restartDegreeReverse = 360 .0f - restartDegree;
338+
339+ if (TRM_ON_THE_HOUR == repeatMode) {
340+ // red pie
341+ if (remainSec < restartSec) {
342+ // 0 --> restart
343+ fillDonut (G, &redPieBrush, pieBegin, pieEnd, restartDegreeReverse, 360 .0f - remainDegree - restartDegreeReverse);
344+ }
345+
346+ // faint red pie
347+ // 0 --> remain/restart
348+ REAL faintRedDegree = (restartSec < remainSec) ? restartDegree : remainDegree;
349+ fillDonut (G, &faintRedBrush, pieBegin, pieEnd, 0 .0f , -faintRedDegree);
350+
351+ // green pie
352+ if (restartSec < remainSec) {
353+ // spare --> 0
354+ REAL spareDegree = secToDegree (spareSec - (remainSec - restartSec));
355+ fillDonut (G, &greenPieBrush, pieBegin, pieEnd, 0 .0f , spareDegree);
356+ }
357+
358+ // faint green pie
359+ // restart --> spare
360+ REAL spareDegree = (remainSec < restartSec) ? restartDegreeReverse : secToDegree (spareSec - (maxSec () - remainSec));
361+ fillDonut (G, &faintGreenBrush, pieBegin, pieEnd, restartDegreeReverse, -spareDegree);
362+ }
333363
364+ #if 0
334365 // red pie
335366 if (0 < remainSec && remainSec < restartSec) {
336- // 0 ~ remain CW
337- fillDonut (G, &redPieBrush, pieBegin, pieEnd, 0 .0f , -remainDegree);
367+ // 0 ~ remain
368+ fillDonut(G, &redPieBrush, pieBegin, pieEnd, 1 .0f, -remainDegree);
338369 }
339370
371+
340372 // faint red pie
341- // restart ~ remain/0 CCW
373+ // remain/0 ~ restart
342374 REAL faintRedDiffDegree = (0 < remainSec) ? restartDegree - remainDegree : restartDegree;
343375 fillDonut(G, &faintRedBrush, pieBegin, pieEnd, -restartDegree, faintRedDiffDegree);
344376
@@ -353,6 +385,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
353385 // 0 ~ spare CCW
354386 REAL spareDegree = (0 < remainSec) ? (360.0f - restartDegree) : -remainDegree;
355387 fillDonut(G, &faintGreenBrush, pieBegin, pieEnd, 0.0f, spareDegree);
388+ #endif
356389
357390 // Restart Line
358391 Pen restartPen (blendColor (remainPieColor, sparePieColor), 0 .01f );
@@ -373,7 +406,14 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
373406 remainTextFormat.SetAlignment (StringAlignmentCenter);
374407 remainTextFormat.SetLineAlignment (StringAlignmentCenter);
375408
376- int oSec = (0 < remainSec) ? remainSec : (restartSec - remainSec);
409+ int oSec;
410+
411+ if (TRM_ON_THE_HOUR == repeatMode) {
412+ oSec = (remainSec < restartSec) ? restartSec - remainSec : spareSec - (remainSec - restartSec);
413+ }
414+ else {
415+ oSec = (0 < remainSec) ? remainSec : (restartSec - remainSec);
416+ }
377417 int rHour = oSec / 60 / 60 ;
378418 int rMin = oSec / 60 % 60 ;
379419 int rSec = oSec % 60 ;
@@ -400,6 +440,10 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
400440 GetLocalTime (&time);
401441 drawString (G, &remainTextFont, -0 .5f , 90 .0f , &remainTextFormat, &remainTextBrush,
402442 L" %2d:%02d" , time.wHour , time.wMinute );
443+ #if 0
444+ drawString(G, &remainTextFont, -0.7f, 90.0f, &remainTextFormat, &remainTextBrush,
445+ L"%3d %3d", remainSec / 60, restartSec / 60);
446+ #endif
403447
404448 G.Flush ();
405449}
0 commit comments