1.10
shapes.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SHAPES_H
7#define EGT_SHAPES_H
8
14#include <egt/detail/meta.h>
15#include <egt/frame.h>
16#include <egt/serialize.h>
17#include <egt/widget.h>
18#include <memory>
19
20namespace egt
21{
22inline namespace v1
23{
24
35class EGT_API CircleWidget : public Widget
36{
37public:
38
42 explicit CircleWidget(const Circle& circle = Circle());
43
48 explicit CircleWidget(Frame& parent, const Circle& circle = Circle());
49
54 : CircleWidget(props, false)
55 {
56 }
57
58protected:
59
60 explicit CircleWidget(Serializer::Properties& props, bool is_derived);
61
62public:
63
67 EGT_NODISCARD Circle::DimType radius() const
68 {
69 return m_radius;
70 }
71
72 void draw(Painter& painter, const Rect&) override;
73
77 void serialize(Serializer& serializer) const override;
78
79 void resize(const Size& size) override;
80
81protected:
82
84 Circle::DimType m_radius{};
85
86private:
90 void deserialize(Serializer::Properties& props);
91};
92
98class EGT_API LineWidget : public Widget
99{
100public:
101
105 explicit LineWidget(const Rect& rect = {})
106 : Widget(rect)
107 {
108 name("LineWidget" + std::to_string(m_widgetid));
109 fill_flags().clear();
110 }
111
116 explicit LineWidget(Frame& parent, const Rect& rect = {})
117 : LineWidget(rect)
118 {
119 parent.add(*this);
120 }
121
126 : LineWidget(props, false)
127 {
128 }
129
130protected:
131
132 explicit LineWidget(Serializer::Properties& props, bool is_derived);
133
134public:
135
136 void draw(Painter& painter, const Rect&) override;
137
141 EGT_NODISCARD bool horizontal() const { return m_horizontal; }
142
146 void horizontal(bool horizontal)
147 {
148 if (detail::change_if_diff<>(m_horizontal, horizontal))
149 damage();
150 }
151
155 void serialize(Serializer& serializer) const override;
156
157protected:
159 bool m_horizontal{true};
160
161private:
165 void deserialize(Serializer::Properties& props);
166};
167
173class EGT_API RectangleWidget : public Widget
174{
175public:
176
180 explicit RectangleWidget(const Rect& rect = {})
181 : Widget(rect)
182 {
183 name("RectangleWidget" + std::to_string(m_widgetid));
184 fill_flags(Theme::FillFlag::blend);
185 }
186
191 explicit RectangleWidget(Frame& parent, const Rect& rect = {})
192 : RectangleWidget(rect)
193 {
194 parent.add(*this);
195 }
196
201 : RectangleWidget(props, false)
202 {
203 }
204
205protected:
206
207 explicit RectangleWidget(Serializer::Properties& props, bool is_derived)
208 : Widget(props, true)
209 {
210 if (!is_derived)
211 deserialize_leaf(props);
212 }
213
214public:
215
216 void draw(Painter& painter, const Rect& rect) override;
217};
218
219}
220}
221
222#endif
A basic circle with a center point and radius.
Definition geometry.h:1204
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1210
Basic Circle Widget.
Definition shapes.h:36
void draw(Painter &painter, const Rect &) override
Draw the widget.
void resize(const Size &size) override
Resize the widget.
void serialize(Serializer &serializer) const override
Serialize the widget to the specified serializer.
CircleWidget(Frame &parent, const Circle &circle=Circle())
CircleWidget(const Circle &circle=Circle())
CircleWidget(Serializer::Properties &props, bool is_derived)
CircleWidget(Serializer::Properties &props)
Definition shapes.h:53
EGT_NODISCARD Circle::DimType radius() const
Get the radius of the widget.
Definition shapes.h:67
A Frame is a Widget that has children widgets.
Definition frame.h:45
virtual void add(const std::shared_ptr< Widget > &widget)
Add a child widget.
Basic Line Widget.
Definition shapes.h:99
LineWidget(Frame &parent, const Rect &rect={})
Definition shapes.h:116
void horizontal(bool horizontal)
Set the horizontal state of the widget.
Definition shapes.h:146
void draw(Painter &painter, const Rect &) override
Draw the widget.
EGT_NODISCARD bool horizontal() const
Get the horizontal state of the widget.
Definition shapes.h:141
LineWidget(Serializer::Properties &props, bool is_derived)
LineWidget(Serializer::Properties &props)
Definition shapes.h:125
void serialize(Serializer &serializer) const override
Serialize the widget to the specified serializer.
LineWidget(const Rect &rect={})
Definition shapes.h:105
Drawing interface for 2D graphics.
Definition painter.h:45
Basic Rectangle Widget.
Definition shapes.h:174
RectangleWidget(Serializer::Properties &props)
Definition shapes.h:200
void draw(Painter &painter, const Rect &rect) override
Draw the widget.
RectangleWidget(const Rect &rect={})
Definition shapes.h:180
RectangleWidget(Serializer::Properties &props, bool is_derived)
Definition shapes.h:207
RectangleWidget(Frame &parent, const Rect &rect={})
Definition shapes.h:191
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Base Widget class.
Definition widget.h:53
EGT framework namespace.
Definition animation.h:24