blob: 6c33473ab2dd520f61a3fc80e9d2e101c4a9ff73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#pragma once
#include "RenderObject.hpp"
namespace cru::ui::render {
class BorderRenderObject : public RenderObject {
public:
BorderRenderObject();
BorderRenderObject(const BorderRenderObject& other) = delete;
BorderRenderObject(BorderRenderObject&& other) = delete;
BorderRenderObject& operator=(const BorderRenderObject& other) = delete;
BorderRenderObject& operator=(BorderRenderObject&& other) = delete;
~BorderRenderObject() override;
bool IsBorderEnabled() const { return is_border_enabled_; }
void SetBorderEnabled(bool enabled) { is_border_enabled_ = enabled; }
std::shared_ptr<platform::graph::IBrush> GetBorderBrush() {
return border_brush_;
}
void SetBorderBrush(std::shared_ptr<platform::graph::IBrush> brush) {
if (brush == border_brush_) return;
border_brush_ = std::move(brush);
InvalidatePaint();
}
Thickness GetBorderThickness() { return border_thickness_; }
void SetBorderThickness(const Thickness thickness) {
if (thickness == border_thickness_) return;
border_thickness_ = thickness;
InvalidateLayout();
}
CornerRadius GetBorderRadius() { return border_radius_; }
void SetBorderRadius(const CornerRadius radius) {
if (radius == border_radius_) return;
border_radius_ = radius;
RecreateGeometry();
}
std::shared_ptr<platform::graph::IBrush> GetForegroundBrush() {
return foreground_brush_;
}
void SetForegroundBrush(std::shared_ptr<platform::graph::IBrush> brush) {
if (brush == foreground_brush_) return;
foreground_brush_ = std::move(brush);
InvalidatePaint();
}
std::shared_ptr<platform::graph::IBrush> GetBackgroundBrush() {
return background_brush_;
}
void SetBackgroundBrush(std::shared_ptr<platform::graph::IBrush> brush) {
if (brush == background_brush_) return;
background_brush_ = std::move(brush);
InvalidatePaint();
}
void SetBorderStyle(const BorderStyle& style);
void Draw(platform::graph::IPainter* painter) override;
RenderObject* HitTest(const Point& point) override;
protected:
Size OnMeasureCore(const MeasureRequirement& requirement,
const MeasureSize& preferred_size) override;
void OnLayoutCore() override;
Size OnMeasureContent(const MeasureRequirement& requirement,
const MeasureSize& preferred_size) override;
void OnLayoutContent(const Rect& content_rect) override;
void OnAfterLayout() override;
Rect GetPaddingRect() const override;
Rect GetContentRect() const override;
private:
void RecreateGeometry();
private:
bool is_border_enabled_ = false;
std::shared_ptr<platform::graph::IBrush> border_brush_;
Thickness border_thickness_;
CornerRadius border_radius_;
std::shared_ptr<platform::graph::IBrush> foreground_brush_;
std::shared_ptr<platform::graph::IBrush> background_brush_;
// The ring. Used for painting.
std::unique_ptr<platform::graph::IGeometry> geometry_;
// Area including inner area of the border. Used for painting foreground and
// background.
std::unique_ptr<platform::graph::IGeometry> border_inner_geometry_;
// Area including border ring and inner area. Used for hit test.
std::unique_ptr<platform::graph::IGeometry> border_outer_geometry_;
};
} // namespace cru::ui::render
|