aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-25 20:55:03 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-25 20:55:03 +0800
commit4fab87bfbfed44811d29b9cb4cccb51d0873a72d (patch)
tree037b499f5b5eb2621bb2734c985ccd4121fca0b3
parente14dffeec42cea66780f3dcc7902d76a4a4b8ca7 (diff)
downloadcru-4fab87bfbfed44811d29b9cb4cccb51d0873a72d.tar.gz
cru-4fab87bfbfed44811d29b9cb4cccb51d0873a72d.tar.bz2
cru-4fab87bfbfed44811d29b9cb4cccb51d0873a72d.zip
Clean native window events on osx.
-rw-r--r--include/cru/platform/gui/osx/Window.h18
-rw-r--r--src/platform/gui/osx/Window.mm62
-rw-r--r--src/platform/gui/osx/WindowPrivate.h14
3 files changed, 24 insertions, 70 deletions
diff --git a/include/cru/platform/gui/osx/Window.h b/include/cru/platform/gui/osx/Window.h
index e36f4238..25f85dbb 100644
--- a/include/cru/platform/gui/osx/Window.h
+++ b/include/cru/platform/gui/osx/Window.h
@@ -61,24 +61,10 @@ class OsxWindow : public OsxGuiResource, public INativeWindow {
std::unique_ptr<graphics::IPainter> BeginPaint() override;
- IEvent<std::nullptr_t>* CreateEvent() override;
- IEvent<std::nullptr_t>* DestroyEvent() override;
- IEvent<std::nullptr_t>* PaintEvent() override;
-
- IEvent<WindowVisibilityType>* VisibilityChangeEvent() override;
- IEvent<const Size&>* ResizeEvent() override;
- IEvent<FocusChangeType>* FocusEvent() override;
-
- IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override;
- IEvent<const Point&>* MouseMoveEvent() override;
- IEvent<const NativeMouseButtonEventArgs&>* MouseDownEvent() override;
- IEvent<const NativeMouseButtonEventArgs&>* MouseUpEvent() override;
- IEvent<const NativeMouseWheelEventArgs&>* MouseWheelEvent() override;
- IEvent<const NativeKeyEventArgs&>* KeyDownEvent() override;
- IEvent<const NativeKeyEventArgs&>* KeyUpEvent() override;
-
IInputMethodContext* GetInputMethodContext() override;
+ CRU_DEFINE_CRU_PLATFORM_GUI_I_NATIVE_WINDOW_OVERRIDE_EVENTS()
+
private:
std::unique_ptr<details::OsxWindowPrivate> p_;
};
diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm
index afdde270..9dd4177f 100644
--- a/src/platform/gui/osx/Window.mm
+++ b/src/platform/gui/osx/Window.mm
@@ -49,7 +49,7 @@ OsxWindowPrivate::OsxWindowPrivate(OsxWindow* osx_window) : osx_window_(osx_wind
OsxWindowPrivate::~OsxWindowPrivate() {}
void OsxWindowPrivate::OnWindowWillClose() {
- if (window_) destroy_event_.Raise(nullptr);
+ if (window_) osx_window_->DestroyEvent_.Raise(nullptr);
window_ = nil;
CGLayerRelease(draw_layer_);
draw_layer_ = nullptr;
@@ -92,17 +92,21 @@ void OsxWindowPrivate::OnWindowDidResize() {
CGLayerRelease(draw_layer_);
draw_layer_ = CreateLayer(Convert(content_rect_.GetSize()));
- resize_event_.Raise(osx_window_->GetClientSize());
+ osx_window_->ResizeEvent_.Raise(osx_window_->GetClientSize());
osx_window_->RequestRepaint();
}
-void OsxWindowPrivate::OnBecomeKeyWindow() { focus_event_.Raise(FocusChangeType::Gain); }
+void OsxWindowPrivate::OnBecomeKeyWindow() {
+ osx_window_->FocusEvent_.Raise(FocusChangeType::Gain);
+}
-void OsxWindowPrivate::OnResignKeyWindow() { focus_event_.Raise(FocusChangeType::Lose); }
+void OsxWindowPrivate::OnResignKeyWindow() {
+ osx_window_->FocusEvent_.Raise(FocusChangeType::Lose);
+}
void OsxWindowPrivate::OnMouseEnterLeave(MouseEnterLeaveType type) {
- mouse_enter_leave_event_.Raise(type);
+ osx_window_->MouseEnterLeaveEvent_.Raise(type);
if (type == MouseEnterLeaveType::Enter) {
mouse_in_ = true;
UpdateCursor();
@@ -111,27 +115,29 @@ void OsxWindowPrivate::OnMouseEnterLeave(MouseEnterLeaveType type) {
}
}
-void OsxWindowPrivate::OnMouseMove(Point p) { mouse_move_event_.Raise(TransformMousePoint(p)); }
+void OsxWindowPrivate::OnMouseMove(Point p) {
+ osx_window_->MouseMoveEvent_.Raise(TransformMousePoint(p));
+}
void OsxWindowPrivate::OnMouseDown(MouseButton button, Point p, KeyModifier key_modifier) {
- mouse_down_event_.Raise({button, TransformMousePoint(p), key_modifier});
+ osx_window_->MouseDownEvent_.Raise({button, TransformMousePoint(p), key_modifier});
}
void OsxWindowPrivate::OnMouseUp(MouseButton button, Point p, KeyModifier key_modifier) {
- mouse_up_event_.Raise({button, TransformMousePoint(p), key_modifier});
+ osx_window_->MouseUpEvent_.Raise({button, TransformMousePoint(p), key_modifier});
}
void OsxWindowPrivate::OnMouseWheel(float delta, Point p, KeyModifier key_modifier,
bool horizontal) {
- mouse_wheel_event_.Raise({delta, TransformMousePoint(p), key_modifier, horizontal});
+ osx_window_->MouseWheelEvent_.Raise({delta, TransformMousePoint(p), key_modifier, horizontal});
}
void OsxWindowPrivate::OnKeyDown(KeyCode key, KeyModifier key_modifier) {
- key_down_event_.Raise({key, key_modifier});
+ osx_window_->KeyDownEvent_.Raise({key, key_modifier});
}
void OsxWindowPrivate::OnKeyUp(KeyCode key, KeyModifier key_modifier) {
- key_up_event_.Raise({key, key_modifier});
+ osx_window_->KeyUpEvent_.Raise({key, key_modifier});
}
CGLayerRef OsxWindowPrivate::CreateLayer(const CGSize& size) {
@@ -188,7 +194,7 @@ void OsxWindowPrivate::CreateWindow() {
draw_layer_ = CreateLayer(Convert(content_rect_.GetSize()));
- create_event_.Raise(nullptr);
+ osx_window_->CreateEvent_.Raise(nullptr);
osx_window_->RequestRepaint();
}
@@ -266,10 +272,10 @@ void OsxWindow::SetVisibility(WindowVisibilityType visibility) {
if (p_->window_) {
if (visibility == WindowVisibilityType::Show) {
[p_->window_ orderFront:nil];
- p_->visibility_change_event_.Raise(WindowVisibilityType::Show);
+ VisibilityChangeEvent_.Raise(WindowVisibilityType::Show);
} else if (visibility == WindowVisibilityType::Hide) {
[p_->window_ orderOut:nil];
- p_->visibility_change_event_.Raise(WindowVisibilityType::Hide);
+ VisibilityChangeEvent_.Raise(WindowVisibilityType::Hide);
} else if (visibility == WindowVisibilityType::Minimize) {
[p_->window_ miniaturize:nil];
}
@@ -277,7 +283,7 @@ void OsxWindow::SetVisibility(WindowVisibilityType visibility) {
if (visibility == WindowVisibilityType::Show) {
p_->CreateWindow();
[p_->window_ orderFront:nil];
- p_->visibility_change_event_.Raise(WindowVisibilityType::Show);
+ VisibilityChangeEvent_.Raise(WindowVisibilityType::Show);
}
}
}
@@ -326,7 +332,7 @@ void OsxWindow::SetWindowRect(const Rect& rect) {
void OsxWindow::RequestRepaint() {
if (!p_->draw_timer_) {
p_->draw_timer_.Reset(GetUiApplication()->SetImmediate([this] {
- p_->paint_event_.Raise(nullptr);
+ PaintEvent_.Raise(nullptr);
p_->draw_timer_.Release();
}));
}
@@ -372,30 +378,6 @@ void OsxWindow::SetToForeground() {
[p_->window_ orderFrontRegardless];
}
-IEvent<std::nullptr_t>* OsxWindow::CreateEvent() { return &p_->create_event_; }
-IEvent<std::nullptr_t>* OsxWindow::DestroyEvent() { return &p_->destroy_event_; }
-IEvent<std::nullptr_t>* OsxWindow::PaintEvent() { return &p_->paint_event_; }
-IEvent<WindowVisibilityType>* OsxWindow::VisibilityChangeEvent() {
- return &p_->visibility_change_event_;
-}
-IEvent<const Size&>* OsxWindow::ResizeEvent() { return &p_->resize_event_; }
-IEvent<FocusChangeType>* OsxWindow::FocusEvent() { return &p_->focus_event_; }
-IEvent<MouseEnterLeaveType>* OsxWindow::MouseEnterLeaveEvent() {
- return &p_->mouse_enter_leave_event_;
-}
-IEvent<const Point&>* OsxWindow::MouseMoveEvent() { return &p_->mouse_move_event_; }
-IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseDownEvent() {
- return &p_->mouse_down_event_;
-}
-IEvent<const NativeMouseButtonEventArgs&>* OsxWindow::MouseUpEvent() {
- return &p_->mouse_up_event_;
-}
-IEvent<const NativeMouseWheelEventArgs&>* OsxWindow::MouseWheelEvent() {
- return &p_->mouse_wheel_event_;
-}
-IEvent<const NativeKeyEventArgs&>* OsxWindow::KeyDownEvent() { return &p_->key_down_event_; }
-IEvent<const NativeKeyEventArgs&>* OsxWindow::KeyUpEvent() { return &p_->key_up_event_; }
-
IInputMethodContext* OsxWindow::GetInputMethodContext() { return p_->input_method_context_.get(); }
} // namespace cru::platform::gui::osx
diff --git a/src/platform/gui/osx/WindowPrivate.h b/src/platform/gui/osx/WindowPrivate.h
index c16a2b02..be27e1bc 100644
--- a/src/platform/gui/osx/WindowPrivate.h
+++ b/src/platform/gui/osx/WindowPrivate.h
@@ -98,20 +98,6 @@ class OsxWindowPrivate {
std::unique_ptr<OsxInputMethodContext> input_method_context_;
TimerAutoCanceler draw_timer_;
-
- Event<std::nullptr_t> create_event_;
- Event<std::nullptr_t> destroy_event_;
- Event<std::nullptr_t> paint_event_;
- Event<WindowVisibilityType> visibility_change_event_;
- Event<const Size&> resize_event_;
- Event<FocusChangeType> focus_event_;
- Event<MouseEnterLeaveType> mouse_enter_leave_event_;
- Event<const Point&> mouse_move_event_;
- Event<const NativeMouseButtonEventArgs&> mouse_down_event_;
- Event<const NativeMouseButtonEventArgs&> mouse_up_event_;
- Event<const NativeMouseWheelEventArgs&> mouse_wheel_event_;
- Event<const NativeKeyEventArgs&> key_down_event_;
- Event<const NativeKeyEventArgs&> key_up_event_;
};
} // namespace details
} // namespace cru::platform::gui::osx