Skip to content

Commit

Permalink
Add Color to RoadRun
Browse files Browse the repository at this point in the history
Resolves #34
  • Loading branch information
evanugarte committed Oct 5, 2020
1 parent 17a4d14 commit d7b9155
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/color_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef COLOR_HANDLER_H_
#define COLOR_HANDLER_H_

#include <string_view>

#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
39 changes: 39 additions & 0 deletions src/color_handler.cc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/game_environment.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "game_environment.h"
#include "color_handler.h"

namespace roadrun
{
Expand Down

0 comments on commit d7b9155

Please sign in to comment.