From 7351020a582d70a1495249fba87d342c8a1fb634 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 10 Apr 2019 19:42:46 +0800 Subject: Refactor. --- include/cru/platform/basic_types.hpp | 11 -- include/cru/platform/brush.hpp | 13 -- include/cru/platform/debug.hpp | 2 +- include/cru/platform/exception.hpp | 11 ++ include/cru/platform/font.hpp | 8 -- include/cru/platform/geometry.hpp | 26 ---- include/cru/platform/graph/brush.hpp | 13 ++ include/cru/platform/graph/font.hpp | 8 ++ include/cru/platform/graph/geometry.hpp | 25 ++++ include/cru/platform/graph/graph_factory.hpp | 26 ++++ include/cru/platform/graph/painter.hpp | 26 ++++ include/cru/platform/graph/painter_util.hpp | 18 +++ include/cru/platform/graph/text_layout.hpp | 24 ++++ include/cru/platform/graph_factory.hpp | 24 ---- include/cru/platform/native/basic_types.hpp | 11 ++ include/cru/platform/native/native_window.hpp | 50 ++++++++ include/cru/platform/native/ui_applicaition.hpp | 31 +++++ include/cru/platform/native_window.hpp | 48 -------- include/cru/platform/painter.hpp | 26 ---- include/cru/platform/painter_util.hpp | 18 --- include/cru/platform/string_util.hpp | 2 +- include/cru/platform/text_layout.hpp | 24 ---- include/cru/platform/ui_applicaition.hpp | 32 ----- include/cru/platform/win/d2d_util.hpp | 108 ----------------- include/cru/platform/win/exception.hpp | 49 -------- include/cru/platform/win/god_window.hpp | 32 ----- include/cru/platform/win/graph_manager.hpp | 44 ------- include/cru/platform/win/win_application.hpp | 67 ----------- include/cru/platform/win/win_brush.hpp | 31 ----- include/cru/platform/win/win_font.hpp | 26 ---- include/cru/platform/win/win_geometry.hpp | 45 ------- include/cru/platform/win/win_graph_factory.hpp | 28 ----- include/cru/platform/win/win_native_window.hpp | 132 --------------------- include/cru/platform/win/win_painter.hpp | 42 ------- include/cru/platform/win/win_pre_config.hpp | 13 -- include/cru/platform/win/win_text_layout.hpp | 42 ------- include/cru/platform/win/window_class.hpp | 26 ---- .../win/window_native_message_event_args.hpp | 45 ------- include/cru/platform/win/window_render_target.hpp | 44 ------- 39 files changed, 245 insertions(+), 1006 deletions(-) delete mode 100644 include/cru/platform/basic_types.hpp delete mode 100644 include/cru/platform/brush.hpp create mode 100644 include/cru/platform/exception.hpp delete mode 100644 include/cru/platform/font.hpp delete mode 100644 include/cru/platform/geometry.hpp create mode 100644 include/cru/platform/graph/brush.hpp create mode 100644 include/cru/platform/graph/font.hpp create mode 100644 include/cru/platform/graph/geometry.hpp create mode 100644 include/cru/platform/graph/graph_factory.hpp create mode 100644 include/cru/platform/graph/painter.hpp create mode 100644 include/cru/platform/graph/painter_util.hpp create mode 100644 include/cru/platform/graph/text_layout.hpp delete mode 100644 include/cru/platform/graph_factory.hpp create mode 100644 include/cru/platform/native/basic_types.hpp create mode 100644 include/cru/platform/native/native_window.hpp create mode 100644 include/cru/platform/native/ui_applicaition.hpp delete mode 100644 include/cru/platform/native_window.hpp delete mode 100644 include/cru/platform/painter.hpp delete mode 100644 include/cru/platform/painter_util.hpp delete mode 100644 include/cru/platform/text_layout.hpp delete mode 100644 include/cru/platform/ui_applicaition.hpp delete mode 100644 include/cru/platform/win/d2d_util.hpp delete mode 100644 include/cru/platform/win/exception.hpp delete mode 100644 include/cru/platform/win/god_window.hpp delete mode 100644 include/cru/platform/win/graph_manager.hpp delete mode 100644 include/cru/platform/win/win_application.hpp delete mode 100644 include/cru/platform/win/win_brush.hpp delete mode 100644 include/cru/platform/win/win_font.hpp delete mode 100644 include/cru/platform/win/win_geometry.hpp delete mode 100644 include/cru/platform/win/win_graph_factory.hpp delete mode 100644 include/cru/platform/win/win_native_window.hpp delete mode 100644 include/cru/platform/win/win_painter.hpp delete mode 100644 include/cru/platform/win/win_pre_config.hpp delete mode 100644 include/cru/platform/win/win_text_layout.hpp delete mode 100644 include/cru/platform/win/window_class.hpp delete mode 100644 include/cru/platform/win/window_native_message_event_args.hpp delete mode 100644 include/cru/platform/win/window_render_target.hpp (limited to 'include/cru/platform') diff --git a/include/cru/platform/basic_types.hpp b/include/cru/platform/basic_types.hpp deleted file mode 100644 index e6ab4b59..00000000 --- a/include/cru/platform/basic_types.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include "cru/common/pre_config.hpp" - -namespace cru::platform { -struct Dpi { - float x; - float y; -}; - -enum class MouseButton { Left, Right, Middle }; -} // namespace cru::platform diff --git a/include/cru/platform/brush.hpp b/include/cru/platform/brush.hpp deleted file mode 100644 index 713d302d..00000000 --- a/include/cru/platform/brush.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" - -namespace cru::platform { -struct Brush : public virtual Interface {}; - -struct SolidColorBrush : public virtual Brush { - virtual ui::Color GetColor() = 0; - virtual void SetColor(const ui::Color& color) = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/debug.hpp b/include/cru/platform/debug.hpp index 21c2b646..18472201 100644 --- a/include/cru/platform/debug.hpp +++ b/include/cru/platform/debug.hpp @@ -3,6 +3,6 @@ #include -namespace cru::platform::debug { +namespace cru::platform { void DebugMessage(const std::wstring_view& message); } diff --git a/include/cru/platform/exception.hpp b/include/cru/platform/exception.hpp new file mode 100644 index 00000000..6dae08c5 --- /dev/null +++ b/include/cru/platform/exception.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "cru/common/pre_config.hpp" + +#include + +namespace cru::platform { +class PlatformException : public std::runtime_error { + public: + using runtime_error::runtime_error; // inherent constructors +}; +} // namespace cru::platform diff --git a/include/cru/platform/font.hpp b/include/cru/platform/font.hpp deleted file mode 100644 index 750aaae1..00000000 --- a/include/cru/platform/font.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -namespace cru::platform { -struct FontDescriptor : virtual Interface { - -}; -} diff --git a/include/cru/platform/geometry.hpp b/include/cru/platform/geometry.hpp deleted file mode 100644 index aa93fe37..00000000 --- a/include/cru/platform/geometry.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "basic_types.hpp" -#include "cru/common/ui_base.hpp" - -namespace cru::platform { -struct Geometry : virtual Interface { - virtual bool FillContains(const ui::Point& point) = 0; -}; - -struct GeometryBuilder : virtual Interface { - virtual bool IsValid() = 0; - virtual void BeginFigure(const ui::Point& point) = 0; - virtual void LineTo(const ui::Point& point) = 0; - virtual void QuadraticBezierTo(const ui::Point& control_point, - const ui::Point& end_point) = 0; - virtual void CloseFigure(bool close) = 0; - virtual Geometry* Build() = 0; - - Geometry* BuildAndDeleteThis() { - Build(); - delete this; - } -}; -} // namespace cru::platform diff --git a/include/cru/platform/graph/brush.hpp b/include/cru/platform/graph/brush.hpp new file mode 100644 index 00000000..8ffbfc97 --- /dev/null +++ b/include/cru/platform/graph/brush.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "cru/common/ui_base.hpp" + +namespace cru::platform::graph { +struct Brush : public virtual Interface {}; + +struct SolidColorBrush : public virtual Brush { + virtual ui::Color GetColor() = 0; + virtual void SetColor(const ui::Color& color) = 0; +}; +} // namespace cru::platform diff --git a/include/cru/platform/graph/font.hpp b/include/cru/platform/graph/font.hpp new file mode 100644 index 00000000..5af369e5 --- /dev/null +++ b/include/cru/platform/graph/font.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "cru/common/base.hpp" + +namespace cru::platform::graph { +struct FontDescriptor : virtual Interface { + +}; +} diff --git a/include/cru/platform/graph/geometry.hpp b/include/cru/platform/graph/geometry.hpp new file mode 100644 index 00000000..7a7ad8b2 --- /dev/null +++ b/include/cru/platform/graph/geometry.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "cru/common/ui_base.hpp" + +namespace cru::platform::graph { +struct Geometry : virtual Interface { + virtual bool FillContains(const ui::Point& point) = 0; +}; + +struct GeometryBuilder : virtual Interface { + virtual bool IsValid() = 0; + virtual void BeginFigure(const ui::Point& point) = 0; + virtual void LineTo(const ui::Point& point) = 0; + virtual void QuadraticBezierTo(const ui::Point& control_point, + const ui::Point& end_point) = 0; + virtual void CloseFigure(bool close) = 0; + virtual Geometry* Build() = 0; + + Geometry* BuildAndDeleteThis() { + Build(); + delete this; + } +}; +} // namespace cru::platform diff --git a/include/cru/platform/graph/graph_factory.hpp b/include/cru/platform/graph/graph_factory.hpp new file mode 100644 index 00000000..51cf6f15 --- /dev/null +++ b/include/cru/platform/graph/graph_factory.hpp @@ -0,0 +1,26 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "cru/common/ui_base.hpp" + +#include +#include +#include + +namespace cru::platform::graph { +struct SolidColorBrush; +struct GeometryBuilder; +struct FontDescriptor; +struct TextLayout; + +struct GraphFactory : virtual Interface { + static GraphFactory* GetInstance(); + + virtual SolidColorBrush* CreateSolidColorBrush(const ui::Color& color) = 0; + virtual GeometryBuilder* CreateGeometryBuilder() = 0; + virtual FontDescriptor* CreateFontDescriptor( + const std::wstring_view& font_family, float font_size) = 0; + virtual TextLayout* CreateTextLayout(std::shared_ptr font, + std::wstring text) = 0; +}; +} // namespace cru::platform diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp new file mode 100644 index 00000000..199ebbad --- /dev/null +++ b/include/cru/platform/graph/painter.hpp @@ -0,0 +1,26 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "cru/common/ui_base.hpp" +#include "../matrix.hpp" + +namespace cru::platform::graph { +struct Brush; +struct Geometry; +struct TextLayout; + +struct Painter : virtual Interface { + virtual Matrix GetTransform() = 0; + virtual void SetTransform(const Matrix& matrix) = 0; + virtual void Clear(const ui::Color& color) = 0; + virtual void StrokeRectangle(const ui::Rect& rectangle, Brush* brush, + float width) = 0; + virtual void FillRectangle(const ui::Rect& rectangle, Brush* brush) = 0; + virtual void StrokeGeometry(Geometry* geometry, Brush* brush, + float width) = 0; + virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0; + virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush) = 0; + virtual void EndDraw() = 0; + virtual bool IsDisposed() = 0; +}; +} // namespace cru::platform diff --git a/include/cru/platform/graph/painter_util.hpp b/include/cru/platform/graph/painter_util.hpp new file mode 100644 index 00000000..c137e8cb --- /dev/null +++ b/include/cru/platform/graph/painter_util.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "painter.hpp" + +#include +#include + +namespace cru::platform::graph::util { +template +inline void WithTransform(Painter* painter, const Matrix& matrix, + const Fn& action) { + static_assert(std::is_invocable_v, + "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/platform/graph/text_layout.hpp b/include/cru/platform/graph/text_layout.hpp new file mode 100644 index 00000000..eb13c115 --- /dev/null +++ b/include/cru/platform/graph/text_layout.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "cru/common/ui_base.hpp" + +#include +#include +#include + +namespace cru::platform::graph { +struct FontDescriptor; + +struct TextLayout : virtual Interface { + virtual std::wstring GetText() = 0; + virtual void SetText(std::wstring new_text) = 0; + virtual std::shared_ptr GetFont() = 0; + virtual void SetFont(std::shared_ptr font) = 0; + virtual void SetMaxWidth(float max_width) = 0; + virtual void SetMaxHeight(float max_height) = 0; + virtual ui::Rect GetTextBounds() = 0; + virtual std::vector TextRangeRect( + const ui::TextRange& text_range) = 0; +}; +} // namespace cru::platform diff --git a/include/cru/platform/graph_factory.hpp b/include/cru/platform/graph_factory.hpp deleted file mode 100644 index f6122241..00000000 --- a/include/cru/platform/graph_factory.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" - -#include -#include -#include - -namespace cru::platform { -struct SolidColorBrush; -struct GeometryBuilder; -struct FontDescriptor; -struct TextLayout; - -struct GraphFactory : virtual Interface { - virtual SolidColorBrush* CreateSolidColorBrush(const ui::Color& color) = 0; - virtual GeometryBuilder* CreateGeometryBuilder() = 0; - virtual FontDescriptor* CreateFontDescriptor( - const std::wstring_view& font_family, float font_size) = 0; - virtual TextLayout* CreateTextLayout(std::shared_ptr font, - std::wstring text) = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/native/basic_types.hpp b/include/cru/platform/native/basic_types.hpp new file mode 100644 index 00000000..573a9e76 --- /dev/null +++ b/include/cru/platform/native/basic_types.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "cru/common/pre_config.hpp" + +namespace cru::platform::native { +struct Dpi { + float x; + float y; +}; + +enum class MouseButton { Left, Right, Middle }; +} // namespace cru::platform diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp new file mode 100644 index 00000000..a82e7a23 --- /dev/null +++ b/include/cru/platform/native/native_window.hpp @@ -0,0 +1,50 @@ +#pragma once +#include "cru/common/base.hpp" + +#include "basic_types.hpp" +#include "cru/common/event.hpp" +#include "cru/common/ui_base.hpp" + +namespace cru::platform::graph { +struct Painter; +} + +namespace cru::platform::native { +struct NativeWindow : public virtual Interface { + // Return if the window is still valid, that is, hasn't been closed or + // destroyed. + virtual bool IsValid() = 0; + virtual void SetDeleteThisOnDestroy(bool value) = 0; + + virtual void Close() = 0; + + virtual NativeWindow* GetParent() = 0; + + virtual bool IsVisible() = 0; + virtual void SetVisible(bool is_visible) = 0; + + virtual ui::Size GetClientSize() = 0; + virtual void SetClientSize(const ui::Size& size) = 0; + + // Get the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual ui::Rect GetWindowRect() = 0; + + // Set the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual void SetWindowRect(const ui::Rect& rect) = 0; + + virtual graph::Painter* BeginPaint() = 0; + + virtual Event<>* DestroyEvent() = 0; + virtual Event* ResizeEvent() = 0; + virtual Event<>* PaintEvent() = 0; + virtual Event* FocusEvent() = 0; + virtual Event* MouseEnterLeaveEvent() = 0; + virtual Event* MouseMoveEvent() = 0; + virtual Event* MouseDownEvent() = 0; + virtual Event* MouseUpEvent() = 0; + virtual Event* KeyDownEvent() = 0; + virtual Event* KeyUpEvent() = 0; +}; +} // namespace cru::platform::ui diff --git a/include/cru/platform/native/ui_applicaition.hpp b/include/cru/platform/native/ui_applicaition.hpp new file mode 100644 index 00000000..8d42d813 --- /dev/null +++ b/include/cru/platform/native/ui_applicaition.hpp @@ -0,0 +1,31 @@ +#pragma once +#include "cru/common/base.hpp" + +#include +#include +#include + +namespace cru::platform::graph { +struct GraphFactory; +} + +namespace cru::platform::native { +struct NativeWindow; + +struct UiApplication : public virtual Interface { + static UiApplication* GetInstance(); + + virtual int Run() = 0; + virtual void Quit(int quite_code) = 0; + + virtual void InvokeLater(const std::function& action) = 0; + virtual unsigned long SetTimeout(std::chrono::milliseconds milliseconds, + const std::function& action) = 0; + virtual unsigned long SetInterval(std::chrono::milliseconds milliseconds, + const std::function& action) = 0; + virtual void CancelTimer(unsigned long id) = 0; + + virtual std::vector GetAllWindow() = 0; + virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; +}; +} // namespace cru::platform::ui diff --git a/include/cru/platform/native_window.hpp b/include/cru/platform/native_window.hpp deleted file mode 100644 index f68fd3a4..00000000 --- a/include/cru/platform/native_window.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "basic_types.hpp" -#include "cru/common/event.hpp" -#include "cru/common/ui_base.hpp" - -namespace cru::platform { -struct Painter; - -struct NativeWindow : public virtual Interface { - // Return if the window is still valid, that is, hasn't been closed or - // destroyed. - virtual bool IsValid() = 0; - virtual void SetDeleteThisOnDestroy(bool value) = 0; - - virtual void Close() = 0; - - virtual NativeWindow* GetParent() = 0; - - virtual bool IsVisible() = 0; - virtual void SetVisible(bool is_visible) = 0; - - virtual ui::Size GetClientSize() = 0; - virtual void SetClientSize(const ui::Size& size) = 0; - - // Get the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual ui::Rect GetWindowRect() = 0; - - // Set the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual void SetWindowRect(const ui::Rect& rect) = 0; - - virtual Painter* BeginPaint() = 0; - - virtual Event<>* DestroyEvent() = 0; - virtual Event* ResizeEvent() = 0; - virtual Event<>* PaintEvent() = 0; - virtual Event* FocusEvent() = 0; - virtual Event* MouseEnterLeaveEvent() = 0; - virtual Event* MouseMoveEvent() = 0; - virtual Event* MouseDownEvent() = 0; - virtual Event* MouseUpEvent() = 0; - virtual Event* KeyDownEvent() = 0; - virtual Event* KeyUpEvent() = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/painter.hpp b/include/cru/platform/painter.hpp deleted file mode 100644 index b7b89fc9..00000000 --- a/include/cru/platform/painter.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" -#include "matrix.hpp" - -namespace cru::platform { -struct Brush; -struct Geometry; -struct TextLayout; - -struct Painter : virtual Interface { - virtual Matrix GetTransform() = 0; - virtual void SetTransform(const Matrix& matrix) = 0; - virtual void Clear(const ui::Color& color) = 0; - virtual void StrokeRectangle(const ui::Rect& rectangle, Brush* brush, - float width) = 0; - virtual void FillRectangle(const ui::Rect& rectangle, Brush* brush) = 0; - virtual void StrokeGeometry(Geometry* geometry, Brush* brush, - float width) = 0; - virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0; - virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush) = 0; - virtual void EndDraw() = 0; - virtual bool IsDisposed() = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/painter_util.hpp b/include/cru/platform/painter_util.hpp deleted file mode 100644 index 5711d099..00000000 --- a/include/cru/platform/painter_util.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "painter.hpp" - -#include -#include - -namespace cru::platform::util { -template -inline void WithTransform(Painter* painter, const Matrix& matrix, - const Fn& action) { - static_assert(std::is_invocable_v, - "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/platform/string_util.hpp b/include/cru/platform/string_util.hpp index c3b9f93b..822c0c95 100644 --- a/include/cru/platform/string_util.hpp +++ b/include/cru/platform/string_util.hpp @@ -4,6 +4,6 @@ #include #include -namespace cru::platform::util { +namespace cru::platform { std::string ToUtf8String(const std::wstring_view& string); } diff --git a/include/cru/platform/text_layout.hpp b/include/cru/platform/text_layout.hpp deleted file mode 100644 index e43adfde..00000000 --- a/include/cru/platform/text_layout.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" - -#include -#include -#include - -namespace cru::platform { -struct FontDescriptor; - -struct TextLayout : virtual Interface { - virtual std::wstring GetText() = 0; - virtual void SetText(std::wstring new_text) = 0; - virtual std::shared_ptr GetFont() = 0; - virtual void SetFont(std::shared_ptr font) = 0; - virtual void SetMaxWidth(float max_width) = 0; - virtual void SetMaxHeight(float max_height) = 0; - virtual ui::Rect GetTextBounds() = 0; - virtual std::vector TextRangeRect( - const ui::TextRange& text_range) = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/ui_applicaition.hpp b/include/cru/platform/ui_applicaition.hpp deleted file mode 100644 index 16739f9d..00000000 --- a/include/cru/platform/ui_applicaition.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include "basic_types.hpp" - -#include -#include -#include - -namespace cru::platform { -struct NativeWindow; -struct GraphFactory; - -struct UiApplication : public virtual Interface { - static UiApplication* GetInstance(); - - virtual int Run() = 0; - virtual void Quit(int quite_code) = 0; - - virtual void InvokeLater(const std::function& action) = 0; - virtual unsigned long SetTimeout(std::chrono::milliseconds milliseconds, - const std::function& action) = 0; - virtual unsigned long SetInterval(std::chrono::milliseconds milliseconds, - const std::function& action) = 0; - virtual void CancelTimer(unsigned long id) = 0; - - virtual std::vector GetAllWindow() = 0; - virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; - - virtual GraphFactory* GetGraphFactory() = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/win/d2d_util.hpp b/include/cru/platform/win/d2d_util.hpp deleted file mode 100644 index 51aea4f8..00000000 --- a/include/cru/platform/win/d2d_util.hpp +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../matrix.hpp" -#include "cru/common/ui_base.hpp" - -namespace cru::platform::win::util { -inline D2D1_MATRIX_3X2_F Convert(const Matrix& matrix) { - D2D1_MATRIX_3X2_F m; - m._11 = matrix.m11; - m._12 = matrix.m12; - m._21 = matrix.m21; - m._22 = matrix.m22; - m._31 = matrix.m31; - m._32 = matrix.m32; - return m; -} - -inline D2D1_COLOR_F Convert(const ui::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) { - return D2D1::Point2F(point.x, point.y); -} - -inline D2D1_RECT_F Convert(const ui::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) { - return D2D1::RoundedRect(Convert(rounded_rect.rect), rounded_rect.radius_x, - rounded_rect.radius_y); -} - -inline D2D1_ELLIPSE Convert(const ui::Ellipse& ellipse) { - return D2D1::Ellipse(Convert(ellipse.center), ellipse.radius_x, - ellipse.radius_y); -} - -inline Matrix Convert(const D2D1_MATRIX_3X2_F& matrix) { - return Matrix{matrix._11, matrix._12, matrix._21, - matrix._22, matrix._31, matrix._32}; -} - -inline ui::Color Convert(const D2D1_COLOR_F& color) { - auto floor = [](float n) { return static_cast(n + 0.5f); }; - return ui::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 ui::Rect Convert(const D2D1_RECT_F& rect) { - return ui::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, - rounded_rect.radiusY); -} - -inline ui::Ellipse Convert(const D2D1_ELLIPSE& ellipse) { - return ui::Ellipse(Convert(ellipse.point), ellipse.radiusX, ellipse.radiusY); -} - -inline bool operator==(const D2D1_POINT_2F& left, const D2D1_POINT_2F& right) { - return left.x == right.x && left.y == right.y; -} - -inline bool operator!=(const D2D1_POINT_2F& left, const D2D1_POINT_2F& right) { - return !(left == right); -} - -inline bool operator==(const D2D1_RECT_F& left, const D2D1_RECT_F& right) { - return left.left == right.left && left.top == right.top && - left.right == right.right && left.bottom == right.bottom; -} - -inline bool operator!=(const D2D1_RECT_F& left, const D2D1_RECT_F& right) { - return !(left == right); -} - -inline bool operator==(const D2D1_ROUNDED_RECT& left, - const D2D1_ROUNDED_RECT& right) { - return left.rect == right.rect && left.radiusX == right.radiusX && - left.radiusY == right.radiusY; -} - -inline bool operator!=(const D2D1_ROUNDED_RECT& left, - const D2D1_ROUNDED_RECT& right) { - return !(left == right); -} - -inline bool operator==(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) { - return left.point == right.point && left.radiusX == right.radiusX && - left.radiusY == right.radiusY; -} - -inline bool operator!=(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) { - return !(left == right); -} -} // namespace cru::platform::win::util diff --git a/include/cru/platform/win/exception.hpp b/include/cru/platform/win/exception.hpp deleted file mode 100644 index 01b139b4..00000000 --- a/include/cru/platform/win/exception.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include -#include - -namespace cru::platform::win { -class HResultError : public std::runtime_error { - 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); -} - -class Win32Error : public std::runtime_error { - public: - explicit Win32Error(DWORD error_code); - Win32Error(DWORD error_code, const std::string_view& additional_message); - Win32Error(const Win32Error& other) = default; - Win32Error(Win32Error&& other) = default; - Win32Error& operator=(const Win32Error& other) = default; - Win32Error& operator=(Win32Error&& other) = default; - ~Win32Error() override = default; - - HRESULT GetErrorCode() const { return error_code_; } - - private: - DWORD error_code_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/god_window.hpp b/include/cru/platform/win/god_window.hpp deleted file mode 100644 index 95a253e9..00000000 --- a/include/cru/platform/win/god_window.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include - -#include "cru/common/base.hpp" - -namespace cru::platform::win { -class WinApplication; -class WindowClass; - -class GodWindow : public Object { - public: - explicit GodWindow(WinApplication* application); - GodWindow(const GodWindow& other) = delete; - GodWindow(GodWindow&& other) = delete; - GodWindow& operator=(const GodWindow& other) = delete; - GodWindow& operator=(GodWindow&& other) = delete; - ~GodWindow() override; - - HWND GetHandle() const { return hwnd_; } - - bool HandleGodWindowMessage(HWND hwnd, UINT msg, WPARAM w_param, - LPARAM l_param, LRESULT* result); - - private: - WinApplication* application_; - - std::shared_ptr god_window_class_; - HWND hwnd_; -}; -} // namespace cru::platform::win \ No newline at end of file diff --git a/include/cru/platform/win/graph_manager.hpp b/include/cru/platform/win/graph_manager.hpp deleted file mode 100644 index f2e29c22..00000000 --- a/include/cru/platform/win/graph_manager.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../basic_types.hpp" -#include "cru/common/base.hpp" - -namespace cru::platform::win { -class WindowRenderTarget; - -class GraphManager final : public Object { - public: - GraphManager(); - GraphManager(const GraphManager& other) = delete; - GraphManager(GraphManager&& other) = delete; - GraphManager& operator=(const GraphManager& other) = delete; - GraphManager& operator=(GraphManager&& other) = delete; - ~GraphManager() override = default; - - public: - ID2D1Factory1* GetD2D1Factory() const { return d2d1_factory_.Get(); } - - ID2D1DeviceContext* GetD2D1DeviceContext() const { - return d2d1_device_context_.Get(); - } - - ID3D11Device* GetD3D11Device() const { return d3d11_device_.Get(); } - - IDXGIFactory2* GetDxgiFactory() const { return dxgi_factory_.Get(); } - - IDWriteFactory* GetDWriteFactory() const { return dwrite_factory_.Get(); } - - IDWriteFontCollection* GetSystemFontCollection() const { - return dwrite_system_font_collection_.Get(); - } - - private: - Microsoft::WRL::ComPtr d3d11_device_; - Microsoft::WRL::ComPtr d2d1_factory_; - Microsoft::WRL::ComPtr d2d1_device_context_; - Microsoft::WRL::ComPtr dxgi_factory_; - Microsoft::WRL::ComPtr dwrite_factory_; - Microsoft::WRL::ComPtr dwrite_system_font_collection_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_application.hpp b/include/cru/platform/win/win_application.hpp deleted file mode 100644 index f8150aed..00000000 --- a/include/cru/platform/win/win_application.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../ui_applicaition.hpp" -#include "cru/common/base.hpp" - -#include - -namespace cru::platform::win { -class GodWindow; -class TimerManager; -class WindowManager; -class GraphManager; -class WinGraphFactory; - -class WinApplication : public Object, public virtual UiApplication { - public: - static WinApplication* GetInstance(); - - private: - static WinApplication* instance_; - - private: - explicit WinApplication(HINSTANCE h_instance); - - public: - WinApplication(const WinApplication&) = delete; - WinApplication(WinApplication&&) = delete; - WinApplication& operator=(const WinApplication&) = delete; - WinApplication& operator=(WinApplication&&) = delete; - ~WinApplication() override; - - public: - int Run() override; - void Quit(int quit_code) override; - - void InvokeLater(const std::function& action) override; - unsigned long SetTimeout(std::chrono::milliseconds milliseconds, - const std::function& action) override; - unsigned long SetInterval(std::chrono::milliseconds milliseconds, - const std::function& action) override; - void CancelTimer(unsigned long id) override; - - std::vector GetAllWindow() override; - NativeWindow* CreateWindow(NativeWindow* parent) override; - - GraphFactory* GetGraphFactory() override; - - - HINSTANCE GetInstanceHandle() const { return h_instance_; } - - GodWindow* GetGodWindow() const { return god_window_.get(); } - TimerManager* GetTimerManager() const { return timer_manager_.get(); } - WindowManager* GetWindowManager() const { return window_manager_.get(); } - GraphManager* GetGraphManager() const { return graph_manager_.get(); } - WinGraphFactory* GetWinGraphFactory() const { return graph_factory_.get(); } - - private: - HINSTANCE h_instance_; - - std::shared_ptr god_window_; - std::shared_ptr timer_manager_; - std::shared_ptr window_manager_; - std::shared_ptr graph_manager_; - std::shared_ptr graph_factory_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_brush.hpp b/include/cru/platform/win/win_brush.hpp deleted file mode 100644 index d32f6bbc..00000000 --- a/include/cru/platform/win/win_brush.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../brush.hpp" - -namespace cru::platform::win { -struct WinBrush : virtual Brush { - virtual ID2D1Brush* GetD2DBrush() = 0; -}; - -class WinSolidColorBrush : public Object, - public virtual SolidColorBrush, - public virtual WinBrush { - public: - explicit WinSolidColorBrush( - Microsoft::WRL::ComPtr brush); - 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 brush_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_font.hpp b/include/cru/platform/win/win_font.hpp deleted file mode 100644 index f03ff3c8..00000000 --- a/include/cru/platform/win/win_font.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../font.hpp" - -#include - -namespace cru::platform::win { -class GraphManager; - -class WinFontDescriptor : public Object, public virtual FontDescriptor { - public: - explicit WinFontDescriptor(GraphManager* graph_manager, - 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; - - IDWriteTextFormat* GetDWriteTextFormat() const { return text_format_.Get(); } - - private: - Microsoft::WRL::ComPtr text_format_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_geometry.hpp b/include/cru/platform/win/win_geometry.hpp deleted file mode 100644 index e8ab7796..00000000 --- a/include/cru/platform/win/win_geometry.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../geometry.hpp" - -namespace cru::platform::win { -class WinGeometryBuilder : public Object, public virtual GeometryBuilder { - public: - explicit WinGeometryBuilder(Microsoft::WRL::ComPtr geometry); - WinGeometryBuilder(const WinGeometryBuilder& other) = delete; - WinGeometryBuilder(WinGeometryBuilder&& other) = delete; - WinGeometryBuilder& operator=(const WinGeometryBuilder& other) = delete; - WinGeometryBuilder& operator=(WinGeometryBuilder&& other) = delete; - ~WinGeometryBuilder() override; - - bool IsValid() override { return geometry_ != nullptr; } - 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 CloseFigure(bool close) override; - Geometry* Build() override; - - private: - Microsoft::WRL::ComPtr geometry_; - Microsoft::WRL::ComPtr geometry_sink_; -}; - -class WinGeometry : public Object, public virtual Geometry { - public: - explicit WinGeometry(Microsoft::WRL::ComPtr geometry); - WinGeometry(const WinGeometry& other) = delete; - WinGeometry(WinGeometry&& other) = delete; - WinGeometry& operator=(const WinGeometry& other) = delete; - WinGeometry& operator=(WinGeometry&& other) = delete; - ~WinGeometry() override = default; - - bool FillContains(const ui::Point& point) override; - - ID2D1PathGeometry* GetNative() const { return geometry_.Get(); } - - private: - Microsoft::WRL::ComPtr geometry_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_graph_factory.hpp b/include/cru/platform/win/win_graph_factory.hpp deleted file mode 100644 index ca83be86..00000000 --- a/include/cru/platform/win/win_graph_factory.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../graph_factory.hpp" - -namespace cru::platform::win { -class GraphManager; - -class WinGraphFactory : public Object, public virtual GraphFactory { - public: - explicit WinGraphFactory(GraphManager* graph_manager); - WinGraphFactory(const WinGraphFactory& other) = delete; - WinGraphFactory(WinGraphFactory&& other) = delete; - WinGraphFactory& operator=(const WinGraphFactory& other) = delete; - WinGraphFactory& operator=(WinGraphFactory&& other) = delete; - ~WinGraphFactory() override = default; - - SolidColorBrush* CreateSolidColorBrush(const ui::Color& color) override; - GeometryBuilder* CreateGeometryBuilder() override; - FontDescriptor* CreateFontDescriptor(const std::wstring_view& font_family, - float font_size); - TextLayout* CreateTextLayout(std::shared_ptr font, - std::wstring text); - - private: - GraphManager* graph_manager_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_native_window.hpp b/include/cru/platform/win/win_native_window.hpp deleted file mode 100644 index 7b93fd5c..00000000 --- a/include/cru/platform/win/win_native_window.hpp +++ /dev/null @@ -1,132 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../native_window.hpp" -#include "window_native_message_event_args.hpp" - -#include - -namespace cru::platform::win { -class WinApplication; -class WindowClass; -class WindowManager; -class WindowRenderTarget; - -class WinNativeWindow : public Object, public virtual NativeWindow { - public: - WinNativeWindow(WinApplication* application, - std::shared_ptr window_class, DWORD window_style, - WinNativeWindow* parent); - WinNativeWindow(const WinNativeWindow& other) = delete; - WinNativeWindow(WinNativeWindow&& other) = delete; - WinNativeWindow& operator=(const WinNativeWindow& other) = delete; - WinNativeWindow& operator=(WinNativeWindow&& other) = delete; - ~WinNativeWindow() override; - - bool IsValid() override; - void SetDeleteThisOnDestroy(bool value) override; - - void Close() override; - - NativeWindow* GetParent() override { return parent_window_; } - - bool IsVisible() override; - void SetVisible(bool is_visible) override; - - ui::Size GetClientSize() override; - void SetClientSize(const ui::Size& size) override; - - // Get the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - ui::Rect GetWindowRect() override; - - // Set the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - void SetWindowRect(const ui::Rect& rect) override; - - Painter* BeginPaint() override; - - Event<>* DestroyEvent() override { return &destroy_event_; } - Event* ResizeEvent() override { return &resize_event_; } - Event<>* PaintEvent() override { return &paint_event_; } - Event* FocusEvent() override { return &focus_event_; } - Event* MouseEnterLeaveEvent() override { - return &mouse_enter_leave_event_; - } - Event* MouseMoveEvent() override { return &mouse_move_event_; } - Event* MouseDownEvent() override { - return &mouse_down_event_; - } - Event* MouseUpEvent() override { - return &mouse_up_event_; - } - Event* KeyDownEvent() override { return &key_down_event_; } - Event* KeyUpEvent() override { return &key_up_event_; } - - Event* NativeMessageEvent() { - return &native_message_event_; - } - - // Get the handle of the window. Return null if window is invalid. - HWND GetWindowHandle() const { return hwnd_; } - - bool HandleNativeWindowMessage(HWND hwnd, UINT msg, WPARAM w_param, - LPARAM l_param, LRESULT* result); - - WindowRenderTarget* GetWindowRenderTarget() const { - return window_render_target_.get(); - } - - private: - // Get the client rect in pixel. - RECT GetClientRectPixel(); - - //*************** region: native messages *************** - - void OnDestroyInternal(); - void OnPaintInternal(); - void OnResizeInternal(int new_width, int new_height); - - void OnSetFocusInternal(); - void OnKillFocusInternal(); - - void OnMouseMoveInternal(POINT point); - void OnMouseLeaveInternal(); - void OnMouseDownInternal(MouseButton button, POINT point); - void OnMouseUpInternal(MouseButton button, POINT point); - - void OnMouseWheelInternal(short delta, POINT point); - void OnKeyDownInternal(int virtual_code); - void OnKeyUpInternal(int virtual_code); - void OnCharInternal(wchar_t c); - - void OnActivatedInternal(); - void OnDeactivatedInternal(); - - private: - WinApplication* application_; - - bool delete_this_on_destroy_ = true; - - HWND hwnd_; - WinNativeWindow* parent_window_; - - bool has_focus_ = false; - bool is_mouse_in_ = false; - - std::shared_ptr window_render_target_; - - Event<> destroy_event_; - Event resize_event_; - Event<> paint_event_; - Event focus_event_; - Event mouse_enter_leave_event_; - Event mouse_move_event_; - Event mouse_down_event_; - Event mouse_up_event_; - Event key_down_event_; - Event key_up_event_; - - Event native_message_event_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_painter.hpp b/include/cru/platform/win/win_painter.hpp deleted file mode 100644 index 3c37ccb2..00000000 --- a/include/cru/platform/win/win_painter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../painter.hpp" - -namespace cru::platform::win { -class WinNativeWindow; - -class WinPainter : public Object, public virtual Painter { - public: - explicit WinPainter(WinNativeWindow* window); - WinPainter(const WinPainter& other) = delete; - WinPainter(WinPainter&& other) = delete; - WinPainter& operator=(const WinPainter& other) = delete; - WinPainter& operator=(WinPainter&& other) = delete; - ~WinPainter() override; - - Matrix GetTransform() override; - void SetTransform(const Matrix& matrix) override; - void Clear(const ui::Color& color) override; - void StrokeRectangle(const ui::Rect& rectangle, Brush* brush, - float width) override; - void FillRectangle(const ui::Rect& rectangle, Brush* brush) override; - void StrokeGeometry(Geometry* geometry, Brush* brush, float width) override; - void FillGeometry(Geometry* geometry, Brush* brush) override; - void DrawText(const ui::Point& offset, TextLayout* text_layout, - Brush* brush) override; - void EndDraw() override; - bool IsDisposed() override { return is_disposed; } - - void EndDrawAndDeleteThis() { - EndDraw(); - delete this; - } - - private: - WinNativeWindow* window_; - ID2D1RenderTarget* render_target_; - - bool is_disposed = false; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/win_pre_config.hpp b/include/cru/platform/win/win_pre_config.hpp deleted file mode 100644 index 6962eb7b..00000000 --- a/include/cru/platform/win/win_pre_config.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "cru/common/pre_config.hpp" - -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include -#undef CreateWindow -#undef DrawText - -#include -#include -#include -#include -#include diff --git a/include/cru/platform/win/win_text_layout.hpp b/include/cru/platform/win/win_text_layout.hpp deleted file mode 100644 index dfb54264..00000000 --- a/include/cru/platform/win/win_text_layout.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "../text_layout.hpp" -#include "win_font.hpp" - -#include - -namespace cru::platform::win { -class GraphManager; - -class WinTextLayout : public Object, public virtual TextLayout { - public: - explicit WinTextLayout(GraphManager* graph_manager, - std::shared_ptr 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; - - std::wstring GetText() override; - void SetText(std::wstring new_text) override; - std::shared_ptr GetFont(); - void SetFont(std::shared_ptr font); - void SetMaxWidth(float max_width) override; - void SetMaxHeight(float max_height) override; - ui::Rect GetTextBounds() override; - std::vector TextRangeRect( - const ui::TextRange& text_range) override; - - IDWriteTextLayout* GetDWriteTextLayout() const { return text_layout_.Get(); } - - private: - GraphManager* graph_manager_; - std::wstring text_; - std::shared_ptr font_descriptor_; - float max_width_ = 0.0f; - float max_height_ = 0.0f; - Microsoft::WRL::ComPtr text_layout_; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/window_class.hpp b/include/cru/platform/win/window_class.hpp deleted file mode 100644 index be79af13..00000000 --- a/include/cru/platform/win/window_class.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "cru/common/base.hpp" - -#include - -namespace cru::platform::win { -class WindowClass : public Object { - public: - WindowClass(const std::wstring& name, WNDPROC window_proc, HINSTANCE h_instance); - WindowClass(const WindowClass& other) = delete; - WindowClass(WindowClass&& other) = delete; - WindowClass& operator=(const WindowClass& other) = delete; - WindowClass& operator=(WindowClass&& other) = delete; - ~WindowClass() override = default; - - const wchar_t* GetName() const { return name_.c_str(); } - - ATOM GetAtom() const { return atom_; } - - private: - std::wstring name_; - ATOM atom_; -}; -} // namespace cru::ui diff --git a/include/cru/platform/win/window_native_message_event_args.hpp b/include/cru/platform/win/window_native_message_event_args.hpp deleted file mode 100644 index b3419c24..00000000 --- a/include/cru/platform/win/window_native_message_event_args.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "cru/common/base.hpp" - -namespace cru::platform::win { -struct WindowNativeMessage { - HWND hwnd; - UINT msg; - WPARAM w_param; - LPARAM l_param; -}; - -class WindowNativeMessageEventArgs : public Object { - public: - WindowNativeMessageEventArgs(const WindowNativeMessage& message) - : message_(message) {} - WindowNativeMessageEventArgs(const WindowNativeMessageEventArgs& other) = - default; - WindowNativeMessageEventArgs(WindowNativeMessageEventArgs&& other) = default; - WindowNativeMessageEventArgs& operator=( - const WindowNativeMessageEventArgs& other) = default; - WindowNativeMessageEventArgs& operator=( - WindowNativeMessageEventArgs&& other) = default; - ~WindowNativeMessageEventArgs() override = default; - - WindowNativeMessage GetWindowMessage() const { return message_; } - - LRESULT GetResult() const { return result_; } - void SetResult(LRESULT result) { result_ = result; } - - bool IsHandled() const { return handled_; } - void SetHandled(bool handled) { handled_ = handled; } - - void HandledAndSetResult(LRESULT result) { - handled_ = true; - result_ = result; - } - - private: - WindowNativeMessage message_; - LRESULT result_; - bool handled_ = false; -}; -} // namespace cru::platform::win diff --git a/include/cru/platform/win/window_render_target.hpp b/include/cru/platform/win/window_render_target.hpp deleted file mode 100644 index f328a84a..00000000 --- a/include/cru/platform/win/window_render_target.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "win_pre_config.hpp" - -#include "cru/common/base.hpp" - - -namespace cru::platform::win { -class GraphManager; - -// Represents a window render target. -class WindowRenderTarget : public Object { - public: - WindowRenderTarget(GraphManager* graph_manager, HWND hwnd); - WindowRenderTarget(const WindowRenderTarget& other) = delete; - WindowRenderTarget(WindowRenderTarget&& other) = delete; - WindowRenderTarget& operator=(const WindowRenderTarget& other) = delete; - WindowRenderTarget& operator=(WindowRenderTarget&& other) = delete; - ~WindowRenderTarget() override = default; - - public: - // Get the graph manager that created the render target. - GraphManager* GetGraphManager() const { return graph_manager_; } - - // Get the target bitmap which can be set as the ID2D1DeviceContext's target. - ID2D1Bitmap1* GetTargetBitmap() const { return target_bitmap_.Get(); } - - // Resize the underlying buffer. - void ResizeBuffer(int width, int height); - - // Set this render target as the d2d device context's target. - void SetAsTarget(); - - // Present the data of the underlying buffer to the window. - void Present(); - - private: - void CreateTargetBitmap(); - - private: - GraphManager* graph_manager_; - Microsoft::WRL::ComPtr dxgi_swap_chain_; - Microsoft::WRL::ComPtr target_bitmap_; -}; -} // namespace cru::graph -- cgit v1.2.3