diff options
author | crupest <crupest@outlook.com> | 2022-05-15 13:56:40 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-05-15 13:56:40 +0800 |
commit | 9e0c9d3499bc50c3534b4dc500d8b5d0b5f22752 (patch) | |
tree | 7342f6991771fa31b16fd6a5ed892ff6025f3d05 /include/cru/platform/graphics/direct2d/Painter.h | |
parent | 41de54bad2c0f857821fcc83f41af3334d068b6d (diff) | |
download | cru-9e0c9d3499bc50c3534b4dc500d8b5d0b5f22752.tar.gz cru-9e0c9d3499bc50c3534b4dc500d8b5d0b5f22752.tar.bz2 cru-9e0c9d3499bc50c3534b4dc500d8b5d0b5f22752.zip |
...
Diffstat (limited to 'include/cru/platform/graphics/direct2d/Painter.h')
-rw-r--r-- | include/cru/platform/graphics/direct2d/Painter.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/include/cru/platform/graphics/direct2d/Painter.h b/include/cru/platform/graphics/direct2d/Painter.h new file mode 100644 index 00000000..f85d840a --- /dev/null +++ b/include/cru/platform/graphics/direct2d/Painter.h @@ -0,0 +1,80 @@ +#pragma once +#include "ComResource.h" +#include "Resource.h" + +#include "cru/common/Base.h" +#include "cru/platform/graphics/Painter.h" + +#include <vector> + +namespace cru::platform::graphics::direct2d { +class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter + : public DirectResource, + public virtual IPainter, + public virtual IComResource<ID2D1DeviceContext1> { + CRU_DEFINE_CLASS_LOG_TAG(u"D2DDeviceContextPainter") + public: + explicit D2DDeviceContextPainter(ID2D1DeviceContext1* device_context, + bool release = false); + + CRU_DELETE_COPY(D2DDeviceContextPainter) + CRU_DELETE_MOVE(D2DDeviceContextPainter) + + ~D2DDeviceContextPainter() override; + + public: + ID2D1DeviceContext1* GetComInterface() const override { + return device_context_; + } + + public: + Matrix GetTransform() override; + void SetTransform(const platform::Matrix& matrix) override; + void ConcatTransform(const Matrix& matrix) override; + + void Clear(const Color& color) override; + + void DrawLine(const Point& start, const Point& end, IBrush* brush, + float width) override; + void StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) override; + void FillRectangle(const Rect& rectangle, IBrush* brush) override; + void StrokeEllipse(const Rect& outline_rect, IBrush* brush, + float width) override; + void FillEllipse(const Rect& outline_rect, 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 DrawImage(const Point& offset, IImage* image) override; + + void PushLayer(const Rect& bounds) override; + void PopLayer() override; + + void PushState() override; + void PopState() override; + + void EndDraw() override final; + + protected: + virtual void DoEndDraw() {} + + private: + bool IsValid() { return is_drawing_; } + void CheckValidation(); + + private: + ID2D1DeviceContext1* device_context_; + + std::vector<Microsoft::WRL::ComPtr<ID2D1Layer>> layers_; + std::vector<Microsoft::WRL::ComPtr<ID2D1DrawingStateBlock>> + drawing_state_stack_; + + bool is_drawing_ = true; + + bool release_; +}; +} // namespace cru::platform::graphics::direct2d |