diff --git a/include/color_handler.h b/include/color_handler.h new file mode 100644 index 0000000..2657a35 --- /dev/null +++ b/include/color_handler.h @@ -0,0 +1,30 @@ +#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(int y, int x, const char* str, int color_pair); + static void PrintRed(int y, int x, const char* str); + static void PrintGreen(int y, int x, const char* str); + static void PrintYellow(int y, int x, const char* str); + static void PrintBlue(int y, int x, const char* str); + static void PrintMagenta(int y, int x, const char* str); + static void PrintCyan(int y, int x, const char* str); + static void PrintWhite(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..3c936b4 --- /dev/null +++ b/src/color_handler.cc @@ -0,0 +1,39 @@ +#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(int y, int x, const char* str, int color_pair) { + attron(COLOR_PAIR(color_pair)); + mvprintw(y, x, str); + attroff(COLOR_PAIR(color_pair)); +} +void ColorHandler::PrintRed(int y, int x, const char* str) { + PrintColor(y, x, str, kColorRed); +} +void ColorHandler::PrintGreen(int y, int x, const char* str) { + PrintColor(y, x, str, kColorGreen); +} +void ColorHandler::PrintYellow(int y, int x, const char* str) { + PrintColor(y, x, str, kColorYellow); +} +void ColorHandler::PrintBlue(int y, int x, const char* str) { + PrintColor(y, x, str, kColorBlue); +} +void ColorHandler::PrintMagenta(int y, int x, const char* str) { + PrintColor(y, x, str, kColorMagenta); +} +void ColorHandler::PrintCyan(int y, int x, const char* str) { + PrintColor(y, x, str, kColorCyan); +} +void ColorHandler::PrintWhite(int y, int x, const char* str) { + PrintColor(y, x, str, kColorWhite); +} +} // namespace roadrun diff --git a/src/game_environment.cc b/src/game_environment.cc index ac1e149..6d3ec9c 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 {