diff options
author | crupest <crupest@outlook.com> | 2019-12-12 23:26:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-12-12 23:26:04 +0800 |
commit | f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0 (patch) | |
tree | b045d35bb2cf7281ab69abbd51302c85ea9ec3ef /include/cru/win/native | |
parent | 02f46ada9ef85165759f5e58d665510077149ef3 (diff) | |
download | cru-f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0.tar.gz cru-f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0.tar.bz2 cru-f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0.zip |
...
Diffstat (limited to 'include/cru/win/native')
-rw-r--r-- | include/cru/win/native/cursor.hpp | 26 | ||||
-rw-r--r-- | include/cru/win/native/god_window.hpp | 12 | ||||
-rw-r--r-- | include/cru/win/native/resource.hpp | 23 | ||||
-rw-r--r-- | include/cru/win/native/ui_application.hpp | 55 | ||||
-rw-r--r-- | include/cru/win/native/window.hpp (renamed from include/cru/win/native/native_window.hpp) | 38 | ||||
-rw-r--r-- | include/cru/win/native/window_class.hpp | 13 | ||||
-rw-r--r-- | include/cru/win/native/window_native_message_event_args.hpp | 11 | ||||
-rw-r--r-- | include/cru/win/native/window_render_target.hpp | 17 |
8 files changed, 107 insertions, 88 deletions
diff --git a/include/cru/win/native/cursor.hpp b/include/cru/win/native/cursor.hpp index 3ef480ea..e5728b1c 100644 --- a/include/cru/win/native/cursor.hpp +++ b/include/cru/win/native/cursor.hpp @@ -1,32 +1,30 @@ #pragma once -#include <memory> -#include "../win_pre_config.hpp" +#include "resource.hpp" -#include "cru/common/base.hpp" #include "cru/platform/native/cursor.hpp" -#include "cru/win/native/platform_id.hpp" + +#include <memory> namespace cru::platform::native::win { -class WinCursor : public Cursor { +class WinCursor : public WinNativeResource, public virtual ICursor { public: - WinCursor(HCURSOR handle, bool auto_delete); + WinCursor(HCURSOR handle, bool auto_destroy); CRU_DELETE_COPY(WinCursor) CRU_DELETE_MOVE(WinCursor) ~WinCursor() override; - CRU_PLATFORMID_IMPLEMENT_WIN - public: HCURSOR GetHandle() const { return handle_; } private: HCURSOR handle_; - bool auto_delete_; + bool auto_destroy_; }; -class WinCursorManager : public CursorManager { +class WinCursorManager : public WinNativeResource, + public virtual ICursorManager { public: WinCursorManager(); @@ -35,13 +33,11 @@ class WinCursorManager : public CursorManager { ~WinCursorManager() override = default; - CRU_PLATFORMID_IMPLEMENT_WIN - public: - std::shared_ptr<WinCursor> GetSystemWinCursor(SystemCursor type); + std::shared_ptr<WinCursor> GetSystemWinCursor(SystemCursorType type); - std::shared_ptr<Cursor> GetSystemCursor(SystemCursor type) override { - return std::static_pointer_cast<Cursor>(GetSystemWinCursor(type)); + std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) override { + return std::static_pointer_cast<ICursor>(GetSystemWinCursor(type)); } private: diff --git a/include/cru/win/native/god_window.hpp b/include/cru/win/native/god_window.hpp index 9fd20caa..3cf97e0b 100644 --- a/include/cru/win/native/god_window.hpp +++ b/include/cru/win/native/god_window.hpp @@ -12,10 +12,10 @@ class WindowClass; class GodWindow : public Object { public: explicit GodWindow(WinUiApplication* application); - GodWindow(const GodWindow& other) = delete; - GodWindow(GodWindow&& other) = delete; - GodWindow& operator=(const GodWindow& other) = delete; - GodWindow& operator=(GodWindow&& other) = delete; + + CRU_DELETE_COPY(GodWindow) + CRU_DELETE_MOVE(GodWindow) + ~GodWindow() override; HWND GetHandle() const { return hwnd_; } @@ -26,7 +26,7 @@ class GodWindow : public Object { private: WinUiApplication* application_; - std::shared_ptr<WindowClass> god_window_class_; + std::unique_ptr<WindowClass> god_window_class_; HWND hwnd_; }; -} // namespace cru::win::native
\ No newline at end of file +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/resource.hpp b/include/cru/win/native/resource.hpp new file mode 100644 index 00000000..2c76fe6b --- /dev/null +++ b/include/cru/win/native/resource.hpp @@ -0,0 +1,23 @@ +#pragma once +#include "../win_pre_config.hpp" + +#include "cru/platform/resource.hpp" + +namespace cru::platform::native::win { +class WinNativeResource : public Object, public virtual INativeResource { + public: + static constexpr std::string_view k_platform_id = "Windows"; + + protected: + WinNativeResource() = default; + + public: + CRU_DELETE_COPY(WinNativeResource) + CRU_DELETE_MOVE(WinNativeResource) + + ~WinNativeResource() override = default; + + public: + std::string_view GetPlatformId() const final { return k_platform_id; } +}; +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/ui_application.hpp b/include/cru/win/native/ui_application.hpp index 94c4b1eb..65bdc9e4 100644 --- a/include/cru/win/native/ui_application.hpp +++ b/include/cru/win/native/ui_application.hpp @@ -1,39 +1,40 @@ #pragma once -#include "../win_pre_config.hpp" +#include "resource.hpp" #include "cru/platform/native/ui_application.hpp" -#include "platform_id.hpp" -#include "cursor.hpp" - #include <memory> +namespace cru::platform::graph::win::direct { +class DirectGraphFactory; +} + namespace cru::platform::native::win { class GodWindow; class TimerManager; class WindowManager; +class WinCursorManager; -class WinUiApplication : public UiApplication { - friend UiApplication* UiApplication::CreateInstance(); - +class WinUiApplication : public WinNativeResource, + public virtual IUiApplication { public: - static WinUiApplication* GetInstance(); + static WinUiApplication* GetInstance() { return instance; } + + private: + static WinUiApplication* instance; private: - explicit WinUiApplication(HINSTANCE h_instance); + WinUiApplication(); public: - WinUiApplication(const WinUiApplication&) = delete; - WinUiApplication(WinUiApplication&&) = delete; - WinUiApplication& operator=(const WinUiApplication&) = delete; - WinUiApplication& operator=(WinUiApplication&&) = delete; - ~WinUiApplication() override; + CRU_DELETE_COPY(WinUiApplication) + CRU_DELETE_MOVE(WinUiApplication) - CRU_PLATFORMID_IMPLEMENT_WIN + ~WinUiApplication() override; public: int Run() override; - void Quit(int quit_code) override; + void RequestQuit(int quit_code) override; void AddOnQuitHandler(const std::function<void()>& handler) override; @@ -47,25 +48,29 @@ class WinUiApplication : public UiApplication { std::vector<INativeWindow*> GetAllWindow() override; INativeWindow* CreateWindow(INativeWindow* parent) override; - WinCursorManager* GetCursorManager() override; + cru::platform::graph::IGraphFactory* GetGraphFactory() override; + + cru::platform::graph::win::direct::DirectGraphFactory* GetDirectFactory() { + return graph_factory_.get(); + } - bool IsAutoDelete() const { return auto_delete_; } - void SetAutoDelete(bool value) { auto_delete_ = value; } + ICursorManager* GetCursorManager() override; - HINSTANCE GetInstanceHandle() const { return h_instance_; } + HINSTANCE GetInstanceHandle() const { return instance_handle_; } GodWindow* GetGodWindow() const { return god_window_.get(); } TimerManager* GetTimerManager() const { return timer_manager_.get(); } WindowManager* GetWindowManager() const { return window_manager_.get(); } private: - bool auto_delete_ = false; + HINSTANCE instance_handle_; - HINSTANCE h_instance_; + std::unique_ptr<cru::platform::graph::win::direct::DirectGraphFactory> + graph_factory_; - std::shared_ptr<GodWindow> god_window_; - std::shared_ptr<TimerManager> timer_manager_; - std::shared_ptr<WindowManager> window_manager_; + std::unique_ptr<GodWindow> god_window_; + std::unique_ptr<TimerManager> timer_manager_; + std::unique_ptr<WindowManager> window_manager_; std::unique_ptr<WinCursorManager> cursor_manager_; diff --git a/include/cru/win/native/native_window.hpp b/include/cru/win/native/window.hpp index 16b14dbf..9752682f 100644 --- a/include/cru/win/native/native_window.hpp +++ b/include/cru/win/native/window.hpp @@ -1,30 +1,28 @@ #pragma once -#include "../win_pre_config.hpp" +#include "resource.hpp" -#include "cru/platform/native/native_window.hpp" -#include "platform_id.hpp" +#include "cru/platform/native/window.hpp" #include "window_native_message_event_args.hpp" #include <memory> namespace cru::platform::native::win { class WinUiApplication; +class WinCursor; class WindowClass; class WindowManager; class WindowRenderTarget; -class WinNativeWindow : public INativeWindow { +class WinNativeWindow : public WinNativeResource, public virtual INativeWindow { public: WinNativeWindow(WinUiApplication* application, - std::shared_ptr<WindowClass> window_class, DWORD window_style, + WindowClass* 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; - CRU_PLATFORMID_IMPLEMENT_WIN + CRU_DELETE_COPY(WinNativeWindow) + CRU_DELETE_MOVE(WinNativeWindow) + + ~WinNativeWindow() override; public: bool IsValid() override; @@ -53,16 +51,16 @@ class WinNativeWindow : public INativeWindow { bool CaptureMouse() override; bool ReleaseMouse() override; - void Repaint() override; - graph::Painter* BeginPaint() override; + void RequestRepaint() override; + std::unique_ptr<graph::IPainter> BeginPaint() override; - void SetCursor(std::shared_ptr<Cursor> cursor) override; + void SetCursor(std::shared_ptr<ICursor> cursor) override; IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; } IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; } IEvent<Size>* ResizeEvent() override { return &resize_event_; } - IEvent<bool>* FocusEvent() override { return &focus_event_; } - IEvent<bool>* MouseEnterLeaveEvent() override { + IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; } + IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override { return &mouse_enter_leave_event_; } IEvent<Point>* MouseMoveEvent() override { return &mouse_move_event_; } @@ -128,13 +126,15 @@ class WinNativeWindow : public INativeWindow { bool has_focus_ = false; bool is_mouse_in_ = false; - std::shared_ptr<WindowRenderTarget> window_render_target_; + std::unique_ptr<WindowRenderTarget> window_render_target_; + + std::shared_ptr<WinCursor> cursor_; Event<std::nullptr_t> destroy_event_; Event<std::nullptr_t> paint_event_; Event<Size> resize_event_; - Event<bool> focus_event_; - Event<bool> mouse_enter_leave_event_; + Event<FocusChangeType> focus_event_; + Event<MouseEnterLeaveType> mouse_enter_leave_event_; Event<Point> mouse_move_event_; Event<platform::native::NativeMouseButtonEventArgs> mouse_down_event_; Event<platform::native::NativeMouseButtonEventArgs> mouse_up_event_; diff --git a/include/cru/win/native/window_class.hpp b/include/cru/win/native/window_class.hpp index fec3b32e..fd5102a5 100644 --- a/include/cru/win/native/window_class.hpp +++ b/include/cru/win/native/window_class.hpp @@ -8,12 +8,11 @@ namespace cru::platform::native::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(std::wstring name, WNDPROC window_proc, HINSTANCE h_instance); + + CRU_DELETE_COPY(WindowClass) + CRU_DELETE_MOVE(WindowClass) + ~WindowClass() override = default; const wchar_t* GetName() const { return name_.c_str(); } @@ -24,4 +23,4 @@ class WindowClass : public Object { std::wstring name_; ATOM atom_; }; -} // namespace cru::win::native +} // namespace cru::platform::native::win 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 4cf744f2..18de1f46 100644 --- a/include/cru/win/native/window_native_message_event_args.hpp +++ b/include/cru/win/native/window_native_message_event_args.hpp @@ -15,13 +15,8 @@ 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; + CRU_DEFAULT_COPY(WindowNativeMessageEventArgs) + CRU_DEFAULT_MOVE(WindowNativeMessageEventArgs) ~WindowNativeMessageEventArgs() override = default; WindowNativeMessage GetWindowMessage() const { return message_; } @@ -42,4 +37,4 @@ class WindowNativeMessageEventArgs : public Object { LRESULT result_; bool handled_ = false; }; -} // namespace cru::win::native +} // namespace cru::platform::native::win diff --git a/include/cru/win/native/window_render_target.hpp b/include/cru/win/native/window_render_target.hpp index bde47f4f..248bfc25 100644 --- a/include/cru/win/native/window_render_target.hpp +++ b/include/cru/win/native/window_render_target.hpp @@ -4,22 +4,23 @@ #include "cru/common/base.hpp" namespace cru::platform::graph::win::direct { -struct IDirectFactory; +class DirectGraphFactory; } namespace cru::platform::native::win { // Represents a window render target. class WindowRenderTarget : public Object { public: - WindowRenderTarget(graph::win::direct::IDirectFactory* factory, HWND hwnd); - WindowRenderTarget(const WindowRenderTarget& other) = delete; - WindowRenderTarget(WindowRenderTarget&& other) = delete; - WindowRenderTarget& operator=(const WindowRenderTarget& other) = delete; - WindowRenderTarget& operator=(WindowRenderTarget&& other) = delete; + WindowRenderTarget(graph::win::direct::DirectGraphFactory* factory, + HWND hwnd); + + CRU_DELETE_COPY(WindowRenderTarget) + CRU_DELETE_MOVE(WindowRenderTarget) + ~WindowRenderTarget() override = default; public: - graph::win::direct::IDirectFactory* GetWinNativeFactory() const { + graph::win::direct::DirectGraphFactory* GetDirectFactory() const { return factory_; } @@ -39,7 +40,7 @@ class WindowRenderTarget : public Object { void CreateTargetBitmap(); private: - graph::win::direct::IDirectFactory* factory_; + graph::win::direct::DirectGraphFactory* factory_; Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_; Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_; }; |