Remove action-driven keyboard brush, which is the same as paste as far as I can see.
[ardour2.git] / gtk2_ardour / led.cc
blob76d71bc35e7316446b172526c234744680e4f85a
1 /*
2 Copyright (C) 2010 Paul Davis
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.
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.
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.
20 #include <iostream>
21 #include <cmath>
22 #include <algorithm>
24 #include "led.h"
26 using namespace Gdk;
27 using namespace Gtk;
28 using namespace Glib;
30 LED::LED()
31 : _visual_state (0)
32 , _active (false)
33 , _diameter (0.0)
34 , _fixed_diameter (false)
35 , _red (0.0)
36 , _green (1.0)
37 , _blue (0.0)
42 LED::~LED()
46 void
47 LED::render (cairo_t* cr)
49 if (!_fixed_diameter) {
50 _diameter = std::min (_width, _height);
53 //background
55 Widget* parent;
56 RefPtr<Style> style;
57 Color c;
59 parent = get_parent ();
61 while (parent && !parent->get_has_window()) {
62 parent = parent->get_parent();
65 if (parent && parent->get_has_window()) {
66 style = parent->get_style ();
67 c = style->get_bg (parent->get_state());
68 } else {
69 style = get_style ();
70 c = style->get_bg (get_state());
74 cairo_rectangle(cr, 0, 0, _width, _height);
75 cairo_stroke_preserve(cr);
76 cairo_set_source_rgb(cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
77 cairo_fill(cr);
79 cairo_translate(cr, _width/2, _height/2);
81 #if 0
82 //inset
83 cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
84 cairo_pattern_add_color_stop_rgba (pat, 0, 0,0,0, 0.4);
85 cairo_pattern_add_color_stop_rgba (pat, 1, 1,1,1, 0.7);
86 cairo_arc (cr, 0, 0, _diameter/2, 0, 2 * M_PI);
87 cairo_set_source (cr, pat);
88 cairo_fill (cr);
89 cairo_pattern_destroy (pat);
91 //black ring
92 cairo_set_source_rgb (cr, 0, 0, 0);
93 cairo_arc (cr, 0, 0, _diameter/2-2, 0, 2 * M_PI);
94 cairo_fill(cr);
96 //knob color
97 cairo_set_source_rgba (cr, _red, _green, _blue, _active ? 0.8 : 0.2);
98 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
99 cairo_fill(cr);
101 //reflection
102 cairo_scale(cr, 0.7, 0.7);
103 cairo_pattern_t *pat2 = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
104 cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, _active ? 0.4 : 0.2);
105 cairo_pattern_add_color_stop_rgba (pat2, 1, 1,1,1, 0.0);
106 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
107 cairo_set_source (cr, pat2);
108 cairo_fill (cr);
109 cairo_pattern_destroy (pat2);
110 #endif
112 cairo_set_source_rgba (cr, _red, _green, _blue, 1.0);
113 cairo_arc (cr, 0, 0, _diameter/2-5, 0, 2 * M_PI);
114 cairo_fill(cr);
116 cairo_stroke (cr);
119 void
120 LED::set_visual_state (int32_t s)
122 if (s != _visual_state) {
124 _visual_state = s;
125 set_colors_from_style ();
129 void
130 LED::set_diameter (float d)
132 _diameter = (d*2) + 5.0;
134 if (_diameter != 0.0) {
135 _fixed_diameter = true;
138 set_dirty ();
141 void
142 LED::on_realize ()
144 set_colors_from_style ();
145 CairoWidget::on_realize ();
148 void
149 LED::on_size_request (Gtk::Requisition* req)
151 if (_fixed_diameter) {
152 req->width = _diameter;
153 req->height = _diameter;
154 } else {
155 CairoWidget::on_size_request (req);
159 void
160 LED::set_colors_from_style ()
162 RefPtr<Style> style = get_style();
163 Color c;
165 switch (_visual_state) {
166 case 0:
167 c = style->get_fg (STATE_NORMAL);
168 break;
169 default:
170 c = style->get_fg (STATE_ACTIVE);
171 break;
174 _red = c.get_red_p ();
175 _green = c.get_green_p ();
176 _blue = c.get_blue_p ();
178 set_dirty ();