diff options
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r-- | src/ui/control.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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()); |