diff options
author | crupest <crupest@outlook.com> | 2019-03-21 21:42:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-21 21:42:28 +0800 |
commit | fdbb02b2cbdd4e4069005d0535a343229f7c4d32 (patch) | |
tree | 3cc25c18b3b019f09d6478b8b9f7b4ddbaed9eb6 /src/ui/render/window_render_object.cpp | |
parent | 616ebd78b543876388cb3d64f108abea041d4983 (diff) | |
download | cru-fdbb02b2cbdd4e4069005d0535a343229f7c4d32.tar.gz cru-fdbb02b2cbdd4e4069005d0535a343229f7c4d32.tar.bz2 cru-fdbb02b2cbdd4e4069005d0535a343229f7c4d32.zip |
...
Diffstat (limited to 'src/ui/render/window_render_object.cpp')
-rw-r--r-- | src/ui/render/window_render_object.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp new file mode 100644 index 00000000..52452bd4 --- /dev/null +++ b/src/ui/render/window_render_object.cpp @@ -0,0 +1,48 @@ +#include "window_render_object.hpp" + +#include <cassert> + +#include "graph/graph.hpp" +#include "ui/window.hpp" + +namespace cru::ui::render { +void WindowRenderObject::MeasureAndLayout() { + const auto client_size = window_->GetClientSize(); + Measure(client_size); + Layout(Rect{Point::Zero(), client_size}); +} + +void WindowRenderObject::Draw(ID2D1RenderTarget* render_target) { + if (const auto child = GetChild()) { + auto offset = child->GetOffset(); + graph::WithTransform(render_target, + D2D1::Matrix3x2F::Translation(offset.x, offset.y), + [child](auto rt) { child->Draw(rt); }); + } +} + +RenderObject* WindowRenderObject::HitTest(const Point& point) { + if (const auto child = GetChild()) { + auto offset = child->GetOffset(); + Point p{point.x - offset.x, point.y - offset.y}; + const auto result = child->HitTest(point); + if (result != nullptr) { + return result; + } + } + return Rect{Point::Zero(), GetSize()}.IsPointInside(point) ? this : nullptr; +} + +void WindowRenderObject::OnAddChild(RenderObject* new_child, int position) { + assert(GetChildren().size() == 1); +} + +Size WindowRenderObject::OnMeasureContent(const Size& available_size) { + if (const auto child = GetChild()) child->Measure(available_size); + return available_size; +} + +void WindowRenderObject::OnLayoutContent(const Rect& content_rect) { + if (const auto child = GetChild()) child->Layout(content_rect); +} +} // namespace cru::ui::render |