diff options
author | crupest <crupest@outlook.com> | 2019-04-02 21:01:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-02 21:01:16 +0800 |
commit | 4ea8be24492f58564ff1b1efe9f7c4673078bcbc (patch) | |
tree | 7494d20ed04763936555547a6a10caa870567353 /include/cru | |
parent | 1091b720bab98908dc89931b3d54c37729d33df2 (diff) | |
download | cru-4ea8be24492f58564ff1b1efe9f7c4673078bcbc.tar.gz cru-4ea8be24492f58564ff1b1efe9f7c4673078bcbc.tar.bz2 cru-4ea8be24492f58564ff1b1efe9f7c4673078bcbc.zip |
...
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/platform/painter_util.hpp | 8 | ||||
-rw-r--r-- | include/cru/ui/render/border_render_object.hpp | 25 |
2 files changed, 21 insertions, 12 deletions
diff --git a/include/cru/platform/painter_util.hpp b/include/cru/platform/painter_util.hpp index fed0c487..5711d099 100644 --- a/include/cru/platform/painter_util.hpp +++ b/include/cru/platform/painter_util.hpp @@ -2,13 +2,17 @@ #include "painter.hpp" #include <functional> +#include <type_traits> namespace cru::platform::util { +template <typename Fn> inline void WithTransform(Painter* painter, const Matrix& matrix, - const std::function<void(Painter*)>& action) { + const Fn& action) { + static_assert(std::is_invocable_v<decltype(action), Painter*>, + "Action must can be be invoked with painter."); const auto old = painter->GetTransform(); painter->SetTransform(old * matrix); action(painter); painter->SetTransform(old); } -} +} // namespace cru::platform::util diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index a96ccf99..35b98948 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -1,9 +1,12 @@ #pragma once #include "render_object.hpp" +#include <memory> + namespace cru::platform { struct Brush; -} +struct Geometry; +} // namespace cru::platform namespace cru::ui::render { struct CornerRadius { @@ -29,18 +32,20 @@ struct CornerRadius { class BorderRenderObject : public RenderObject { public: - explicit BorderRenderObject(platform::Brush* brush); + explicit BorderRenderObject(std::shared_ptr<platform::Brush> brush); BorderRenderObject(const BorderRenderObject& other) = delete; BorderRenderObject(BorderRenderObject&& other) = delete; BorderRenderObject& operator=(const BorderRenderObject& other) = delete; BorderRenderObject& operator=(BorderRenderObject&& other) = delete; - ~BorderRenderObject() override; + ~BorderRenderObject() override = default; bool IsEnabled() const { return is_enabled_; } void SetEnabled(bool enabled) { is_enabled_ = enabled; } - ID2D1Brush* GetBrush() const { return border_brush_; } - void SetBrush(ID2D1Brush* new_brush); + std::shared_ptr<platform::Brush> GetBrush() const { return border_brush_; } + void SetBrush(std::shared_ptr<platform::Brush> new_brush) { + border_brush_ = std::move(new_brush); + } Thickness GetBorderWidth() const { return border_thickness_; } void SetBorderWidth(const Thickness& thickness) { @@ -54,7 +59,7 @@ class BorderRenderObject : public RenderObject { void Refresh() { RecreateGeometry(); } - void Draw(ID2D1RenderTarget* render_target) override; + void Draw(platform::Painter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -78,11 +83,11 @@ class BorderRenderObject : public RenderObject { private: bool is_enabled_ = false; - ID2D1Brush* border_brush_ = nullptr; - Thickness border_thickness_ = Thickness::Zero(); + std::shared_ptr<platform::Brush> border_brush_ = nullptr; + Thickness border_thickness_{}; CornerRadius corner_radius_{}; - ID2D1Geometry* geometry_ = nullptr; - ID2D1Geometry* border_outer_geometry_ = nullptr; + std::shared_ptr<platform::Geometry> geometry_ = nullptr; + std::shared_ptr<platform::Geometry> border_outer_geometry_ = nullptr; }; } // namespace cru::ui::render |