#ifndef LLMR_STYLE_STYLE #define LLMR_STYLE_STYLE #include #include #include #include #include #include #include #include #include #include #include #include #include namespace llmr { class Sprite; class StyleLayer; typedef std::vector> StyleLayerGroup; class StyleLayer { public: typedef std::shared_ptr Ptr; public: template const T &getProperties() { if (style.is()) { return style.get(); } else { return defaultStyleProperties(); } } public: std::string id; StyleBucket::Ptr bucket; std::unordered_map styles; StyleProperties style; std::unique_ptr rasterize; std::shared_ptr layers; }; class Style { public: struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} }; public: Style(); void reset(); void loadJSON(const uint8_t *const data); size_t layerCount() const; void cascade(float z); bool needsTransition() const; void updateTransitions(time now); void cancelTransitions(); void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0); void updateSources(); const std::set> getActiveSources() const; const std::vector &getAppliedClasses() const; void toggleClass(const std::string &name); public: std::shared_ptr sprite; std::shared_ptr layers; std::shared_ptr background; std::vector appliedClasses; private: void updateSources(const std::shared_ptr &layers); void cascade(const std::shared_ptr &layers, float z); private: std::set> activeSources; // This is static information parsed from the stylesheet. // // This is unused!!! // std::map buckets; // // // std::vector layers; // // // These are unused!!! // std::map classes; // // // Currently applied settings. // struct { // BackgroundProperties background; // std::unordered_map fills; // std::unordered_map lines; // std::unordered_map icons; // std::unordered_map texts; // std::unordered_map rasters; // std::unordered_map composites; // std::unordered_map> effective_classes; // } computed; private: // bool transitionInProgress(const std::string &layer_name, TransitionablePropertyKey key, time start); // bool transitionExists(const std::string &layer_name, TransitionablePropertyKey key) const; // bool inNeedOfTransition(const std::string &layer_name, TransitionablePropertyKey key) const; // uint64_t transitionDuration(const std::string &layer_name, TransitionablePropertyKey key) const; // uint64_t transitionDelay(const std::string &layer_name, TransitionablePropertyKey key) const; // // void cascadeProperties(GenericProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(FillProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(LineProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(IconProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(TextProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(RasterProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(CompositeProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); // void cascadeProperties(BackgroundProperties &properties, const ClassProperties& klass, const std::string& layer_name, const std::string& class_name, float z); private: // Last applied settings. // struct { // BackgroundProperties background; // std::unordered_map fills; // std::unordered_map lines; // std::unordered_map icons; // std::unordered_map texts; // std::unordered_map rasters; // std::unordered_map composites; // std::unordered_map> effective_classes; // } previous; // // Settings values currently being transitioned. // struct { // BackgroundProperties background; // std::unordered_map fills; // std::unordered_map lines; // std::unordered_map icons; // std::unordered_map texts; // std::unordered_map rasters; // std::unordered_map composites; // } transitioning; // std::unordered_map> properties_to_transition; // std::unordered_map>> transitions; uint64_t default_transition_duration = 0; bool initial_render_complete = false; mutable uv::rwlock mtx; }; } #endif