aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 15:29:13 +0800
committercrupest <crupest@outlook.com>2019-06-27 15:29:13 +0800
commit8c5b05bcfce96495b4ffc4209ab8feda12597729 (patch)
treea0a8bc99d8ffb42dc231696a4e4dfd1e7607eea0 /include/cru
parentbaa7cf141b8121473edceae16c1a20a6d47bd202 (diff)
downloadcru-8c5b05bcfce96495b4ffc4209ab8feda12597729.tar.gz
cru-8c5b05bcfce96495b4ffc4209ab8feda12597729.tar.bz2
cru-8c5b05bcfce96495b4ffc4209ab8feda12597729.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/platform/graph/painter.hpp2
-rw-r--r--include/cru/win/graph/direct/brush.hpp22
-rw-r--r--include/cru/win/graph/direct/com_resource.hpp2
-rw-r--r--include/cru/win/graph/direct/font.hpp35
-rw-r--r--include/cru/win/graph/direct/geometry.hpp71
-rw-r--r--include/cru/win/graph/direct/graph_factory.hpp25
-rw-r--r--include/cru/win/graph/direct/painter.hpp65
-rw-r--r--include/cru/win/graph/direct/platform_id.hpp19
-rw-r--r--include/cru/win/graph/direct/text_layout.hpp55
9 files changed, 195 insertions, 101 deletions
diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp
index 1096aa7c..97d4b4cf 100644
--- a/include/cru/platform/graph/painter.hpp
+++ b/include/cru/platform/graph/painter.hpp
@@ -37,5 +37,7 @@ class Painter : public NativeResource {
virtual void DrawText(const Point& offset, TextLayout* text_layout,
Brush* brush) = 0;
+
+ virtual void EndDraw() = 0;
};
} // namespace cru::platform::graph
diff --git a/include/cru/win/graph/direct/brush.hpp b/include/cru/win/graph/direct/brush.hpp
index 9775b5c1..1f1c319f 100644
--- a/include/cru/win/graph/direct/brush.hpp
+++ b/include/cru/win/graph/direct/brush.hpp
@@ -1,21 +1,39 @@
#pragma once
#include "com_resource.hpp"
#include "direct_factory.hpp"
+#include "platform_id.hpp"
#include "cru/platform/graph/brush.hpp"
namespace cru::platform::graph::win::direct {
+struct ID2DBrush {
+ virtual ~ID2DBrush() = default;
+
+ virtual ID2D1Brush* GetD2DBrushInterface() const = 0;
+};
+
class D2DSolidColorBrush : public SolidColorBrush,
+ public ID2DBrush,
public IComResource<ID2D1SolidColorBrush> {
public:
explicit D2DSolidColorBrush(IDirectFactory* factory);
+
D2DSolidColorBrush(const D2DSolidColorBrush& other) = delete;
- D2DSolidColorBrush(D2DSolidColorBrush&& other) = delete;
D2DSolidColorBrush& operator=(const D2DSolidColorBrush& other) = delete;
+
+ D2DSolidColorBrush(D2DSolidColorBrush&& other) = delete;
D2DSolidColorBrush& operator=(D2DSolidColorBrush&& other) = delete;
+
~D2DSolidColorBrush() override = default;
- ID2D1SolidColorBrush* GetComInterface() override { return brush_.Get(); }
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
+
+ public:
+ ID2D1Brush* GetD2DBrushInterface() const override { return brush_.Get(); }
+
+ ID2D1SolidColorBrush* GetComInterface() const override {
+ return brush_.Get();
+ }
protected:
void OnSetColor(const Color& color) override;
diff --git a/include/cru/win/graph/direct/com_resource.hpp b/include/cru/win/graph/direct/com_resource.hpp
index aa2c366b..22d1d6f0 100644
--- a/include/cru/win/graph/direct/com_resource.hpp
+++ b/include/cru/win/graph/direct/com_resource.hpp
@@ -6,6 +6,6 @@ template<typename TInterface>
struct IComResource {
virtual ~IComResource() = default;
- virtual TInterface* GetComInterface() = 0;
+ virtual TInterface* GetComInterface() const = 0;
};
} // namespace cru::platform::graph::win_direct
diff --git a/include/cru/win/graph/direct/font.hpp b/include/cru/win/graph/direct/font.hpp
index 44fa7edd..d3376503 100644
--- a/include/cru/win/graph/direct/font.hpp
+++ b/include/cru/win/graph/direct/font.hpp
@@ -1,28 +1,33 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "com_resource.hpp"
+#include "direct_factory.hpp"
+#include "platform_id.hpp"
#include "cru/platform/graph/font.hpp"
#include <string_view>
-namespace cru::win::graph {
-struct IWinNativeFactory;
+namespace cru::platform::graph::win::direct {
-class WinFontDescriptor : public Object,
- public virtual platform::graph::IFontDescriptor {
+class DWriteFont : public Font, public IComResource<IDWriteTextFormat> {
public:
- explicit WinFontDescriptor(IWinNativeFactory* factory,
- const std::wstring_view& font_family,
- float font_size);
- WinFontDescriptor(const WinFontDescriptor& other) = delete;
- WinFontDescriptor(WinFontDescriptor&& other) = delete;
- WinFontDescriptor& operator=(const WinFontDescriptor& other) = delete;
- WinFontDescriptor& operator=(WinFontDescriptor&& other) = delete;
- ~WinFontDescriptor() override = default;
+ DWriteFont(IDirectFactory* factory, const std::wstring_view& font_family,
+ float font_size);
- IDWriteTextFormat* GetDWriteTextFormat() const { return text_format_.Get(); }
+ DWriteFont(const DWriteFont& other) = delete;
+ DWriteFont& operator=(const DWriteFont& other) = delete;
+
+ DWriteFont(DWriteFont&& other) = delete;
+ DWriteFont& operator=(DWriteFont&& other) = delete;
+
+ ~DWriteFont() override = default;
+
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
+
+ public:
+ IDWriteTextFormat* GetComInterface() const override { return text_format_.Get(); }
private:
Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format_;
};
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/geometry.hpp b/include/cru/win/graph/direct/geometry.hpp
index e312f13c..f40db7af 100644
--- a/include/cru/win/graph/direct/geometry.hpp
+++ b/include/cru/win/graph/direct/geometry.hpp
@@ -1,48 +1,63 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "com_resource.hpp"
+#include "direct_factory.hpp"
+#include "platform_id.hpp"
#include "cru/platform/graph/geometry.hpp"
-namespace cru::win::graph {
-struct IWinNativeFactory;
+namespace cru::platform::graph::win::direct {
+class D2DGeometryBuilder : public GeometryBuilder {
+ public:
+ explicit D2DGeometryBuilder(IDirectFactory* factory);
+
+ D2DGeometryBuilder(const D2DGeometryBuilder& other) = delete;
+ D2DGeometryBuilder& operator=(const D2DGeometryBuilder& other) = delete;
+
+ D2DGeometryBuilder(D2DGeometryBuilder&& other) = delete;
+ D2DGeometryBuilder& operator=(D2DGeometryBuilder&& other) = delete;
+
+ ~D2DGeometryBuilder() override;
+
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
-class WinGeometryBuilder : public Object,
- public virtual platform::graph::IGeometryBuilder {
public:
- explicit WinGeometryBuilder(IWinNativeFactory* factory);
- WinGeometryBuilder(const WinGeometryBuilder& other) = delete;
- WinGeometryBuilder(WinGeometryBuilder&& other) = delete;
- WinGeometryBuilder& operator=(const WinGeometryBuilder& other) = delete;
- WinGeometryBuilder& operator=(WinGeometryBuilder&& other) = delete;
- ~WinGeometryBuilder() override;
-
- void BeginFigure(const ui::Point& point) override;
- void LineTo(const ui::Point& point) override;
- void QuadraticBezierTo(const ui::Point& control_point,
- const ui::Point& end_point) override;
+ void BeginFigure(const Point& point) override;
+ void LineTo(const Point& point) override;
+ void QuadraticBezierTo(const Point& control_point,
+ const Point& end_point) override;
void CloseFigure(bool close) override;
- platform::graph::IGeometry* End() override;
- bool IsEnded() const override { return geometry_ != nullptr; }
+
+ Geometry* Build() override;
+
+ private:
+ bool IsValid() { return geometry_ != nullptr; }
private:
Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry_;
Microsoft::WRL::ComPtr<ID2D1GeometrySink> geometry_sink_;
};
-class WinGeometry : public Object, public virtual platform::graph::IGeometry {
+class D2DGeometry : public Geometry, public IComResource<ID2D1Geometry> {
public:
- explicit WinGeometry(Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry);
- WinGeometry(const WinGeometry& other) = delete;
- WinGeometry(WinGeometry&& other) = delete;
- WinGeometry& operator=(const WinGeometry& other) = delete;
- WinGeometry& operator=(WinGeometry&& other) = delete;
- ~WinGeometry() override = default;
+ explicit D2DGeometry(Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry);
+
+ D2DGeometry(const D2DGeometry& other) = delete;
+ D2DGeometry& operator=(const D2DGeometry& other) = delete;
+
+ D2DGeometry(D2DGeometry&& other) = delete;
+ D2DGeometry& operator=(D2DGeometry&& other) = delete;
+
+ ~D2DGeometry() override = default;
- bool FillContains(const ui::Point& point) override;
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
- ID2D1PathGeometry* GetNative() const { return geometry_.Get(); }
+ public:
+ ID2D1Geometry* GetComInterface() const override { return geometry_.Get(); }
+
+ public:
+ bool FillContains(const Point& point) override;
private:
Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry_;
};
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/graph_factory.hpp b/include/cru/win/graph/direct/graph_factory.hpp
index b3c901be..841dd104 100644
--- a/include/cru/win/graph/direct/graph_factory.hpp
+++ b/include/cru/win/graph/direct/graph_factory.hpp
@@ -1,7 +1,11 @@
#pragma once
#include "direct_factory.hpp"
+#include "platform_id.hpp"
#include "brush.hpp"
+#include "font.hpp"
+#include "geometry.hpp"
+#include "text_layout.hpp"
#include "cru/platform/graph/graph_factory.hpp"
@@ -17,11 +21,16 @@ class DirectGraphFactory : public GraphFactory, IDirectFactory {
public:
DirectGraphFactory(const DirectGraphFactory& other) = delete;
- DirectGraphFactory(DirectGraphFactory&& other) = delete;
DirectGraphFactory& operator=(const DirectGraphFactory& other) = delete;
+
+ DirectGraphFactory(DirectGraphFactory&& other) = delete;
DirectGraphFactory& operator=(DirectGraphFactory&& other) = delete;
+
~DirectGraphFactory() override;
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
+
+ public:
ID2D1Factory1* GetD2D1Factory() const override { return d2d1_factory_.Get(); }
ID2D1DeviceContext* GetD2D1DeviceContext() const override {
return d2d1_device_context_.Get();
@@ -35,14 +44,16 @@ class DirectGraphFactory : public GraphFactory, IDirectFactory {
return dwrite_system_font_collection_.Get();
}
+ public:
D2DSolidColorBrush* CreateSolidColorBrush() override;
D2DGeometryBuilder* CreateGeometryBuilder() override;
- D2DFont* CreateFont(
- const std::wstring_view& font_family, float font_size) override;
- DWriteTextLayout* CreateTextLayout(
- std::shared_ptr<Font> font,
- std::wstring text) override;
+
+ DWriteFont* CreateFont(const std::wstring_view& font_family,
+ float font_size) override;
+
+ DWriteTextLayout* CreateTextLayout(std::shared_ptr<Font> font,
+ std::wstring text) override;
bool IsAutoDelete() const override { return auto_delete_; }
void SetAutoDelete(bool value) override { auto_delete_ = value; }
@@ -57,4 +68,4 @@ class DirectGraphFactory : public GraphFactory, IDirectFactory {
Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_factory_;
Microsoft::WRL::ComPtr<IDWriteFontCollection> dwrite_system_font_collection_;
};
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/painter.hpp b/include/cru/win/graph/direct/painter.hpp
index f218488c..d8791c7f 100644
--- a/include/cru/win/graph/direct/painter.hpp
+++ b/include/cru/win/graph/direct/painter.hpp
@@ -1,43 +1,54 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "com_resource.hpp"
+#include "platform_id.hpp"
#include "cru/platform/graph/painter.hpp"
-namespace cru::win::graph {
-class GraphManager;
+namespace cru::platform::graph::win::direct {
+class D2DPainter : public Painter, public IComResource<ID2D1RenderTarget> {
+ public:
+ explicit D2DPainter(ID2D1RenderTarget* render_target);
+
+ D2DPainter(const D2DPainter& other) = delete;
+ D2DPainter& operator=(const D2DPainter& other) = delete;
+
+ D2DPainter(D2DPainter&& other) = delete;
+ D2DPainter& operator=(D2DPainter&& other) = delete;
+
+ ~D2DPainter() override = default;
+
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
+
+ public:
+ ID2D1RenderTarget* GetComInterface() const override { return render_target_; }
-class WinPainter : public Object, public virtual platform::graph::IPainter {
public:
- explicit WinPainter(ID2D1RenderTarget* render_target);
- WinPainter(const WinPainter& other) = delete;
- WinPainter(WinPainter&& other) = delete;
- WinPainter& operator=(const WinPainter& other) = delete;
- WinPainter& operator=(WinPainter&& other) = delete;
- ~WinPainter() override = default;
-
- platform::Matrix GetTransform() override;
+ Matrix GetTransform() override;
void SetTransform(const platform::Matrix& matrix) override;
- void Clear(const ui::Color& color) override;
- void StrokeRectangle(const ui::Rect& rectangle, platform::graph::IBrush* brush,
+
+ void Clear(const Color& color) override;
+
+ void StrokeRectangle(const Rect& rectangle, Brush* brush,
float width) override;
- void FillRectangle(const ui::Rect& rectangle,
- platform::graph::IBrush* brush) override;
- void StrokeGeometry(platform::graph::IGeometry* geometry,
- platform::graph::IBrush* brush, float width) override;
- void FillGeometry(platform::graph::IGeometry* geometry,
- platform::graph::IBrush* brush) override;
- void DrawText(const ui::Point& offset,
- platform::graph::ITextLayout* text_layout,
- platform::graph::IBrush* brush) override;
- void End() override final;
- bool IsEnded() const override final { return is_draw_ended_; }
+ void FillRectangle(const Rect& rectangle, Brush* brush) override;
+
+ void StrokeGeometry(Geometry* geometry, Brush* brush, float width) override;
+ void FillGeometry(Geometry* geometry, Brush* brush) override;
+
+ void DrawText(const Point& offset, TextLayout* text_layout,
+ Brush* brush) override;
+
+ void EndDraw() override final;
protected:
virtual void DoEndDraw() = 0;
private:
+ bool IsValid() { return is_drawing_; }
+
+ private:
ID2D1RenderTarget* render_target_;
- bool is_draw_ended_ = false;
+ bool is_drawing_ = true;
};
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/platform_id.hpp b/include/cru/win/graph/direct/platform_id.hpp
new file mode 100644
index 00000000..ff02eb27
--- /dev/null
+++ b/include/cru/win/graph/direct/platform_id.hpp
@@ -0,0 +1,19 @@
+#pragma once
+#include <cru/platform/native_resource.hpp>
+
+#include <stdexcept>
+#include <string_view>
+
+namespace cru::platform::graph::win::direct {
+constexpr std::wstring_view platform_id = L"Windows Direct";
+
+bool IsDirectResource(NativeResource* resource) {
+ return resource->GetPlatformId() == platform_id;
+}
+
+} // namespace cru::platform::graph::win::direct
+
+#define CRU_PLATFORMID_IMPLEMENT_DIRECT \
+ std::wstring_view GetPlatformId() const override { \
+ return ::cru::platform::graph::win::direct::platform_id; \
+ }
diff --git a/include/cru/win/graph/direct/text_layout.hpp b/include/cru/win/graph/direct/text_layout.hpp
index 7339eff9..c7657762 100644
--- a/include/cru/win/graph/direct/text_layout.hpp
+++ b/include/cru/win/graph/direct/text_layout.hpp
@@ -1,42 +1,55 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "com_resource.hpp"
+#include "direct_factory.hpp"
+#include "platform_id.hpp"
#include "cru/platform/graph/text_layout.hpp"
+#include "font.hpp"
+
#include <memory>
-namespace cru::win::graph {
-struct IWinNativeFactory;
-class WinFontDescriptor;
+namespace cru::platform::graph::win::direct {
+class DWriteTextLayout : public TextLayout,
+ public IComResource<IDWriteTextLayout> {
+ public:
+ explicit DWriteTextLayout(IDirectFactory* factory, std::shared_ptr<Font> font,
+ std::wstring text);
+
+ DWriteTextLayout(const DWriteTextLayout& other) = delete;
+ DWriteTextLayout& operator=(const DWriteTextLayout& other) = delete;
+
+ DWriteTextLayout(DWriteTextLayout&& other) = delete;
+ DWriteTextLayout& operator=(DWriteTextLayout&& other) = delete;
+
+ ~DWriteTextLayout() override = default;
+
+ CRU_PLATFORMID_IMPLEMENT_DIRECT
-class WinTextLayout : public Object, public virtual platform::graph::ITextLayout {
public:
- explicit WinTextLayout(IWinNativeFactory* factory,
- std::shared_ptr<WinFontDescriptor> font, std::wstring text);
- WinTextLayout(const WinTextLayout& other) = delete;
- WinTextLayout(WinTextLayout&& other) = delete;
- WinTextLayout& operator=(const WinTextLayout& other) = delete;
- WinTextLayout& operator=(WinTextLayout&& other) = delete;
- ~WinTextLayout() override = default;
+ IDWriteTextLayout* GetComInterface() const override {
+ return text_layout_.Get();
+ }
+ public:
std::wstring GetText() override;
void SetText(std::wstring new_text) override;
- std::shared_ptr<platform::graph::IFontDescriptor> GetFont();
- void SetFont(std::shared_ptr<platform::graph::IFontDescriptor> font);
+
+ std::shared_ptr<Font> GetFont();
+ void SetFont(std::shared_ptr<Font> font);
+
void SetMaxWidth(float max_width) override;
void SetMaxHeight(float max_height) override;
- ui::Rect GetTextBounds() override;
- std::vector<ui::Rect> TextRangeRect(
- const ui::TextRange& text_range) override;
- IDWriteTextLayout* GetDWriteTextLayout() const { return text_layout_.Get(); }
+ Rect GetTextBounds() override;
+ std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
private:
- IWinNativeFactory* factory_;
+ IDirectFactory* factory_;
std::wstring text_;
- std::shared_ptr<WinFontDescriptor> font_descriptor_;
+ std::shared_ptr<DWriteFont> font_;
float max_width_ = 0.0f;
float max_height_ = 0.0f;
Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_;
};
-} // namespace cru::platform::win
+} // namespace cru::platform::graph::win::direct