Move to update

This commit is contained in:
Grayson Riffe 2025-01-21 01:46:44 -06:00
parent ab198d6778
commit ecca252027
2 changed files with 26 additions and 19 deletions

View File

@ -4,7 +4,7 @@
#include "resources.h"
// Define window message to update the timer display
#define WM_UPDATETIME WM_USER
#define WM_UPDATEAPP WM_USER
// Enable visual styles
#pragma comment(linker, "\"/manifestdependency:type='win32' \
@ -16,6 +16,7 @@ namespace mainspring {
: m_appName(appName)
, m_appVersion(appVersion)
, m_timing(false)
, m_startpauseButtonPressed(false)
, m_elapsedSaved()
{
std::cout << std::format("{} {}\n", m_appName, m_appVersion);
@ -55,9 +56,9 @@ namespace mainspring {
HFONT timeFont = CreateFontIndirect(&lFont);
SendMessage(GetDlgItem(dlg, IDC_STATICTIME), WM_SETFONT, reinterpret_cast<WPARAM>(timeFont), NULL);
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, "Start");
SendMessage(dlg, WM_UPDATEAPP, NULL, NULL);
SendMessage(dlg, WM_UPDATETIME, NULL, NULL);
SetTimer(dlg, 1, 50, nullptr);
return TRUE;
}
@ -65,20 +66,7 @@ namespace mainspring {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_BUTTONSTARTPAUSE:
if (!app->m_timing) {
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, "Pause");
app->m_startTime = Clock::now();
// Timer to update time
SetTimer(dlg, 1, 50, nullptr);
}
else {
KillTimer(dlg, 1);
app->m_elapsedSaved += app->getElapsed();
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, !app->m_elapsedSaved ? "Start" : "Resume");
}
app->m_timing = !app->m_timing;
app->m_startpauseButtonPressed = true;
return TRUE;
case ID_HELP_ABOUT:
@ -89,10 +77,27 @@ namespace mainspring {
return FALSE;
case WM_TIMER:
SendMessage(dlg, WM_UPDATETIME, NULL, NULL);
SendMessage(dlg, WM_UPDATEAPP, NULL, NULL);
return TRUE;
case WM_UPDATETIME: {
case WM_UPDATEAPP: {
if (app->m_startpauseButtonPressed) {
app->m_startpauseButtonPressed = false;
if (!app->m_timing)
app->m_startTime = Clock::now();
else
app->m_elapsedSaved += app->getElapsed();
app->m_timing = !app->m_timing;
}
if (app->m_timing)
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, "Pause");
else
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, !app->m_elapsedSaved ? "Start" : "Resume");
Seconds totalTime = app->m_elapsedSaved + app->getElapsed();
uint32_t hr = totalTime / (3600), min = totalTime % (3600) / 60, sec = totalTime % 60;
@ -103,6 +108,7 @@ namespace mainspring {
case WM_CLOSE:
// TODO: Ask to / save time here
KillTimer(dlg, 1);
EndDialog(dlg, 0);
return TRUE;
}

View File

@ -22,6 +22,7 @@ namespace mainspring {
// Current "Time" (state of the app)
bool m_timing; // Currently timing?
bool m_startpauseButtonPressed; // Was the start / pause button pressed?
Seconds m_elapsedSaved; // Time saved
TimePoint m_startTime; // When the current timing session was started
};