diff --git a/constants.hpp b/constants.hpp index be4843e..52cb9b7 100644 --- a/constants.hpp +++ b/constants.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "color.hpp" constexpr const int TEXTURE_WIDTH=256; constexpr const int TEXTURE_HEIGHT=256; @@ -15,6 +16,13 @@ constexpr const int FRAME_LIMIT=60; constexpr const int NUM_SPRITES=1; constexpr const int MAX_LOG_MESSAGES=17; +constexpr const int GUECS_PADDING = 3; +constexpr const int GUECS_BORDER_PX = 1; +constexpr const int GUECS_FONT_SIZE = 30; +const sf::Color GUECS_FILL_COLOR = ColorValue::DARK_MID; +const sf::Color GUECS_BG_COLOR = ColorValue::MID; +const sf::Color GUECS_BORDER_COLOR = ColorValue::MID; + #ifdef NDEBUG constexpr const bool DEBUG_BUILD=false; #else diff --git a/guecs.cpp b/guecs.cpp index 575ac60..b21ef4c 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -1,5 +1,4 @@ #include "guecs.hpp" -#include "constants.hpp" namespace guecs { UI::UI() { @@ -55,9 +54,14 @@ namespace guecs { auto sprite_texture = textures.get(sprite.name); sprite.texture = sprite_texture.texture; sprite.sprite = make_shared(*sprite.texture); - sprite.sprite->setPosition({float(cell.x + 5), float(cell.y + 5)}); + sprite.sprite->setPosition({ + float(cell.x + GUECS_PADDING), + float(cell.y + GUECS_PADDING)}); + auto size = sprite.texture->getSize(); - sprite.sprite->setScale({float(cell.w - 10) / size.x, float(cell.h - 10) / size.y}); + sprite.sprite->setScale({ + float(cell.w - GUECS_PADDING * 2) / size.x, + float(cell.h - GUECS_PADDING * 2) / size.y}); }); } diff --git a/guecs.hpp b/guecs.hpp index 1e90a0c..ef223e0 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -8,13 +8,14 @@ #include "texture.hpp" #include #include "events.hpp" +#include "constants.hpp" namespace guecs { using std::shared_ptr, std::make_shared; struct Label { std::string label; - unsigned int size = 30; + unsigned int size = GUECS_FONT_SIZE; shared_ptr font = nullptr; shared_ptr text = nullptr; @@ -30,14 +31,14 @@ namespace guecs { struct Textual { std::string content; - unsigned int size = 30; + unsigned int size = GUECS_FONT_SIZE; shared_ptr font = nullptr; shared_ptr text = nullptr; void init(lel::Cell &cell, shared_ptr font_ptr) { if(font == nullptr) font = font_ptr; if(text == nullptr) text = make_shared(*font, content, size); - text->setPosition({float(cell.x + 6), float(cell.y + 6)}); + text->setPosition({float(cell.x + GUECS_PADDING * 2), float(cell.y + GUECS_PADDING * 2)}); text->setCharacterSize(size); } @@ -61,12 +62,12 @@ namespace guecs { shared_ptr shape = nullptr; void init(lel::Cell& cell) { - sf::Vector2f size{float(cell.w) - 6, float(cell.h) - 6}; + sf::Vector2f size{float(cell.w) - GUECS_PADDING * 2, float(cell.h) - GUECS_PADDING * 2}; if(shape == nullptr) shape = make_shared(size); - shape->setPosition({float(cell.x + 3), float(cell.y + 3)}); - shape->setFillColor(ColorValue::DARK_MID); - shape->setOutlineColor(ColorValue::MID); - shape->setOutlineThickness(1); + shape->setPosition({float(cell.x + GUECS_PADDING), float(cell.y + GUECS_PADDING)}); + shape->setFillColor(GUECS_FILL_COLOR); + shape->setOutlineColor(GUECS_BORDER_COLOR); + shape->setOutlineThickness(GUECS_BORDER_PX); } }; @@ -104,7 +105,7 @@ namespace guecs { sf::Vector2f size{float(w), float(h)}; if(shape == nullptr) shape = make_shared(size); shape->setPosition({float(x), float(y)}); - shape->setFillColor(ColorValue::MID); + shape->setFillColor(GUECS_BG_COLOR); } };