2 Copyright (C) 2009 Paul Davis
3 Copyright (C) 2015 Robin Gareus <robin@gareus.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <math.h> // For M_PI
23 #include "gtkmm2ext/ardour_icon.h"
25 // "canvas/types.h" Color == uint32_t
26 // from libs/canvas/utils.cc
27 static void ardour_canvas_set_source_rgba (cairo_t *cr, uint32_t color)
29 cairo_set_source_rgba ( cr,
30 ((color >> 24) & 0xff) / 255.0,
31 ((color >> 16) & 0xff) / 255.0,
32 ((color >> 8) & 0xff) / 255.0,
33 ((color >> 0) & 0xff) / 255.0
38 Gtkmm2ext::ArdourIcon::render (cairo_t *cr,
39 const enum Gtkmm2ext::ArdourIcon::Icon icon,
40 const int width, const int height,
41 const Gtkmm2ext::ActiveState state,
42 const uint32_t fg_color)
45 #define VECTORICONSTROKEFILL(fillalpha) \
46 cairo_set_line_width(cr, 1.5); \
47 cairo_set_source_rgba (cr, 0, 0, 0, 1.0); \
48 cairo_stroke_preserve(cr); \
49 cairo_set_source_rgba (cr, 1, 1, 1, (fillalpha)); \
52 #define VECTORICONSTROKEOUTLINE() \
53 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); \
54 cairo_set_line_width(cr, 3.0); \
55 cairo_set_source_rgba (cr, 0, 0, 0, 1.0); \
56 cairo_stroke_preserve(cr); \
57 ardour_canvas_set_source_rgba (cr, fg_color); \
58 cairo_set_line_width(cr, 1.5); \
62 /* TODO separate these into dedicated class
63 * it may also be efficient to render them only once for every size (image-surface) */
66 case Gtkmm2ext::ArdourIcon::RecTapeMode:
68 const double x = width * .5;
69 const double y = height * .5;
70 const double r = std::min(x, y) * .6;
71 const double slit = .11 * M_PI;
73 cairo_translate(cr, x, y);
75 cairo_arc (cr, 0, 0, r, 0, 2 * M_PI);
76 if (state == Gtkmm2ext::ExplicitActive) {
77 cairo_set_source_rgba (cr, .95, .1, .1, 1.);
79 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
81 cairo_fill_preserve(cr);
82 cairo_set_source_rgba (cr, .0, .0, .0, .5);
83 cairo_set_line_width(cr, 1);
87 cairo_set_source_rgba (cr, .15, .07, .07, 1.0);
89 cairo_rotate (cr, -.5 * M_PI);
90 cairo_move_to(cr, 0, 0);
91 cairo_arc (cr, 0, 0, r *.85, -slit, slit);
92 cairo_line_to(cr, 0, 0);
96 cairo_rotate (cr, 2. * M_PI / 3.);
98 cairo_move_to(cr, 0, 0);
99 cairo_arc (cr, 0, 0, r *.85, -slit, slit);
100 cairo_line_to(cr, 0, 0);
101 cairo_close_path(cr);
104 cairo_rotate (cr, 2. * M_PI / 3.);
105 cairo_move_to(cr, 0, 0);
106 cairo_arc (cr, 0, 0, r *.85, -slit, slit);
107 cairo_line_to(cr, 0, 0);
108 cairo_close_path(cr);
113 cairo_arc (cr, 0, 0, r * .3, 0, 2 * M_PI);
114 if (state == Gtkmm2ext::ExplicitActive)
115 cairo_set_source_rgba (cr, .95, .1, .1, 1.);
117 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
119 cairo_set_source_rgba (cr, .0, .0, .0, 1.0);
120 cairo_arc (cr, 0, 0, r *.15, 0, 2 * M_PI); // hole in the middle
126 case Gtkmm2ext::ArdourIcon::RecButton:
128 const double x = width * .5;
129 const double y = height * .5;
130 const double r = std::min(x, y) * .55;
131 cairo_arc (cr, x, y, r, 0, 2 * M_PI);
132 if (state == Gtkmm2ext::ExplicitActive)
133 cairo_set_source_rgba (cr, .95, .1, .1, 1.);
135 cairo_set_source_rgba (cr, .95, .44, .44, 1.); // #f46f6f
136 cairo_fill_preserve(cr);
137 cairo_set_source_rgba (cr, .0, .0, .0, .8);
138 cairo_set_line_width(cr, 1);
142 case Gtkmm2ext::ArdourIcon::CloseCross:
144 const double x = width * .5;
145 const double y = height * .5;
146 const double o = .5 + std::min(x, y) * .4;
147 ardour_canvas_set_source_rgba (cr, fg_color);
148 cairo_set_line_width(cr, 1);
149 cairo_move_to(cr, x-o, y-o);
150 cairo_line_to(cr, x+o, y+o);
151 cairo_move_to(cr, x+o, y-o);
152 cairo_line_to(cr, x-o, y+o);
156 case Gtkmm2ext::ArdourIcon::StripWidth:
158 const double x0 = width * .2;
159 const double x1 = width * .8;
161 const double y0 = height * .25;
162 const double y1= height * .75;
164 const double ym= height * .5;
167 const double xa0= height * .39;
168 const double xa1= height * .61;
169 const double ya0= height * .35;
170 const double ya1= height * .65;
172 ardour_canvas_set_source_rgba (cr, fg_color);
173 cairo_set_line_width(cr, 1);
176 cairo_move_to(cr, x0, y0);
177 cairo_line_to(cr, x0, y1);
178 cairo_move_to(cr, x1, y0);
179 cairo_line_to(cr, x1, y1);
182 cairo_move_to(cr, x0, ym);
183 cairo_line_to(cr, x1, ym);
186 cairo_move_to(cr, x0, ym);
187 cairo_line_to(cr, xa0, ya0);
188 cairo_move_to(cr, x0, ym);
189 cairo_line_to(cr, xa0, ya1);
192 cairo_move_to(cr, x1, ym);
193 cairo_line_to(cr, xa1, ya0);
194 cairo_move_to(cr, x1, ym);
195 cairo_line_to(cr, xa1, ya1);
199 case Gtkmm2ext::ArdourIcon::DinMidi:
201 const double x = width * .5;
202 const double y = height * .5;
203 const double r = std::min(x, y) * .75;
204 ardour_canvas_set_source_rgba (cr, fg_color);
205 cairo_set_line_width(cr, 1);
206 cairo_arc (cr, x, y, r, .57 * M_PI, 2.43 * M_PI);
209 // pins equally spaced 45deg
210 cairo_arc (cr, x, y * 0.5, r * .15, 0, 2 * M_PI);
212 cairo_arc (cr, x * 0.5, y, r * .15, 0, 2 * M_PI);
214 cairo_arc (cr, x * 1.5, y, r * .15, 0, 2 * M_PI);
216 // .5 + .5 * .5 * sin(45deg), 1.5 - .5 * .5 * cos(45deg)
217 cairo_arc (cr, x * 0.677, y * .677, r * .15, 0, 2 * M_PI);
219 cairo_arc (cr, x * 1.323, y * .677, r * .15, 0, 2 * M_PI);
223 cairo_arc (cr, x, y+r, r * .26, 1.05 * M_PI, 1.95 * M_PI);
227 case Gtkmm2ext::ArdourIcon::TransportStop:
229 const int wh = std::min (width, height);
231 (width - wh) * .5 + wh * .25,
232 (height - wh) * .5 + wh * .25,
235 VECTORICONSTROKEFILL(0.8);
238 case Gtkmm2ext::ArdourIcon::TransportPlay:
240 const int wh = std::min (width, height) * .5;
241 const double y = height * .5;
242 const double x = width - wh;
244 const float tri = ceil(.577 * wh); // 1/sqrt(3)
246 cairo_move_to (cr, x + wh * .5, y);
247 cairo_line_to (cr, x - wh * .5, y - tri);
248 cairo_line_to (cr, x - wh * .5, y + tri);
249 cairo_close_path (cr);
251 VECTORICONSTROKEFILL(0.8);
254 case Gtkmm2ext::ArdourIcon::TransportPanic:
256 const int wh = std::min (width, height) * .1;
257 const double xc = width * .5;
258 const double yh = height;
262 VECTORICONSTROKEFILL(0.8);
264 cairo_arc (cr, xc, yh *.75, wh, 0, 2 * M_PI);
265 VECTORICONSTROKEFILL(0.8);
268 case Gtkmm2ext::ArdourIcon::TransportStart:
269 case Gtkmm2ext::ArdourIcon::TransportEnd:
270 case Gtkmm2ext::ArdourIcon::TransportRange:
272 // small play triangle
273 int wh = std::min (width, height);
274 const double y = height * .5;
275 const double x = width - wh * .5;
277 const float tri = ceil(.577 * wh * 2); // 1/sqrt(3)
279 const float ln = std::min (width, height) * .07;
281 if (icon == Gtkmm2ext::ArdourIcon::TransportStart || icon == Gtkmm2ext::ArdourIcon::TransportRange) {
283 x - wh - ln, y - tri * 1.7,
286 VECTORICONSTROKEFILL(1.0);
289 if (icon == Gtkmm2ext::ArdourIcon::TransportEnd || icon == Gtkmm2ext::ArdourIcon::TransportRange) {
291 x + wh - ln, y - tri * 1.7,
294 VECTORICONSTROKEFILL(1.0);
297 if (icon == Gtkmm2ext::ArdourIcon::TransportStart) {
298 cairo_move_to (cr, x - wh, y);
299 cairo_line_to (cr, x + wh, y - tri);
300 cairo_line_to (cr, x + wh, y + tri);
302 cairo_move_to (cr, x + wh, y);
303 cairo_line_to (cr, x - wh, y - tri);
304 cairo_line_to (cr, x - wh, y + tri);
307 cairo_close_path (cr);
308 VECTORICONSTROKEFILL(1.0);
311 case Gtkmm2ext::ArdourIcon::TransportLoop:
313 const double x = width * .5;
314 const double y = height * .5;
315 const double r = std::min(x, y);
317 cairo_arc (cr, x, y, r * .62, 0, 2 * M_PI);
318 cairo_arc_negative (cr, x, y, r * .35, 2 * M_PI, 0);
320 VECTORICONSTROKEFILL(1.0);
321 #define ARCARROW(rad, ang) \
322 x + (rad) * sin((ang) * 2.0 * M_PI), y + (rad) * cos((ang) * 2.0 * M_PI)
324 cairo_move_to (cr, ARCARROW(r * .35, .72));
325 cairo_line_to (cr, ARCARROW(r * .15, .72));
326 cairo_line_to (cr, ARCARROW(r * .56, .60));
327 cairo_line_to (cr, ARCARROW(r * .75, .72));
328 cairo_line_to (cr, ARCARROW(r * .62, .72));
330 cairo_set_source_rgba (cr, 0, 0, 0, 1.0);
331 cairo_stroke_preserve(cr);
332 cairo_close_path (cr);
333 cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
338 case Gtkmm2ext::ArdourIcon::TransportMetronom:
340 const double x = width * .5;
341 const double y = height * .5;
342 const double wh = std::min(x, y);
343 const double h = wh * .85;
344 const double w = wh * .55;
345 const double lw = w * .34;
348 x - w * .7, y + h * .25,
351 VECTORICONSTROKEFILL(1.0);
353 cairo_move_to (cr, x - w, y + h);
354 cairo_line_to (cr, x + w, y + h);
355 cairo_line_to (cr, x + w * .35, y - h);
356 cairo_line_to (cr, x - w * .35, y - h);
357 cairo_line_to (cr, x - w, y + h);
359 cairo_move_to (cr, x - w + lw, y + h -lw);
360 cairo_line_to (cr, x - w * .35 + lw, y - h + lw);
361 cairo_line_to (cr, x + w * .35 - lw, y - h + lw);
362 cairo_line_to (cr, x + w - lw, y + h -lw);
363 cairo_line_to (cr, x - w + lw, y + h -lw);
365 VECTORICONSTROKEFILL(1.0);
367 // ddx = .70 w = .75 * .5 wh = .375 wh
368 // ddy = .75 h - lw = .75 * .8 wh - wh .5 * .2 = .5 wh
370 // -> angle = atan (ang) = atan (375 / .5) ~= 36deg
371 const double dx = lw * .2; // 1 - cos(tan^-1(ang))
372 const double dy = lw * .4; // 1 - sin(tan^-1(ang))
373 cairo_move_to (cr, x - w * .3 , y + h * .25 + lw * .5);
374 cairo_line_to (cr, x - w + dx , y - h + lw + dy);
375 cairo_line_to (cr, x - w + lw , y - h + lw);
376 cairo_line_to (cr, x - w * .3 + lw, y + h * .25 + lw * .5);
377 cairo_close_path (cr);
379 VECTORICONSTROKEFILL(1.0);
382 x - w * .7, y + h * .25,
387 case Gtkmm2ext::ArdourIcon::NudgeLeft:
389 const double x = width * .5;
390 const double y = height * .5;
391 const double wh = std::min (x, y);
393 const double tri_x = .3 * wh;
394 const double tri_y = .6 * wh;
396 cairo_move_to (cr, x + tri_x, y - tri_y);
397 cairo_line_to (cr, x - tri_x, y);
398 cairo_line_to (cr, x + tri_x, y + tri_y);
399 VECTORICONSTROKEOUTLINE();
402 case Gtkmm2ext::ArdourIcon::NudgeRight:
405 const double x = width * .5;
406 const double y = height * .5;
407 const double wh = std::min (x, y);
409 const double tri_x = .3 * wh;
410 const double tri_y = .6 * wh;
412 cairo_move_to (cr, x - tri_x, y - tri_y);
413 cairo_line_to (cr, x + tri_x, y);
414 cairo_line_to (cr, x - tri_x, y + tri_y);
415 VECTORICONSTROKEOUTLINE();
423 #undef VECTORICONSTROKEFILL
424 #undef VECTORICONSTROKEOUTLINE