Browse Source

fix: solidlayers do not have to use fullscreen, somewhat apply conditions for dynamic values

Almamu 9 tháng trước cách đây
mục cha
commit
aad6a8e296

+ 37 - 0
src/WallpaperEngine/Data/Model/DynamicValue.cpp

@@ -79,6 +79,10 @@ const bool& DynamicValue::getBool () const {
     return this->m_bool;
 }
 
+const std::string& DynamicValue::getString () const {
+    return this->m_string;
+}
+
 DynamicValue::UnderlyingType DynamicValue::getType () const {
     return this->m_type;
 }
@@ -118,6 +122,7 @@ void DynamicValue::update (const float newValue) {
     this->m_float = newValue;
     this->m_int = static_cast<int> (newValue);
     this->m_bool = static_cast<int> (newValue) != 0;
+    this->m_string = "";
     this->m_type = UnderlyingType::Float;
 
     this->propagate ();
@@ -133,6 +138,7 @@ void DynamicValue::update (const int newValue) {
     this->m_float = static_cast<float> (newValue);
     this->m_int = newValue;
     this->m_bool = newValue != 0;
+    this->m_string = "";
     this->m_type = UnderlyingType::Int;
 
     this->propagate ();
@@ -148,6 +154,7 @@ void DynamicValue::update (const bool newValue) {
     this->m_float = newValue;
     this->m_int = newValue;
     this->m_bool = newValue;
+    this->m_string = "";
     this->m_type = UnderlyingType::Boolean;
 
     this->propagate ();
@@ -163,6 +170,7 @@ void DynamicValue::update(const glm::vec2& newValue) {
     this->m_float = newValue.x;
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0.0f;
+    this->m_string = "";
     this->m_type = UnderlyingType::Vec2;
 
     this->propagate ();
@@ -178,6 +186,7 @@ void DynamicValue::update(const glm::vec3& newValue) {
     this->m_float = newValue.x;
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0.0f;
+    this->m_string = "";
     this->m_type = UnderlyingType::Vec3;
 
     this->propagate ();
@@ -193,6 +202,7 @@ void DynamicValue::update(const glm::vec4& newValue) {
     this->m_float = newValue.x;
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0.0f;
+    this->m_string = "";
     this->m_type = UnderlyingType::Vec4;
 
     this->propagate ();
@@ -208,6 +218,7 @@ void DynamicValue::update(const glm::ivec2& newValue) {
     this->m_float = static_cast<float> (newValue.x);
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0;
+    this->m_string = "";
     this->m_type = UnderlyingType::IVec2;
 
     this->propagate ();
@@ -223,6 +234,7 @@ void DynamicValue::update(const glm::ivec3& newValue) {
     this->m_float = static_cast<float> (newValue.x);
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0;
+    this->m_string = "";
     this->m_type = UnderlyingType::IVec3;
 
     this->propagate ();
@@ -238,11 +250,26 @@ void DynamicValue::update(const glm::ivec4& newValue) {
     this->m_float = static_cast<float> (newValue.x);
     this->m_int = static_cast<int> (newValue.x);
     this->m_bool = newValue.x != 0;
+    this->m_string = "";
     this->m_type = UnderlyingType::IVec4;
 
     this->propagate ();
 }
 
+void DynamicValue::update (const std::string& newValue) {
+    this->m_ivec4 = glm::ivec4(0);
+    this->m_ivec3 = glm::ivec3(0);
+    this->m_ivec2 = glm::ivec2(0);
+    this->m_vec2 = glm::vec2(0.0f);
+    this->m_vec3 = glm::vec3(0.0f);
+    this->m_vec4 = glm::vec4(0.0f);
+    this->m_float = 0.0f;
+    this->m_int = 0;
+    this->m_bool = false;
+    this->m_string = newValue;
+    this->m_type = UnderlyingType::String;
+}
+
 void DynamicValue::update (const DynamicValue& other) {
     this->m_ivec4 = other.getIVec4 ();
     this->m_ivec3 = other.getIVec3 ();
@@ -255,6 +282,11 @@ void DynamicValue::update (const DynamicValue& other) {
     this->m_bool = other.getBool ();
     this->m_type = other.getType ();
 
+    if (this->m_condition.has_value () && other.getType () == UnderlyingType::String) {
+        // TODO: DOES THIS NEED TO HAPPEN WITH OTHER TYPES TOO?
+        this->m_bool = this->m_condition.value ().condition == other.getString ();
+    }
+
     this->propagate ();
 }
 
@@ -308,6 +340,11 @@ void DynamicValue::disconnect () {
     this->m_connections.clear ();
 }
 
+void DynamicValue::attachCondition (const ConditionInfo& condition) {
+    this->m_condition = condition;
+}
+
+
 void DynamicValue::propagate () const {
     for (const auto& callback : this->m_listeners) {
         callback(*this);

+ 19 - 1
src/WallpaperEngine/Data/Model/DynamicValue.h

@@ -3,8 +3,14 @@
 #include <glm/glm.hpp>
 #include <string>
 #include <functional>
+#include <optional>
 
 namespace WallpaperEngine::Data::Model {
+struct ConditionInfo {
+    std::string name;
+    std::string condition;
+};
+
 /**
  * Class that represents different types of dynamic values
  */
@@ -20,7 +26,8 @@ class DynamicValue {
         Vec2 = 6,
         Float = 7,
         Int = 8,
-        Boolean = 9
+        Boolean = 9,
+        String = 10
     };
 
     DynamicValue () = default;
@@ -44,6 +51,7 @@ class DynamicValue {
     [[nodiscard]] const float& getFloat () const;
     [[nodiscard]] const int& getInt () const;
     [[nodiscard]] const bool& getBool () const;
+    [[nodiscard]] const std::string& getString () const;
     [[nodiscard]] UnderlyingType getType () const;
     [[nodiscard]] virtual std::string toString () const;
 
@@ -56,6 +64,7 @@ class DynamicValue {
     virtual void update (const glm::ivec2& newValue);
     virtual void update (const glm::ivec3& newValue);
     virtual void update (const glm::ivec4& newValue);
+    virtual void update (const std::string& newValue);
     virtual void update (const DynamicValue& other);
     /**
      * Sets the current value to null
@@ -86,6 +95,13 @@ class DynamicValue {
      */
     void disconnect ();
 
+    /**
+     * Associates a condition with the dynamic value to apply proper checks
+     *
+     * @param condition
+     */
+    void attachCondition (const ConditionInfo& condition);
+
   private:
     /**
      * Notifies any listeners that the value has changed
@@ -104,6 +120,8 @@ class DynamicValue {
     float m_float = 0.0f;
     int m_int = 0;
     bool m_bool = false;
+    std::string m_string = "";
     UnderlyingType m_type = Null;
+    std::optional<ConditionInfo> m_condition = std::nullopt;
 };
 }

+ 11 - 19
src/WallpaperEngine/Data/Model/Property.h

@@ -31,7 +31,7 @@ class Property : public DynamicValue, public TypeCaster, public PropertyData {
 
     using DynamicValue::update;
     virtual void update(const std::string& value) = 0;
-    virtual std::string dump () const = 0;
+    [[nodiscard]] virtual std::string dump () const = 0;
 };
 
 class PropertySlider final : public Property, SliderData {
@@ -45,7 +45,7 @@ class PropertySlider final : public Property, SliderData {
         this->update (std::stof (value));
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - slider" << std::endl
@@ -70,7 +70,7 @@ class PropertyBoolean final : public Property {
         this->update (value == "true" || value == "1");
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - boolean" << std::endl
@@ -133,7 +133,7 @@ class PropertyColor final : public Property {
         this->update (VectorBuilder::parse <glm::vec3> (copy));
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - color" << std::endl
@@ -152,16 +152,11 @@ class PropertyCombo final : public Property, ComboData {
 
     using Property::update;
     void update(const std::string& value) override {
-        // search for the value in the combo options
-        if (this->values.contains (value)) {
-            this->m_value = this->values.at (value);
-        } else {
-            // default to a textual value if it's not found
-            this->m_value = value;
-        }
+        // search for the value in the combo options or default to the textual value
+        this->DynamicValue::update (this->values.contains (value) ? this->values.at (value) : value);
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - combo" << std::endl
@@ -175,9 +170,6 @@ class PropertyCombo final : public Property, ComboData {
 
         return ss.str ();
     }
-
-  private:
-    std::string m_value;
 };
 
 class PropertyText final : public Property {
@@ -193,7 +185,7 @@ class PropertyText final : public Property {
         return this->text;
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - text" << std::endl
@@ -214,7 +206,7 @@ class PropertySceneTexture final : public Property {
         this->m_value = value;
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - scene texture" << std::endl
@@ -238,7 +230,7 @@ class PropertyFile final : public Property {
         this->m_value = value;
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - file" << std::endl
@@ -262,7 +254,7 @@ class PropertyTextInput final : public Property {
         this->m_value = value;
     }
 
-    std::string dump () const override {
+    [[nodiscard]] std::string dump () const override {
         std::stringstream ss;
 
         ss << this->name << " - textinput" << std::endl

+ 0 - 5
src/WallpaperEngine/Data/Model/UserSetting.h

@@ -7,11 +7,6 @@
 #include "Types.h"
 
 namespace WallpaperEngine::Data::Model {
-struct ConditionInfo {
-    std::string name;
-    std::string condition;
-};
-
 struct UserSetting {
     /**
      * The value of this setting, can be a few different things:

+ 4 - 0
src/WallpaperEngine/Data/Parsers/UserSettingParser.cpp

@@ -69,6 +69,10 @@ UserSettingUniquePtr UserSettingParser::parse (const json& data, const Propertie
     // TODO: This might need to be removed if it causes issues with default values
     // Connect to property if one is specified (this allows property overrides to propagate)
     if (property != nullptr) {
+        if (condition.has_value ()) {
+            value->attachCondition (condition.value ());
+        }
+
         value->connect (property.get());
     }
 

+ 1 - 1
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -55,7 +55,7 @@ CImage::CImage (Wallpapers::CScene& scene, const Image& image) :
             this->m_texture = this->getContext ().resolveTexture (textureName);
         }
     } else {
-        if (this->m_image.model->solidlayer) {
+        if (this->m_image.model->solidlayer && size.x == 0.0f && size.y == 0.0f) {
             size.x = scene_width;
             size.y = scene_height;
         }