11
11
12
12
namespace cycfi ::elements
13
13
{
14
- class sprite_button_styler : public sprite
14
+ template <typename Subject>
15
+ class sprite_button_styler : public proxy <Subject>
15
16
{
16
17
public:
17
- sprite_button_styler (sprite const & s);
18
+
19
+ using base_type = proxy<Subject>;
20
+
21
+ sprite_button_styler (Subject subject);
18
22
19
23
void draw (context const & ctx) override ;
20
24
};
@@ -23,52 +27,62 @@ namespace cycfi::elements
23
27
concepts::MomentaryButton Base = basic_button
24
28
, concepts::SpriteSubject Styler
25
29
>
26
- inline proxy<sprite_button_styler, Base>
30
+ inline proxy<sprite_button_styler< remove_cvref_t <Styler>> , Base>
27
31
momentary_button (Styler&& s)
28
32
{
29
- return {sprite_button_styler{std::forward<Styler>(s)}};
33
+ using styler_type = sprite_button_styler<remove_cvref_t <Styler>>;
34
+ return {styler_type{std::forward<Styler>(s)}};
30
35
}
31
36
32
37
template <
33
38
concepts::ToggleButton Base = basic_toggle_button
34
39
, concepts::SpriteSubject Styler
35
40
>
36
- inline proxy<sprite_button_styler, Base>
41
+ inline proxy<sprite_button_styler< remove_cvref_t <Styler>> , Base>
37
42
toggle_button (Styler&& s)
38
43
{
39
- return {sprite_button_styler{std::forward<Styler>(s)}};
44
+ using styler_type = sprite_button_styler<remove_cvref_t <Styler>>;
45
+ return {styler_type{std::forward<Styler>(s)}};
40
46
}
41
47
42
48
template <
43
49
concepts::LatchingButton Base = basic_latching_button
44
50
, concepts::SpriteSubject Styler
45
51
>
46
- inline proxy<sprite_button_styler, Base>
52
+ inline proxy<sprite_button_styler< remove_cvref_t <Styler>> , Base>
47
53
latching_button (Styler&& s)
48
54
{
49
- return {sprite_button_styler{std::forward<Styler>(s)}};
55
+ using styler_type = sprite_button_styler<remove_cvref_t <Styler>>;
56
+ return {styler_type{std::forward<Styler>(s)}};
50
57
}
51
58
52
59
// --------------------------------------------------------------------------
53
60
// Inlines
54
61
// --------------------------------------------------------------------------
55
- inline sprite_button_styler::sprite_button_styler (sprite const & s)
56
- : sprite(s)
62
+
63
+ template <typename Subject>
64
+ inline sprite_button_styler<Subject>::sprite_button_styler(Subject subject)
65
+ : base_type{std::move (subject)}
57
66
{}
58
67
59
- inline void sprite_button_styler::draw (context const & ctx)
68
+ template <typename Subject>
69
+ inline void sprite_button_styler<Subject>::draw(context const & ctx)
60
70
{
61
71
auto btn = find_parent<basic_button*>(ctx);
62
72
if (!btn)
63
73
return ;
64
74
65
- auto value = btn->value ();
66
- auto hilite = btn->hilite ();
67
- if (!ctx.enabled && num_frames () > 4 )
68
- index (4 ); // disabled
69
- else
70
- index ((value? 2 : 0 ) + hilite); // enabled
71
- basic_sprite::draw (ctx);
75
+ auto sp = find_subject<sprite*>(this );
76
+ if (sp)
77
+ {
78
+ auto value = btn->value ();
79
+ auto hilite = btn->hilite ();
80
+ if (!ctx.enabled && sp->num_frames () > 4 )
81
+ sp->index (4 ); // disabled
82
+ else
83
+ sp->index ((value? 2 : 0 ) + hilite); // enabled
84
+ sp->draw (ctx);
85
+ }
72
86
}
73
87
}
74
88
0 commit comments