Skip to content

Commit 6e4e9e9

Browse files
committed
Merge branch 'skia_2024'
2 parents dd1593f + dd03b64 commit 6e4e9e9

File tree

8 files changed

+381
-211
lines changed

8 files changed

+381
-211
lines changed

lib/include/elements/element/dial.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ namespace cycfi::elements
6767

6868
basic_dial(double init_value = 0.0);
6969

70-
void prepare_subject(context& ctx) override;
7170
element* hit_test(context const& ctx, point p, bool leaf, bool control) override;
72-
7371
bool scroll(context const& ctx, point dir, point p) override;
7472
void keep_tracking(context const& ctx, tracker_info& track_info) override;
7573

lib/include/elements/element/image.hpp

+27-76
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define ELEMENTS_IMAGE_APRIL_24_2016
88

99
#include <elements/element/element.hpp>
10+
#include <elements/element/proxy.hpp>
1011
#include <elements/support/canvas.hpp>
1112
#include <elements/support/pixmap.hpp>
1213
#include <infra/filesystem.hpp>
@@ -116,28 +117,6 @@ namespace cycfi::elements
116117
void draw(context const& ctx) override;
117118
};
118119

119-
/**
120-
* \class sprite_as_double
121-
*
122-
* \brief
123-
* A template structure to handle sprite images used as 'double'
124-
* receivers.
125-
*
126-
* Receives a 'double' value in the range of 0.0 to 1.0, which
127-
* indicates which frame of the sprite image should be displayed. The
128-
* double value essentially represents the frame number, scaled down to
129-
* fit within the 0.0 to 1.0 range.
130-
*
131-
* \tparam Derived
132-
* The derived class type.
133-
*/
134-
template <typename Derived>
135-
struct sprite_as_double : receiver<double>
136-
{
137-
void value(double val) override;
138-
double value() const override;
139-
};
140-
141120
/**
142121
* \class basic_sprite
143122
*
@@ -168,24 +147,33 @@ namespace cycfi::elements
168147
float _height;
169148
};
170149

171-
/**
172-
* \class sprite
173-
*
174-
* \brief
175-
* A class representing a sprite image that can be used as controls.
176-
*
177-
* `sprite` extends `basic_sprite` to utilize both `sprite_as_int` and
178-
* `sprite_as_double`, making it usable as both an 'int' and a 'double'
179-
* receiver.
180-
*
181-
* Sprites are images used as controls. Various frames are laid out in
182-
* a single (big) image but only one frame is drawn at any single time.
183-
* Useful for switches, knobs and basic (sprite) animation.
184-
*/
185-
struct sprite : basic_sprite, sprite_as_double<sprite>
150+
using sprite = basic_sprite;
151+
152+
namespace detail
186153
{
187-
using basic_sprite::basic_sprite;
188-
};
154+
template <typename T>
155+
constexpr auto is_sprite()
156+
{
157+
if constexpr (std::is_base_of_v<proxy_base, T>)
158+
return is_sprite<typename T::subject_type>();
159+
else
160+
return std::false_type{};
161+
}
162+
163+
template <>
164+
constexpr auto is_sprite<sprite>()
165+
{
166+
return std::true_type{};
167+
}
168+
}
169+
170+
namespace concepts
171+
{
172+
template <typename T>
173+
concept SpriteSubject
174+
= concepts::Element<T> &&
175+
decltype(detail::is_sprite<std::decay_t<T>>())::value;
176+
}
189177

190178
//--------------------------------------------------------------------------
191179
// Inlines
@@ -202,43 +190,6 @@ namespace cycfi::elements
202190
{
203191
return _index;
204192
}
205-
206-
/**
207-
* \brief
208-
* Returns the index of the currently displayed frame in
209-
* sprite_as_double as a fraction of the total frames.
210-
*
211-
* \tparam Derived
212-
* The derived class type.
213-
*
214-
* \returns
215-
* The index of the currently displayed frame as a fraction of the
216-
* total frames (between 0.0 to 1.0).
217-
*/
218-
template <typename Derived>
219-
double sprite_as_double<Derived>::value() const
220-
{
221-
auto this_ = static_cast<Derived const*>(this);
222-
return this_->index() / this_->num_frames()-1;
223-
}
224-
225-
/**
226-
* \brief
227-
* Sets the index of the sprite_as_double to the provided value.
228-
*
229-
* \tparam Derived
230-
* The derived class type.
231-
*
232-
* \param val
233-
* The value to set the index to. It's a value between 0.0 and 1.0
234-
* representing the relative position in the sequence of frames.
235-
*/
236-
template <typename Derived>
237-
void sprite_as_double<Derived>::value(double val)
238-
{
239-
auto this_ = static_cast<Derived*>(this);
240-
this_->index(val * (this_->num_frames()-1));
241-
}
242193
}
243194

