led\'s for solo-safe and solo-isolate, rather than a context menu (mixer strip only...
[ardour.git] / gtk2_ardour / led.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
23
24 #include "led.h"
25
26 using namespace Gdk;
27 using namespace Gtk;
28 using namespace Glib;
29
30 LED::LED()
31         : _visual_state (0)
32         , _active (false)
33         , _red (0.0)
34         , _green (1.0)
35         , _blue (0.0)
36
37 {
38 }
39
40 LED::~LED()
41 {
42 }
43
44 void
45 LED::render (cairo_t* cr)
46 {
47         float diameter = std::min (_width, _height);
48
49         //background
50         cairo_rectangle(cr, 0, 0, _width, _height);
51         cairo_stroke_preserve(cr);
52         cairo_set_source_rgb(cr, 0, 0, 0);
53         cairo_fill(cr);
54
55         cairo_translate(cr, _width/2, _height/2);
56
57 #if 0
58         //inset
59         cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, diameter);
60         cairo_pattern_add_color_stop_rgba (pat, 0, 0,0,0, 0.4);
61         cairo_pattern_add_color_stop_rgba (pat, 1, 1,1,1, 0.7);
62         cairo_arc (cr, 0, 0, diameter/2, 0, 2 * M_PI);
63         cairo_set_source (cr, pat);
64         cairo_fill (cr);
65         cairo_pattern_destroy (pat);
66
67         //black ring
68         cairo_set_source_rgb (cr, 0, 0, 0);
69         cairo_arc (cr, 0, 0, diameter/2-2, 0, 2 * M_PI);
70         cairo_fill(cr);
71
72         //knob color
73         cairo_set_source_rgba (cr, _red, _green, _blue, _active ? 0.8 : 0.2);
74         cairo_arc (cr, 0, 0, diameter/2-3, 0, 2 * M_PI);
75         cairo_fill(cr);
76
77         //reflection
78         cairo_scale(cr, 0.7, 0.7);
79         cairo_pattern_t *pat2 = cairo_pattern_create_linear (0.0, 0.0, 0.0, diameter/2-3);
80         cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, _active ? 0.4 : 0.2);
81         cairo_pattern_add_color_stop_rgba (pat2, 1, 1,1,1, 0.0);
82         cairo_arc (cr, 0, 0, diameter/2-3, 0, 2 * M_PI);
83         cairo_set_source (cr, pat2);
84         cairo_fill (cr);
85         cairo_pattern_destroy (pat2);
86 #endif
87
88         cairo_set_source_rgba (cr, _red, _green, _blue,  1.0);
89         cairo_arc (cr, 0, 0, diameter/2-5, 0, 2 * M_PI);
90         cairo_fill(cr);
91
92         cairo_stroke (cr);
93 }
94
95 void
96 LED::set_visual_state (int32_t s)
97 {
98         if (s != _visual_state) {
99
100                 _visual_state = s;
101
102                 RefPtr<Style> style = get_style();
103                 Color c;
104                 
105                 switch (_visual_state) {
106                 case 0:
107                         c = style->get_fg (STATE_NORMAL);
108                         break;
109                 default:
110                         c = style->get_fg (STATE_ACTIVE);
111                         break;
112                 }
113
114                 _red = c.get_red_p ();
115                 _green = c.get_green_p ();
116                 _blue = c.get_blue_p ();
117                 
118                 set_dirty ();
119         }
120 }