Tempo
Tempo is an app that allows users to create and manage timers, stopwatches, and alarms.
Public Member Functions | Private Attributes
Menu Class Reference

The Menu class manages the main menu and user input for the Timer Stopwatch and Alarm. More...

#include <Menu.hpp>

Collaboration diagram for Menu:
Collaboration graph
[legend]

Public Member Functions

 Menu (bool testing)
 Constructs a Menu object. More...
 
char getMenuInput (int &selected)
 Waits for the user to press a valid key (1 2 3 or Q) for menu selection. More...
 
char getSettingsInput (int &selected)
 Waits for the user to press a valid key (1 2 3 4 or Q) for settings selection. More...
 
void wait (double seconds)
 Waits for a specific duration using busy-waiting. More...
 
void waitForInput ()
 Waits for any key press from the user. More...
 
void checkTimerInput (Timer &timer, bool &run)
 Checks and handles user input for the Timer. More...
 
void checkStopwatchInput (Stopwatch &stopwatch, bool &run)
 Checks and handles user input for the Stopwatch. More...
 
void checkAlarmInput (Alarm &alarm, bool &run)
 Checks and handles user input for the Alarm. More...
 
void mainMenu (int selected)
 Starts the main menu loop allowing the user to choose between Timer Stopwatch and Alarm. More...
 
void settingsMenu (int selected)
 Starts the settings menu loop allowing the user to change the notification and font settings. More...
 
void loadSettings ()
 Loads the notification and font settings from a file. More...
 
void saveSettings ()
 Saves the notification and font settings to a file. More...
 
void credits ()
 Displays the credits for the Timer Stopwatch and Alarm. More...
 
void timerSequence ()
 Displays the help menu for the Timer Stopwatch and Alarm. More...
 
void stopwatchSequence ()
 Displays the help menu for the Timer Stopwatch and Alarm. More...
 
void alarmSequence ()
 Displays the help menu for the Timer Stopwatch and Alarm. More...
 
Timer createTimer (bool &run)
 Creates a Timer object with user input for the duration. More...
 
Alarm createAlarm (bool &run)
 Creates a Alarm object with user input for the duration. More...
 
void printTimerInput (int, int, int)
 Prints the Timer's input duration to the console. More...
 
void printArt (vector< string > art, string formatting)
 Prints the Alarm's input duration to the console. More...
 

Private Attributes

Display _display
 Instance of Display to manage the visual representation. More...
 
bool _run
 Boolean to control the main loop execution. More...
 
bool _testing
 
vector< string > _menuFormats
 
vector< string > _settingsFormats
 
bool _notiSetting
 
int _fontSetting
 
vector< string > _logoArt
 
vector< string > _credits
 
vector< string > _menuArt
 
vector< string > _menuTimer
 
vector< string > _menuStopwatch
 
vector< string > _menuAlarm
 
vector< string > _menuSettings
 
vector< string > _menuQuit
 
vector< string > _menuBlank
 
vector< string > _settingsArt
 
vector< string > _settingsFont1
 
vector< string > _settingsFont2
 
vector< string > _settingsFont3
 
vector< string > _settingsFont4
 
vector< string > _settingsNotiOn
 
vector< string > _settingsNotiOff
 
vector< string > _settingsCredits
 
vector< string > _settingsBack
 
vector< string > _settingsBlank
 
vector< string > _stopMessages
 

Detailed Description

The Menu class manages the main menu and user input for the Timer Stopwatch and Alarm.

Definition at line 21 of file Menu.hpp.

Constructor & Destructor Documentation

◆ Menu()

Menu::Menu ( bool  testing)

Constructs a Menu object.

Constructs a Menu object and initializes its state.

Definition at line 16 of file Menu.cpp.

References Display::BOLD_WHITE.

16  {
17  srand(static_cast<unsigned int>(chrono::high_resolution_clock::now().time_since_epoch().count()));
18  _display = Display();
19  _run = true;
20  _testing = testing;
23 
24  _notiSetting = true;
25  _fontSetting = 1;
26 
27  loadSettings();
28 
30 
32  mainMenu(0);
33 }
void mainMenu(int selected)
Starts the main menu loop allowing the user to choose between Timer Stopwatch and Alarm...
Definition: Menu.cpp:127
static const string BOLD_WHITE
Definition: Display.hpp:47
bool _run
Boolean to control the main loop execution.
Definition: Menu.hpp:190
void setFont(int num)
Sets the font style for the terminal.
Definition: Display.cpp:79
void loadSettings()
Loads the notification and font settings from a file.
Definition: Menu.cpp:85
vector< string > _menuFormats
Definition: Menu.hpp:193
vector< string > _settingsFormats
Definition: Menu.hpp:194
bool _notiSetting
Definition: Menu.hpp:196
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
int _fontSetting
Definition: Menu.hpp:197
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
The Display class manages the visual representation and interaction logic for timers, stopwatches, and alarms.
Definition: Display.hpp:23

Member Function Documentation

◆ alarmSequence()

void Menu::alarmSequence ( )

Displays the help menu for the Timer Stopwatch and Alarm.

Runs the alarm sequence, allowing the user to set and interact with an alarm.

Definition at line 349 of file Menu.cpp.

References Alarm::isDone(), and LOOPTIME.

