diff --git a/source/TimerGraphic.cpp b/source/TimerGraphic.cpp index bee95c2..180c294 100644 --- a/source/TimerGraphic.cpp +++ b/source/TimerGraphic.cpp @@ -64,6 +64,7 @@ GdiPlusInit::~GdiPlusInit() { TimerGraphic::TimerGraphic(const std::string& id) : id_(id), + repeatMode(TRM_ON_THE_HOUR), maxSecIndex(TM_60), restartSec(restartDefaultSec[maxSecIndex]), remainSec(restartDefaultSec[maxSecIndex]), @@ -75,8 +76,8 @@ TimerGraphic::TimerGraphic(const std::string& id) : pieEnd(0.95f), scaleColor(alpha, 96, 96, 96), smallScaleThickness(0.01f), - smallScaleBegin(0.975f), - smallScaleEnd(1.0f), + smallScaleBegin(0.925f), + smallScaleEnd(0.975f), bigScaleThickness(0.02f), bigScaleBegin(0.90f), bigScaleEnd(1.0f), @@ -176,6 +177,7 @@ static void fillCircle(Graphics& G, Brush* brush, REAL r) G.FillEllipse(brush, -r, -r, 2*r, 2*r); } +// CCW s ~ e static void fillDonut(Graphics& G, Brush* brush, REAL r1, REAL r2, REAL s, REAL e) { GraphicsPath gp(Gdiplus::FillModeAlternate); @@ -328,17 +330,47 @@ void TimerGraphic::draw(HDC hdc, int w, int h) SolidBrush greenPieBrush(sparePieColor); SolidBrush faintGreenBrush(faintColor(sparePieColor, faintDiv)); + int spareSec = maxSec() - restartSec; REAL remainDegree = secToDegree(remainSec); REAL restartDegree = secToDegree(restartSec); + //REAL remainDegreeReverse = 360.0f - remainDegree; + REAL restartDegreeReverse = 360.0f - restartDegree; + + if (TRM_ON_THE_HOUR == repeatMode) { + // red pie + if (remainSec < restartSec) { + // 0 --> restart + fillDonut(G, &redPieBrush, pieBegin, pieEnd, restartDegreeReverse, 360.0f - remainDegree - restartDegreeReverse); + } + + // faint red pie + // 0 --> remain/restart + REAL faintRedDegree = (restartSec < remainSec) ? restartDegree : remainDegree; + fillDonut(G, &faintRedBrush, pieBegin, pieEnd, 0.0f, -faintRedDegree); + + // green pie + if (restartSec < remainSec) { + // spare --> 0 + REAL spareDegree = secToDegree(spareSec - (remainSec - restartSec)); + fillDonut(G, &greenPieBrush, pieBegin, pieEnd, 0.0f, spareDegree); + } + + // faint green pie + // restart --> spare + REAL spareDegree = (remainSec < restartSec) ? restartDegreeReverse : secToDegree(spareSec - (maxSec() - remainSec)); + fillDonut(G, &faintGreenBrush, pieBegin, pieEnd, restartDegreeReverse, -spareDegree); + } +#if 0 // red pie if (0 < remainSec && remainSec < restartSec) { - // 0 ~ remain CW - fillDonut(G, &redPieBrush, pieBegin, pieEnd, 0.0f, -remainDegree); + // 0 ~ remain + fillDonut(G, &redPieBrush, pieBegin, pieEnd, 1.0f, -remainDegree); } + // faint red pie - // restart ~ remain/0 CCW + // remain/0 ~ restart REAL faintRedDiffDegree = (0 < remainSec) ? restartDegree - remainDegree : restartDegree; fillDonut(G, &faintRedBrush, pieBegin, pieEnd, -restartDegree, faintRedDiffDegree); @@ -353,6 +385,7 @@ void TimerGraphic::draw(HDC hdc, int w, int h) // 0 ~ spare CCW REAL spareDegree = (0 < remainSec) ? (360.0f - restartDegree) : -remainDegree; fillDonut(G, &faintGreenBrush, pieBegin, pieEnd, 0.0f, spareDegree); +#endif // Restart Line Pen restartPen(blendColor(remainPieColor, sparePieColor), 0.01f); @@ -373,7 +406,14 @@ void TimerGraphic::draw(HDC hdc, int w, int h) remainTextFormat.SetAlignment(StringAlignmentCenter); remainTextFormat.SetLineAlignment(StringAlignmentCenter); - int oSec = (0 < remainSec) ? remainSec : (restartSec - remainSec); + int oSec; + + if (TRM_ON_THE_HOUR == repeatMode) { + oSec = (remainSec < restartSec) ? restartSec - remainSec : spareSec - (remainSec - restartSec); + } + else { + oSec = (0 < remainSec) ? remainSec : (restartSec - remainSec); + } int rHour = oSec / 60 / 60; int rMin = oSec / 60 % 60; int rSec = oSec % 60; @@ -400,6 +440,10 @@ void TimerGraphic::draw(HDC hdc, int w, int h) GetLocalTime(&time); drawString(G, &remainTextFont, -0.5f, 90.0f, &remainTextFormat, &remainTextBrush, L"%2d:%02d", time.wHour, time.wMinute); +#if 0 + drawString(G, &remainTextFont, -0.7f, 90.0f, &remainTextFormat, &remainTextBrush, + L"%3d %3d", remainSec / 60, restartSec / 60); +#endif G.Flush(); } diff --git a/source/TimerGraphic.h b/source/TimerGraphic.h index f1fdc2d..ab5755f 100644 --- a/source/TimerGraphic.h +++ b/source/TimerGraphic.h @@ -20,6 +20,13 @@ class GdiPlusInit /////////////////////////////////////////////////////////////////////////////// +enum TimerRepeatMode { + TRM_NONE, + TRM_RESTART, + TRM_RESTART_SPARE, + TRM_ON_THE_HOUR +}; + enum TimerMax { TM_5 = 0, @@ -72,6 +79,7 @@ class TimerGraphic public: const std::string& id_; + TimerRepeatMode repeatMode; TimerMax maxSecIndex; int restartSec; int remainSec; diff --git a/source/TimerWindow.cpp b/source/TimerWindow.cpp index 8251495..6fdc627 100644 --- a/source/TimerWindow.cpp +++ b/source/TimerWindow.cpp @@ -9,7 +9,7 @@ namespace bugiii_timer_window { ATOM classAtom_ = 0; int windowCount_ = 0; const int timerPeriod = debug ? 100 : 1000; - const int timeDiv = debug ? 100 : 10000; + const int timeDiv = debug ? 10 : 10000; } using namespace bugiii_timer_window; @@ -26,7 +26,6 @@ TimerWindow::TimerWindow(const std::string& id) : hwnd_(0), graph_(new TimerGraphic(id)), captured_(false), - repeatMode_(TRM_ON_THE_HOUR), startTime_(setupStartTime()), zoom_() { @@ -135,7 +134,7 @@ uint64_t TimerWindow::setupStartTime() { uint64_t time = currentTime(); - if (TRM_ON_THE_HOUR == repeatMode_) { + if (TRM_ON_THE_HOUR == graph_->repeatMode) { //uint64_t maxTime = graph_->maxSec() * 1000ULL/*ms*/ / timeDiv; //time = time / maxTime * maxTime; // nomalized to the max time uint64_t maxTime = 60 * 60 * 1000ULL/*ms*/ / timeDiv; // one hour @@ -147,18 +146,19 @@ uint64_t TimerWindow::setupStartTime() void TimerWindow::processTime() { - uint64_t diffSec = (currentTime() - graph_->restartSec) / 1000ULL/*ms*/ / timeDiv; + uint64_t diffSec = (currentTime() - graph_->restartSec) / 1000ULL/*ms*/ / timeDiv; //??? unit ??? uint64_t modSec = diffSec % graph_->maxSec(); - switch (repeatMode_) { + switch (graph_->repeatMode) { case TRM_NONE: break; case TRM_RESTART: break; case TRM_RESTART_SPARE: + graph_->remainSec = graph_->maxSec() - static_cast(modSec) - (graph_->maxSec() - graph_->restartSec); break; case TRM_ON_THE_HOUR: - graph_->remainSec = graph_->maxSec() - static_cast(modSec) - (graph_->maxSec() - graph_->restartSec); + graph_->remainSec = currentTime() / 1000ULL / timeDiv % graph_->maxSec(); break; } } diff --git a/source/TimerWindow.h b/source/TimerWindow.h index 5b73276..82ba2c6 100644 --- a/source/TimerWindow.h +++ b/source/TimerWindow.h @@ -1,15 +1,7 @@ #pragma once #include - -class TimerGraphic; - -enum TimerRepeatMode { - TRM_NONE, - TRM_RESTART, - TRM_RESTART_SPARE, - TRM_ON_THE_HOUR -}; +#include "TimerGraphic.h" class TimerWindow { @@ -49,7 +41,6 @@ class TimerWindow HWND hwnd_; TimerGraphic* graph_; bool captured_; - TimerRepeatMode repeatMode_; uint64_t startTime_; // must be after repeatMode_ Zoom zoom_; }; diff --git a/source/Utils.cpp b/source/Utils.cpp index 499955c..b0da912 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -67,8 +67,8 @@ BOOL stickSide(HWND hwnd, LPWINDOWPOS lpwpos) // using current mouse x y POINT p; GetCursorPos(&p); - lpwpos->x = p.x - lpwpos->cx / 2; - lpwpos->y = p.y - lpwpos->cy / 2; + //lpwpos->x = p.x - lpwpos->cx / 2; + //lpwpos->y = p.y - lpwpos->cy / 2; HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); if (NULL != monitor) {