aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/control.cpp33
-rw-r--r--src/ui/control.hpp29
2 files changed, 51 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);
}
}
diff --git a/src/ui/control.hpp b/src/ui/control.hpp
index 776eacb0..a1ad7ea7 100644
--- a/src/ui/control.hpp
+++ b/src/ui/control.hpp
@@ -129,6 +129,29 @@ namespace cru::ui
virtual void Repaint();
+ Microsoft::WRL::ComPtr<ID2D1Brush> GetForegroundBrush() const
+ {
+ return foreground_brush_;
+ }
+
+ void SetForegroundBrush(Microsoft::WRL::ComPtr<ID2D1Brush> foreground_brush)
+ {
+ foreground_brush_ = std::move(foreground_brush);
+ Repaint();
+ }
+
+ Microsoft::WRL::ComPtr<ID2D1Brush> GetBackgroundBrush() const
+ {
+ return background_brush_;
+ }
+
+ void SetBackgroundBrush(Microsoft::WRL::ComPtr<ID2D1Brush> background_brush)
+ {
+ background_brush_ = std::move(background_brush);
+ Repaint();
+ }
+
+
//*************** region: focus ***************
bool RequestFocus();
@@ -245,6 +268,8 @@ namespace cru::ui
void OnDrawCore(ID2D1DeviceContext* device_context);
protected:
+
+ //*************** region: graphic events ***************
virtual void OnDrawContent(ID2D1DeviceContext* device_context);
virtual void OnDrawForeground(ID2D1DeviceContext* device_context);
virtual void OnDrawBackground(ID2D1DeviceContext* device_context);
@@ -373,6 +398,10 @@ namespace cru::ui
BorderProperty border_property_;
Microsoft::WRL::ComPtr<ID2D1Geometry> border_geometry_ = nullptr;
+ Microsoft::WRL::ComPtr<ID2D1Geometry> in_border_geometry_ = nullptr; //used for foreground and background brush.
+
+ Microsoft::WRL::ComPtr<ID2D1Brush> foreground_brush_ = nullptr;
+ Microsoft::WRL::ComPtr<ID2D1Brush> background_brush_ = nullptr;
AnyMap additional_property_map_{};