349  {
351 
352  bool run = true;
353  bool notified = false;
354 
355  Alarm alarm = createAlarm(run);
356 
358 
359  while(run){
360  // Display a message when the alarm finishes
361  if(alarm.isDone()) {
362  _display.setSplash("ALARM FINISHED");
363  if(_notiSetting && !notified){
364  Notification noti("Tempo", "Your alarm is finished!");
365  notified = true;
366  }
367  }
368 
369  _display.tickAlarm(alarm);
370 
371  checkAlarmInput(alarm, run);
372 
373  wait(LOOPTIME);
374 
375  if(_testing){
376  run = false;
377  }
378  }
379 }
A class to manage alarms with time-based triggers.
Definition: Alarm.hpp:13
void checkAlarmInput(Alarm &alarm, bool &run)
Checks and handles user input for the Alarm.
Definition: Menu.cpp:701
bool isDone()
Checks if the alarm has finished.
Definition: Alarm.cpp:134
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
A class to handle system notifications using PowerShell scripts.
Alarm createAlarm(bool &run)
Creates a Alarm object with user input for the duration.
Definition: Menu.cpp:453
bool _notiSetting
Definition: Menu.hpp:196
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
void tickAlarm(Alarm &alarm)
Updates the display based on the state of the provided Alarm object.
Definition: Display.cpp:899
const double LOOPTIME
Definition: Menu.cpp:5
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void setSplash(string str)
Sets the splash screen text.
Definition: Display.cpp:162
Here is the call graph for this function:

◆ checkAlarmInput()

void Menu::checkAlarmInput ( Alarm alarm,
bool &  run 
)

Checks and handles user input for the Alarm.

This function processes user input to control the Alarm. It updates the Alarm's state based on the key pressed.

Parameters
alarmThe Alarm object to control.
runA boolean reference that determines whether to continue the loop.

Definition at line 701 of file Menu.cpp.

701  {
702  if(_kbhit() || _testing){
703  char ch;
704  if(!_testing) { ch = _getch(); }
705  if(_testing) { ch = 'a'; }
706  if(ch == 'A' || ch == 'a'){
709  alarm = createAlarm(run);
710  }
711  if(_testing) { ch = 'q'; }
712  if(ch == 'Q' || ch == 'q' || ch == 27){
714  run = false;
715  return;
716  }
717  return;
718  }
719 }
void clearSplash()
Clears the splash screen.
Definition: Display.cpp:170
Alarm createAlarm(bool &run)
Creates a Alarm object with user input for the duration.
Definition: Menu.cpp:453
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189

◆ checkStopwatchInput()

void Menu::checkStopwatchInput ( Stopwatch stopwatch,
bool &  run 
)

Checks and handles user input for the Stopwatch.

This function processes user input to control the Stopwatch. It updates the Stopwatch's state based on the key pressed.

Parameters
stopwatchThe Stopwatch object to control.
runA boolean reference that determines whether to continue the loop.

Definition at line 647 of file Menu.cpp.

References Stopwatch::addSplit(), Stopwatch::currentMilliseconds(), Stopwatch::isRunning(), Stopwatch::pause(), Stopwatch::reset(), and Stopwatch::resume().

647  {
648  if(_kbhit() || _testing){
649  char ch;
650  if(!_testing) { ch = _getch(); }
651  if(_testing) { ch = 's'; }
652  if(ch == 's' || ch == 'S'){
653  if(stopwatch.isRunning()){
654  stopwatch.pause();
655  if ((stopwatch.currentMilliseconds() / 10) % 100 == 0){
656  int i = rand() % _stopMessages.size();
658  }
659  else{
660  _display.setSplash("STOPWATCH PAUSED");
661  }
662  }
663  else{
665  stopwatch.resume();
666  }
667  }
668  if(_testing) { ch = 'r'; }
669  if(ch == 'R' || ch == 'r'){
670  stopwatch.reset();
672  _display.setSplash("STOPWATCH RESET, PRESS 'S' TO START");
673  }
674  if(_testing) { ch = 'a'; }
675  if(ch == 'A' || ch == 'a'){
676  stopwatch.addSplit();
677  _display.setSplash("SPLIT CREATED");
678  }
679  if(_testing) { ch = 'q'; }
680  if(ch == 'Q' || ch == 'q' || ch == 27){
682  run = false;
683  return;
684  }
685  return;
686  }
687 }
void clearSplash()
Clears the splash screen.
Definition: Display.cpp:170
void addSplit()
Records and prints the current split time in milliseconds.
Definition: Stopwatch.cpp:64
void reset()
Resets the stopwatch to 0 milliseconds and stops it.
Definition: Stopwatch.cpp:148
void resume()
Resumes the stopwatch from the last paused time.
Definition: Stopwatch.cpp:134
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
int currentMilliseconds()
Returns the current elapsed time in milliseconds.
Definition: Stopwatch.cpp:44
void pause()
Pauses the stopwatch.
Definition: Stopwatch.cpp:119
bool _testing
Definition: Menu.hpp:191
vector< string > _stopMessages
Definition: Menu.hpp:415
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
bool isRunning()
Checks if the stopwatch is currently running.
Definition: Stopwatch.cpp:163
void setSplash(string str)
Sets the splash screen text.
Definition: Display.cpp:162
Here is the call graph for this function:

◆ checkTimerInput()

void Menu::checkTimerInput ( Timer timer,
bool &  run 
)

Checks and handles user input for the Timer.

This function processes user input to control the Timer. It updates the Timer's state based on the key pressed.

Parameters
timerThe Timer object to control.
runA boolean reference that determines whether to continue the loop.

Definition at line 599 of file Menu.cpp.

References Timer::isRunning(), Timer::pause(), Timer::remainingMilliseconds(), Timer::reset(), and Timer::resume().

