From 6aa2201797a9ed64ce0178215ae941d0c5f09579 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Oct 2020 00:07:57 +0800 Subject: ... --- include/cru/win/graphics/direct/Painter.hpp | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/cru/win/graphics/direct/Painter.hpp (limited to 'include/cru/win/graphics/direct/Painter.hpp') diff --git a/include/cru/win/graphics/direct/Painter.hpp b/include/cru/win/graphics/direct/Painter.hpp new file mode 100644 index 00000000..93c768e7 --- /dev/null +++ b/include/cru/win/graphics/direct/Painter.hpp @@ -0,0 +1,60 @@ +#pragma once +#include "ComResource.hpp" +#include "Resource.hpp" + +#include "cru/platform/graphics/Painter.hpp" + +#include + +namespace cru::platform::graphics::win::direct { +class D2DPainter : public DirectResource, + public virtual IPainter, + public virtual IComResource { + public: + explicit D2DPainter(ID2D1RenderTarget* render_target); + + CRU_DELETE_COPY(D2DPainter) + CRU_DELETE_MOVE(D2DPainter) + + ~D2DPainter() override = default; + + public: + ID2D1RenderTarget* GetComInterface() const override { return render_target_; } + + public: + Matrix GetTransform() override; + void SetTransform(const platform::Matrix& matrix) override; + + void Clear(const Color& color) override; + + void StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) override; + void FillRectangle(const Rect& rectangle, IBrush* brush) override; + + void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override; + void FillGeometry(IGeometry* geometry, IBrush* brush) override; + + void DrawText(const Point& offset, ITextLayout* text_layout, + IBrush* brush) override; + + void PushLayer(const Rect& bounds) override; + + void PopLayer() override; + + void EndDraw() override final; + + protected: + virtual void DoEndDraw() = 0; + + private: + bool IsValid() { return is_drawing_; } + void CheckValidation(); + + private: + ID2D1RenderTarget* render_target_; + + std::vector> layers_; + + bool is_drawing_ = true; +}; +} // namespace cru::platform::graphics::win::direct -- cgit v1.2.3