aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/native/win_native_window.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-04-10 19:42:46 +0800
committercrupest <crupest@outlook.com>2019-04-10 19:42:46 +0800
commit7351020a582d70a1495249fba87d342c8a1fb634 (patch)
treee80f225041dc3816b3dce21c7e15aadbb211602e /include/cru/win/native/win_native_window.hpp
parenta94a806f69586e08a30fff0cdb3e52b0ce7acfa5 (diff)
downloadcru-7351020a582d70a1495249fba87d342c8a1fb634.tar.gz
cru-7351020a582d70a1495249fba87d342c8a1fb634.tar.bz2
cru-7351020a582d70a1495249fba87d342c8a1fb634.zip
Refactor.
Diffstat (limited to 'include/cru/win/native/win_native_window.hpp')
-rw-r--r--include/cru/win/native/win_native_window.hpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/include/cru/win/native/win_native_window.hpp b/include/cru/win/native/win_native_window.hpp
new file mode 100644
index 00000000..2b9be25d
--- /dev/null
+++ b/include/cru/win/native/win_native_window.hpp
@@ -0,0 +1,137 @@
+#pragma once
+#include "../win_pre_config.hpp"
+
+#include "cru/platform/native/native_window.hpp"
+#include "window_native_message_event_args.hpp"
+
+#include <memory>
+
+namespace cru::win::native {
+class WinApplication;
+class WindowClass;
+class WindowManager;
+class WindowRenderTarget;
+
+class WinNativeWindow : public Object,
+ public virtual platform::native::NativeWindow {
+ public:
+ WinNativeWindow(WinApplication* application,
+ std::shared_ptr<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;
+
+ 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;
+
+ platform::graph::Painter* BeginPaint() override;
+
+ Event<>* DestroyEvent() override { return &destroy_event_; }
+ Event<const ui::Size&>* ResizeEvent() override { return &resize_event_; }
+ Event<>* PaintEvent() override { return &paint_event_; }
+ Event<bool>* FocusEvent() override { return &focus_event_; }
+ Event<bool>* MouseEnterLeaveEvent() override {
+ return &mouse_enter_leave_event_;
+ }
+ Event<const ui::Point&>* MouseMoveEvent() override {
+ return &mouse_move_event_;
+ }
+ Event<platform::native::MouseButton, const ui::Point&>* MouseDownEvent()
+ override {
+ return &mouse_down_event_;
+ }
+ Event<platform::native::MouseButton, const ui::Point&>* MouseUpEvent()
+ override {
+ return &mouse_up_event_;
+ }
+ Event<int>* KeyDownEvent() override { return &key_down_event_; }
+ Event<int>* KeyUpEvent() override { return &key_up_event_; }
+
+ Event<WindowNativeMessageEventArgs&>* 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(platform::native::MouseButton button, POINT point);
+ void OnMouseUpInternal(platform::native::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<WindowRenderTarget> window_render_target_;
+
+ Event<> destroy_event_;
+ Event<const ui::Size&> resize_event_;
+ Event<> paint_event_;
+ Event<bool> focus_event_;
+ Event<bool> mouse_enter_leave_event_;
+ Event<const ui::Point&> mouse_move_event_;
+ Event<platform::native::MouseButton, const ui::Point&> mouse_down_event_;
+ Event<platform::native::MouseButton, const ui::Point&> mouse_up_event_;
+ Event<int> key_down_event_;
+ Event<int> key_up_event_;
+
+ Event<WindowNativeMessageEventArgs&> native_message_event_;
+};
+} // namespace cru::win::native