Skip to content

Commit

Permalink
Fix red pie to shrink first.
Browse files Browse the repository at this point in the history
  • Loading branch information
bugiii committed Mar 18, 2019
1 parent 30c41b8 commit 216779e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
51 changes: 33 additions & 18 deletions source/TimerGraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ void TimerGraphic::setMaxSecIndex(TimerMax value)
remainSec = restartDefaultSec[maxSecIndex];
}

Gdiplus::REAL TimerGraphic::secToDegree(int sec)
{
return sec * 360.0f / maxSec();
}

bool TimerGraphic::inKnob(HWND hwnd, int x, int y)
{
RECT rect;
Expand Down Expand Up @@ -295,7 +300,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
SolidBrush indexTextBrush(Color::Black);
Font indexTextFont(L"Segoe UI", indexTextFontSize);
//Gdiplus::Font indexTextFont(L"Arial", fontSize, FontStyleBold, UnitWorld);
RectF indexTextRect(-knobEnd, -bigScaleBegin, 2*knobEnd, knobEnd);
RectF indexTextRect(-knobEnd, -bigScaleBegin, 2 * knobEnd, knobEnd);
StringFormat indexTextFormat;
indexTextFormat.SetAlignment(StringAlignmentCenter);
indexTextFormat.SetLineAlignment(StringAlignmentCenter);
Expand All @@ -318,26 +323,36 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
}

// Pie
SolidBrush pieBrush(remainPieColor);
REAL remainDegree = -remainSec * 360.0f / maxSec();
fillDonut(G, &pieBrush, pieBegin, pieEnd, 0.0f, remainDegree);

SolidBrush faintBrush(faintColor(remainPieColor, faintDiv));
REAL restartDegree = (maxSec() - restartSec) * 360.0f / maxSec();
REAL diffDegree = (remainSec - restartSec) * 360.0f / maxSec();

if (remainSec < restartSec) {
fillDonut(G, &faintBrush, pieBegin, pieEnd, restartDegree, -diffDegree);
SolidBrush redPieBrush(remainPieColor);
SolidBrush faintRedBrush(faintColor(remainPieColor, faintDiv));
SolidBrush greenPieBrush(sparePieColor);
SolidBrush faintGreenBrush(faintColor(sparePieColor, faintDiv));

REAL remainDegree = secToDegree(remainSec);
REAL restartDegree = secToDegree(restartSec);

// red pie
if (0 < remainSec && remainSec < restartSec) {
// 0 ~ remain CW
fillDonut(G, &redPieBrush, pieBegin, pieEnd, 0.0f, -remainDegree);
}

if (restartSec < remainSec) {
pieBrush.SetColor(sparePieColor);
REAL spareDegree = (maxSec() - remainSec) * 360.0f / maxSec();
fillDonut(G, &pieBrush, pieBegin, pieEnd, spareDegree, diffDegree);
// faint red pie
// restart ~ remain/0 CCW
REAL faintRedDiffDegree = (0 < remainSec) ? restartDegree - remainDegree : restartDegree;
fillDonut(G, &faintRedBrush, pieBegin, pieEnd, -restartDegree, faintRedDiffDegree);

// green pie
// restart ~ spare/0 CW
if (remainSec < 0) {
REAL greenDiffDegee = (360.0f - restartDegree) + remainDegree;
fillDonut(G, &greenPieBrush, pieBegin, pieEnd, -restartDegree, -greenDiffDegee);
}

faintBrush.SetColor(faintColor(sparePieColor, faintDiv));
fillDonut(G, &faintBrush, pieBegin, pieEnd, 0, restartDegree);
// faint green pie
// 0 ~ spare CCW
REAL spareDegree = (0 < remainSec) ? (360.0f - restartDegree) : -remainDegree;
fillDonut(G, &faintGreenBrush, pieBegin, pieEnd, 0.0f, spareDegree);

// Restart Line
Pen restartPen(blendColor(remainPieColor, sparePieColor), 0.01f);
Expand All @@ -358,7 +373,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h)
remainTextFormat.SetAlignment(StringAlignmentCenter);
remainTextFormat.SetLineAlignment(StringAlignmentCenter);

int oSec = (remainSec <= restartSec) ? remainSec : (remainSec - restartSec);
int oSec = (0 < remainSec) ? remainSec : (restartSec - remainSec);
int rHour = oSec / 60 / 60;
int rMin = oSec / 60 % 60;
int rSec = oSec % 60;
Expand Down
1 change: 1 addition & 0 deletions source/TimerGraphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TimerGraphic
int secFromXY(HWND hwnd, int x, int y);
int maxSec();
void setMaxSecIndex(TimerMax value);
Gdiplus::REAL secToDegree(int sec);

private:
void draw(HDC hdc, int w, int h);
Expand Down
2 changes: 1 addition & 1 deletion source/TimerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void TimerWindow::processTime()
case TRM_RESTART_SPARE:
break;
case TRM_ON_THE_HOUR:
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec);
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
break;
}
}
Expand Down

0 comments on commit 216779e

Please sign in to comment.