@@ -106,6 +106,11 @@ void TimerGraphic::setMaxSecIndex(TimerMax value)
106106 remainSec = restartDefaultSec[maxSecIndex];
107107}
108108
109+ Gdiplus::REAL TimerGraphic::secToDegree (int sec)
110+ {
111+ return sec * 360 .0f / maxSec ();
112+ }
113+
109114bool TimerGraphic::inKnob (HWND hwnd, int x, int y)
110115{
111116 RECT rect;
@@ -295,7 +300,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
295300 SolidBrush indexTextBrush (Color::Black);
296301 Font indexTextFont (L" Segoe UI" , indexTextFontSize);
297302 // Gdiplus::Font indexTextFont(L"Arial", fontSize, FontStyleBold, UnitWorld);
298- RectF indexTextRect (-knobEnd, -bigScaleBegin, 2 * knobEnd, knobEnd);
303+ RectF indexTextRect (-knobEnd, -bigScaleBegin, 2 * knobEnd, knobEnd);
299304 StringFormat indexTextFormat;
300305 indexTextFormat.SetAlignment (StringAlignmentCenter);
301306 indexTextFormat.SetLineAlignment (StringAlignmentCenter);
@@ -318,26 +323,36 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
318323 }
319324
320325 // Pie
321- SolidBrush pieBrush (remainPieColor);
322- REAL remainDegree = -remainSec * 360 .0f / maxSec ();
323- fillDonut (G, &pieBrush, pieBegin, pieEnd, 0 .0f , remainDegree);
324-
325- SolidBrush faintBrush (faintColor (remainPieColor, faintDiv));
326- REAL restartDegree = (maxSec () - restartSec) * 360 .0f / maxSec ();
327- REAL diffDegree = (remainSec - restartSec) * 360 .0f / maxSec ();
328-
329- if (remainSec < restartSec) {
330- fillDonut (G, &faintBrush, pieBegin, pieEnd, restartDegree, -diffDegree);
326+ SolidBrush redPieBrush (remainPieColor);
327+ SolidBrush faintRedBrush (faintColor (remainPieColor, faintDiv));
328+ SolidBrush greenPieBrush (sparePieColor);
329+ SolidBrush faintGreenBrush (faintColor (sparePieColor, faintDiv));
330+
331+ REAL remainDegree = secToDegree (remainSec);
332+ REAL restartDegree = secToDegree (restartSec);
333+
334+ // red pie
335+ if (0 < remainSec && remainSec < restartSec) {
336+ // 0 ~ remain CW
337+ fillDonut (G, &redPieBrush, pieBegin, pieEnd, 0 .0f , -remainDegree);
331338 }
332339
333- if (restartSec < remainSec) {
334- pieBrush.SetColor (sparePieColor);
335- REAL spareDegree = (maxSec () - remainSec) * 360 .0f / maxSec ();
336- fillDonut (G, &pieBrush, pieBegin, pieEnd, spareDegree, diffDegree);
340+ // faint red pie
341+ // restart ~ remain/0 CCW
342+ REAL faintRedDiffDegree = (0 < remainSec) ? restartDegree - remainDegree : restartDegree;
343+ fillDonut (G, &faintRedBrush, pieBegin, pieEnd, -restartDegree, faintRedDiffDegree);
344+
345+ // green pie
346+ // restart ~ spare/0 CW
347+ if (remainSec < 0 ) {
348+ REAL greenDiffDegee = (360 .0f - restartDegree) + remainDegree;
349+ fillDonut (G, &greenPieBrush, pieBegin, pieEnd, -restartDegree, -greenDiffDegee);
337350 }
338351
339- faintBrush.SetColor (faintColor (sparePieColor, faintDiv));
340- fillDonut (G, &faintBrush, pieBegin, pieEnd, 0 , restartDegree);
352+ // faint green pie
353+ // 0 ~ spare CCW
354+ REAL spareDegree = (0 < remainSec) ? (360 .0f - restartDegree) : -remainDegree;
355+ fillDonut (G, &faintGreenBrush, pieBegin, pieEnd, 0 .0f , spareDegree);
341356
342357 // Restart Line
343358 Pen restartPen (blendColor (remainPieColor, sparePieColor), 0 .01f );
@@ -358,7 +373,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
358373 remainTextFormat.SetAlignment (StringAlignmentCenter);
359374 remainTextFormat.SetLineAlignment (StringAlignmentCenter);
360375
361- int oSec = (remainSec <= restartSec ) ? remainSec : (remainSec - restartSec );
376+ int oSec = (0 < remainSec ) ? remainSec : (restartSec - remainSec );
362377 int rHour = oSec / 60 / 60 ;
363378 int rMin = oSec / 60 % 60 ;
364379 int rSec = oSec % 60 ;
0 commit comments