diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-12-11 23:51:58 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-12-11 23:51:58 +0800 |
| commit | c0c0106cf47fdff397756913b8646541f3bb9928 (patch) | |
| tree | 945d0a3662ac92577c966f49578e46ba743ea84b /src/ui/controls/ControlHost.cpp | |
| parent | e833e810aaa324d7de1630c2fb0528564b182742 (diff) | |
| download | cru-c0c0106cf47fdff397756913b8646541f3bb9928.tar.gz cru-c0c0106cf47fdff397756913b8646541f3bb9928.tar.bz2 cru-c0c0106cf47fdff397756913b8646541f3bb9928.zip | |
Add paint invalid area.
Diffstat (limited to 'src/ui/controls/ControlHost.cpp')
| -rw-r--r-- | src/ui/controls/ControlHost.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
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 <cassert> @@ -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(); |
