Skip to content

Commit

Permalink
Modify to decrease in CW under 'on the hour' repeat mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
bugiii committed Mar 19, 2019
1 parent 216779e commit 06fd5f9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
56 changes: 50 additions & 6 deletions source/TimerGraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
}
8 changes: 8 additions & 0 deletions source/TimerGraphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class GdiPlusInit

///////////////////////////////////////////////////////////////////////////////

enum TimerRepeatMode {
TRM_NONE,
TRM_RESTART,
TRM_RESTART_SPARE,
TRM_ON_THE_HOUR
};

enum TimerMax
{
TM_5 = 0,
Expand Down Expand Up @@ -72,6 +79,7 @@ class TimerGraphic

public:
const std::string& id_;
TimerRepeatMode repeatMode;
TimerMax maxSecIndex;
int restartSec;
int remainSec;
Expand Down
12 changes: 6 additions & 6 deletions source/TimerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_()
{
Expand Down Expand Up @@ -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
Expand All @@ -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<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
break;
case TRM_ON_THE_HOUR:
graph_->remainSec = graph_->maxSec() - static_cast<int>(modSec) - (graph_->maxSec() - graph_->restartSec);
graph_->remainSec = currentTime() / 1000ULL / timeDiv % graph_->maxSec();
break;
}
}
Expand Down
11 changes: 1 addition & 10 deletions source/TimerWindow.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#pragma once

#include <string>

class TimerGraphic;

enum TimerRepeatMode {
TRM_NONE,
TRM_RESTART,
TRM_RESTART_SPARE,
TRM_ON_THE_HOUR
};
#include "TimerGraphic.h"

class TimerWindow
{
Expand Down Expand Up @@ -49,7 +41,6 @@ class TimerWindow
HWND hwnd_;
TimerGraphic* graph_;
bool captured_;
TimerRepeatMode repeatMode_;
uint64_t startTime_; // must be after repeatMode_
Zoom zoom_;
};
4 changes: 2 additions & 2 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 06fd5f9

Please sign in to comment.