599  {
600  if(_kbhit() || _testing){
601  char ch;
602  if(!_testing) { ch = _getch(); }
603  if(_testing) { ch = 's'; }
604  if(ch == 's' || ch == 'S'){
605  if(timer.isRunning()){
606  timer.pause();
607  _display.setSplash("TIMER PAUSED");
608  }
609  else if(timer.remainingMilliseconds() > 0){
611  timer.resume();
612  }
613  }
614  if(_testing) { ch = 'r'; }
615  if(ch == 'R' || ch == 'r'){
616  timer.reset();
618  _display.setSplash("TIMER RESET, PRESS 'S' TO START");
619  }
620  if(_testing) { ch = 'a'; }
621  if(ch == 'A' || ch == 'a'){
624  timer = createTimer(run);
625  }
626  if(_testing) { ch = 'q'; }
627  if(ch == 'Q' || ch == 'q' || ch == 27){
629  run = false;
630  return;
631  }
632  }
633 }
void clearSplash()
Clears the splash screen.
Definition: Display.cpp:170
void resume()
Resumes the timer from where it was paused by recalculating the end time.
Definition: Timer.cpp:65
int remainingMilliseconds()
Returns the remaining time in milliseconds.
Definition: Timer.cpp:118
Timer createTimer(bool &run)
Creates a Timer object with user input for the duration.
Definition: Menu.cpp:386
void pause()
Pauses the timer and calculates the remaining milliseconds.
Definition: Timer.cpp:50
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
bool isRunning()
Checks if the timer is currently running.
Definition: Timer.cpp:143
void reset()
Resets the timer to its original duration and pauses it.
Definition: Timer.cpp:78
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void setSplash(string str)
Sets the splash screen text.
Definition: Display.cpp:162
Here is the call graph for this function:

◆ createAlarm()

Alarm Menu::createAlarm ( bool &  run)

Creates a Alarm object with user input for the duration.

Creates a new Alarm object based on user input.

This function prompts the user to enter the hours minutes and seconds for the Alarm. It then creates a Alarm object with the specified duration and returns it.

Parameters
runA boolean reference that determines whether to continue the loop.
Returns
The Alarm object created with the user's input.
Parameters
runA reference to a boolean flag indicating whether to continue running the sequence.
Returns
An Alarm object initialized with the user's input.

Definition at line 453 of file Menu.cpp.

References LOOPTIME.

453  {
454  int h = 0;
455  int m = 0;
456 
457  string input = "0000";
458 
459  string to_print = "00:00";
460 
461  bool isAM = true;
462 
463  _display.tickAlarmSetup(to_print, isAM);
464 
465  int index = 3;
466 
467 
468  while (true) {
469  char ch;
470 
471  if(_testing){
472  ch = '1';
473  }
474 
475  else if(_kbhit()){
476  ch = _getch();
477 
478  if(ch == -32 || ch == 224 || ch == 0){
479  ch = getch();
480  switch(ch){
481  case 75:
482  isAM = 1;
483  break;
484  case 77:
485  isAM = 0;
486  break;
487  default:
488  break;
489  }
490  }
491  }
492 
493  else{
494  ch = 0;
495  }
496 
497  if (ch == 13 && h) {
498  break;
499  }
500  else if (ch >= '0' && ch <= '9') {
501  input = input.substr(1) + ch;
502  }
503  else if (ch == 8) {
504  input = '0' + input.substr(0, 3);
505  }
506 
507  if(ch == 'q' || ch == 'Q' || ch == 27){
508  run = false;
509  return Alarm(0,0);
510  }
511 
512  h = stoi(input.substr(0, 2));
513  m = stoi(input.substr(2, 2));
514 
515  if(h > 12) {
516  h = 12;
517  }
518 
519  if(h && m > 59) {
520  m = 59;
521  }
522 
523  to_print = (h < 10 ? "0" : "") + to_string(h) + ":"
524  + (m < 10 ? "0" : "") + to_string(m);
525 
526  input = to_print.substr(0, 2) + to_print.substr(3, 2);
527 
528  _display.tickAlarmSetup(to_print, isAM);
529 
530  wait(LOOPTIME);
531 
532  if(_testing){
533  break;
534  }
535  }
537  Alarm alarm(0,0);
538 
539  if(isAM){
540  if(h == 12){
541  alarm = Alarm(0,m);
542  }
543  else{
544  alarm = Alarm(h,m);
545  }
546  }
547  else{
548  if(h == 12){
549  alarm = Alarm(12,m);
550  }
551  else{
552  alarm = Alarm(h+12,m);
553  }
554  }
555  return alarm;
556 }
A class to manage alarms with time-based triggers.
Definition: Alarm.hpp:13
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
const double LOOPTIME
Definition: Menu.cpp:5
void tickAlarmSetup(string to_print, bool isAM)
Updates the alarm setup display, showing the current input with a blinking cursor.
Definition: Display.cpp:705
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189

◆ createTimer()

Timer Menu::createTimer ( bool &  run)

Creates a Timer object with user input for the duration.

Creates a new Timer object based on user input.

This function prompts the user to enter the hours minutes and seconds for the Timer. It then creates a Timer object with the specified duration and returns it.

Parameters
runA boolean reference that determines whether to continue the loop.
Returns
Timer The Timer object created with the user's input.
Parameters
runA reference to a boolean flag indicating whether to continue running the sequence.
Returns
A Timer object initialized with the user's input.

Definition at line 386 of file Menu.cpp.

References LOOPTIME.

386  {
387  int h = 0;
388  int m = 0;
389  int s = 0;
390  int countdownSeconds = 0;
391 
392  string input = "000000";
393 
394  string to_print = "00:00:00";
395 
396  _display.tickTimerSetup(to_print);
397 
398  int index = 5;
399 
400  while (true) {
401  char ch;
402  if(_testing){
403  ch = '1';
404  }
405  else if(_kbhit()){
406  ch = _getch();
407  }
408  else{
409  ch = 0;
410  }
411 
412  if (ch == 13 && (h || m || s)) {
413  break;
414  }
415  else if (ch >= '0' && ch <= '9') {
416  input = input.substr(1) + ch;
417  }
418  else if (ch == 8) {
419  input = '0' + input.substr(0, 5);
420  }
421 
422  if(ch == 'q' || ch == 'Q' || ch == 27){
423  run = false;
424  return Timer(0,0,0);
425  }
426 
427  h = stoi(input.substr(0, 2));
428  m = stoi(input.substr(2, 2));
429  s = stoi(input.substr(4, 2));
430 
431  to_print = (h < 10 ? "0" : "") + to_string(h) + ":"
432  + (m < 10 ? "0" : "") + to_string(m) + ":"
433  + (s < 10 ? "0" : "") + to_string(s);
434 
435  _display.tickTimerSetup(to_print);
436 
437  wait(LOOPTIME);
438 
439  if(_testing){
440  break;
441  }
442  }
444  Timer timer(h,m,s);
445  return timer;
446 }
The Timer class provides a countdown timer with start, pause, resume, reset, and time adjustment func...
Definition: Timer.hpp:12
void tickTimerSetup(string to_print)
Updates the timer setup display, showing the current input with a blinking cursor.
Definition: Display.cpp:663
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
const double LOOPTIME
Definition: Menu.cpp:5
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189

