Quickly pulled out some of the magic numbers but this isn't the ideal way to configure this stuff.

master
Zed A. Shaw 3 weeks ago
parent e04c03b381
commit f2b7871d12
  1. 8
      constants.hpp
  2. 10
      guecs.cpp
  3. 19
      guecs.hpp

@ -1,6 +1,7 @@
#pragma once
#include <string>
#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

@ -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<sf::Sprite>(*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});
});
}

@ -8,13 +8,14 @@
#include "texture.hpp"
#include <functional>
#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<sf::Font> font = nullptr;
shared_ptr<sf::Text> 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<sf::Font> font = nullptr;
shared_ptr<sf::Text> text = nullptr;
void init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
if(font == nullptr) font = font_ptr;
if(text == nullptr) text = make_shared<sf::Text>(*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<sf::RectangleShape> 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<sf::RectangleShape>(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<sf::RectangleShape>(size);
shape->setPosition({float(x), float(y)});
shape->setFillColor(ColorValue::MID);
shape->setFillColor(GUECS_BG_COLOR);
}
};

Loading…
Cancel
Save