aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/border_delegate.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
committerYuqian Yang <crupest@outlook.com>2018-10-01 17:11:11 +0000
commit30ecda8bb354d5982978af97aa90b5f49d9ea195 (patch)
treea271bddb244fa2041f14f8d46d249457cee09e5f /src/ui/controls/border_delegate.cpp
parent398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff)
parent040a6c18f18100b825a56443a73aa1de64e4518c (diff)
downloadcru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.gz
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.bz2
cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.zip
Merge branch '9-border' into 'master'
Resolve "Abstract out border control of button and border." Closes #9 See merge request crupest/CruUI!11
Diffstat (limited to 'src/ui/controls/border_delegate.cpp')
-rw-r--r--src/ui/controls/border_delegate.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/ui/controls/border_delegate.cpp b/src/ui/controls/border_delegate.cpp
new file mode 100644
index 00000000..c8855e0f
--- /dev/null
+++ b/src/ui/controls/border_delegate.cpp
@@ -0,0 +1,97 @@
+#include "border_delegate.h"
+#include "graph/graph.h"
+
+namespace cru::ui::controls
+{
+ BorderProperty::Ptr BorderProperty::Create()
+ {
+ return std::make_shared<BorderProperty>(graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)));
+ }
+
+ BorderProperty::BorderProperty(Microsoft::WRL::ComPtr<ID2D1Brush> brush)
+ : brush_(std::move(brush))
+ {
+
+ }
+
+ void BorderProperty::SetBrush(Microsoft::WRL::ComPtr<ID2D1Brush> brush)
+ {
+ brush_ = std::move(brush);
+ RaisePropertyChangedEvent(brush_property_name);
+ }
+
+ void BorderProperty::SetWidth(const float width)
+ {
+ width_ = width;
+ RaisePropertyChangedEvent(width_property_name);
+ }
+
+ void BorderProperty::SetStrokeStyle(Microsoft::WRL::ComPtr<ID2D1StrokeStyle> stroke_style)
+ {
+ stroke_style_ = std::move(stroke_style);
+ RaisePropertyChangedEvent(stroke_style_property_name);
+ }
+
+ void BorderProperty::SetRadiusX(const float radius_x)
+ {
+ radius_x_ = radius_x;
+ RaisePropertyChangedEvent(radius_x_property_name);
+ }
+
+ void BorderProperty::SetRadiusY(const float radius_y)
+ {
+ radius_y_ = radius_y;
+ RaisePropertyChangedEvent(radius_y_property_name);
+ }
+
+ BorderDelegate::BorderDelegate(Control* control)
+ : BorderDelegate(control, BorderProperty::Create())
+ {
+
+ }
+
+ BorderDelegate::BorderDelegate(Control* control, std::shared_ptr<BorderProperty> border_property)\
+ : control_(control),
+ border_property_changed_listener_(CreateFunctionPtr<void(String)>([this](String property_name)
+ {
+ if (property_name == BorderProperty::width_property_name)
+ control_->InvalidateLayout();
+ control_->Repaint();
+ }))
+ {
+ border_property_ = std::move(border_property);
+ border_property_->AddPropertyChangedListener(border_property_changed_listener_);
+ }
+
+ BorderDelegate::~BorderDelegate()
+ {
+ border_property_->RemovePropertyChangedListener(border_property_changed_listener_);
+ }
+
+ void BorderDelegate::SetBorderProperty(std::shared_ptr<BorderProperty> border_property)
+ {
+ border_property_->RemovePropertyChangedListener(border_property_changed_listener_);
+ border_property_ = std::move(border_property);
+ border_property_->AddPropertyChangedListener(border_property_changed_listener_);
+ control_->Repaint();
+ }
+
+ void BorderDelegate::Draw(ID2D1DeviceContext* device_context, const Size& size) const
+ {
+ device_context->DrawRoundedRectangle(
+ D2D1::RoundedRect(
+ D2D1::RectF(
+ border_property_->GetWidth() / 2.0f,
+ border_property_->GetWidth() / 2.0f,
+ size.width - border_property_->GetWidth(),
+ size.height - border_property_->GetWidth()
+ ),
+ border_property_->GetRadiusX(),
+ border_property_->GetRadiusY()
+ ),
+ border_property_->GetBrush().Get(),
+ border_property_->GetWidth(),
+ border_property_->GetStrokeStyle().Get()
+ );
+ }
+}