◆ credits()

void Menu::credits ( )

Displays the credits for the Timer Stopwatch and Alarm.

Displays the start screen with logo art and credits.

Definition at line 58 of file Menu.cpp.

References Display::BOLD_CYAN, and Display::WHITE.

58  {
60 
61  string lBuffer = " ";
62 
64 
66  cout << endl;
67  for (string line : _credits){
68  cout << lBuffer << line << endl;
69  }
71 
72  _display.setCursor(1,1);
73 
74  waitForInput();
75 
77 }
vector< string > _logoArt
Definition: Menu.hpp:200
void waitForInput()
Waits for any key press from the user.
Definition: Menu.cpp:580
void setCursor(int x, int y)
Sets the cursor position in the terminal.
Definition: Display.cpp:101
void setFormat(const string &code)
Sets the terminal text color.
Definition: Display.cpp:138
void clearFormat()
Clears the terminal text color.
Definition: Display.cpp:147
static const string WHITE
Definition: Display.hpp:38
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
static const string BOLD_CYAN
Definition: Display.hpp:46
vector< string > _credits
Definition: Menu.hpp:218
void printArt(vector< string > art, string formatting)
Prints the Alarm&#39;s input duration to the console.
Definition: Menu.cpp:45
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189

◆ getMenuInput()

char Menu::getMenuInput ( int &  selected)

Waits for the user to press a valid key (1 2 3 or Q) for menu selection.

Waits for the user to press a valid key (1, 2, 3, or Q) for menu selection.

This function repeatedly checks for user input until a valid menu option is pressed. It then returns the corresponding character for the selected menu option.

Returns
char The character corresponding to the user's menu selection.

Definition at line 732 of file Menu.cpp.

References LOOPTIME.

732  {
733  while(true){
734  if(_kbhit() || _testing){
735  char ch = -1;
736  if(!_testing) { ch = _getch(); }
737 
738  if(ch == 13){
739  return selected + '1';
740  }
741 
742  if(ch == -32 || ch == 224 || ch == 0){
743  ch = getch();
744  switch(ch){
745  case 72:
746  selected = max(0,selected-1);
747  break;
748  case 80:
749  selected = min(4,selected+1);
750  break;
751  default:
752  break;
753  }
754  return '0';
755  }
756 
757  else{
758  if(_testing) { ch = 27; }
759  switch(ch){
760  case '1':
761  case '2':
762  case '3':
763  selected = ch - '1';
764  return ch;
765  case 'S':
766  case 's':
767  selected = 3;
768  return 's';
769  case 'Q':
770  case 'q':
771  case 27:
772  selected = 4;
773  return 'q';
774  default:
775  break;
776  }
777  }
778 
779  }
780  wait(LOOPTIME); // Slight delay before checking input again
781  }
782 }
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
const double LOOPTIME
Definition: Menu.cpp:5
bool _testing
Definition: Menu.hpp:191

◆ getSettingsInput()

char Menu::getSettingsInput ( int &  selected)

Waits for the user to press a valid key (1 2 3 4 or Q) for settings selection.

Waits for the user to press a valid key (1, 2, 3, or Q) for settings selection.

This function repeatedly checks for user input until a valid settings option is pressed. It then returns the corresponding character for the selected settings option.

Returns
char The character corresponding to the user's settings selection.
Parameters
selectedThe current selected setting.
Returns
char The character corresponding to the user's settings selection.

Definition at line 789 of file Menu.cpp.

References LOOPTIME.

789  {
790  while(true){
791  if(_kbhit() || _testing){
792  char ch = -1;
793  if(!_testing) { ch = _getch(); }
794 
795  if(ch == 13){
797  return selected + '1';
798  }
799 
800  if(ch == -32 || ch == 224 || ch == 0){
801  ch = getch();
802  switch(ch){
803  case 72:
804  selected = max(0,selected-1);
805  break;
806  case 80:
807  selected = min(3,selected+1);
808  break;
809  default:
810  break;
811  }
812  return '0';
813  }
814  else{
815  if(_testing) { ch = 27; }
816  switch(ch){
817  case '1':
818  case '2':
819  case '3':
820  selected = ch - '1';
821  return ch;
822  case 'Q':
823  case 'q':
824  case 27:
825  selected = 3;
826  return 'q';
827  default:
828  break;
829  }
830  }
831  }
832  wait(LOOPTIME); // Slight delay before checking input again
833  }
834 }
vector< string > _settingsBlank
Definition: Menu.hpp:380
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
const double LOOPTIME
Definition: Menu.cpp:5
void printArt(vector< string > art, string formatting)
Prints the Alarm&#39;s input duration to the console.
Definition: Menu.cpp:45
bool _testing
Definition: Menu.hpp:191

◆ loadSettings()

void Menu::loadSettings ( )

Loads the notification and font settings from a file.

Loads the user's settings from a file.

This function reads the font setting and notification setting from a "settings.txt" file if it exists, otherwise it uses default values.

Definition at line 85 of file Menu.cpp.

85  {
86  ifstream settingsFile("settings.txt");
87 
88  if (settingsFile.is_open()) {
89  settingsFile >> _fontSetting;
90  settingsFile >> _notiSetting;
91  settingsFile.close();
92  } else {
93  // Default settings if the file doesn't exist
94  _fontSetting = 1;
95  _notiSetting = true;
96  }
97 }
bool _notiSetting
Definition: Menu.hpp:196
int _fontSetting
Definition: Menu.hpp:197

◆ mainMenu()

void Menu::mainMenu ( int  selected)

Starts the main menu loop allowing the user to choose between Timer Stopwatch and Alarm.

Starts the main menu loop, allowing the user to choose between Timer, Stopwatch, and Alarm.

The menu displays options to the user processes the user's selection and runs the appropriate sequence for Timer Stopwatch or Alarm. It handles the input and output and returns to the menu after each operation unless the user chooses to quit.

The menu displays options to the user, processes the user's selection, and runs the appropriate sequence for Timer, Stopwatch, or Alarm. It handles the input and output and returns to the menu after each operation unless the user chooses to quit.

Definition at line 127 of file Menu.cpp.

References Display::BOLD_CYAN, Display::BOLD_WHITE, and Display::SELECTED.

127  {
128 
129  for (int i = 0; i < _menuFormats.size(); ++i) {
130  if (i == selected) {
132  } else {
134  }
135  }
136 
137  _display.setCursor(1,1);
138 
140 
142 
144 
146 
148 
150 
151  _display.setCursor(1,1);
152 
153  char in = getMenuInput(selected);
154 
155  if(_testing){ in = '1'; }
156  // ENTER TIMER SEQUENCE
157  if(in == '1'){
158  timerSequence();
160  }
161 
162  if(_testing){ in = '2'; }
163  // ENTER STOPWATCH SEQUENCE
164  if(in == '2'){
167  }
168 
169  if(_testing){ in = '3'; }
170  // ENTER ALARM SEQUENCE
171  if(in == '3'){
172  alarmSequence();
174  }
175 
176  if(_testing){ in = '4'; }
177  // ENTER SETTINGS SEQUENCE
178  if(in == 's' || in == '4'){
180  settingsMenu(0);
182  }
183 
184  if(_testing){ in = '5'; }
185  // QUIT PROGRAM
186  if(in == 'q' || in == '5'){
188  return;
189  }
190 
191  // Restart menu loop
192  mainMenu(selected);
193 }
char getMenuInput(int &selected)
Waits for the user to press a valid key (1 2 3 or Q) for menu selection.
Definition: Menu.cpp:732
void mainMenu(int selected)
Starts the main menu loop allowing the user to choose between Timer Stopwatch and Alarm...
Definition: Menu.cpp:127
static const string BOLD_WHITE
Definition: Display.hpp:47
void setCursor(int x, int y)
Sets the cursor position in the terminal.
Definition: Display.cpp:101
void stopwatchSequence()
Displays the help menu for the Timer Stopwatch and Alarm.
Definition: Menu.cpp:319
static const string SELECTED
Definition: Display.hpp:27
vector< string > _menuStopwatch
Definition: Menu.hpp:249
void timerSequence()
Displays the help menu for the Timer Stopwatch and Alarm.
Definition: Menu.cpp:284
vector< string > _menuTimer
Definition: Menu.hpp:243
vector< string > _menuFormats
Definition: Menu.hpp:193
vector< string > _menuSettings
Definition: Menu.hpp:261
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
static const string BOLD_CYAN
Definition: Display.hpp:46
vector< string > _menuArt
Definition: Menu.hpp:235
void alarmSequence()
Displays the help menu for the Timer Stopwatch and Alarm.
Definition: Menu.cpp:349
vector< string > _menuQuit
Definition: Menu.hpp:267
void printArt(vector< string > art, string formatting)
Prints the Alarm&#39;s input duration to the console.
Definition: Menu.cpp:45
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void settingsMenu(int selected)
Starts the settings menu loop allowing the user to change the notification and font settings...
Definition: Menu.cpp:202
vector< string > _menuAlarm
Definition: Menu.hpp:255

◆ printArt()

void Menu::printArt ( vector< string >  art,
string  formatting 
)

Prints the Alarm's input duration to the console.

Prints ASCII art to the display with specified formatting.

This function prints the hours minutes and seconds of the Alarm's input duration to the console.

Parameters
hoursThe hours of the Alarm's input duration.
minutesThe minutes of the Alarm's input duration.
secondsThe seconds of the Alarm's input duration.
artA vector of strings representing the ASCII art.
formattingThe display format for the art.

Definition at line 45 of file Menu.cpp.

45  {
46  _display.setFormat(formatting);
47 
48  for (string line : art){
49  cout << line << endl;
50  }
51 
53 }
void setFormat(const string &code)
Sets the terminal text color.
Definition: Display.cpp:138
void clearFormat()
Clears the terminal text color.
Definition: Display.cpp:147
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189

◆ printTimerInput()

void Menu::printTimerInput ( int  ,
int  ,
int   
)

Prints the Timer's input duration to the console.

This function prints the hours minutes and seconds of the Timer's input duration to the console.

Parameters
hoursThe hours of the Timer's input duration.
minutesThe minutes of the Timer's input duration.
secondsThe seconds of the Timer's input duration.

◆ saveSettings()

void Menu::saveSettings ( )

Saves the notification and font settings to a file.

Saves the user's settings to a file.

This function writes the font setting and notification setting to a "settings.txt" file.

Definition at line 105 of file Menu.cpp.

105  {
106  ofstream settingsFile("settings.txt");
107 
108  if (settingsFile.is_open()) {
109  settingsFile << _fontSetting << endl;
110  settingsFile << _notiSetting << endl;
111  settingsFile.close();
112  }
113 }
bool _notiSetting
Definition: Menu.hpp:196
int _fontSetting
Definition: Menu.hpp:197

◆ settingsMenu()

void Menu::settingsMenu ( int  selected)

Starts the settings menu loop allowing the user to change the notification and font settings.

Displays the settings menu and allows the user to modify settings.

The settings menu displays options to the user processes the user's selection and runs the appropriate sequence for changing the notification and font settings. It handles the input and output and returns to the settings menu after each operation unless the user chooses to quit.

