From 6508f54333497ef665dfc4262017f9cd4248552e Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 10 Mar 2023 19:41:06 +0800 Subject: [PATCH] =?UTF-8?q?MaterialStyle=E5=8A=A0=E5=85=A5=E6=B7=B1?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E6=96=B9=E6=B3=95clone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LayerStyleDialog.cpp | 2 +- .../src/Editor/LayerStyle.cpp | 8 +++---- .../src/Editor/LayerStyle.h | 6 +++--- .../src/Renderer/Painting/BaseStyle.h | 1 + .../Renderer/Painting/MaterialStyleFill.cpp | 10 +++++++++ .../src/Renderer/Painting/MaterialStyleFill.h | 17 ++++++++------- .../Renderer/Painting/MaterialStyleStroke.cpp | 21 +++++++++++++------ .../Renderer/Painting/MaterialStyleStroke.h | 6 +++++- 8 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp index ffc3899..7a7db8d 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp @@ -18,7 +18,7 @@ LayerStyleDialog::LayerStyleDialog( if (existedStyle) { - this->modifyingStyle = std::make_unique(existedStyle->clonePtr()); + this->modifyingStyle = existedStyle->clonePtr(); this->styleContainer = nullptr; this->styleWidget = modifyingStyle->getInputWidget(); diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index d4ba2ad..c76432f 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -54,9 +54,9 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& } } -std::shared_ptr StrokeElementLayerStyle::clonePtr() const +std::unique_ptr StrokeElementLayerStyle::clonePtr() const { - return std::make_shared(StrokeElementLayerStyle(*this)); + return std::make_unique(StrokeElementLayerStyle(*this)); } std::vector FillElementLayerStyle::toBaseStyles() const @@ -97,7 +97,7 @@ FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other) } } -std::shared_ptr FillElementLayerStyle::clonePtr() const +std::unique_ptr FillElementLayerStyle::clonePtr() const { - return std::make_shared(FillElementLayerStyle(*this)); + return std::make_unique(FillElementLayerStyle(*this)); } diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 4f10384..79a49ec 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -24,7 +24,7 @@ public: virtual QWidget* getInputWidget() const = 0; virtual QWidget* getListDisplayWidget() const = 0; virtual ~LayerStyle() {}; - virtual std::shared_ptr clonePtr() const = 0; + virtual std::unique_ptr clonePtr() const = 0; }; class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle @@ -38,7 +38,7 @@ public: StrokeElementLayerStyle(const StrokeElementLayerStyle& other); ~StrokeElementLayerStyle() = default; std::vector> materialStyles; - std::shared_ptr clonePtr() const override; + std::unique_ptr clonePtr() const override; }; class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle @@ -52,5 +52,5 @@ public: FillElementLayerStyle(const FillElementLayerStyle& other); ~FillElementLayerStyle() = default; std::vector> materialStyles; - std::shared_ptr clonePtr() const override; + std::unique_ptr clonePtr() const override; }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/BaseStyle.h b/ArchitectureColoredPainting/src/Renderer/Painting/BaseStyle.h index 0a23c1a..6a1e7a8 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/BaseStyle.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/BaseStyle.h @@ -23,6 +23,7 @@ namespace Renderer public: virtual MaterialStyleType type() const = 0; virtual std::vector encoded() const = 0; + virtual std::unique_ptr clone() const = 0; virtual bool operator==(const MaterialStyle&) const = 0; }; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.cpp index 889b72e..318895c 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.cpp @@ -18,6 +18,11 @@ std::vector Renderer::FillPlain::encoded() const glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())))}; } +std::unique_ptr Renderer::FillPlain::clone() const +{ + return std::make_unique(*this); +} + bool Renderer::FillPlain::operator==(const MaterialFill& m) const { return type() == m.type() @@ -42,6 +47,11 @@ std::vector Renderer::MaterialStyleFill::encoded() const return materialFill->encoded(); } +std::unique_ptr Renderer::MaterialStyleFill::clone() const +{ + return std::make_unique(materialFill->clone()); +} + bool Renderer::MaterialStyleFill::operator==(const MaterialStyle& m) const { return type() == m.type() && *materialFill == *static_cast(m).materialFill; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.h b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.h index 6280936..e3c1001 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleFill.h @@ -10,6 +10,7 @@ namespace Renderer public: virtual MaterialFillType type() const = 0; virtual std::vector encoded() const = 0; + virtual std::unique_ptr clone() const = 0; virtual bool operator==(const MaterialFill&) const = 0; }; @@ -19,6 +20,7 @@ namespace Renderer FillPlain(QColor color, float metallic, float roughness); virtual MaterialFillType type() const override; virtual std::vector encoded() const override; + virtual std::unique_ptr clone() const override; virtual bool operator==(const MaterialFill&) const override; QColor color; @@ -26,16 +28,17 @@ namespace Renderer float roughness; }; - class MaterialStyleFill : public MaterialStyle - { - public: + class MaterialStyleFill : public MaterialStyle + { + public: MaterialStyleFill(std::shared_ptr materialFill); - virtual MaterialStyleType type() const override; - virtual std::vector encoded() const override; + virtual MaterialStyleType type() const override; + virtual std::vector encoded() const override; + virtual std::unique_ptr clone() const override; virtual bool operator==(const MaterialStyle&) const override; - //protected: + //protected: std::shared_ptr materialFill; - }; + }; } diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp index 7834d21..340b767 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp @@ -18,6 +18,11 @@ MaterialStrokeType Renderer::StrokePlain::type() const return MaterialStrokeType::kPlain; } +std::unique_ptr Renderer::StrokePlain::clone() const +{ + return std::make_unique(*this); +} + std::vector Renderer::StrokePlain::encoded() const { return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))), @@ -58,6 +63,11 @@ std::vector Renderer::StrokeRadialGradient::encoded() const return result; } +std::unique_ptr Renderer::StrokeRadialGradient::clone() const +{ + return std::make_unique(*this); +} + bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const { return type() == m.type() @@ -70,12 +80,6 @@ Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strok { } -Renderer::MaterialStyleStroke::MaterialStyleStroke(const MaterialStyleStroke& s) - :halfWidth(s.halfWidth), strokeType(s.strokeType), endType(s.endType), materialStroke(std::make_shared(*s.materialStroke)) -{ - -} - MaterialStyleType Renderer::MaterialStyleStroke::type() const { return MaterialStyleType::kStroke; @@ -93,6 +97,11 @@ std::vector Renderer::MaterialStyleStroke::encoded() const return v; } +std::unique_ptr Renderer::MaterialStyleStroke::clone() const +{ + return std::make_unique(halfWidth*2, strokeType, endType, materialStroke->clone()); +} + bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const { return type() == m.type() && *materialStroke == *static_cast(m).materialStroke; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h index 6da06ff..db5ddbf 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h @@ -11,6 +11,7 @@ namespace Renderer public: virtual MaterialStrokeType type() const = 0; virtual std::vector encoded() const = 0; + virtual std::unique_ptr clone() const = 0; virtual bool operator==(const MaterialStroke&) const = 0; }; @@ -20,7 +21,9 @@ namespace Renderer StrokePlain(QColor color, float metallic, float roughness); StrokePlain(const Material& material); virtual MaterialStrokeType type() const override; + virtual std::unique_ptr clone() const override; virtual std::vector encoded() const override; + virtual bool operator==(const MaterialStroke&) const override; Material material; @@ -32,6 +35,7 @@ namespace Renderer StrokeRadialGradient(const std::map& materialMap, bool gradual); virtual MaterialStrokeType type() const override; virtual std::vector encoded() const override; + virtual std::unique_ptr clone() const override; virtual bool operator==(const MaterialStroke&) const override; std::map materialMap; @@ -45,9 +49,9 @@ namespace Renderer { public: MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr materialStroke); - MaterialStyleStroke(const MaterialStyleStroke&); virtual MaterialStyleType type() const override; virtual std::vector encoded() const override; + virtual std::unique_ptr clone() const override; virtual bool operator==(const MaterialStyle&) const override; float getHalfWidth() const; //protected: