diff --git a/include/color_handler.h b/include/color_handler.h new file mode 100644 index 0000000..21b48f0 --- /dev/null +++ b/include/color_handler.h @@ -0,0 +1,31 @@ +#ifndef COLOR_HANDLER_H_ +#define COLOR_HANDLER_H_ + +#include + +#include "curses.h" + +namespace roadrun { +const int kColorRed = COLOR_RED; +const int kColorGreen = COLOR_GREEN; +const int kColorYellow = COLOR_YELLOW; +const int kColorBlue = COLOR_BLUE; +const int kColorMagenta = COLOR_MAGENTA; +const int kColorCyan = COLOR_CYAN; +const int kColorWhite = COLOR_WHITE; +class ColorHandler { + public: + static void InitializeColorPairs(); + static void PrintColor(WINDOW* window, int y, int x, const char* str, + int color_pair, ...); + static void PrintRed(WINDOW* window, int y, int x, const char* str, ...); + static void PrintGreen(WINDOW* window, int y, int x, const char* str, ...); + static void PrintYellow(WINDOW* window, int y, int x, const char* str, ...); + static void PrintBlue(WINDOW* window, int y, int x, const char* str, ...); + static void PrintMagenta(WINDOW* window, int y, int x, const char* str, ...); + static void PrintCyan(WINDOW* window, int y, int x, const char* str, ...); + static void PrintWhite(WINDOW* window, int y, int x, const char* str, ...); +}; +} // namespace roadrun + +#endif diff --git a/src/color_handler.cc b/src/color_handler.cc new file mode 100644 index 0000000..4d50c25 --- /dev/null +++ b/src/color_handler.cc @@ -0,0 +1,47 @@ +#include "color_handler.h" + +namespace roadrun { +void ColorHandler::InitializeColorPairs() { + init_pair(kColorRed, COLOR_RED, COLOR_BLACK); + init_pair(kColorGreen, COLOR_GREEN, COLOR_BLACK); + init_pair(kColorYellow, COLOR_YELLOW, COLOR_BLACK); + init_pair(kColorBlue, COLOR_BLUE, COLOR_BLACK); + init_pair(kColorMagenta, COLOR_MAGENTA, COLOR_BLACK); + init_pair(kColorCyan, COLOR_CYAN, COLOR_BLACK); + init_pair(kColorWhite, COLOR_WHITE, COLOR_BLACK); +} +void ColorHandler::PrintColor(WINDOW* window, int y, int x, const char* str, + int color_pair, ...) { + attron(COLOR_PAIR(color_pair)); + mvwprintw(window, y, x, str); + attroff(COLOR_PAIR(color_pair)); +} +void ColorHandler::PrintRed(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorRed); +} +void ColorHandler::PrintGreen(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorGreen); +} +void ColorHandler::PrintYellow(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorYellow); +} +void ColorHandler::PrintBlue(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorBlue); +} +void ColorHandler::PrintMagenta(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorMagenta); +} +void ColorHandler::PrintCyan(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorCyan); +} +void ColorHandler::PrintWhite(WINDOW* window, int y, int x, const char* str, + ...) { + PrintColor(window, y, x, str, kColorWhite); +} +} // namespace roadrun diff --git a/src/game_environment.cc b/src/game_environment.cc index ac1e149..687abd5 100644 --- a/src/game_environment.cc +++ b/src/game_environment.cc @@ -1,4 +1,5 @@ #include "game_environment.h" +#include "color_handler.h" namespace roadrun { @@ -20,6 +21,7 @@ namespace roadrun int GameEnvironment::PlayGame() { + ColorHandler::InitializeColorPairs(); while(1) { main_menu->PrintMenu(); diff --git a/src/main_menu.cc b/src/main_menu.cc index bf50b25..2f2529f 100644 --- a/src/main_menu.cc +++ b/src/main_menu.cc @@ -1,4 +1,5 @@ #include "main_menu.h" +#include "color_handler.h" using namespace std; @@ -21,10 +22,10 @@ namespace roadrun wattron(menu_win, A_REVERSE); mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i])); wattroff(menu_win, A_REVERSE); - } - else - { - mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i])); + } else { + ColorHandler::PrintGreen(menu_win, y, x, "%s", + MenuItemToString(choices, menu_item_list[i])); + // mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i])); } ++y; }