The settings include font selection and notifications.

Parameters
selectedThe index of the selected settings option.

Definition at line 202 of file Menu.cpp.

References Display::BOLD_CYAN, Display::BOLD_WHITE, NUM_FONTS, and Display::SELECTED.

202  {
203 
204  for (int i = 0; i < _settingsFormats.size(); ++i) {
205  if (i == selected) {
207  } else {
209  }
210  }
211 
212  _display.setCursor(1,1);
213 
215 
216  switch(_fontSetting){
217  case 1:
219  break;
220  case 2:
222  break;
223  case 3:
225  break;
226  case 4:
228  break;
229  }
230 
231  if(_notiSetting){
233  }
234  else{
236  }
237 
239 
241 
242  _display.setCursor(1,1);
243 
244  char in = getSettingsInput(selected);
245 
246  if(_testing){ in = '1'; }
247  if(in == '1'){
248  //Rotate fonts
249  if(_fontSetting < NUM_FONTS){
250  _fontSetting++;
251  }
252  else{
253  _fontSetting = 1;
254  }
255  saveSettings();
256  }
257 
258  if(_testing){ in = '2'; }
259  if(in == '2'){
260  //Toggle notifications
262  saveSettings();
263  }
264 
265  if(_testing){ in = '3'; }
266  if(in == '3'){
267  credits();
268  }
269 
270  if(_testing){ in = '4'; }
271  if(in == 'q' || in == '4' ){
272  saveSettings();
274  return;
275  }
276 
277  //printArt(_settingsBlank, "");
278  settingsMenu(selected);
279 }
vector< string > _settingsCredits
Definition: Menu.hpp:367
void credits()
Displays the credits for the Timer Stopwatch and Alarm.
Definition: Menu.cpp:58
static const string BOLD_WHITE
Definition: Display.hpp:47
const int NUM_FONTS
Definition: Menu.cpp:7
void setCursor(int x, int y)
Sets the cursor position in the terminal.
Definition: Display.cpp:101
void saveSettings()
Saves the notification and font settings to a file.
Definition: Menu.cpp:105
void setFont(int num)
Sets the font style for the terminal.
Definition: Display.cpp:79
static const string SELECTED
Definition: Display.hpp:27
vector< string > _settingsBack
Definition: Menu.hpp:373
vector< string > _settingsNotiOn
Definition: Menu.hpp:355
vector< string > _settingsFormats
Definition: Menu.hpp:194
bool _notiSetting
Definition: Menu.hpp:196
static const string BOLD_CYAN
Definition: Display.hpp:46
int _fontSetting
Definition: Menu.hpp:197
vector< string > _settingsNotiOff
Definition: Menu.hpp:361
vector< string > _settingsFont4
Definition: Menu.hpp:344
void printArt(vector< string > art, string formatting)
Prints the Alarm&#39;s input duration to the console.
Definition: Menu.cpp:45
char getSettingsInput(int &selected)
Waits for the user to press a valid key (1 2 3 4 or Q) for settings selection.
Definition: Menu.cpp:789
bool _testing
Definition: Menu.hpp:191
vector< string > _settingsFont3
Definition: Menu.hpp:333
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void settingsMenu(int selected)
Starts the settings menu loop allowing the user to change the notification and font settings...
Definition: Menu.cpp:202
vector< string > _settingsArt
Definition: Menu.hpp:308
vector< string > _settingsFont2
Definition: Menu.hpp:327
vector< string > _settingsFont1
Definition: Menu.hpp:316

◆ stopwatchSequence()

void Menu::stopwatchSequence ( )

Displays the help menu for the Timer Stopwatch and Alarm.

Runs the stopwatch sequence, allowing the user to start, stop, and record splits.

Definition at line 319 of file Menu.cpp.

References LOOPTIME.

319  {
320 
322 
323  Stopwatch stopwatch;
324 
325  bool run = true;
326 
327  _display.setSplash("PRESS 'S' TO START");
328 
329  _display.tickStopwatch(stopwatch);
330 
331  //_display.clearScreen();
332 
333  while(run){
334  _display.tickStopwatch(stopwatch);
335 
336  checkStopwatchInput(stopwatch, run);
337 
338  wait(LOOPTIME);
339 
340  if(_testing){
341  run = false;
342  }
343  }
344 }
The Stopwatch class provides a simple timer with start, pause, resume, and reset functionalities.
Definition: Stopwatch.hpp:13
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
void checkStopwatchInput(Stopwatch &stopwatch, bool &run)
Checks and handles user input for the Stopwatch.
Definition: Menu.cpp:647
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
void tickStopwatch(Stopwatch &stopwatch)
Updates the display based on the state of the provided Stopwatch object.
Definition: Display.cpp:856
const double LOOPTIME
Definition: Menu.cpp:5
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void setSplash(string str)
Sets the splash screen text.
Definition: Display.cpp:162

◆ timerSequence()

void Menu::timerSequence ( )

Displays the help menu for the Timer Stopwatch and Alarm.

Runs the timer sequence, allowing the user to set and interact with a timer.

Definition at line 284 of file Menu.cpp.

References LOOPTIME, and Timer::remainingMilliseconds().

