diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-12-19 03:41:57 +0100 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-12-24 22:57:56 +0100 |
commit | 3770de7a03879a8ff6b8cf22b402217c19fa2b53 (patch) | |
tree | 0d77d82ab8cea8955e2b86d883d1c2fd10813717 /src/openvic-simulation/interface | |
parent | 14e47d58b85f657ec1fed8abf88219f09bd3efbb (diff) |
Change colour_t to be a strongly typed structure
Make RGB default of `colour_t`
Distinguish RGB and ARGB colors by type and colour_traits
Add `_colour` and `_argb` colour user-defined literals
Add `OpenVic::utility::unreachable`
Diffstat (limited to 'src/openvic-simulation/interface')
-rw-r--r-- | src/openvic-simulation/interface/GFX.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GFX.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/interface/UI.cpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/interface/UI.hpp | 2 |
4 files changed, 14 insertions, 8 deletions
diff --git a/src/openvic-simulation/interface/GFX.cpp b/src/openvic-simulation/interface/GFX.cpp index 927b832..6f5ebf9 100644 --- a/src/openvic-simulation/interface/GFX.cpp +++ b/src/openvic-simulation/interface/GFX.cpp @@ -4,8 +4,8 @@ using namespace OpenVic; using namespace OpenVic::GFX; using namespace OpenVic::NodeTools; -Font::Font(std::string_view new_identifier, colour_t new_colour, std::string_view new_fontname) - : HasIdentifierAndColour { new_identifier, new_colour, false, true }, fontname { new_fontname } {} +Font::Font(std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname) + : HasIdentifierAndAlphaColour { new_identifier, new_colour, false }, fontname { new_fontname } {} node_callback_t Sprite::expect_sprite(callback_t<std::unique_ptr<Sprite>&&> callback) { return expect_dictionary_keys( diff --git a/src/openvic-simulation/interface/GFX.hpp b/src/openvic-simulation/interface/GFX.hpp index ff27613..5e750cc 100644 --- a/src/openvic-simulation/interface/GFX.hpp +++ b/src/openvic-simulation/interface/GFX.hpp @@ -8,7 +8,7 @@ namespace OpenVic { namespace OpenVic::GFX { - struct Font : HasIdentifierAndColour { + struct Font : HasIdentifierAndAlphaColour { friend class OpenVic::UIManager; private: @@ -16,7 +16,7 @@ namespace OpenVic::GFX { // TODO - colorcodes, effect - Font(std::string_view new_identifier, colour_t new_colour, std::string_view new_fontname); + Font(std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname); public: Font(Font&&) = default; diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp index 3fc8295..344fc15 100644 --- a/src/openvic-simulation/interface/UI.cpp +++ b/src/openvic-simulation/interface/UI.cpp @@ -1,17 +1,23 @@ #include "UI.hpp" +#include "openvic-simulation/types/Colour.hpp" + using namespace OpenVic; using namespace OpenVic::NodeTools; using namespace OpenVic::GFX; using namespace OpenVic::GUI; -bool UIManager::add_font(std::string_view identifier, colour_t colour, std::string_view fontname) { +bool UIManager::add_font(std::string_view identifier, colour_argb_t colour, std::string_view fontname) { if (identifier.empty()) { Logger::error("Invalid font identifier - empty!"); return false; } + if (colour.alpha == colour_argb_t::colour_traits::null) { + Logger::error("Invalid colour for font ", identifier, " - completely transparent! (", colour, ")"); + return false; + } if (fontname.empty()) { - Logger::error("Invalid culture colour for ", identifier, ": ", colour_to_hex_string(colour)); + Logger::error("Invalid fontname for font ", identifier, " - empty!"); return false; } return fonts.add_item({ identifier, colour, fontname }, duplicate_warning_callback); @@ -19,7 +25,7 @@ bool UIManager::add_font(std::string_view identifier, colour_t colour, std::stri bool UIManager::_load_font(ast::NodeCPtr node) { std::string_view identifier, fontname; - colour_t colour = NULL_COLOUR; + colour_argb_t colour = colour_argb_t::null(); bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(identifier)), "fontname", ONE_EXACTLY, expect_string(assign_variable_callback(fontname)), diff --git a/src/openvic-simulation/interface/UI.hpp b/src/openvic-simulation/interface/UI.hpp index ce9336c..286e4f7 100644 --- a/src/openvic-simulation/interface/UI.hpp +++ b/src/openvic-simulation/interface/UI.hpp @@ -12,7 +12,7 @@ namespace OpenVic { bool _load_font(ast::NodeCPtr node); public: - bool add_font(std::string_view identifier, colour_t colour, std::string_view fontname); + bool add_font(std::string_view identifier, colour_argb_t colour, std::string_view fontname); bool load_gfx_file(ast::NodeCPtr root); bool load_gui_file(std::string_view scene_name, ast::NodeCPtr root); |