aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/graph
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 00:18:48 +0800
committercrupest <crupest@outlook.com>2019-06-27 00:18:48 +0800
commitbaa7cf141b8121473edceae16c1a20a6d47bd202 (patch)
tree9349633a9d0bc286fe29f480bd70e4c2ad1f3075 /include/cru/win/graph
parentf404a3b2eb7bb9865d0c6f938538899996a53d8c (diff)
downloadcru-baa7cf141b8121473edceae16c1a20a6d47bd202.tar.gz
cru-baa7cf141b8121473edceae16c1a20a6d47bd202.tar.bz2
cru-baa7cf141b8121473edceae16c1a20a6d47bd202.zip
......
Diffstat (limited to 'include/cru/win/graph')
-rw-r--r--include/cru/win/graph/direct/brush.hpp26
-rw-r--r--include/cru/win/graph/direct/com_resource.hpp11
-rw-r--r--include/cru/win/graph/direct/convert_util.hpp (renamed from include/cru/win/graph/util/convert_util.hpp)36
-rw-r--r--include/cru/win/graph/direct/direct_factory.hpp (renamed from include/cru/win/graph/win_native_factory.hpp)12
-rw-r--r--include/cru/win/graph/direct/exception.hpp36
-rw-r--r--include/cru/win/graph/direct/font.hpp (renamed from include/cru/win/graph/win_font.hpp)0
-rw-r--r--include/cru/win/graph/direct/geometry.hpp (renamed from include/cru/win/graph/win_geometry.hpp)0
-rw-r--r--include/cru/win/graph/direct/graph_factory.hpp (renamed from include/cru/win/graph/win_graph_factory.hpp)43
-rw-r--r--include/cru/win/graph/direct/painter.hpp (renamed from include/cru/win/graph/win_painter.hpp)0
-rw-r--r--include/cru/win/graph/direct/text_layout.hpp (renamed from include/cru/win/graph/win_text_layout.hpp)0
-rw-r--r--include/cru/win/graph/win_brush.hpp32
11 files changed, 118 insertions, 78 deletions
diff --git a/include/cru/win/graph/direct/brush.hpp b/include/cru/win/graph/direct/brush.hpp
new file mode 100644
index 00000000..9775b5c1
--- /dev/null
+++ b/include/cru/win/graph/direct/brush.hpp
@@ -0,0 +1,26 @@
+#pragma once
+#include "com_resource.hpp"
+#include "direct_factory.hpp"
+
+#include "cru/platform/graph/brush.hpp"
+
+namespace cru::platform::graph::win::direct {
+class D2DSolidColorBrush : public SolidColorBrush,
+ public IComResource<ID2D1SolidColorBrush> {
+ public:
+ explicit D2DSolidColorBrush(IDirectFactory* factory);
+ D2DSolidColorBrush(const D2DSolidColorBrush& other) = delete;
+ D2DSolidColorBrush(D2DSolidColorBrush&& other) = delete;
+ D2DSolidColorBrush& operator=(const D2DSolidColorBrush& other) = delete;
+ D2DSolidColorBrush& operator=(D2DSolidColorBrush&& other) = delete;
+ ~D2DSolidColorBrush() override = default;
+
+ ID2D1SolidColorBrush* GetComInterface() override { return brush_.Get(); }
+
+ protected:
+ void OnSetColor(const Color& color) override;
+
+ private:
+ Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush_;
+};
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/com_resource.hpp b/include/cru/win/graph/direct/com_resource.hpp
new file mode 100644
index 00000000..aa2c366b
--- /dev/null
+++ b/include/cru/win/graph/direct/com_resource.hpp
@@ -0,0 +1,11 @@
+#pragma once
+#include "../../win_pre_config.hpp"
+
+namespace cru::platform::graph::win::direct {
+template<typename TInterface>
+struct IComResource {
+ virtual ~IComResource() = default;
+
+ virtual TInterface* GetComInterface() = 0;
+};
+} // namespace cru::platform::graph::win_direct
diff --git a/include/cru/win/graph/util/convert_util.hpp b/include/cru/win/graph/direct/convert_util.hpp
index 4b5368b1..2c45c63a 100644
--- a/include/cru/win/graph/util/convert_util.hpp
+++ b/include/cru/win/graph/direct/convert_util.hpp
@@ -1,10 +1,10 @@
#pragma once
#include "../../win_pre_config.hpp"
-#include "cru/common/ui_base.hpp"
+#include "cru/platform/graphic_base.hpp"
#include "cru/platform/matrix.hpp"
-namespace cru::win::graph::util {
+namespace cru::platform::graph::win::direct {
inline D2D1_MATRIX_3X2_F Convert(const platform::Matrix& matrix) {
D2D1_MATRIX_3X2_F m;
m._11 = matrix.m11;
@@ -16,26 +16,26 @@ inline D2D1_MATRIX_3X2_F Convert(const platform::Matrix& matrix) {
return m;
}
-inline D2D1_COLOR_F Convert(const ui::Color& color) {
+inline D2D1_COLOR_F Convert(const Color& color) {
return D2D1::ColorF(color.red / 255.0f, color.green / 255.0f,
color.blue / 255.0f, color.alpha / 255.0f);
}
-inline D2D1_POINT_2F Convert(const ui::Point& point) {
+inline D2D1_POINT_2F Convert(const Point& point) {
return D2D1::Point2F(point.x, point.y);
}
-inline D2D1_RECT_F Convert(const ui::Rect& rect) {
+inline D2D1_RECT_F Convert(const Rect& rect) {
return D2D1::RectF(rect.left, rect.top, rect.left + rect.width,
rect.top + rect.height);
}
-inline D2D1_ROUNDED_RECT Convert(const ui::RoundedRect& rounded_rect) {
+inline D2D1_ROUNDED_RECT Convert(const RoundedRect& rounded_rect) {
return D2D1::RoundedRect(Convert(rounded_rect.rect), rounded_rect.radius_x,
rounded_rect.radius_y);
}
-inline D2D1_ELLIPSE Convert(const ui::Ellipse& ellipse) {
+inline D2D1_ELLIPSE Convert(const Ellipse& ellipse) {
return D2D1::Ellipse(Convert(ellipse.center), ellipse.radius_x,
ellipse.radius_y);
}
@@ -45,28 +45,28 @@ inline platform::Matrix Convert(const D2D1_MATRIX_3X2_F& matrix) {
matrix._22, matrix._31, matrix._32};
}
-inline ui::Color Convert(const D2D1_COLOR_F& color) {
+inline Color Convert(const D2D1_COLOR_F& color) {
auto floor = [](float n) { return static_cast<std::uint8_t>(n + 0.5f); };
- return ui::Color{floor(color.r * 255.0f), floor(color.g * 255.0f),
+ return Color{floor(color.r * 255.0f), floor(color.g * 255.0f),
floor(color.b * 255.0f), floor(color.a * 255.0f)};
}
-inline ui::Point Convert(const D2D1_POINT_2F& point) {
- return ui::Point(point.x, point.y);
+inline Point Convert(const D2D1_POINT_2F& point) {
+ return Point(point.x, point.y);
}
-inline ui::Rect Convert(const D2D1_RECT_F& rect) {
- return ui::Rect(rect.left, rect.top, rect.right - rect.left,
+inline Rect Convert(const D2D1_RECT_F& rect) {
+ return Rect(rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top);
}
-inline ui::RoundedRect Convert(const D2D1_ROUNDED_RECT& rounded_rect) {
- return ui::RoundedRect(Convert(rounded_rect.rect), rounded_rect.radiusX,
+inline RoundedRect Convert(const D2D1_ROUNDED_RECT& rounded_rect) {
+ return RoundedRect(Convert(rounded_rect.rect), rounded_rect.radiusX,
rounded_rect.radiusY);
}
-inline ui::Ellipse Convert(const D2D1_ELLIPSE& ellipse) {
- return ui::Ellipse(Convert(ellipse.point), ellipse.radiusX, ellipse.radiusY);
+inline Ellipse Convert(const D2D1_ELLIPSE& ellipse) {
+ return Ellipse(Convert(ellipse.point), ellipse.radiusX, ellipse.radiusY);
}
inline bool operator==(const D2D1_POINT_2F& left, const D2D1_POINT_2F& right) {
@@ -105,4 +105,4 @@ inline bool operator==(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) {
inline bool operator!=(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) {
return !(left == right);
}
-} // namespace cru::win::graph::util
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/win_native_factory.hpp b/include/cru/win/graph/direct/direct_factory.hpp
index f5ad033c..b150d5aa 100644
--- a/include/cru/win/graph/win_native_factory.hpp
+++ b/include/cru/win/graph/direct/direct_factory.hpp
@@ -1,11 +1,11 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "../../win_pre_config.hpp"
-#include "cru/common/base.hpp"
-
-namespace cru::win::graph {
+namespace cru::platform::graph::win::direct {
// Interface provides access to root d2d resources.
-struct IWinNativeFactory : virtual Interface {
+struct IDirectFactory {
+ virtual ~IDirectFactory() = default;
+
virtual ID2D1Factory1* GetD2D1Factory() const = 0;
virtual ID2D1DeviceContext* GetD2D1DeviceContext() const = 0;
virtual ID3D11Device* GetD3D11Device() const = 0;
@@ -13,4 +13,4 @@ struct IWinNativeFactory : virtual Interface {
virtual IDWriteFactory* GetDWriteFactory() const = 0;
virtual IDWriteFontCollection* GetSystemFontCollection() const = 0;
};
-}
+} // namespace cru::platform::graph::win::direct
diff --git a/include/cru/win/graph/direct/exception.hpp b/include/cru/win/graph/direct/exception.hpp
new file mode 100644
index 00000000..bfa14aaf
--- /dev/null
+++ b/include/cru/win/graph/direct/exception.hpp
@@ -0,0 +1,36 @@
+#pragma once
+#include "../../win_pre_config.hpp"
+
+#include "cru/platform/exception.hpp"
+
+#include <stdexcept>
+#include <string_view>
+
+namespace cru::platform::graph::win::direct {
+
+class HResultError : public PlatformException {
+ public:
+ explicit HResultError(HRESULT h_result);
+ explicit HResultError(HRESULT h_result,
+ const std::string_view& additional_message);
+ HResultError(const HResultError& other) = default;
+ HResultError(HResultError&& other) = default;
+ HResultError& operator=(const HResultError& other) = default;
+ HResultError& operator=(HResultError&& other) = default;
+ ~HResultError() override = default;
+
+ HRESULT GetHResult() const { return h_result_; }
+
+ private:
+ HRESULT h_result_;
+};
+
+inline void ThrowIfFailed(const HRESULT h_result) {
+ if (FAILED(h_result)) throw HResultError(h_result);
+}
+
+inline void ThrowIfFailed(const HRESULT h_result,
+ const std::string_view& message) {
+ if (FAILED(h_result)) throw HResultError(h_result, message);
+}
+} // namespace cru::platform::graph::win::direct \ No newline at end of file
diff --git a/include/cru/win/graph/win_font.hpp b/include/cru/win/graph/direct/font.hpp
index 44fa7edd..44fa7edd 100644
--- a/include/cru/win/graph/win_font.hpp
+++ b/include/cru/win/graph/direct/font.hpp
diff --git a/include/cru/win/graph/win_geometry.hpp b/include/cru/win/graph/direct/geometry.hpp
index e312f13c..e312f13c 100644
--- a/include/cru/win/graph/win_geometry.hpp
+++ b/include/cru/win/graph/direct/geometry.hpp
diff --git a/include/cru/win/graph/win_graph_factory.hpp b/include/cru/win/graph/direct/graph_factory.hpp
index 2df7ed9a..b3c901be 100644
--- a/include/cru/win/graph/win_graph_factory.hpp
+++ b/include/cru/win/graph/direct/graph_factory.hpp
@@ -1,27 +1,26 @@
#pragma once
-#include "../win_pre_config.hpp"
+#include "direct_factory.hpp"
+
+#include "brush.hpp"
#include "cru/platform/graph/graph_factory.hpp"
-#include "win_native_factory.hpp"
-namespace cru::win::graph {
-class WinGraphFactory : public Object,
- public virtual platform::graph::IGraphFactory,
- public virtual IWinNativeFactory {
- friend IGraphFactory* IGraphFactory::CreateInstance();
+namespace cru::platform::graph::win::direct {
+class DirectGraphFactory : public GraphFactory, IDirectFactory {
+ friend GraphFactory* GraphFactory::CreateInstance();
public:
- static WinGraphFactory* GetInstance();
+ static DirectGraphFactory* GetInstance();
private:
- explicit WinGraphFactory();
+ DirectGraphFactory();
public:
- WinGraphFactory(const WinGraphFactory& other) = delete;
- WinGraphFactory(WinGraphFactory&& other) = delete;
- WinGraphFactory& operator=(const WinGraphFactory& other) = delete;
- WinGraphFactory& operator=(WinGraphFactory&& other) = delete;
- ~WinGraphFactory() override;
+ DirectGraphFactory(const DirectGraphFactory& other) = delete;
+ DirectGraphFactory(DirectGraphFactory&& other) = delete;
+ DirectGraphFactory& operator=(const DirectGraphFactory& other) = delete;
+ DirectGraphFactory& operator=(DirectGraphFactory&& other) = delete;
+ ~DirectGraphFactory() override;
ID2D1Factory1* GetD2D1Factory() const override { return d2d1_factory_.Get(); }
ID2D1DeviceContext* GetD2D1DeviceContext() const override {
@@ -36,14 +35,14 @@ class WinGraphFactory : public Object,
return dwrite_system_font_collection_.Get();
}
- platform::graph::ISolidColorBrush* CreateSolidColorBrush(
- const ui::Color& color) override;
- platform::graph::IGeometryBuilder* CreateGeometryBuilder() override;
- platform::graph::IFontDescriptor* CreateFontDescriptor(
- const std::wstring_view& font_family, float font_size);
- platform::graph::ITextLayout* CreateTextLayout(
- std::shared_ptr<platform::graph::IFontDescriptor> font,
- std::wstring text);
+ 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;
bool IsAutoDelete() const override { return auto_delete_; }
void SetAutoDelete(bool value) override { auto_delete_ = value; }
diff --git a/include/cru/win/graph/win_painter.hpp b/include/cru/win/graph/direct/painter.hpp
index f218488c..f218488c 100644
--- a/include/cru/win/graph/win_painter.hpp
+++ b/include/cru/win/graph/direct/painter.hpp
diff --git a/include/cru/win/graph/win_text_layout.hpp b/include/cru/win/graph/direct/text_layout.hpp
index 7339eff9..7339eff9 100644
--- a/include/cru/win/graph/win_text_layout.hpp
+++ b/include/cru/win/graph/direct/text_layout.hpp
diff --git a/include/cru/win/graph/win_brush.hpp b/include/cru/win/graph/win_brush.hpp
deleted file mode 100644
index c81019c0..00000000
--- a/include/cru/win/graph/win_brush.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#pragma once
-#include "../win_pre_config.hpp"
-
-#include "cru/platform/graph/brush.hpp"
-
-namespace cru::win::graph {
-struct IWinNativeFactory;
-
-struct IWinBrush : virtual platform::graph::IBrush {
- virtual ID2D1Brush* GetD2DBrush() = 0;
-};
-
-class WinSolidColorBrush : public Object,
- public virtual platform::graph::ISolidColorBrush,
- public virtual IWinBrush {
- public:
- WinSolidColorBrush(IWinNativeFactory* factory, const ui::Color& color);
- WinSolidColorBrush(const WinSolidColorBrush& other) = delete;
- WinSolidColorBrush(WinSolidColorBrush&& other) = delete;
- WinSolidColorBrush& operator=(const WinSolidColorBrush& other) = delete;
- WinSolidColorBrush& operator=(WinSolidColorBrush&& other) = delete;
- ~WinSolidColorBrush() override = default;
-
- ui::Color GetColor() override;
- void SetColor(const ui::Color& color) override;
-
- ID2D1Brush* GetD2DBrush() override { return brush_.Get(); }
-
- private:
- Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush_;
-};
-} // namespace cru::win::graph