Add times together
This commit is contained in:
parent
fd6a14675b
commit
d60cedf10d
@ -16,7 +16,7 @@ namespace mainspring {
|
||||
: m_appName(appName)
|
||||
, m_appVersion(appVersion)
|
||||
, m_timing(false)
|
||||
, m_elapsed()
|
||||
, m_elapsedSaved()
|
||||
{
|
||||
std::cout << std::format("{} {}\n", m_appName, m_appVersion);
|
||||
}
|
||||
@ -63,10 +63,8 @@ namespace mainspring {
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam)) {
|
||||
case IDC_BUTTONSTARTPAUSE: {
|
||||
app->m_timing = !app->m_timing;
|
||||
|
||||
if (app->m_timing) {
|
||||
case IDC_BUTTONSTARTPAUSE:
|
||||
if (!app->m_timing) {
|
||||
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, "Pause");
|
||||
app->m_startTime = Clock::now();
|
||||
// Timer to update time
|
||||
@ -75,10 +73,12 @@ namespace mainspring {
|
||||
else {
|
||||
SetDlgItemText(dlg, IDC_BUTTONSTARTPAUSE, "Start");
|
||||
KillTimer(dlg, 1);
|
||||
app->m_elapsedSaved += app->getElapsed();
|
||||
}
|
||||
|
||||
app->m_timing = !app->m_timing;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case ID_HELP_ABOUT:
|
||||
MessageBox(dlg, std::format("{} {}\nCopyright Grayson Riffe 2025\ngraysonriffe.com", app->m_appName, app->m_appVersion).c_str(), std::format("About {}", app->m_appName).c_str(), MB_OK);
|
||||
@ -87,17 +87,12 @@ namespace mainspring {
|
||||
|
||||
return FALSE;
|
||||
|
||||
case WM_TIMER: {
|
||||
case WM_TIMER:
|
||||
SendMessage(dlg, WM_UPDATETIME, NULL, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_UPDATETIME: {
|
||||
Seconds sinceLastStart = 0;
|
||||
if(app->m_timing)
|
||||
sinceLastStart = Duration(Clock::now() - app->m_startTime).count();
|
||||
|
||||
Seconds totalTime = app->m_elapsed + sinceLastStart;
|
||||
Seconds totalTime = app->m_elapsedSaved + app->getElapsed();
|
||||
|
||||
uint32_t hr = totalTime / (3600), min = totalTime % (3600) / 60, sec = totalTime % 60;
|
||||
SetDlgItemText(dlg, IDC_STATICTIME, std::format("{:02}:{:02}:{:02}", hr, min, sec).c_str());
|
||||
@ -113,4 +108,11 @@ namespace mainspring {
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Seconds Application::getElapsed() {
|
||||
if (m_timing)
|
||||
return Duration(Clock::now() - m_startTime).count();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -15,12 +15,14 @@ namespace mainspring {
|
||||
private:
|
||||
static BOOL CALLBACK mainDlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
Seconds getElapsed(); // Gets the current timing session time
|
||||
|
||||
const char* m_appName;
|
||||
const char* m_appVersion;
|
||||
|
||||
// Current "Time" (state of the app)
|
||||
bool m_timing; // Currently counting time?
|
||||
Seconds m_elapsed; // in seconds
|
||||
TimePoint m_startTime; // When the timer was started
|
||||
bool m_timing; // Currently timing?
|
||||
Seconds m_elapsedSaved; // Time saved
|
||||
TimePoint m_startTime; // When the current timing session was started
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user