284  {
286 
287  bool run = true;
288  bool notified = false;
289 
290  Timer timer = createTimer(run);
291 
293 
294  while(run){
295  // Display a message when the timer finishes
296  if(timer.remainingMilliseconds() == 0) {
297  _display.setSplash("TIMER FINISHED");
298  if(_notiSetting && !notified){
299  Notification noti("Tempo", "Your timer is finished!");
300  notified = true;
301  }
302  }
303 
304  _display.tickTimer(timer);
305 
306  checkTimerInput(timer, run);
307 
308  wait(LOOPTIME);
309 
310  if(_testing){
311  run = false;
312  }
313  }
314 }
void checkTimerInput(Timer &timer, bool &run)
Checks and handles user input for the Timer.
Definition: Menu.cpp:599
The Timer class provides a countdown timer with start, pause, resume, reset, and time adjustment func...
Definition: Timer.hpp:12
int remainingMilliseconds()
Returns the remaining time in milliseconds.
Definition: Timer.cpp:118
void wait(double seconds)
Waits for a specific duration using busy-waiting.
Definition: Menu.cpp:566
Timer createTimer(bool &run)
Creates a Timer object with user input for the duration.
Definition: Menu.cpp:386
A class to handle system notifications using PowerShell scripts.
bool _notiSetting
Definition: Menu.hpp:196
void tickTimer(Timer &timer)
Updates the display based on the state of the provided Timer object.
Definition: Display.cpp:812
void clearScreen()
Clears the terminal screen.
Definition: Display.cpp:67
const double LOOPTIME
Definition: Menu.cpp:5
bool _testing
Definition: Menu.hpp:191
Display _display
Instance of Display to manage the visual representation.
Definition: Menu.hpp:189
void setSplash(string str)
Sets the splash screen text.
Definition: Display.cpp:162
Here is the call graph for this function:

◆ wait()

void Menu::wait ( double  seconds)

Waits for a specific duration using busy-waiting.

This function uses a high-resolution clock to wait for the specified amount of time (in seconds). It continuously checks the elapsed time until the desired duration has passed.

Parameters
secondsThe amount of time to wait in seconds.

This function uses a high-resolution clock to wait for the specified amount of time (in seconds). It continuously checks the elapsed time until the desired duration has passed.

Parameters
secondsThe amount of time to wait, in seconds.

Definition at line 566 of file Menu.cpp.

566  {
567  int milli = 1000 * seconds;
568  this_thread::sleep_for(chrono::milliseconds(milli));
569 }

◆ waitForInput()

void Menu::waitForInput ( )

Waits for any key press from the user.

This function blocks until the user presses a key using _getch() to capture the input.

This function blocks until the user presses a key, using _getch() to capture the input.

Definition at line 580 of file Menu.cpp.

580  {
581  if(_testing){
582  return;
583  }
584  _getch();
585 }
bool _testing
Definition: Menu.hpp:191

Field Documentation

◆ _credits

vector<string> Menu::_credits
private
Initial value:
= {
"-------------------------------------",
" Tempo v1.0 ",
"-------------------------------------",
" A lightweight timer, stopwatch,",
" and alarm terminal app.",
"-------------------------------------",
" Developed by:",
" William Donnelly",
" Kevin Albert",
" Rowan Zeszut",
" Ben Sampson",
"-------------------------------------",
"",
" Press any key to continue...",
}

Definition at line 218 of file Menu.hpp.

◆ _display

Display Menu::_display
private

Instance of Display to manage the visual representation.

Definition at line 189 of file Menu.hpp.

◆ _fontSetting

int Menu::_fontSetting
private

Definition at line 197 of file Menu.hpp.

◆ _logoArt

vector<string> Menu::_logoArt
private
Initial value:
= {
" ",
" &&&&&&&&&&&&&&&& ",
" &&&&&&&&&&&&&&& ",
" &&&&&& &&&&&&&&&&&&& &&&&&& &&&&&&& &&&&&&&& &&&&&&&&&&& &&&&&&&&&&&&& ",
" &&&&&% &&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&& &&&&&&&&&&&&&&& ",
" &&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&& &&&&&& ",
" &&&&&& &&&&&&&&&&&&&&& &&&&&& &&&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&&& ",
" &&&&&&& &&&&&& &&&&&& &&&&&& &&&&&& &&&&&&& &&&&&& &&&&&& &&&&&& ",
" &&&&&& &&&&&&& &&&& &&&&&& &&&&&&# &&&&&& &&&&&&&&&&&&&&& &&&&&&&&&&&&&&& ",
" &&&&&&& %&&&&&&&&&&&&& &&&&&& &&&&&& #&&&&&& &&&&&&&&&&&& &&&&&&&&&&&& ",
" &&&&&& ",
" &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ",
" &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ",
" "
}

Definition at line 200 of file Menu.hpp.

◆ _menuAlarm

vector<string> Menu::_menuAlarm
private
Initial value:
= {
" _ _ ",
" _) o /\\ | /\\ |_) |\\/| ",
" _) o /--\\ |_ /--\\ | \\ | | ",
" ",
}

Definition at line 255 of file Menu.hpp.

◆ _menuArt

vector<string> Menu::_menuArt
private
Initial value:
= {
" ___ _ ",
" |\\/| /\\ | |\\ | |\\/| |_ |\\ | | | ",
" | | /--\\ _|_ | \\| | | |_ | \\| |_| ",
"________________________________________________",
"",
}

Definition at line 235 of file Menu.hpp.

◆ _menuBlank

vector<string> Menu::_menuBlank
private

Definition at line 273 of file Menu.hpp.

◆ _menuFormats

vector<string> Menu::_menuFormats
private

Definition at line 193 of file Menu.hpp.

◆ _menuQuit

vector<string> Menu::_menuQuit
private
Initial value:
= {
" _ _ ___ ___ ",
"/ \\ o / \\ | | | | ",
"\\_X o \\_X |_| _|_ | ",
" ",
}

Definition at line 267 of file Menu.hpp.

◆ _menuSettings

vector<string> Menu::_menuSettings
private
Initial value:
= {
" __ __ _ ___ ___ ___ __ __ ",
"(_ o (_ |_ | | | |\\ | /__ (_ ",
"__) o __) |_ | | _|_ | \\| \\_| __) ",
" ",
}

Definition at line 261 of file Menu.hpp.

◆ _menuStopwatch

vector<string> Menu::_menuStopwatch
private
Initial value:
= {
" _ __ ___ _ _ ___ _ ",
" ) o (_ | / \\ |_) \\ / /\\ | / |_| ",
" /_ o __) | \\_/ | \\/\\/ /--\\ | \\_ | | ",
" ",
}

