@@ -68,190 +68,6 @@ namespace cycfi::elements
68
68
{
69
69
return element::hit_test (ctx, p, leaf, false ); // accept non-control subjects
70
70
}
71
-
72
- // //////////////////////////////////////////////////////////////////////////
73
- // Basic Knob (You can use this as the subject of dial)
74
- // //////////////////////////////////////////////////////////////////////////
75
- template <std::size_t _size>
76
- class basic_knob_element : public element , public receiver <double >
77
- {
78
- public:
79
-
80
- static std::size_t const size = _size;
81
-
82
- basic_knob_element (color c = colors::black)
83
- : _color(c), _value(0 )
84
- {}
85
-
86
- view_limits limits (basic_context const & ctx) const override ;
87
- void draw (context const & ctx) override ;
88
-
89
- double value () const override { return _value; }
90
- void value (double val) override ;
91
-
92
- private:
93
-
94
- color _color;
95
- float _value;
96
- };
97
-
98
- template <std::size_t size>
99
- inline view_limits basic_knob_element<size>::limits(basic_context const & /* ctx */ ) const
100
- {
101
- auto pt = point{float (size), float (size)};
102
- return view_limits{pt, pt};
103
- }
104
-
105
- template <std::size_t size>
106
- inline void basic_knob_element<size>::draw(context const & ctx)
107
- {
108
- auto & thm = get_theme ();
109
- auto & cnv = ctx.canvas ;
110
- auto indicator_color = thm.indicator_color .level (1.5 );
111
- auto cp = circle{center_point (ctx.bounds ), ctx.bounds .width ()/2 };
112
-
113
- draw_knob (cnv, cp, _color);
114
- draw_radial_indicator (cnv, cp, _value, indicator_color);
115
- }
116
-
117
- template <std::size_t size>
118
- inline void basic_knob_element<size>::value(double val)
119
- {
120
- _value = val;
121
- }
122
-
123
- template <std::size_t size>
124
- inline basic_knob_element<size> basic_knob (color c = colors::black)
125
- {
126
- return {c};
127
- }
128
-
129
- // //////////////////////////////////////////////////////////////////////////
130
- // Radial Element Base (common base class for radial elements)
131
- // //////////////////////////////////////////////////////////////////////////
132
- template <std::size_t _size, concepts::Element Subject>
133
- class radial_element_base : public proxy <Subject>
134
- {
135
- public:
136
-
137
- static std::size_t const size = _size;
138
-
139
- using base_type = proxy<Subject>;
140
-
141
- radial_element_base (Subject subject)
142
- : base_type(std::move(subject))
143
- {}
144
-
145
- view_limits limits (basic_context const & ctx) const override ;
146
- void prepare_subject (context& ctx) override ;
147
- };
148
-
149
- template <std::size_t size, concepts::Element Subject>
150
- inline view_limits
151
- radial_element_base<size, Subject>::limits(basic_context const & ctx) const
152
- {
153
- auto sl = this ->subject ().limits (ctx);
154
-
155
- sl.min .x += size;
156
- sl.max .x += size;
157
- sl.min .y += size;
158
- sl.max .y += size;
159
-
160
- clamp_max (sl.max .x , full_extent);
161
- clamp_max (sl.max .y , full_extent);
162
- return sl;
163
- }
164
-
165
- template <std::size_t size, concepts::Element Subject>
166
- inline void
167
- radial_element_base<size, Subject>::prepare_subject(context& ctx)
168
- {
169
- auto size_div2 = size /2 ;
170
- ctx.bounds .top += size_div2;
171
- ctx.bounds .left += size_div2;
172
- ctx.bounds .bottom -= size_div2;
173
- ctx.bounds .right -= size_div2;
174
- }
175
-
176
- // //////////////////////////////////////////////////////////////////////////
177
- // Radial Marks (You can use this to place dial tick marks around dials)
178
- // //////////////////////////////////////////////////////////////////////////
179
- template <std::size_t _size, concepts::Element Subject>
180
- class radial_marks_element : public radial_element_base <_size, Subject>
181
- {
182
- public:
183
-
184
- static std::size_t const size = _size;
185
- using base_type = radial_element_base<_size, Subject>;
186
- using base_type::base_type;
187
-
188
- void draw (context const & ctx) override ;
189
- };
190
-
191
- template <std::size_t size, concepts::Element Subject>
192
- inline void
193
- radial_marks_element<size, Subject>::draw(context const & ctx)
194
- {
195
- // Draw the subject
196
- base_type::draw (ctx);
197
-
198
- // Draw radial lines
199
- auto cp = circle{center_point (ctx.bounds ), ctx.bounds .width ()/2 };
200
- draw_radial_marks (ctx.canvas , cp, size-2 , colors::light_gray);
201
- }
202
-
203
- template <std::size_t size, concepts::Element Subject>
204
- inline radial_marks_element<size, remove_cvref_t <Subject>>
205
- radial_marks (Subject&& subject)
206
- {
207
- return {std::forward<Subject>(subject)};
208
- }
209
-
210
- // //////////////////////////////////////////////////////////////////////////
211
- // Radial Labels (You can use this to place dial labels around dials)
212
- // //////////////////////////////////////////////////////////////////////////
213
- template <std::size_t _size, concepts::Element Subject, std::size_t num_labels>
214
- class radial_labels_element : public radial_element_base <_size, Subject>
215
- {
216
- public:
217
-
218
- static std::size_t const size = _size;
219
- using base_type = radial_element_base<_size, Subject>;
220
- using string_array = std::array<std::string, num_labels>;
221
-
222
- radial_labels_element (Subject subject, float font_size)
223
- : base_type(std::move(subject))
224
- , _font_size(font_size)
225
- {}
226
-
227
- void draw (context const & ctx) override ;
228
-
229
- string_array _labels;
230
- float _font_size;
231
- };
232
-
233
- template <std::size_t size, concepts::Element Subject, std::size_t num_labels>
234
- inline void
235
- radial_labels_element<size, Subject, num_labels>::draw(context const & ctx)
236
- {
237
- // Draw the subject
238
- base_type::draw (ctx);
239
-
240
- // Draw the labels
241
- auto cp = circle{center_point (ctx.bounds ), ctx.bounds .width ()/2 };
242
- draw_radial_labels (
243
- ctx.canvas , cp, _font_size, _labels.data (), num_labels);
244
- }
245
-
246
- template <std::size_t size, concepts::Element Subject, typename ... S>
247
- inline radial_labels_element<size, remove_cvref_t <Subject>, sizeof ...(S)>
248
- radial_labels (Subject&& subject, float font_size, S&&... s)
249
- {
250
- auto r = radial_labels_element<size, remove_cvref_t <Subject>, sizeof ...(S)>
251
- {std::move (subject), font_size};
252
- r._labels = {{std::move (s)...}};
253
- return r;
254
- }
255
71
}
256
72
257
73
#endif
0 commit comments