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.
29 using namespace Gtkmm2ext;
36 , _fixed_diameter (false)
45 LED::render (cairo_t* cr, cairo_rectangle_t*)
47 if (!_fixed_diameter) {
48 _diameter = std::min (get_width(), get_height());
57 parent = get_parent ();
59 while (parent && !parent->get_has_window()) {
60 parent = parent->get_parent();
63 if (parent && parent->get_has_window()) {
64 style = parent->get_style ();
65 c = style->get_bg (parent->get_state());
68 c = style->get_bg (get_state());
72 cairo_rectangle(cr, 0, 0, _width, _height);
73 cairo_stroke_preserve(cr);
74 cairo_set_source_rgb(cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
78 cairo_translate(cr, get_width()/2, get_height()/2);
81 cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
82 cairo_pattern_add_color_stop_rgba (pat, 0, 0,0,0, 0.4);
83 cairo_pattern_add_color_stop_rgba (pat, 1, 1,1,1, 0.7);
84 cairo_arc (cr, 0, 0, _diameter/2, 0, 2 * M_PI);
85 cairo_set_source (cr, pat);
87 cairo_pattern_destroy (pat);
90 cairo_set_source_rgb (cr, 0, 0, 0);
91 cairo_arc (cr, 0, 0, _diameter/2-2, 0, 2 * M_PI);
95 cairo_set_source_rgba (cr, _red, _green, _blue, (active_state() == Gtkmm2ext::ExplicitActive) ? 0.8 : 0.2);
96 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
100 cairo_scale(cr, 0.7, 0.7);
101 cairo_pattern_t *pat2 = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
102 cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, active_state() ? 0.4 : 0.2);
103 cairo_pattern_add_color_stop_rgba (pat2, 1, 1,1,1, 0.0);
104 cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
105 cairo_set_source (cr, pat2);
107 cairo_pattern_destroy (pat2);
113 LED::set_diameter (float d)
115 _diameter = (d*2) + 5.0;
117 if (_diameter != 0.0) {
118 _fixed_diameter = true;
127 set_colors_from_style ();
128 CairoWidget::on_realize ();
132 LED::on_size_request (Gtk::Requisition* req)
134 if (_fixed_diameter) {
135 req->width = _diameter;
136 req->height = _diameter;
138 CairoWidget::on_size_request (req);
143 LED::set_colors_from_style ()
145 RefPtr<Style> style = get_style();
148 switch (_visual_state) {
150 c = style->get_fg (STATE_NORMAL);
153 c = style->get_fg (STATE_ACTIVE);
157 _red = c.get_red_p ();
158 _green = c.get_green_p ();
159 _blue = c.get_blue_p ();