Definition at line 249 of file Menu.hpp.

◆ _menuTimer

vector<string> Menu::_menuTimer
private
Initial value:
= {
" ___ ___ _ _ ",
" /| o | | |\\/| |_ |_) ",
" | o | _|_ | | |_ | \\ ",
" ",
}

Definition at line 243 of file Menu.hpp.

◆ _notiSetting

bool Menu::_notiSetting
private

Definition at line 196 of file Menu.hpp.

◆ _run

bool Menu::_run
private

Boolean to control the main loop execution.

Definition at line 190 of file Menu.hpp.

◆ _settingsArt

vector<string> Menu::_settingsArt
private
Initial value:
= {
" __ _ ___ ___ ___ __ __ ",
" (_ |_ | | | |\\ | /__ (_ ",
" __) |_ | | _|_ | \\| \\_| __) ",
"____________________________________ ",
" ",
}

Definition at line 308 of file Menu.hpp.

◆ _settingsBack

vector<string> Menu::_settingsBack
private
Initial value:
= {
" _ _ _ ",
"/ \\ o |_) /\\ / |/ ",
"\\_X o |_) /--\\ \\_ |\\ ",
" ",
}

Definition at line 373 of file Menu.hpp.

◆ _settingsBlank

vector<string> Menu::_settingsBlank
private

Definition at line 380 of file Menu.hpp.

◆ _settingsCredits

vector<string> Menu::_settingsCredits
private
Initial value:
= {
" _ _ _ _ _ ___ ___ __ ",
" _) o / |_) |_ | \\ | | (_ ",
" _) o \\_ | \\ |_ |_/ _|_ | __) ",
" ",
}

Definition at line 367 of file Menu.hpp.

◆ _settingsFont1

vector<string> Menu::_settingsFont1
private
Initial value:
= {
" $$\\ ",
" $$$$ | ",
" _ ___ __ ___ ___ _ _ ___ \\_$$ | ",
" /| o | \\ | /__ | | |_ / \\ |\\ | | __ $$ | ",
" | o |_/ _|_ \\_| _|_ | | \\_/ | \\| | $$ | ",
" $$ | ",
" $$$$$$\\ ",
" \\______| ",
}

Definition at line 316 of file Menu.hpp.

◆ _settingsFont2

vector<string> Menu::_settingsFont2
private
Initial value:
= {
" _ ___ __ ___ ___ _ _ ___ _ ",
" /| o | \\ | /__ | | |_ / \\ |\\ | | __ ) ",
" | o |_/ _|_ \\_| _|_ | | \\_/ | \\| | /_ ",
" ",
}

Definition at line 327 of file Menu.hpp.

◆ _settingsFont3

vector<string> Menu::_settingsFont3
private
Initial value:
= {
" .--. ",
" / \\ ",
" (___)`. | ",
" _ ___ __ ___ ___ _ _ ___ .-' / ",
" /| o | \\ | /__ | | |_ / \\ |\\ | | __ '. \\ ",
" | o |_/ _|_ \\_| _|_ | | \\_/ | \\| | ___ \\ ' ",
" ( ) ; | ",
" \\ `-' / ",
" ',__.' ",
}

Definition at line 333 of file Menu.hpp.

◆ _settingsFont4

vector<string> Menu::_settingsFont4
private
Initial value:
= {
" d8888 ",
" d8P888 ",
" _ ___ __ ___ ___ _ _ ___ d8P 888 ",
" /| o | \\ | /__ | | |_ / \\ |\\ | | __ d8P 888 ",
" | o |_/ _|_ \\_| _|_ | | \\_/ | \\| | d88 888 ",
" 8888888888 ",
" 888 ",
" 888 ",
}

Definition at line 344 of file Menu.hpp.

◆ _settingsFormats

vector<string> Menu::_settingsFormats
private

Definition at line 194 of file Menu.hpp.

◆ _settingsNotiOff

vector<string> Menu::_settingsNotiOff
private
Initial value:
= {
" _ _ ___ ___ _ ___ _ ___ ___ _ __ _ _ _ ",
" ) o |\\ | / \\ | | |_ | / /\\ | | / \\ |\\ | (_ __ / \\ |_ |_ ",
" /_ o | \\| \\_/ | _|_ | _|_ \\_ /--\\ | _|_ \\_/ | \\| __) \\_/ | | ",
" ",
}

Definition at line 361 of file Menu.hpp.

◆ _settingsNotiOn

vector<string> Menu::_settingsNotiOn
private
Initial value:
= {
" _ _ ___ ___ _ ___ _ ___ ___ _ __ _ ",
" ) o |\\ | / \\ | | |_ | / /\\ | | / \\ |\\ | (_ __ / \\ |\\ | ",
" /_ o | \\| \\_/ | _|_ | _|_ \\_ /--\\ | _|_ \\_/ | \\| __) \\_/ | \\| ",
" ",
}

Definition at line 355 of file Menu.hpp.

◆ _stopMessages

vector<string> Menu::_stopMessages
private
Initial value:
= {
"EXACTLY ON THE DOT! YOU MUST BE A TIME WIZARD.",
"THERE'S NO WAY YOU MEANT TO DO THAT...",
"YOU'VE ACHIEVED STOPWATCH ZEN.",
"IF YOU DID THAT ON PURPOSE, I'M IMPRESSED.",
"DAMN, NICE REFLEXES.",
"YOU'RE A MEAN GREEN STOPWATCH MACHINE.",
"MEAN GREEN STOPWATCH MACHINE",
"YOU HAVE TO BE A ROBOT, RIGHT?",
"EVEN QUICKSILVER COULDN'T HAVE DONE IT BETTER.",
"YOU ARE A BUM, GO HOME LOSER!!!!"
}

Definition at line 415 of file Menu.hpp.

◆ _testing

bool Menu::_testing
private

Definition at line 191 of file Menu.hpp.


The documentation for this class was generated from the following files: