diff options
author | crupest <crupest@outlook.com> | 2019-06-27 17:02:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-06-27 17:02:58 +0800 |
commit | b53527fbe50a953ad0e3225cc812eb76b8a1f82d (patch) | |
tree | eb81cd14d0a165c47f841ad94835f8987109de7e /include/cru | |
parent | 8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff) | |
download | cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2 cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip |
...
Diffstat (limited to 'include/cru')
28 files changed, 225 insertions, 170 deletions
diff --git a/include/cru/platform/graph/graph_factory.hpp b/include/cru/platform/graph/graph_factory.hpp index 69afc7b3..0b1034cc 100644 --- a/include/cru/platform/graph/graph_factory.hpp +++ b/include/cru/platform/graph/graph_factory.hpp @@ -55,5 +55,8 @@ class GraphFactory : public NativeResource { virtual TextLayout* CreateTextLayout(std::shared_ptr<Font> font, std::wstring text) = 0; + + virtual bool IsAutoDelete() const = 0; + virtual void SetAutoDelete(bool value) = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/util/painter_util.hpp b/include/cru/platform/graph/util/painter_util.hpp index 71e125c3..7a655a34 100644 --- a/include/cru/platform/graph/util/painter_util.hpp +++ b/include/cru/platform/graph/util/painter_util.hpp @@ -6,9 +6,9 @@ namespace cru::platform::graph::util { template <typename Fn> -inline void WithTransform(IPainter* painter, const Matrix& matrix, +inline void WithTransform(Painter* painter, const Matrix& matrix, const Fn& action) { - static_assert(std::is_invocable_v<decltype(action), IPainter*>, + static_assert(std::is_invocable_v<decltype(action), Painter*>, "Action must can be be invoked with painter."); const auto old = painter->GetTransform(); painter->SetTransform(old * matrix); diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp index b0165a88..cbb55c78 100644 --- a/include/cru/platform/matrix.hpp +++ b/include/cru/platform/matrix.hpp @@ -37,8 +37,8 @@ struct Matrix { return Product(*this, matrix); } - ui::Point TransformPoint(const ui::Point& point) const { - return ui::Point{point.x * m11 + point.y * m21 + m31, + Point TransformPoint(const Point& point) const { + return Point{point.x * m11 + point.y * m21 + m31, point.x * m12 + point.y * m22 + m32}; } diff --git a/include/cru/platform/native/native_event.hpp b/include/cru/platform/native/native_event.hpp index 21db5f90..54bab00c 100644 --- a/include/cru/platform/native/native_event.hpp +++ b/include/cru/platform/native/native_event.hpp @@ -1,12 +1,11 @@ #pragma once -#include "cru/common/base.hpp" +#include "../graphic_base.hpp" #include "basic_types.hpp" -#include "cru/common/ui_base.hpp" namespace cru::platform::native { struct NativeMouseButtonEventArgs { MouseButton button; - ui::Point point; + Point point; }; } // namespace cru::platform::native diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp index bb97ef21..22a2dce0 100644 --- a/include/cru/platform/native/native_window.hpp +++ b/include/cru/platform/native/native_window.hpp @@ -1,13 +1,13 @@ #pragma once -#include "cru/common/base.hpp" +#include "../native_resource.hpp" +#include "../graphic_base.hpp" #include "basic_types.hpp" #include "cru/common/event.hpp" -#include "cru/common/ui_base.hpp" #include "native_event.hpp" namespace cru::platform::graph { -struct IPainter; +class Painter; } namespace cru::platform::native { @@ -19,7 +19,20 @@ namespace cru::platform::native { // Close or closed by the user, which leads to an invalid instance. You can // check the validity by IsValid. When you call perform native operations on the // invalid instance, there is no effect. -struct INativeWindow : public virtual Interface { +class NativeWindow : public NativeResource { + protected: + NativeWindow() = default; + + public: + NativeWindow(const NativeWindow& other) = delete; + NativeWindow& operator=(const NativeWindow& other) = delete; + + NativeWindow(NativeWindow&& other) = delete; + NativeWindow& operator=(NativeWindow&& other) = delete; + + ~NativeWindow() override = default; + + public: // Return if the window is still valid, that is, hasn't been closed or // destroyed. virtual bool IsValid() = 0; @@ -27,30 +40,30 @@ struct INativeWindow : public virtual Interface { virtual void Close() = 0; - virtual INativeWindow* GetParent() = 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; + virtual Size GetClientSize() = 0; + virtual void SetClientSize(const 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; + virtual 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 void SetWindowRect(const Rect& rect) = 0; - virtual graph::IPainter* BeginPaint() = 0; + virtual graph::Painter* BeginPaint() = 0; virtual IEvent<std::nullptr_t>* DestroyEvent() = 0; virtual IEvent<std::nullptr_t>* PaintEvent() = 0; - virtual IEvent<ui::Size>* ResizeEvent() = 0; + virtual IEvent<Size>* ResizeEvent() = 0; virtual IEvent<bool>* FocusEvent() = 0; virtual IEvent<bool>* MouseEnterLeaveEvent() = 0; - virtual IEvent<ui::Point>* MouseMoveEvent() = 0; + virtual IEvent<Point>* MouseMoveEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0; virtual IEvent<int>* KeyDownEvent() = 0; diff --git a/include/cru/platform/native/ui_applicaition.hpp b/include/cru/platform/native/ui_applicaition.hpp index 655b8ea0..aa8d98da 100644 --- a/include/cru/platform/native/ui_applicaition.hpp +++ b/include/cru/platform/native/ui_applicaition.hpp @@ -1,29 +1,41 @@ #pragma once -#include "cru/common/base.hpp" - -#include "cru/common/auto_delete.hpp" +#include "../native_resource.hpp" #include <chrono> #include <functional> #include <vector> namespace cru::platform::native { -struct INativeWindow; +class NativeWindow; // The entry point of a ui application. // It will call IGraphFactory::CreateInstance during its creation // and set graph factory to be auto deleted. If you want to keep // the graph factory then you should manually set it to false after // creating the ui application. -struct IUiApplication : virtual Interface, virtual IAutoDelete { +class UiApplication : public NativeResource { + public: // Create a platform-specific instance and save it as the global instance. // Do not create the instance twice. Implements should assert for that. // After creating, get the instance by GetInstance. - static IUiApplication* CreateInstance(); + static UiApplication* CreateInstance(); // Get the global instance. If it is not created, then return nullptr. - static IUiApplication* GetInstance(); + static UiApplication* GetInstance(); + + protected: + UiApplication() = default; + + public: + UiApplication(const UiApplication& other) = delete; + UiApplication& operator=(const UiApplication& other) = delete; + + UiApplication(UiApplication&& other) = delete; + UiApplication& operator=(UiApplication&& other) = delete; + + ~UiApplication() override = default; + public: virtual int Run() = 0; virtual void Quit(int quite_code) = 0; @@ -36,7 +48,7 @@ struct IUiApplication : virtual Interface, virtual IAutoDelete { const std::function<void()>& action) = 0; virtual void CancelTimer(unsigned long id) = 0; - virtual std::vector<INativeWindow*> GetAllWindow() = 0; - virtual INativeWindow* CreateWindow(INativeWindow* parent) = 0; + virtual std::vector<NativeWindow*> GetAllWindow() = 0; + virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; }; -} // namespace cru::platform::ui +} // namespace cru::platform::native diff --git a/include/cru/platform/native_resource.hpp b/include/cru/platform/native_resource.hpp index 787c46a5..ec7f01b6 100644 --- a/include/cru/platform/native_resource.hpp +++ b/include/cru/platform/native_resource.hpp @@ -9,8 +9,9 @@ class NativeResource : public Object { NativeResource() = default; public: - NativeResource(NativeResource&& other) = delete; - NativeResource& operator=(NativeResource&& other) = delete; + NativeResource(const NativeResource& other) = delete; + NativeResource& operator=(const NativeResource& other) = delete; + NativeResource(NativeResource&& other) = delete; NativeResource& operator=(NativeResource&& other) = delete; diff --git a/include/cru/ui/base.hpp b/include/cru/ui/base.hpp new file mode 100644 index 00000000..427615b9 --- /dev/null +++ b/include/cru/ui/base.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "cru/platform/graphic_base.hpp" +#include "cru/platform/matrix.hpp" +#include "cru/platform/native/basic_types.hpp" + +namespace cru::ui { +using cru::platform::Color; +using cru::platform::Ellipse; +using cru::platform::Matrix; +using cru::platform::Point; +using cru::platform::Rect; +using cru::platform::RoundedRect; +using cru::platform::Size; +using cru::platform::TextRange; +using cru::platform::Thickness; +using cru::platform::native::MouseButton; + +namespace colors { +using namespace cru::platform::colors; +} +} // namespace cru::ui
\ No newline at end of file diff --git a/include/cru/ui/control.hpp b/include/cru/ui/control.hpp index 652efe89..15eeb6fa 100644 --- a/include/cru/ui/control.hpp +++ b/include/cru/ui/control.hpp @@ -1,5 +1,6 @@ #pragma once #include "cru/common/base.hpp" +#include "base.hpp" #include "cru/platform/native/basic_types.hpp" #include "event/ui_event.hpp" diff --git a/include/cru/ui/event/ui_event.hpp b/include/cru/ui/event/ui_event.hpp index 2704cc4f..62045808 100644 --- a/include/cru/ui/event/ui_event.hpp +++ b/include/cru/ui/event/ui_event.hpp @@ -1,14 +1,13 @@ #pragma once #include "cru/common/base.hpp" +#include "../base.hpp" #include "cru/common/event.hpp" -#include "cru/common/ui_base.hpp" -#include "cru/platform/native/basic_types.hpp" #include <optional> namespace cru::platform::graph { -struct IPainter; +class Painter; } namespace cru::ui { @@ -79,7 +78,7 @@ class MouseButtonEventArgs : public MouseEventArgs { public: MouseButtonEventArgs(Object* sender, Object* original_sender, const Point& point, - const platform::native::MouseButton button) + const MouseButton button) : MouseEventArgs(sender, original_sender, point), button_(button) {} MouseButtonEventArgs(const MouseButtonEventArgs& other) = default; MouseButtonEventArgs(MouseButtonEventArgs&& other) = default; @@ -87,10 +86,10 @@ class MouseButtonEventArgs : public MouseEventArgs { MouseButtonEventArgs& operator=(MouseButtonEventArgs&& other) = default; ~MouseButtonEventArgs() override = default; - platform::native::MouseButton GetMouseButton() const { return button_; } + MouseButton GetMouseButton() const { return button_; } private: - platform::native::MouseButton button_; + MouseButton button_; }; class MouseWheelEventArgs : public MouseEventArgs { @@ -113,7 +112,7 @@ class MouseWheelEventArgs : public MouseEventArgs { class PaintEventArgs : public UiEventArgs { public: PaintEventArgs(Object* sender, Object* original_sender, - platform::graph::IPainter* painter) + platform::graph::Painter* painter) : UiEventArgs(sender, original_sender), painter_(painter) {} PaintEventArgs(const PaintEventArgs& other) = default; PaintEventArgs(PaintEventArgs&& other) = default; @@ -121,10 +120,10 @@ class PaintEventArgs : public UiEventArgs { PaintEventArgs& operator=(PaintEventArgs&& other) = default; ~PaintEventArgs() = default; - platform::graph::IPainter* GetPainter() const { return painter_; } + platform::graph::Painter* GetPainter() const { return painter_; } private: - platform::graph::IPainter* painter_; + platform::graph::Painter* painter_; }; class FocusChangeEventArgs : public UiEventArgs { diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 407edbb3..ab424e60 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -4,9 +4,9 @@ #include <memory> namespace cru::platform::graph { -struct IBrush; -struct IGeometry; -} // namespace cru::platform +class Brush; +class Geometry; +} // namespace cru::platform::graph namespace cru::ui::render { struct CornerRadius { @@ -32,7 +32,7 @@ struct CornerRadius { class BorderRenderObject : public RenderObject { public: - explicit BorderRenderObject(std::shared_ptr<platform::graph::IBrush> brush); + explicit BorderRenderObject(std::shared_ptr<platform::graph::Brush> brush); BorderRenderObject(const BorderRenderObject& other) = delete; BorderRenderObject(BorderRenderObject&& other) = delete; BorderRenderObject& operator=(const BorderRenderObject& other) = delete; @@ -42,8 +42,10 @@ class BorderRenderObject : public RenderObject { bool IsEnabled() const { return is_enabled_; } void SetEnabled(bool enabled) { is_enabled_ = enabled; } - std::shared_ptr<platform::graph::IBrush> GetBrush() const { return border_brush_; } - void SetBrush(std::shared_ptr<platform::graph::IBrush> new_brush) { + std::shared_ptr<platform::graph::Brush> GetBrush() const { + return border_brush_; + } + void SetBrush(std::shared_ptr<platform::graph::Brush> new_brush) { border_brush_ = std::move(new_brush); } @@ -59,7 +61,7 @@ class BorderRenderObject : public RenderObject { void Refresh() { RecreateGeometry(); } - void Draw(platform::graph::IPainter* painter) override; + void Draw(platform::graph::Painter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -83,11 +85,11 @@ class BorderRenderObject : public RenderObject { private: bool is_enabled_ = false; - std::shared_ptr<platform::graph::IBrush> border_brush_ = nullptr; + std::shared_ptr<platform::graph::Brush> border_brush_ = nullptr; Thickness border_thickness_{}; CornerRadius corner_radius_{}; - std::shared_ptr<platform::graph::IGeometry> geometry_ = nullptr; - std::shared_ptr<platform::graph::IGeometry> border_outer_geometry_ = nullptr; + std::shared_ptr<platform::graph::Geometry> geometry_ = nullptr; + std::shared_ptr<platform::graph::Geometry> border_outer_geometry_ = nullptr; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp index 8d881239..1234b920 100644 --- a/include/cru/ui/render/flex_layout_render_object.hpp +++ b/include/cru/ui/render/flex_layout_render_object.hpp @@ -64,7 +64,7 @@ class FlexLayoutRenderObject : public RenderObject { FlexChildLayoutData* GetChildLayoutData(int position); - void Draw(platform::graph::IPainter* painter) override; + void Draw(platform::graph::Painter* painter) override; RenderObject* HitTest(const Point& point) override; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index b6614317..dca254cc 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -1,7 +1,7 @@ #pragma once #include "cru/common/base.hpp" -#include "cru/common/ui_base.hpp" +#include "../base.hpp" #include <vector> @@ -11,7 +11,7 @@ class Control; } namespace cru::platform::graph { -struct IPainter; +class Painter; } namespace cru::ui::render { @@ -58,7 +58,7 @@ class RenderObject : public Object { void Measure(const Size& available_size); void Layout(const Rect& rect); - virtual void Draw(platform::graph::IPainter* painter) = 0; + virtual void Draw(platform::graph::Painter* painter) = 0; virtual RenderObject* HitTest(const Point& point) = 0; diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index ecad6bb8..054d9b47 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -6,17 +6,17 @@ // forward declarations namespace cru::platform::graph { -struct IBrush; -struct IFontDescriptor; -struct ITextLayout; +class Brush; +class Font; +class TextLayout; } // namespace cru::platform::graph namespace cru::ui::render { class TextRenderObject : public RenderObject { public: - TextRenderObject(std::shared_ptr<platform::graph::IBrush> brush, - std::shared_ptr<platform::graph::IFontDescriptor> font, - std::shared_ptr<platform::graph::IBrush> selection_brush); + TextRenderObject(std::shared_ptr<platform::graph::Brush> brush, + std::shared_ptr<platform::graph::Font> font, + std::shared_ptr<platform::graph::Brush> selection_brush); TextRenderObject(const TextRenderObject& other) = delete; TextRenderObject(TextRenderObject&& other) = delete; TextRenderObject& operator=(const TextRenderObject& other) = delete; @@ -26,13 +26,13 @@ class TextRenderObject : public RenderObject { std::wstring GetText() const; void SetText(std::wstring new_text); - std::shared_ptr<platform::graph::IBrush> GetBrush() const { return brush_; } - void SetBrush(std::shared_ptr<platform::graph::IBrush> new_brush) { + std::shared_ptr<platform::graph::Brush> GetBrush() const { return brush_; } + void SetBrush(std::shared_ptr<platform::graph::Brush> new_brush) { new_brush.swap(brush_); } - std::shared_ptr<platform::graph::IFontDescriptor> GetFont() const; - void SetFont(std::shared_ptr<platform::graph::IFontDescriptor> font); + std::shared_ptr<platform::graph::Font> GetFont() const; + void SetFont(std::shared_ptr<platform::graph::Font> font); std::optional<TextRange> GetSelectionRange() const { return selection_range_; @@ -41,14 +41,14 @@ class TextRenderObject : public RenderObject { selection_range_ = std::move(new_range); } - std::shared_ptr<platform::graph::IBrush> GetSelectionBrush() const { + std::shared_ptr<platform::graph::Brush> GetSelectionBrush() const { return selection_brush_; } - void SetSelectionBrush(std::shared_ptr<platform::graph::IBrush> new_brush) { + void SetSelectionBrush(std::shared_ptr<platform::graph::Brush> new_brush) { new_brush.swap(selection_brush_); } - void Draw(platform::graph::IPainter* painter) override; + void Draw(platform::graph::Painter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -59,11 +59,11 @@ class TextRenderObject : public RenderObject { void OnLayoutContent(const Rect& content_rect) override; private: - std::shared_ptr<platform::graph::IBrush> brush_; - std::shared_ptr<platform::graph::IFontDescriptor> font_; - std::shared_ptr<platform::graph::ITextLayout> text_layout_; + std::shared_ptr<platform::graph::Brush> brush_; + std::shared_ptr<platform::graph::Font> font_; + std::shared_ptr<platform::graph::TextLayout> text_layout_; std::optional<TextRange> selection_range_ = std::nullopt; - std::shared_ptr<platform::graph::IBrush> selection_brush_; + std::shared_ptr<platform::graph::Brush> selection_brush_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index b95acbce..dfeae487 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -17,7 +17,7 @@ class WindowRenderObject : public RenderObject { void MeasureAndLayout(); - void Draw(platform::graph::IPainter* painter) override; + void Draw(platform::graph::Painter* painter) override; RenderObject* HitTest(const Point& point) override; diff --git a/include/cru/ui/ui_manager.hpp b/include/cru/ui/ui_manager.hpp index f3f78722..d2b8ad53 100644 --- a/include/cru/ui/ui_manager.hpp +++ b/include/cru/ui/ui_manager.hpp @@ -1,15 +1,16 @@ #pragma once +#include "base.hpp" #include "cru/common/base.hpp" #include <memory> namespace cru::platform::graph { -struct IBrush; -struct IFontDescriptor; -} // namespace cru::platform +class Brush; +class Font; +} // namespace cru::platform::graph namespace cru::ui { -//TODO: Make this theme resource. +// TODO: Make this theme resource. class PredefineResources : public Object { public: PredefineResources(); @@ -20,12 +21,12 @@ class PredefineResources : public Object { ~PredefineResources() override = default; // region Button - std::shared_ptr<platform::graph::IBrush> button_normal_border_brush; + std::shared_ptr<platform::graph::Brush> button_normal_border_brush; // region TextBlock - std::shared_ptr<platform::graph::IBrush> text_block_selection_brush; - std::shared_ptr<platform::graph::IBrush> text_block_text_brush; - std::shared_ptr<platform::graph::IFontDescriptor> text_block_font; + std::shared_ptr<platform::graph::Brush> text_block_selection_brush; + std::shared_ptr<platform::graph::Brush> text_block_text_brush; + std::shared_ptr<platform::graph::Font> text_block_font; }; class UiManager : public Object { diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp index e175b234..311f1487 100644 --- a/include/cru/ui/window.hpp +++ b/include/cru/ui/window.hpp @@ -9,7 +9,7 @@ #include <vector> namespace cru::platform::native { -struct INativeWindow; +class NativeWindow; } namespace cru::ui { @@ -41,7 +41,7 @@ class Window final : public ContentControl, public SelfResovable<Window> { render::RenderObject* GetRenderObject() const override; - platform::native::INativeWindow* GetNativeWindow() const { + platform::native::NativeWindow* GetNativeWindow() const { return native_window_; } @@ -91,7 +91,7 @@ class Window final : public ContentControl, public SelfResovable<Window> { const Point& point); private: - platform::native::INativeWindow* native_window_; + platform::native::NativeWindow* native_window_; std::vector<EventRevokerGuard> event_revoker_guards_; std::shared_ptr<render::WindowRenderObject> render_object_; diff --git a/include/cru/win/graph/direct/exception.hpp b/include/cru/win/graph/direct/exception.hpp index bfa14aaf..8e955825 100644 --- a/include/cru/win/graph/direct/exception.hpp +++ b/include/cru/win/graph/direct/exception.hpp @@ -1,36 +1,7 @@ #pragma once -#include "../../win_pre_config.hpp" - -#include "cru/platform/exception.hpp" - -#include <stdexcept> -#include <string_view> +#include "../../exception.hpp" 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); -} +using platform::win::HResultError; +using platform::win::ThrowIfFailed; } // namespace cru::platform::graph::win::direct
\ No newline at end of file diff --git a/include/cru/win/graph/direct/graph_factory.hpp b/include/cru/win/graph/direct/graph_factory.hpp index 841dd104..fb26a7c5 100644 --- a/include/cru/win/graph/direct/graph_factory.hpp +++ b/include/cru/win/graph/direct/graph_factory.hpp @@ -10,7 +10,7 @@ #include "cru/platform/graph/graph_factory.hpp" namespace cru::platform::graph::win::direct { -class DirectGraphFactory : public GraphFactory, IDirectFactory { +class DirectGraphFactory : public GraphFactory, public IDirectFactory { friend GraphFactory* GraphFactory::CreateInstance(); public: diff --git a/include/cru/win/graph/direct/platform_id.hpp b/include/cru/win/graph/direct/platform_id.hpp index ff02eb27..edac38f1 100644 --- a/include/cru/win/graph/direct/platform_id.hpp +++ b/include/cru/win/graph/direct/platform_id.hpp @@ -1,19 +1,18 @@ #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"; +constexpr std::wstring_view win_direct_platform_id = L"Windows Direct"; -bool IsDirectResource(NativeResource* resource) { - return resource->GetPlatformId() == platform_id; +inline bool IsDirectResource(NativeResource* resource) { + return resource->GetPlatformId() == win_direct_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; \ +#define CRU_PLATFORMID_IMPLEMENT_DIRECT \ + std::wstring_view GetPlatformId() const override { \ + return ::cru::platform::graph::win::direct::win_direct_platform_id; \ } diff --git a/include/cru/win/native/exception.hpp b/include/cru/win/native/exception.hpp new file mode 100644 index 00000000..637f021d --- /dev/null +++ b/include/cru/win/native/exception.hpp @@ -0,0 +1,6 @@ +#pragma once +#include "../exception.hpp" + +namespace cru::platform::native::win { +using platform::win::Win32Error; +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/god_window.hpp b/include/cru/win/native/god_window.hpp index 9ac49858..9fd20caa 100644 --- a/include/cru/win/native/god_window.hpp +++ b/include/cru/win/native/god_window.hpp @@ -5,13 +5,13 @@ #include <memory> -namespace cru::win::native { -class WinApplication; +namespace cru::platform::native::win { +class WinUiApplication; class WindowClass; class GodWindow : public Object { public: - explicit GodWindow(WinApplication* application); + explicit GodWindow(WinUiApplication* application); GodWindow(const GodWindow& other) = delete; GodWindow(GodWindow&& other) = delete; GodWindow& operator=(const GodWindow& other) = delete; @@ -24,7 +24,7 @@ class GodWindow : public Object { LPARAM l_param, LRESULT* result); private: - WinApplication* application_; + WinUiApplication* application_; std::shared_ptr<WindowClass> god_window_class_; HWND hwnd_; diff --git a/include/cru/win/native/win_native_window.hpp b/include/cru/win/native/native_window.hpp index 18de4f5d..ed678591 100644 --- a/include/cru/win/native/win_native_window.hpp +++ b/include/cru/win/native/native_window.hpp @@ -2,20 +2,20 @@ #include "../win_pre_config.hpp" #include "cru/platform/native/native_window.hpp" +#include "platform_id.hpp" #include "window_native_message_event_args.hpp" #include <memory> -namespace cru::win::native { -class WinApplication; +namespace cru::platform::native::win { +class WinUiApplication; class WindowClass; class WindowManager; class WindowRenderTarget; -class WinNativeWindow : public Object, - public virtual platform::native::INativeWindow { +class WinNativeWindow : public NativeWindow { public: - WinNativeWindow(WinApplication* application, + WinNativeWindow(WinUiApplication* application, std::shared_ptr<WindowClass> window_class, DWORD window_style, WinNativeWindow* parent); WinNativeWindow(const WinNativeWindow& other) = delete; @@ -24,37 +24,40 @@ class WinNativeWindow : public Object, WinNativeWindow& operator=(WinNativeWindow&& other) = delete; ~WinNativeWindow() override; + CRU_PLATFORMID_IMPLEMENT_WIN + + public: bool IsValid() override; void SetDeleteThisOnDestroy(bool value) override; void Close() override; - INativeWindow* GetParent() override { return parent_window_; } + WinNativeWindow* 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; + Size GetClientSize() override; + void SetClientSize(const 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; + 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; + void SetWindowRect(const Rect& rect) override; - platform::graph::IPainter* BeginPaint() override; + graph::Painter* BeginPaint() override; IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; } IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; } - IEvent<ui::Size>* ResizeEvent() override { return &resize_event_; } + IEvent<Size>* ResizeEvent() override { return &resize_event_; } IEvent<bool>* FocusEvent() override { return &focus_event_; } IEvent<bool>* MouseEnterLeaveEvent() override { return &mouse_enter_leave_event_; } - IEvent<ui::Point>* MouseMoveEvent() override { return &mouse_move_event_; } + IEvent<Point>* MouseMoveEvent() override { return &mouse_move_event_; } IEvent<platform::native::NativeMouseButtonEventArgs>* MouseDownEvent() override { return &mouse_down_event_; @@ -107,7 +110,7 @@ class WinNativeWindow : public Object, void OnDeactivatedInternal(); private: - WinApplication* application_; + WinUiApplication* application_; bool delete_this_on_destroy_ = true; @@ -121,10 +124,10 @@ class WinNativeWindow : public Object, Event<std::nullptr_t> destroy_event_; Event<std::nullptr_t> paint_event_; - Event<ui::Size> resize_event_; + Event<Size> resize_event_; Event<bool> focus_event_; Event<bool> mouse_enter_leave_event_; - Event<ui::Point> mouse_move_event_; + Event<Point> mouse_move_event_; Event<platform::native::NativeMouseButtonEventArgs> mouse_down_event_; Event<platform::native::NativeMouseButtonEventArgs> mouse_up_event_; Event<int> key_down_event_; @@ -132,4 +135,4 @@ class WinNativeWindow : public Object, Event<WindowNativeMessageEventArgs&> native_message_event_; }; -} // namespace cru::win::native +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/platform_id.hpp b/include/cru/win/native/platform_id.hpp new file mode 100644 index 00000000..4b018d51 --- /dev/null +++ b/include/cru/win/native/platform_id.hpp @@ -0,0 +1,19 @@ +#pragma once +#include <cru/platform/native_resource.hpp> + +#include <stdexcept> +#include <string_view> + +namespace cru::platform::native::win { +constexpr std::wstring_view win_platform_id = L"Windows"; + +inline bool IsWindowsResource(NativeResource* resource) { + return resource->GetPlatformId() == win_platform_id; +} + +} // namespace cru::platform::native::win + +#define CRU_PLATFORMID_IMPLEMENT_WIN \ + std::wstring_view GetPlatformId() const override { \ + return ::cru::platform::native::win::win_platform_id; \ + } diff --git a/include/cru/win/native/win_application.hpp b/include/cru/win/native/ui_application.hpp index d3e705e1..08a9c3ed 100644 --- a/include/cru/win/native/win_application.hpp +++ b/include/cru/win/native/ui_application.hpp @@ -1,30 +1,34 @@ #pragma once #include "../win_pre_config.hpp" +#include "platform_id.hpp" + #include "cru/platform/native/ui_applicaition.hpp" #include <memory> -namespace cru::win::native { +namespace cru::platform::native::win { class GodWindow; class TimerManager; class WindowManager; -class WinApplication : public Object, - public virtual platform::native::IUiApplication { - friend IUiApplication* IUiApplication::CreateInstance(); +class WinUiApplication : public UiApplication { + friend UiApplication* UiApplication::CreateInstance(); + public: - static WinApplication* GetInstance(); + static WinUiApplication* GetInstance(); private: - explicit WinApplication(HINSTANCE h_instance); + explicit WinUiApplication(HINSTANCE h_instance); public: - WinApplication(const WinApplication&) = delete; - WinApplication(WinApplication&&) = delete; - WinApplication& operator=(const WinApplication&) = delete; - WinApplication& operator=(WinApplication&&) = delete; - ~WinApplication() override; + WinUiApplication(const WinUiApplication&) = delete; + WinUiApplication(WinUiApplication&&) = delete; + WinUiApplication& operator=(const WinUiApplication&) = delete; + WinUiApplication& operator=(WinUiApplication&&) = delete; + ~WinUiApplication() override; + + CRU_PLATFORMID_IMPLEMENT_WIN public: int Run() override; @@ -39,12 +43,11 @@ class WinApplication : public Object, const std::function<void()>& action) override; void CancelTimer(unsigned long id) override; - std::vector<platform::native::INativeWindow*> GetAllWindow() override; - platform::native::INativeWindow* CreateWindow( - platform::native::INativeWindow* parent) override; + std::vector<NativeWindow*> GetAllWindow() override; + NativeWindow* CreateWindow(NativeWindow* parent) override; - bool IsAutoDelete() const override { return auto_delete_; } - void SetAutoDelete(bool value) override { auto_delete_ = value; } + bool IsAutoDelete() const { return auto_delete_; } + void SetAutoDelete(bool value) { auto_delete_ = value; } HINSTANCE GetInstanceHandle() const { return h_instance_; } @@ -63,4 +66,4 @@ class WinApplication : public Object, std::vector<std::function<void()>> quit_handlers_; }; -} // namespace cru::win::native +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/window_class.hpp b/include/cru/win/native/window_class.hpp index 17712958..fec3b32e 100644 --- a/include/cru/win/native/window_class.hpp +++ b/include/cru/win/native/window_class.hpp @@ -5,7 +5,7 @@ #include <string> -namespace cru::win::native { +namespace cru::platform::native::win { class WindowClass : public Object { public: WindowClass(const std::wstring& name, WNDPROC window_proc, diff --git a/include/cru/win/native/window_native_message_event_args.hpp b/include/cru/win/native/window_native_message_event_args.hpp index 37149f36..4cf744f2 100644 --- a/include/cru/win/native/window_native_message_event_args.hpp +++ b/include/cru/win/native/window_native_message_event_args.hpp @@ -3,7 +3,7 @@ #include "cru/common/base.hpp" -namespace cru::win::native { +namespace cru::platform::native::win { struct WindowNativeMessage { HWND hwnd; UINT msg; diff --git a/include/cru/win/native/window_render_target.hpp b/include/cru/win/native/window_render_target.hpp index 5ff8ec87..bde47f4f 100644 --- a/include/cru/win/native/window_render_target.hpp +++ b/include/cru/win/native/window_render_target.hpp @@ -3,15 +3,15 @@ #include "cru/common/base.hpp" -namespace cru::win::graph { -struct IWinNativeFactory; +namespace cru::platform::graph::win::direct { +struct IDirectFactory; } -namespace cru::win::native { +namespace cru::platform::native::win { // Represents a window render target. class WindowRenderTarget : public Object { public: - WindowRenderTarget(graph::IWinNativeFactory* factory, HWND hwnd); + WindowRenderTarget(graph::win::direct::IDirectFactory* factory, HWND hwnd); WindowRenderTarget(const WindowRenderTarget& other) = delete; WindowRenderTarget(WindowRenderTarget&& other) = delete; WindowRenderTarget& operator=(const WindowRenderTarget& other) = delete; @@ -19,7 +19,9 @@ class WindowRenderTarget : public Object { ~WindowRenderTarget() override = default; public: - graph::IWinNativeFactory* GetWinNativeFactory() const { return factory_; } + graph::win::direct::IDirectFactory* GetWinNativeFactory() const { + return factory_; + } // Get the target bitmap which can be set as the ID2D1DeviceContext's target. ID2D1Bitmap1* GetTargetBitmap() const { return target_bitmap_.Get(); } @@ -37,8 +39,8 @@ class WindowRenderTarget : public Object { void CreateTargetBitmap(); private: - graph::IWinNativeFactory* factory_; + graph::win::direct::IDirectFactory* factory_; Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_; Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_; }; -} // namespace cru::win::native +} // namespace cru::platform::native::win |