From eab8d69ccac6f7b306561a49e9c1f8fda21376d2 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 27 Sep 2018 22:53:54 +0800 Subject: Create Border. Make text control relayout when text changed. --- src/ui/controls/border.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/ui/controls/border.cpp (limited to 'src/ui/controls/border.cpp') diff --git a/src/ui/controls/border.cpp b/src/ui/controls/border.cpp new file mode 100644 index 00000000..f79d610f --- /dev/null +++ b/src/ui/controls/border.cpp @@ -0,0 +1,58 @@ +#include "border.h" + +#include "graph/graph.h" + +namespace cru::ui::controls +{ + using graph::CreateSolidBrush; + + Border::Border() : Control(true) + { + border_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)); + } + + void Border::SetDrawBorder(bool draw_border) + { + draw_border_ = draw_border; + Repaint(); + } + + void Border::SetBorderBrush(Microsoft::WRL::ComPtr border_brush) + { + border_brush_ = std::move(border_brush); + Repaint(); + } + + void Border::SetBorderWidth(const float border_width) + { + border_width_ = border_width; + Repaint(); + } + + void Border::SetBorderStrokeStyle(Microsoft::WRL::ComPtr stroke_style) + { + border_stroke_style_ = std::move(stroke_style); + Repaint(); + } + + void Border::SetBorderRadiusX(const float border_radius_x) + { + border_radius_x_ = border_radius_x; + Repaint(); + } + + void Border::SetBorderRadiusY(const float border_radius_y) + { + border_radius_y_ = border_radius_y; + Repaint(); + } + + void Border::OnDraw(ID2D1DeviceContext* device_context) + { + if (draw_border_) + { + const auto size = GetSize(); + device_context->DrawRoundedRectangle(D2D1::RoundedRect(D2D1::RectF(0.0f, 0.0f, size.width, size.height), border_radius_x_, border_radius_y_), border_brush_.Get(), border_width_, border_stroke_style_.Get()); + } + } +} -- cgit v1.2.3