244195
#endif

lib/include/elements/element/proxy.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ namespace cycfi::elements
129129
class proxy : public Base
130130
{
131131
public:
132+
133+
using subject_type = Subject;
134+
132135
template <typename... T>
133136
proxy(Subject subject_, T&&... args);
134137

lib/include/elements/element/style.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <elements/element/style/slide_switch.hpp>
2525
#include <elements/element/style/slider.hpp>
2626
#include <elements/element/style/sprite_button.hpp>
27+
#include <elements/element/style/sprite_dial.hpp>
2728
#include <elements/element/style/tab.hpp>
2829
#include <elements/element/style/text_entry.hpp>
2930
#include <elements/element/style/thumbwheel.hpp>

lib/include/elements/element/style/dial.hpp

+90-71
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,128 @@ namespace cycfi::elements
1414
// Basic Knob (You can use this as the subject of dial)
1515
////////////////////////////////////////////////////////////////////////////
1616
template <std::size_t _size>
17-
class basic_knob_styler : public element, public receiver<double>
17+
class basic_knob_styler : public element
1818
{
1919
public:
2020

2121
static std::size_t const size = _size;
2222

23-
basic_knob_styler(color c = colors::black)
24-
: _color(c), _value(0)
25-
{}
23+
basic_knob_styler(color c = colors::black);
2624

2725
view_limits limits(basic_context const& ctx) const override;
2826
void draw(context const& ctx) override;
2927

30-
double value() const override { return _value; }
31-
void value(double val) override;
32-
3328
private:
3429

3530
color _color;
36-
float _value;
3731
};
3832

33+
template <std::size_t size>
34+
inline basic_knob_styler<size> basic_knob(color c = colors::black);
35+
36+
////////////////////////////////////////////////////////////////////////////
37+
// Radial Element Base (common base class for radial elements)
38+
////////////////////////////////////////////////////////////////////////////
39+
template <std::size_t _size, concepts::Element Subject>
40+
class radial_styler_base : public proxy<Subject>
41+
{
42+
public:
43+
44+
static std::size_t const size = _size;
45+
46+
using base_type = proxy<Subject>;
47+
48+
radial_styler_base(Subject subject);
49+
50+
view_limits limits(basic_context const& ctx) const override;
51+
void prepare_subject(context& ctx) override;
52+
};
53+
54+
////////////////////////////////////////////////////////////////////////////
55+
// Radial Marks (You can use this to place dial tick marks around dials)
56+
////////////////////////////////////////////////////////////////////////////
57+
template <std::size_t _size, concepts::Element Subject>
58+
class radial_marks_styler : public radial_styler_base<_size, Subject>
59+
{
60+
public:
61+
62+
static std::size_t const size = _size;
63+
using base_type = radial_styler_base<_size, Subject>;
64+
using base_type::base_type;
65+
66+
void draw(context const& ctx) override;
67+
};
68+
69+
template <std::size_t size, concepts::Element Subject>
70+
inline radial_marks_styler<size, remove_cvref_t<Subject>>
71+
radial_marks(Subject&& subject);
72+
73+
////////////////////////////////////////////////////////////////////////////
74+
// Radial Labels (You can use this to place dial labels around dials)
75+
////////////////////////////////////////////////////////////////////////////
76+
template <std::size_t _size, concepts::Element Subject, std::size_t num_labels>
77+
class radial_labels_styler : public radial_styler_base<_size, Subject>
78+
{
79+
public:
80+
81+
static std::size_t const size = _size;
82+
using base_type = radial_styler_base<_size, Subject>;
83+
using string_array = std::array<std::string, num_labels>;
84+
85+
radial_labels_styler(Subject subject, float font_size);
86+
87+
void draw(context const& ctx) override;
88+
89+
string_array _labels;
90+
float _font_size;
91+
};
92+
93+
template <std::size_t size, concepts::Element Subject, typename... S>
94+
inline radial_labels_styler<size, remove_cvref_t<Subject>, sizeof...(S)>
95+
radial_labels(Subject&& subject, float font_size, S&&... s);
96+
97+
//--------------------------------------------------------------------------
98+
// Inlines
99+
//--------------------------------------------------------------------------
100+
101+
template <std::size_t size>
102+
inline basic_knob_styler<size>::basic_knob_styler(color c)
103+
: _color(c)
104+
{}
105+
39106
template <std::size_t size>
40107
inline view_limits basic_knob_styler<size>::limits(basic_context const& /*ctx*/) const
41108
{
42-
auto pt = point{float(size), float(size)};
109+
auto pt = point{float(size), float(size)};
43110
return view_limits{pt, pt};
44111
}
45112

46113
template <std::size_t size>
47114
inline void basic_knob_styler<size>::draw(context const& ctx)
48115
{
116+
auto dial = find_parent<basic_dial*>(ctx);
117+
if (!dial)
118+
return;
119+
49120
auto& thm = get_theme();
50121
auto& cnv = ctx.canvas;
51122
auto indicator_color = thm.indicator_color.level(1.5);
52123
auto cp = circle{center_point(ctx.bounds), ctx.bounds.width()/2};
53124

54125
draw_knob(cnv, cp, _color);
55-
draw_radial_indicator(cnv, cp, _value, indicator_color);
126+
draw_radial_indicator(cnv, cp, dial->value(), indicator_color);
56127
}
57128

58129
template <std::size_t size>
59-
inline void basic_knob_styler<size>::value(double val)
60-
{
61-
_value = val;
62-
}
63-
64-
template <std::size_t size>
65-
inline basic_knob_styler<size> basic_knob(color c = colors::black)
130+
inline basic_knob_styler<size> basic_knob(color c)
66131
{
67132
return {c};
68133
}
69134

70-
////////////////////////////////////////////////////////////////////////////
71-
// Radial Element Base (common base class for radial elements)
72-
////////////////////////////////////////////////////////////////////////////
73135
template <std::size_t _size, concepts::Element Subject>
74-
class radial_styler_base : public proxy<Subject>
75-
{
76-
public:
77-
78-
static std::size_t const size = _size;
79-
80-
using base_type = proxy<Subject>;
81-
82-
radial_styler_base(Subject subject)
83-
: base_type(std::move(subject))
84-
{}
85-
86-
view_limits limits(basic_context const& ctx) const override;
87-
void prepare_subject(context& ctx) override;
88-
};
136+
inline radial_styler_base<_size, Subject>::radial_styler_base(Subject subject)
137+
: base_type(std::move(subject))
138+
{}
89139

90140
template <std::size_t size, concepts::Element Subject>
91141
inline view_limits
@@ -114,21 +164,6 @@ namespace cycfi::elements
114164
ctx.bounds.right -= size_div2;
115165
}
116166

117-
////////////////////////////////////////////////////////////////////////////
118-
// Radial Marks (You can use this to place dial tick marks around dials)
119-
////////////////////////////////////////////////////////////////////////////
120-
template <std::size_t _size, concepts::Element Subject>
121-
class radial_marks_styler : public radial_styler_base<_size, Subject>
122-
{
123-
public:
124-
125-
static std::size_t const size = _size;
126-
using base_type = radial_styler_base<_size, Subject>;
127-
using base_type::base_type;
128-
129-
void draw(context const& ctx) override;
130-
};
131-
132167
template <std::size_t size, concepts::Element Subject>
133168
inline void
134169
radial_marks_styler<size, Subject>::draw(context const& ctx)
@@ -148,28 +183,12 @@ namespace cycfi::elements
148183
return {std::forward<Subject>(subject)};
149184
}
150185

151-
////////////////////////////////////////////////////////////////////////////
152-
// Radial Labels (You can use this to place dial labels around dials)
153-
////////////////////////////////////////////////////////////////////////////
154186
template <std::size_t _size, concepts::Element Subject, std::size_t num_labels>
155-
class radial_labels_styler : public radial_styler_base<_size, Subject>
156-
{
157-
public:
158-
159-
static std::size_t const size = _size;
160-
using base_type = radial_styler_base<_size, Subject>;
161-
using string_array = std::array<std::string, num_labels>;
162-
163-
radial_labels_styler(Subject subject, float font_size)
164-
: base_type(std::move(subject))
165-
, _font_size(font_size)
166-
{}
167-
168-
void draw(context const& ctx) override;
169-
170-
string_array _labels;
171-
float _font_size;
172-
};
187+
inline radial_labels_styler<_size, Subject, num_labels>
188+
::radial_labels_styler(Subject subject, float font_size)
189+
: base_type(std::move(subject))
190+
, _font_size(font_size)
191+
{}
173192

174193
template <std::size_t size, concepts::Element Subject, std::size_t num_labels>
175194
inline void

0 commit comments

Comments
 (0)