diff --git a/color.hpp b/color.hpp new file mode 100644 index 0000000..bdf0f54 --- /dev/null +++ b/color.hpp @@ -0,0 +1,14 @@ +#pragma once + +namespace color { + const sf::Color BLACK{1, 4, 2}; + const sf::Color DARK_DARK{9, 29, 16}; + const sf::Color DARK_MID{14, 50, 26}; + const sf::Color DARK_LIGHT{0, 109, 44}; + const sf::Color MID{63, 171, 92}; + const sf::Color LIGHT_DARK{161, 217, 155}; + const sf::Color LIGHT_MID{199, 233, 192}; + const sf::Color LIGHT_LIGHT{229, 245, 224}; + const sf::Color WHITE{255, 255, 255}; + const sf::Color TRANSPARENT = sf::Color::Transparent; +} diff --git a/panel.hpp b/panel.hpp index 61cad1a..1aae1fb 100644 --- a/panel.hpp +++ b/panel.hpp @@ -9,6 +9,7 @@ #include #include #include +#include "color.hpp" const int UI_PANEL_BORDER_PX=5; @@ -22,8 +23,8 @@ struct Panel { bool has_border = false; bool must_clear = true; bool grid = false; - sf::Color default_bg = sf::Color(0,0,0); - sf::Color border_color = sf::Color::Red; + sf::Color default_bg = color::BLACK; + sf::Color border_color = color::MID; int border_px = UI_PANEL_BORDER_PX; bool $dirty = true; diff --git a/render.cpp b/render.cpp index 8788ca0..a4155cb 100644 --- a/render.cpp +++ b/render.cpp @@ -5,36 +5,16 @@ #include #include "map.hpp" #include +#include "color.hpp" using namespace fmt; -std::array VALUES{ - sf::Color{1, 4, 2}, // black - sf::Color{9, 29, 16}, // dark dark - sf::Color{14, 50, 26}, // dark mid - sf::Color{0, 109, 44}, // dark light - sf::Color{63, 171, 92}, // mid - sf::Color{161, 217, 155}, // light dark - sf::Color{199, 233, 192}, // light mid - sf::Color{229, 245, 224}, // light light - sf::Color{255, 255, 255}, // white - sf::Color::Transparent, // white -}; - -sf::Color SFMLRender::color(int val) { - return VALUES[size_t(val)]; -} - -sf::Color SFMLRender::color(Value val) { - return VALUES[size_t(val)]; -} - SFMLRender::SFMLRender() : $window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"), $map_font_size(0), $line_spacing(0), - $default_fg(color(Value::LIGHT_MID)), - $default_bg(color(Value::BLACK)), + $default_fg(color::LIGHT_MID), + $default_bg(color::BLACK), $ansi($default_fg, $default_bg) { // force true color, but maybe I want to support different color sets @@ -43,7 +23,7 @@ SFMLRender::SFMLRender() : $ui_text.setFont($font); $ui_text.setPosition(0,0); $ui_text.setCharacterSize(UI_FONT_SIZE); - $ui_text.setFillColor(color(Value::LIGHT_MID)); + $ui_text.setFillColor(color::LIGHT_MID); sf::Glyph glyph = $font.getGlyph(UI_BASE_CHAR, UI_FONT_SIZE, false); $ui_bounds = glyph.bounds; } diff --git a/render.hpp b/render.hpp index 88cef4f..d4a412f 100644 --- a/render.hpp +++ b/render.hpp @@ -24,12 +24,6 @@ const wchar_t BG_TILE = L'█'; const wchar_t UI_BASE_CHAR = L'█'; const int BG_BOX_OFFSET=5; -enum class Value { - BLACK=0, DARK_DARK, DARK_MID, - DARK_LIGHT, MID, LIGHT_DARK, LIGHT_MID, - LIGHT_LIGHT, WHITE, TRANSPARENT -}; - struct SFMLRender { sf::RenderWindow $window; int $map_font_size; @@ -52,8 +46,6 @@ struct SFMLRender { // disable copy SFMLRender(SFMLRender &other) = delete; - sf::Color color(int val); - sf::Color color(Value val); sf::Sprite &get_text_sprite(wchar_t tile); bool resize_map(int new_size, Point &view_port); void render_grid(const std::wstring &text, float x, float y);