Skip to content

Commit 06fd5f9

Browse files
committed
Modify to decrease in CW under 'on the hour' repeat mode.
1 parent 216779e commit 06fd5f9

5 files changed

Lines changed: 67 additions & 24 deletions

File tree

source/TimerGraphic.cpp

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ GdiPlusInit::~GdiPlusInit() {
6464

6565
TimerGraphic::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
179181
static 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
}

source/TimerGraphic.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class GdiPlusInit
2020

2121
///////////////////////////////////////////////////////////////////////////////
2222

23+
enum TimerRepeatMode {
24+
TRM_NONE,
25+
TRM_RESTART,
26+
TRM_RESTART_SPARE,
27+
TRM_ON_THE_HOUR
28+
};
29+
2330
enum TimerMax
2431
{
2532
TM_5 = 0,
@@ -72,6 +79,7 @@ class TimerGraphic
7279

7380
public:
7481
const std::string& id_;
82+
TimerRepeatMode repeatMode;
7583
TimerMax maxSecIndex;
7684
int restartSec;
7785
int remainSec;

source/TimerWindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace bugiii_timer_window {
99
ATOM classAtom_ = 0;
1010
int windowCount_ = 0;
1111
const int timerPeriod = debug ? 100 : 1000;
12-
const int timeDiv = debug ? 100 : 10000;
12+
const int timeDiv = debug ? 10 : 10000;
1313
}
1414

1515
using namespace bugiii_timer_window;
@@ -26,7 +26,6 @@ TimerWindow::TimerWindow(const std::string& id) :
2626
hwnd_(0),
2727
graph_(new TimerGraphic(id)),
2828
captured_(false),
29-
repeatMode_(TRM_ON_THE_HOUR),
3029
startTime_(setupStartTime()),
3130
zoom_()
3231
{
@@ -135,7 +134,7 @@ uint64_t TimerWindow::setupStartTime()
135134
{
136135
uint64_t time = currentTime();
137136

138-
if (TRM_ON_THE_HOUR == repeatMode_) {
137+
if (TRM_ON_THE_HOUR == graph_->repeatMode) {
139138
//uint64_t maxTime = graph_->maxSec() * 1000ULL/*ms*/ / timeDiv;
140139
//time = time / maxTime * maxTime; // nomalized to the max time
141140
uint64_t maxTime = 60 * 60 * 1000ULL/*ms*/ / timeDiv; // one hour
@@ -147,18 +146,19 @@ uint64_t TimerWindow::setupStartTime()
147146

148147
void TimerWindow::processTime()
149148
{
150-
uint64_t diffSec = (currentTime() - graph_->restartSec) / 1000ULL/*ms*/ / timeDiv;
149+
uint64_t diffSec = (currentTime() - graph_->restartSec) / 1000ULL/*ms*/ / timeDiv; //??? unit ???
151150
uint64_t modSec = diffSec % graph_->maxSec();
152151

153-
switch (repeatMode_) {
152+
switch (graph_->repeatMode) {
154153
case TRM_NONE:
155154
break;
156155
case TRM_RESTART:
157156
break;
158157
case TRM_RESTART_SPARE:
158+
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
159159
break;
160160
case TRM_ON_THE_HOUR:
161-
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
161+
graph_->remainSec = currentTime() / 1000ULL / timeDiv % graph_->maxSec();
162162
break;
163163
}
164164
}

source/TimerWindow.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
#pragma once
22

33
#include <string>
4-
5-
class TimerGraphic;
6-
7-
enum TimerRepeatMode {
8-
TRM_NONE,
9-
TRM_RESTART,
10-
TRM_RESTART_SPARE,
11-
TRM_ON_THE_HOUR
12-
};
4+
#include "TimerGraphic.h"
135

146
class TimerWindow
157
{
@@ -49,7 +41,6 @@ class TimerWindow
4941
HWND hwnd_;
5042
TimerGraphic* graph_;
5143
bool captured_;
52-
TimerRepeatMode repeatMode_;
5344
uint64_t startTime_; // must be after repeatMode_
5445
Zoom zoom_;
5546
};

source/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ BOOL stickSide(HWND hwnd, LPWINDOWPOS lpwpos)
6767
// using current mouse x y
6868
POINT p;
6969
GetCursorPos(&p);
70-
lpwpos->x = p.x - lpwpos->cx / 2;
71-
lpwpos->y = p.y - lpwpos->cy / 2;
70+
//lpwpos->x = p.x - lpwpos->cx / 2;
71+
//lpwpos->y = p.y - lpwpos->cy / 2;
7272

7373
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
7474
if (NULL != monitor) {

0 commit comments

Comments
 (0)