15#include <egt/detail/math.h>
16#include <egt/detail/meta.h>
19#include <egt/widget.h>
65 resize(m_image.size());
71 if (detail::change_if_diff<>(m_mask_color, color))
89 if (!m_gauge || !gauge)
91 if (detail::change_if_diff<>(m_gauge, gauge))
127 using GaugeLayer::GaugeLayer;
140 float angle_start = 0,
141 float angle_stop = 360,
142 bool clockwise =
true) noexcept;
149 EGT_NODISCARD
float angle_start()
const {
return m_angle_start; }
158 float orig = m_angle_start;
159 if (detail::change_if_diff<float>(m_angle_start, angle_start))
167 EGT_NODISCARD
float angle_stop()
const {
return m_angle_stop; }
176 float orig = m_angle_stop;
177 if (detail::change_if_diff<float>(m_angle_stop, angle_stop))
183 EGT_NODISCARD
float min()
const {
return m_min; }
193 if (detail::change_if_diff<float>(m_min, min))
203 EGT_NODISCARD
float max()
const {
return m_max; }
213 if (detail::change_if_diff<float>(m_max, max))
223 EGT_NODISCARD
float value()
const {
return m_value; }
236 value = std::round(detail::clamp<float>(value, m_min, m_max));
238 if (!detail::float_equal(m_value, value))
240 damage(rectangle_of_rotated());
242 on_value_changed.
invoke();
243 damage(rectangle_of_rotated());
265 if (detail::change_if_diff<PointF>(m_point, point))
267 auto dim = std::max(m_image.width(), m_image.height());
268 auto circle =
Circle(
Point(m_point.x(), m_point.y()), dim);
269 auto superrect = circle.rect();
272 resize(superrect.size());
273 move_to_center(superrect.center());
291 if (detail::change_if_diff<PointF>(m_center,
center))
298 EGT_NODISCARD
bool clockwise()
const {
return m_clockwise; }
307 if (detail::change_if_diff<>(m_clockwise, value))
316 void gauge(
Gauge* gauge)
override;
328 float m_angle_start{0.0};
331 float m_angle_stop{360.0};
334 bool m_clockwise{
true};
391 const Flags& flags = {})
noexcept;
399 const Flags& flags = {})
noexcept;
411 void add(
const std::shared_ptr<GaugeLayer>& layer);
421 auto w = std::shared_ptr<GaugeLayer>(&layer, [](
GaugeLayer*) {});
437 EGT_NODISCARD
Size super_size()
const
439 Rect result = content_area().
size();
440 for (
const auto& layer : m_layers)
441 result = Rect::merge(result, layer->box() +
Size(moat() * 2, moat() * 2));
442 return result.
size();
A basic circle with a center point and radius.
Definition geometry.h:1204
32 bit RGBA color.
Definition color.h:41
Utility class for managing a set of flags with the ability to observe changes to the flags.
Definition flags.h:40
A Frame is a Widget that has children widgets.
Definition frame.h:45
Raster image resource used for drawing or displaying.
Definition image.h:39
Drawing interface for 2D graphics.
Definition painter.h:45
EGT_NODISCARD constexpr const SizeType< Dim, DimCompat > & size() const noexcept
Get the SizeType of the rectangle.
Definition geometry.h:738
Signal class used for defining a signal and dispatching events.
Definition signal.h:30
void invoke(Args... args)
Invoke all handlers with the specified args.
Definition signal.h:85
A layer of a Gauge.
Definition gauge.h:35
void mask_color(const Color &color)
Definition gauge.h:69
GaugeLayer(Gauge &gauge, const Image &image={}) noexcept
Construct a gauge layer with an image and a parent gauge.
GaugeLayer(const Image &image={}) noexcept
Construct a gauge layer with an image.
void draw(Painter &painter, const Rect &rect) override
Draw the widget.
void image(const Image &image)
Set the image of the gauge layer.
Definition gauge.h:62
virtual void gauge(Gauge *gauge)
Normally this does not need to be called directly.
Definition gauge.h:87
Color m_mask_color
Optional mask color.
Definition gauge.h:103
EGT_NODISCARD Gauge * gauge() const
Get the gauge of the layer.
Definition gauge.h:78
Image m_image
The Layer image.
Definition gauge.h:97
A Gauge Widget that is composed of GaugeLayer layers.
Definition gauge.h:383
std::vector< std::shared_ptr< GaugeLayer > > LayerArray
Type for an array of layers.
Definition gauge.h:446
void add(const std::shared_ptr< GaugeLayer > &layer)
Add a GaugeLayer to the Gauge.
~Gauge() noexcept override
Gauge(const Rect &rect={}, const Flags &flags={}) noexcept
LayerArray m_layers
The layer's of the gauge.
Definition gauge.h:449
void add(GaugeLayer &layer)
Add a GaugeLayer to the Gauge.
Definition gauge.h:416
Gauge(Frame &parent, const Rect &rect, const Flags &flags={}) noexcept
void remove(GaugeLayer *layer)
Remove a layer from the gauge.
Special GaugeLayer that deals with a rotating needle.
Definition gauge.h:116
float min(float min)
Set the min value.
Definition gauge.h:190
EGT_NODISCARD bool clockwise() const
Get the clockwise value.
Definition gauge.h:298
EGT_NODISCARD float max() const
Get the max value.
Definition gauge.h:203
PointF m_center
Center point of the needle.
Definition gauge.h:337
EGT_NODISCARD PointF needle_center() const
Get the needle center.
Definition gauge.h:280
void needle_center(const PointF ¢er)
Set the needle center.
Definition gauge.h:289
float angle_start(float angle_start)
Set the start angle of the needle.
Definition gauge.h:156
EGT_NODISCARD PointF needle_point() const
Get the needle point.
Definition gauge.h:252
void clockwise(bool value)
Set the clockwise value.
Definition gauge.h:305
NeedleLayer(const Image &image, float min, float max, float angle_start=0, float angle_stop=360, bool clockwise=true) noexcept
EGT_NODISCARD float min() const
Get the min value.
Definition gauge.h:183
float value(float value)
Set the value.
Definition gauge.h:232
Signal on_value_changed
Event signal.
Definition gauge.h:124
EGT_NODISCARD float value() const
Get the value of the needle.
Definition gauge.h:223
EGT_NODISCARD float angle_stop() const
Get the angle stop value.
Definition gauge.h:167
float angle_stop(float angle_stop)
Set the stop angle of the needle.
Definition gauge.h:174
void needle_point(const PointF &point)
Set the needle point.
Definition gauge.h:263
float max(float max)
Set the max value.
Definition gauge.h:210
PointF m_point
Rotate point of the needle on the gauge.
Definition gauge.h:340
Rect rectangle_of_rotated()
T & center(T &widget)
Helper to set alignment of a widget.
Definition widgetflags.h:416
EGT framework namespace.
Definition animation.h:24