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