Color is now in one nice location.

main
Zed A. Shaw 1 month ago
parent c8fa68815b
commit b7002917c1
  1. 14
      color.hpp
  2. 5
      panel.hpp
  3. 28
      render.cpp
  4. 8
      render.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;
}

@ -9,6 +9,7 @@
#include <SFML/Graphics/Color.hpp>
#include <locale>
#include <codecvt>
#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;

@ -5,36 +5,16 @@
#include <array>
#include "map.hpp"
#include <iostream>
#include "color.hpp"
using namespace fmt;
std::array<sf::Color, 10> 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;
}

@ -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);

Loading…
Cancel
Save