2010-05-05 16:29:46 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2010-2012 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2010-05-05 16:29:46 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "led.h"
|
|
|
|
|
|
|
|
using namespace Gdk;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2011-10-31 21:22:08 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2010-05-05 16:29:46 -04:00
|
|
|
|
|
|
|
LED::LED()
|
2011-10-27 16:10:49 -04:00
|
|
|
: _diameter (0.0)
|
|
|
|
, _red (0.0)
|
|
|
|
, _green (1.0)
|
|
|
|
, _blue (0.0)
|
|
|
|
, _fixed_diameter (false)
|
2010-05-05 16:29:46 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LED::~LED()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-20 12:11:56 -04:00
|
|
|
LED::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
|
2010-05-05 16:29:46 -04:00
|
|
|
{
|
2017-03-20 12:11:56 -04:00
|
|
|
cairo_t* cr = ctx->cobj();
|
2011-10-27 16:10:49 -04:00
|
|
|
if (!_fixed_diameter) {
|
2011-11-18 10:35:58 -05:00
|
|
|
_diameter = std::min (get_width(), get_height());
|
2011-10-27 16:10:49 -04:00
|
|
|
}
|
2010-05-05 16:29:46 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
//background
|
2010-05-05 21:31:48 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
Widget* parent;
|
|
|
|
RefPtr<Style> style;
|
2022-08-10 20:14:28 -04:00
|
|
|
Gdk::Color c;
|
2010-05-05 22:48:59 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
parent = get_parent ();
|
2010-05-05 22:48:59 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
while (parent && !parent->get_has_window()) {
|
|
|
|
parent = parent->get_parent();
|
|
|
|
}
|
2010-05-05 21:31:48 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
if (parent && parent->get_has_window()) {
|
|
|
|
style = parent->get_style ();
|
|
|
|
c = style->get_bg (parent->get_state());
|
|
|
|
} else {
|
|
|
|
style = get_style ();
|
|
|
|
c = style->get_bg (get_state());
|
|
|
|
}
|
2010-05-05 22:48:59 -04:00
|
|
|
|
2011-10-26 17:01:14 -04:00
|
|
|
#if 0
|
2011-10-27 16:10:49 -04:00
|
|
|
cairo_rectangle(cr, 0, 0, _width, _height);
|
|
|
|
cairo_stroke_preserve(cr);
|
|
|
|
cairo_set_source_rgb(cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
|
|
|
|
cairo_fill(cr);
|
2011-10-26 17:01:14 -04:00
|
|
|
#endif
|
2010-05-05 16:29:46 -04:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
cairo_translate(cr, get_width()/2, get_height()/2);
|
2010-05-05 16:29:46 -04:00
|
|
|
|
|
|
|
//inset
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_pattern_add_color_stop_rgba (pat, 0, 0,0,0, 0.4);
|
|
|
|
cairo_pattern_add_color_stop_rgba (pat, 1, 1,1,1, 0.7);
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_arc (cr, 0, 0, _diameter/2, 0, 2 * M_PI);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_set_source (cr, pat);
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_pattern_destroy (pat);
|
|
|
|
|
|
|
|
//black ring
|
|
|
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_arc (cr, 0, 0, _diameter/2-2, 0, 2 * M_PI);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
//knob color
|
2012-02-07 12:43:55 -05:00
|
|
|
cairo_set_source_rgba (cr, _red, _green, _blue, (active_state() == Gtkmm2ext::ExplicitActive) ? 0.8 : 0.2);
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
//reflection
|
|
|
|
cairo_scale(cr, 0.7, 0.7);
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_pattern_t *pat2 = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
|
2011-10-27 07:24:43 -04:00
|
|
|
cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, active_state() ? 0.4 : 0.2);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_pattern_add_color_stop_rgba (pat2, 1, 1,1,1, 0.0);
|
2010-05-05 21:31:48 -04:00
|
|
|
cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
|
2010-05-05 16:29:46 -04:00
|
|
|
cairo_set_source (cr, pat2);
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_pattern_destroy (pat2);
|
|
|
|
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
2010-05-05 21:31:48 -04:00
|
|
|
void
|
|
|
|
LED::set_diameter (float d)
|
|
|
|
{
|
2011-10-27 16:10:49 -04:00
|
|
|
_diameter = (d*2) + 5.0;
|
2010-05-05 21:31:48 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
if (_diameter != 0.0) {
|
|
|
|
_fixed_diameter = true;
|
|
|
|
}
|
2010-05-05 21:31:48 -04:00
|
|
|
|
2011-10-27 16:10:49 -04:00
|
|
|
set_dirty ();
|
2010-05-05 21:31:48 -04:00
|
|
|
}
|
|
|
|
|
2010-05-06 14:40:37 -04:00
|
|
|
void
|
|
|
|
LED::on_realize ()
|
|
|
|
{
|
2011-10-27 16:10:49 -04:00
|
|
|
set_colors_from_style ();
|
|
|
|
CairoWidget::on_realize ();
|
2010-05-06 14:40:37 -04:00
|
|
|
}
|
|
|
|
|
2010-05-05 21:31:48 -04:00
|
|
|
void
|
|
|
|
LED::on_size_request (Gtk::Requisition* req)
|
|
|
|
{
|
2011-10-27 16:10:49 -04:00
|
|
|
if (_fixed_diameter) {
|
|
|
|
req->width = _diameter;
|
|
|
|
req->height = _diameter;
|
|
|
|
} else {
|
|
|
|
CairoWidget::on_size_request (req);
|
|
|
|
}
|
2010-05-05 21:31:48 -04:00
|
|
|
}
|
2010-05-06 14:40:37 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
LED::set_colors_from_style ()
|
|
|
|
{
|
2011-10-27 16:10:49 -04:00
|
|
|
RefPtr<Style> style = get_style();
|
2022-08-10 20:14:28 -04:00
|
|
|
Gdk::Color c;
|
2011-10-27 16:10:49 -04:00
|
|
|
|
|
|
|
switch (_visual_state) {
|
2011-11-21 12:03:06 -05:00
|
|
|
case VisualState(0):
|
2011-10-27 16:10:49 -04:00
|
|
|
c = style->get_fg (STATE_NORMAL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c = style->get_fg (STATE_ACTIVE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_red = c.get_red_p ();
|
|
|
|
_green = c.get_green_p ();
|
|
|
|
_blue = c.get_blue_p ();
|
|
|
|
|
|
|
|
set_dirty ();
|
2010-05-06 14:40:37 -04:00
|
|
|
}
|