Skip to content

Commit 216779e

Browse files
committed
Fix red pie to shrink first.
1 parent 30c41b8 commit 216779e

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

source/TimerGraphic.cpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
109114
bool 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;

source/TimerGraphic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TimerGraphic
6565
int secFromXY(HWND hwnd, int x, int y);
6666
int maxSec();
6767
void setMaxSecIndex(TimerMax value);
68+
Gdiplus::REAL secToDegree(int sec);
6869

6970
private:
7071
void draw(HDC hdc, int w, int h);

source/TimerWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void TimerWindow::processTime()
158158
case TRM_RESTART_SPARE:
159159
break;
160160
case TRM_ON_THE_HOUR:
161-
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec);
161+
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
162162
break;
163163
}
164164
}

0 commit comments

Comments
 (0)