diff options
author | crupest <crupest@outlook.com> | 2018-11-20 21:02:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-20 21:03:07 +0800 |
commit | e8589550140d20b675fa7736441d7cdd1daee4d7 (patch) | |
tree | 50b61f34dd63e235a6c89b84511f3910b566af00 /src/ui/control.cpp | |
parent | 30333294fcd5917a9f3572f0c4c6dfc2ec429a3c (diff) | |
download | cru-e8589550140d20b675fa7736441d7cdd1daee4d7.tar.gz cru-e8589550140d20b675fa7736441d7cdd1daee4d7.tar.bz2 cru-e8589550140d20b675fa7736441d7cdd1daee4d7.zip |
Add clip to padding.
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()); |