aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/native
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
committercrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
commitb53527fbe50a953ad0e3225cc812eb76b8a1f82d (patch)
treeeb81cd14d0a165c47f841ad94835f8987109de7e /include/cru/win/native
parent8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff)
downloadcru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip
...
Diffstat (limited to 'include/cru/win/native')
-rw-r--r--include/cru/win/native/exception.hpp6
-rw-r--r--include/cru/win/native/god_window.hpp8
-rw-r--r--include/cru/win/native/native_window.hpp (renamed from include/cru/win/native/win_native_window.hpp)37
-rw-r--r--include/cru/win/native/platform_id.hpp19
-rw-r--r--include/cru/win/native/ui_application.hpp (renamed from include/cru/win/native/win_application.hpp)37
-rw-r--r--include/cru/win/native/window_class.hpp2
-rw-r--r--include/cru/win/native/window_native_message_event_args.hpp2
-rw-r--r--include/cru/win/native/window_render_target.hpp16
8 files changed, 80 insertions, 47 deletions
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