From c0c0106cf47fdff397756913b8646541f3bb9928 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Thu, 11 Dec 2025 23:51:58 +0800 Subject: Add paint invalid area. --- src/ui/controls/ControlHost.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/ui/controls') diff --git a/src/ui/controls/ControlHost.cpp b/src/ui/controls/ControlHost.cpp index f66d3293..290602d4 100644 --- a/src/ui/controls/ControlHost.cpp +++ b/src/ui/controls/ControlHost.cpp @@ -3,6 +3,7 @@ #include "cru/platform/gui/UiApplication.h" #include "cru/platform/gui/Window.h" #include "cru/ui/Base.h" +#include "cru/ui/render/RenderObject.h" #include @@ -102,8 +103,8 @@ ControlHost::CreateNativeWindow() { BindNativeEvent(this, native_window, native_window->DestroyEvent(), &ControlHost::OnNativeDestroy); - BindNativeEvent(this, native_window, native_window->PaintEvent(), - &ControlHost::OnNativePaint); + BindNativeEvent(this, native_window, native_window->Paint1Event(), + &ControlHost::OnNativePaint1); BindNativeEvent(this, native_window, native_window->ResizeEvent(), &ControlHost::OnNativeResize); BindNativeEvent(this, native_window, native_window->FocusEvent(), @@ -134,21 +135,19 @@ void ControlHost::ScheduleRelayout() { [this] { Relayout(); })); } -bool ControlHost::IsLayoutPreferToFillWindow() const { - return layout_prefer_to_fill_window_; -} +Rect ControlHost::GetPaintInvalidArea() { return paint_invalid_area_; } -void ControlHost::SetLayoutPreferToFillWindow(bool value) { - if (value == layout_prefer_to_fill_window_) return; - layout_prefer_to_fill_window_ = value; - ScheduleRelayout(); +void ControlHost::AddPaintInvalidArea(const Rect& area) { + paint_invalid_area_ = paint_invalid_area_.Union(area); } void ControlHost::Repaint() { auto painter = native_window_->BeginPaint(); painter->Clear(colors::white); - root_control_->GetRenderObject()->Draw(painter.get()); + render::RenderObjectDrawContext context{paint_invalid_area_, painter.get()}; + root_control_->GetRenderObject()->Draw(context); painter->EndDraw(); + paint_invalid_area_ = {}; } void ControlHost::Relayout() { @@ -177,6 +176,16 @@ void ControlHost::RelayoutWithSize(const Size& available_size, ScheduleRepaint(); } +bool ControlHost::IsLayoutPreferToFillWindow() const { + return layout_prefer_to_fill_window_; +} + +void ControlHost::SetLayoutPreferToFillWindow(bool value) { + if (value == layout_prefer_to_fill_window_) return; + layout_prefer_to_fill_window_ = value; + ScheduleRelayout(); +} + Control* ControlHost::GetFocusControl() { return focus_control_; } void ControlHost::SetFocusControl(Control* control) { @@ -243,7 +252,11 @@ void ControlHost::OnNativeDestroy(std::nullptr_t) { mouse_captured_control_ = nullptr; } -void ControlHost::OnNativePaint(std::nullptr_t) { Repaint(); } +void ControlHost::OnNativePaint1( + const platform::gui::NativePaintEventArgs& args) { + AddPaintInvalidArea(args.repaint_area); + Repaint(); +} void ControlHost::OnNativeResize([[maybe_unused]] const Size& size) { ScheduleRelayout(); -- cgit v1.2.3