diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-25 17:15:16 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-25 17:15:16 +0800 |
| commit | 376d5bfe0f3b9658cbf2d4ca9b00c0600341ee85 (patch) | |
| tree | 9a4326fbc15a164631c950d37551df372888f6b3 /src | |
| parent | eb280d0ed73c7b3a410c94f4eb995b23cccb9e6a (diff) | |
| download | cru-376d5bfe0f3b9658cbf2d4ca9b00c0600341ee85.tar.gz cru-376d5bfe0f3b9658cbf2d4ca9b00c0600341ee85.tar.bz2 cru-376d5bfe0f3b9658cbf2d4ca9b00c0600341ee85.zip | |
Clean code. Clean events of native window.
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/Base.cpp | 2 | ||||
| -rw-r--r-- | src/platform/gui/Window.cpp | 5 | ||||
| -rw-r--r-- | src/platform/gui/win/Window.cpp | 39 | ||||
| -rw-r--r-- | src/ui/render/TextRenderObject.cpp | 2 |
4 files changed, 30 insertions, 18 deletions
diff --git a/src/base/Base.cpp b/src/base/Base.cpp index 7dd6337d..c97c53a5 100644 --- a/src/base/Base.cpp +++ b/src/base/Base.cpp @@ -7,7 +7,7 @@ namespace cru { void UnreachableCode() { std::terminate(); } -void NotImplemented() { std::terminate(); } +void NotImplemented() { throw NotImplementedException(); } Exception::Exception(std::string message, std::shared_ptr<std::exception> inner) : message_(std::move(message)), inner_(std::move(inner)) {} diff --git a/src/platform/gui/Window.cpp b/src/platform/gui/Window.cpp index fdcfbae4..15a49b06 100644 --- a/src/platform/gui/Window.cpp +++ b/src/platform/gui/Window.cpp @@ -3,4 +3,9 @@ namespace cru::platform::gui { bool INativeWindow::IsCreated() { NotImplemented(); } + +IEvent<const NativePaintEventArgs&>* INativeWindow::Paint1Event() { + NotImplemented(); +} + } // namespace cru::platform::gui diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index 2c0bc5a1..fb2ce024 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -312,7 +312,7 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg, LRESULT* result) { WindowNativeMessageEventArgs args{ WindowNativeMessage{hwnd, msg, w_param, l_param}}; - native_message_event_.Raise(args); + NativeMessageEvent_.Raise(args); if (args.IsHandled()) { *result = args.GetResult(); return true; @@ -510,13 +510,13 @@ void WinNativeWindow::RecreateWindow() { void WinNativeWindow::OnCreateInternal() { CRU_LOG_TAG_DEBUG("A native window is created, hwnd {}.", static_cast<void*>(GetWindowHandle())); - create_event_.Raise(nullptr); + CreateEvent_.Raise(nullptr); } void WinNativeWindow::OnDestroyInternal() { CRU_LOG_TAG_DEBUG("A native window is destroying, hwnd {}.", static_cast<void*>(GetWindowHandle())); - destroy_event_.Raise(nullptr); + DestroyEvent_.Raise(nullptr); hwnd_ = nullptr; if (application_->IsQuitOnAllWindowClosed() && @@ -529,8 +529,14 @@ void WinNativeWindow::OnDestroyInternal() { } void WinNativeWindow::OnPaintInternal() { - paint_event_.Raise(nullptr); - ValidateRect(hwnd_, nullptr); + PaintEvent_.Raise(nullptr); + NativePaintEventArgs args; + ::RECT rect; + if (::GetUpdateRect(hwnd_, &rect, FALSE)) { + args.repaint_area = PixelToDip(rect); + } + Paint1Event_.Raise(args); + ::ValidateRect(hwnd_, nullptr); CRU_LOG_TAG_DEBUG("A repaint is finished."); } @@ -545,18 +551,18 @@ void WinNativeWindow::OnResizeInternal(const int new_width, client_rect_.height = PixelToDip(new_height); if (!(new_width == 0 && new_height == 0)) { window_render_target_->ResizeBuffer(new_width, new_height); - resize_event_.Raise(Size{PixelToDip(new_width), PixelToDip(new_height)}); + ResizeEvent_.Raise(Size{PixelToDip(new_width), PixelToDip(new_height)}); } } void WinNativeWindow::OnSetFocusInternal() { has_focus_ = true; - focus_event_.Raise(FocusChangeType::Gain); + FocusEvent_.Raise(FocusChangeType::Gain); } void WinNativeWindow::OnKillFocusInternal() { has_focus_ = false; - focus_event_.Raise(FocusChangeType::Lose); + FocusEvent_.Raise(FocusChangeType::Lose); } void WinNativeWindow::OnMouseMoveInternal(const POINT point) { @@ -571,43 +577,42 @@ void WinNativeWindow::OnMouseMoveInternal(const POINT point) { TrackMouseEvent(&tme); is_mouse_in_ = true; - mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Enter); + MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Enter); } - mouse_move_event_.Raise(PixelToDip(point)); + MouseMoveEvent_.Raise(PixelToDip(point)); } void WinNativeWindow::OnMouseLeaveInternal() { is_mouse_in_ = false; - mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Leave); + MouseEnterLeaveEvent_.Raise(MouseEnterLeaveType::Leave); } void WinNativeWindow::OnMouseDownInternal(platform::gui::MouseButton button, POINT point) { const auto dip_point = PixelToDip(point); - mouse_down_event_.Raise({button, dip_point, RetrieveKeyModifier()}); + MouseDownEvent_.Raise({button, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnMouseUpInternal(platform::gui::MouseButton button, POINT point) { const auto dip_point = PixelToDip(point); - mouse_up_event_.Raise({button, dip_point, RetrieveKeyModifier()}); + MouseUpEvent_.Raise({button, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnMouseWheelInternal(short delta, POINT point) { const auto dip_point = PixelToDip(point); const float d = -((float)delta / 120.f); - mouse_wheel_event_.Raise({d, dip_point, RetrieveKeyModifier()}); + MouseWheelEvent_.Raise({d, dip_point, RetrieveKeyModifier()}); } void WinNativeWindow::OnKeyDownInternal(int virtual_code) { - key_down_event_.Raise( + KeyDownEvent_.Raise( {VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()}); } void WinNativeWindow::OnKeyUpInternal(int virtual_code) { - key_up_event_.Raise( - {VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()}); + KeyUpEvent_.Raise({VirtualKeyToKeyCode(virtual_code), RetrieveKeyModifier()}); } void WinNativeWindow::OnActivatedInternal() {} diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index 44dee1aa..1fe8e652 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -54,12 +54,14 @@ void TextRenderObject::SetFont( std::shared_ptr<platform::graphics::IFont> font) { Expects(font); text_layout_->SetFont(std::move(font)); + InvalidateLayout(); } bool TextRenderObject::IsEditMode() { return text_layout_->IsEditMode(); } void TextRenderObject::SetEditMode(bool enable) { text_layout_->SetEditMode(enable); + InvalidateLayout(); } Index TextRenderObject::GetLineCount() { return text_layout_->GetLineCount(); } |
