aboutsummaryrefslogtreecommitdiff
path: root/src/ui/control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-14 21:07:59 +0800
committercrupest <crupest@outlook.com>2018-11-14 21:07:59 +0800
commit714a757ee435b83156ddee6b16edc99408357170 (patch)
tree637aaae9536229ef903c403e35418652732889a1 /src/ui/control.cpp
parent77f9d6d47660b642c991809387e4e5c114760f84 (diff)
downloadcru-714a757ee435b83156ddee6b16edc99408357170.tar.gz
cru-714a757ee435b83156ddee6b16edc99408357170.tar.bz2
cru-714a757ee435b83156ddee6b16edc99408357170.zip
Add fore/bakcground brush.
Diffstat (limited to 'src/ui/control.cpp')
-rw-r--r--src/ui/control.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 42e5f71f..0595bf5d 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -407,22 +407,17 @@ namespace cru::ui
}
#endif
- if (is_bordered_)
- {
- const auto border_rect = GetRect(RectRange::HalfBorder);
- device_context->DrawRoundedRectangle(
- D2D1::RoundedRect(
- Convert(border_rect),
- GetBorderProperty().GetRadiusX(),
- GetBorderProperty().GetRadiusY()
- ),
+ if (is_bordered_ && border_geometry_ != nullptr)
+ device_context->DrawGeometry(
+ border_geometry_.Get(),
GetBorderProperty().GetBrush().Get(),
GetBorderProperty().GetStrokeWidth(),
GetBorderProperty().GetStrokeStyle().Get()
);
- }
//draw background.
+ if (in_border_geometry_ != nullptr && background_brush_ != nullptr)
+ device_context->FillGeometry(in_border_geometry_.Get(), background_brush_.Get());
const auto padding_rect = GetRect(RectRange::Padding);
graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(padding_rect.left, padding_rect.top),
[this](ID2D1DeviceContext* device_context)
@@ -442,6 +437,10 @@ namespace cru::ui
draw_content_event.Raise(args);
});
+
+ //draw foreground.
+ if (in_border_geometry_ != nullptr && foreground_brush_ != nullptr)
+ device_context->FillGeometry(in_border_geometry_.Get(), foreground_brush_.Get());
graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(padding_rect.left, padding_rect.top),
[this](ID2D1DeviceContext* device_context)
{
@@ -538,6 +537,17 @@ namespace cru::ui
graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(bound_rounded_rect, &geometry)
);
border_geometry_ = std::move(geometry);
+
+ const auto in_border_rect = GetRect(RectRange::Padding);
+ const auto in_border_rounded_rect = D2D1::RoundedRect(Convert(in_border_rect),
+ GetBorderProperty().GetRadiusX() - GetBorderProperty().GetStrokeWidth() / 2.0f,
+ GetBorderProperty().GetRadiusY() - GetBorderProperty().GetStrokeWidth() / 2.0f);
+
+ Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> geometry2;
+ ThrowIfFailed(
+ graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(in_border_rounded_rect, &geometry2)
+ );
+ in_border_geometry_ = std::move(geometry2);
}
else
{
@@ -546,7 +556,8 @@ namespace cru::ui
ThrowIfFailed(
graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRectangleGeometry(Convert(bound_rect), &geometry)
);
- border_geometry_ = std::move(geometry);
+ border_geometry_ = geometry;
+ in_border_geometry_ = std::move(geometry);
}
}