From e8589550140d20b675fa7736441d7cdd1daee4d7 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 20 Nov 2018 21:02:49 +0800 Subject: Add clip to padding. --- src/ui/control.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/ui/control.cpp') diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 8b91b25a..9afa5497 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -211,6 +211,15 @@ namespace cru::ui return false; } + void Control::SetClipToPadding(const bool clip) + { + if (clip_to_padding_ == clip) + return; + + clip_to_padding_ = clip; + InvalidateDraw(); + } + void Control::Draw(ID2D1DeviceContext* device_context) { D2D1::Matrix3x2F old_transform; @@ -219,11 +228,20 @@ namespace cru::ui const auto position = GetPositionRelative(); device_context->SetTransform(old_transform * D2D1::Matrix3x2F::Translation(position.x, position.y)); + OnDrawDecoration(device_context); + + const auto set_layer = in_border_geometry_ != nullptr && IsClipToPadding(); + if (set_layer) + device_context->PushLayer(D2D1::LayerParameters(D2D1::InfiniteRect(), in_border_geometry_.Get()), nullptr); + OnDrawCore(device_context); for (auto child : GetChildren()) child->Draw(device_context); + if (set_layer) + device_context->PopLayer(); + device_context->SetTransform(old_transform); } @@ -394,9 +412,9 @@ namespace cru::ui window_ = nullptr; } - void Control::OnDrawCore(ID2D1DeviceContext* device_context) + void Control::OnDrawDecoration(ID2D1DeviceContext* device_context) { - #ifdef CRU_DEBUG_LAYOUT +#ifdef CRU_DEBUG_LAYOUT if (GetWindow()->IsDebugLayout()) { if (padding_geometry_ != nullptr) @@ -414,7 +432,10 @@ namespace cru::ui GetBorderProperty().GetStrokeWidth(), GetBorderProperty().GetStrokeStyle().Get() ); + } + void Control::OnDrawCore(ID2D1DeviceContext* device_context) + { //draw background. if (in_border_geometry_ != nullptr && background_brush_ != nullptr) device_context->FillGeometry(in_border_geometry_.Get(), background_brush_.Get()); -- cgit v1.2.3