The colors and other theme elements can be configured in assets/config.json
This commit is contained in:
parent
74a8599977
commit
8a3046e141
2 changed files with 59 additions and 19 deletions
|
@ -338,5 +338,26 @@
|
||||||
"SW": 8665,
|
"SW": 8665,
|
||||||
"W": 8592,
|
"W": 8592,
|
||||||
"NW": 8598
|
"NW": 8598
|
||||||
|
},
|
||||||
|
"theme": {
|
||||||
|
"black": [0, 0, 0, 255],
|
||||||
|
"dark_dark": [10, 10, 10, 255],
|
||||||
|
"dark_mid": [30, 30, 30, 255],
|
||||||
|
"dark_light": [60, 60, 60, 255],
|
||||||
|
"mid": [100, 100, 100, 255],
|
||||||
|
"light_dark": [150, 150, 150, 255],
|
||||||
|
"light_mid": [200, 200, 200, 255],
|
||||||
|
"light_light": [230, 230, 230, 255],
|
||||||
|
"white": [255, 255, 255, 255],
|
||||||
|
"padding": 3,
|
||||||
|
"border_px": 1,
|
||||||
|
"text_size": 20,
|
||||||
|
"label_size": 20,
|
||||||
|
"fill_color": "dark_mid",
|
||||||
|
"text_color": "light_light",
|
||||||
|
"bg_color": "mid",
|
||||||
|
"border_color": "dark_dark",
|
||||||
|
"bg_color_dark": "black",
|
||||||
|
"font_file_name": "assets/text.otf"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
57
backend.cpp
57
backend.cpp
|
@ -5,6 +5,8 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
|
||||||
namespace sfml {
|
namespace sfml {
|
||||||
|
using namespace nlohmann;
|
||||||
|
|
||||||
guecs::SpriteTexture Backend::texture_get(const string& name) {
|
guecs::SpriteTexture Backend::texture_get(const string& name) {
|
||||||
auto sp = textures::get(name);
|
auto sp = textures::get(name);
|
||||||
return {sp.sprite, sp.texture};
|
return {sp.sprite, sp.texture};
|
||||||
|
@ -37,30 +39,47 @@ namespace sfml {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline sf::Color to_color(json& config, const std::string& name) {
|
||||||
|
json& val = config[name];
|
||||||
|
if(val.type() == json::value_t::array) {
|
||||||
|
return sf::Color{val[0], val[1], val[2], val[3]};
|
||||||
|
} else if(val.type() == json::value_t::string) {
|
||||||
|
json& array = config[val];
|
||||||
|
return sf::Color{array[0], array[1], array[2], array[3]};
|
||||||
|
} else {
|
||||||
|
dbc::sentinel(fmt::format(
|
||||||
|
"theme config {} has invalid color setting,"
|
||||||
|
"either use an array of 4 ints or a string"
|
||||||
|
"referencing another config with 4 ints.", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
guecs::Theme Backend::theme() {
|
guecs::Theme Backend::theme() {
|
||||||
|
auto config = Config("assets/config.json")["theme"];
|
||||||
|
|
||||||
guecs::Theme theme {
|
guecs::Theme theme {
|
||||||
.BLACK={0, 0, 0},
|
.BLACK=to_color(config, "black"),
|
||||||
.DARK_DARK={10, 10, 10},
|
.DARK_DARK=to_color(config, "dark_dark"),
|
||||||
.DARK_MID={30, 30, 30},
|
.DARK_MID=to_color(config, "dark_mid"),
|
||||||
.DARK_LIGHT={60, 60, 60},
|
.DARK_LIGHT=to_color(config, "dark_light"),
|
||||||
.MID={100, 100, 100},
|
.MID=to_color(config, "mid"),
|
||||||
.LIGHT_DARK={150, 150, 150},
|
.LIGHT_DARK=to_color(config, "light_dark"),
|
||||||
.LIGHT_MID={200, 200, 200},
|
.LIGHT_MID=to_color(config, "light_mid"),
|
||||||
.LIGHT_LIGHT={230, 230, 230},
|
.LIGHT_LIGHT=to_color(config, "light_light"),
|
||||||
.WHITE={255, 255, 255},
|
.WHITE=to_color(config, "white"),
|
||||||
.TRANSPARENT = sf::Color::Transparent
|
.TRANSPARENT = sf::Color::Transparent
|
||||||
};
|
};
|
||||||
|
|
||||||
theme.PADDING = 3;
|
theme.PADDING = config["padding"];
|
||||||
theme.BORDER_PX = 1;
|
theme.BORDER_PX = config["border_px"];
|
||||||
theme.TEXT_SIZE = 20;
|
theme.TEXT_SIZE = config["text_size"];
|
||||||
theme.LABEL_SIZE = 20;
|
theme.LABEL_SIZE = config["label_size"];
|
||||||
theme.FILL_COLOR = theme.DARK_DARK;
|
theme.FILL_COLOR = to_color(config, "fill_color");
|
||||||
theme.TEXT_COLOR = theme.LIGHT_LIGHT;
|
theme.TEXT_COLOR = to_color(config, "text_color");
|
||||||
theme.BG_COLOR = theme.MID;
|
theme.BG_COLOR = to_color(config, "bg_color");
|
||||||
theme.BORDER_COLOR = theme.LIGHT_DARK;
|
theme.BORDER_COLOR = to_color(config, "border_color");
|
||||||
theme.BG_COLOR_DARK = theme.BLACK;
|
theme.BG_COLOR_DARK = to_color(config, "bg_color_dark");
|
||||||
theme.FONT_FILE_NAME = Config::path_to("assets/text.otf").string();
|
theme.FONT_FILE_NAME = Config::path_to(config["font_file_name"]).string();
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue