diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-02 18:18:38 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-02 18:18:38 +0000 |
commit | 98df33e0a52e086b68df2a62ce2f41cc6b67db63 (patch) | |
tree | 196300dbc07855b130e73b92077ff0e1e701a418 /assetFactory/style.h | |
parent | Remove to specify if the Selection pointer type is shared or not (diff) | |
download | ilt-98df33e0a52e086b68df2a62ce2f41cc6b67db63.tar.bz2 ilt-98df33e0a52e086b68df2a62ce2f41cc6b67db63.tar.xz ilt-98df33e0a52e086b68df2a62ce2f41cc6b67db63.zip |
Parse colour values as they're read
Diffstat (limited to 'assetFactory/style.h')
-rw-r--r-- | assetFactory/style.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/assetFactory/style.h b/assetFactory/style.h index 0c7ad5a..e8fd012 100644 --- a/assetFactory/style.h +++ b/assetFactory/style.h @@ -3,19 +3,31 @@ #include "modelFactoryMesh.h" #include "persistence.h" #include "shape.h" +#include <optional> #include <string> +#include <utility> class Style { public: using StyleStack = std::vector<const Style *>; + using Colour = glm::vec3; + using ColourAlpha = glm::vec4; - static ModelFactoryMesh::Color parseColour(const std::string_view &); void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; - static std::string_view getProperty(const StyleStack & parents, std::string Style::*member); + template<typename T> + static std::optional<std::reference_wrapper<const T>> + getProperty(const StyleStack & parents, T Style::*member, auto && test) + { + if (const auto itr = std::find_if(parents.rbegin(), parents.rend(), std::forward<decltype(test)>(test)); + itr != parents.rend()) { + return (*itr)->*member; + } + return {}; + } - std::string colour; + ColourAlpha colour {}; protected: bool persist(Persistence::PersistenceStore & store); |