2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2014-09-01 16:02:51 -04:00
|
|
|
Copyright (C) 2006 Paul Davis
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id: fastmeter.h 570 2006-06-07 21:21:21Z sampo $
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2014-09-01 16:02:51 -04:00
|
|
|
#include <assert.h>
|
2013-01-16 21:32:48 -05:00
|
|
|
|
2013-01-24 16:58:07 -05:00
|
|
|
#include "pbd/stacktrace.h"
|
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2009-12-10 18:01:45 -05:00
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2012-12-07 17:38:49 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
#include "widgets/ardour_fader.h"
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
2017-07-16 16:13:46 -04:00
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace ArdourWidgets;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-09-03 09:35:11 -04:00
|
|
|
#define CORNER_RADIUS 2.5
|
2014-01-05 07:07:31 -05:00
|
|
|
#define CORNER_SIZE 2
|
|
|
|
#define CORNER_OFFSET 1
|
2014-09-03 09:35:11 -04:00
|
|
|
#define FADER_RESERVE 6
|
2012-12-07 17:38:49 -05:00
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
std::list<ArdourFader::FaderImage*> ArdourFader::_patterns;
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::ArdourFader (Gtk::Adjustment& adj, int orientation, int fader_length, int fader_girth)
|
2014-09-04 20:24:19 -04:00
|
|
|
: _layout (0)
|
|
|
|
, _tweaks (Tweaks(0))
|
|
|
|
, _adjustment (adj)
|
|
|
|
, _text_width (0)
|
|
|
|
, _text_height (0)
|
2014-09-01 22:46:34 -04:00
|
|
|
, _span (fader_length)
|
|
|
|
, _girth (fader_girth)
|
2014-09-02 10:00:24 -04:00
|
|
|
, _min_span (fader_length)
|
|
|
|
, _min_girth (fader_girth)
|
2013-01-10 10:25:11 -05:00
|
|
|
, _orien (orientation)
|
2014-09-01 22:46:34 -04:00
|
|
|
, _pattern (0)
|
2013-01-11 13:33:57 -05:00
|
|
|
, _hovering (false)
|
2014-09-01 22:46:34 -04:00
|
|
|
, _dragging (false)
|
|
|
|
, _centered_text (true)
|
2014-08-29 22:16:18 -04:00
|
|
|
, _current_parent (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-04 20:24:19 -04:00
|
|
|
_default_value = _adjustment.get_value();
|
2013-01-11 13:33:57 -05:00
|
|
|
update_unity_position ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
add_events (
|
|
|
|
Gdk::BUTTON_PRESS_MASK
|
|
|
|
| Gdk::BUTTON_RELEASE_MASK
|
|
|
|
| Gdk::POINTER_MOTION_MASK
|
|
|
|
| Gdk::SCROLL_MASK
|
|
|
|
| Gdk::ENTER_NOTIFY_MASK
|
|
|
|
| Gdk::LEAVE_NOTIFY_MASK
|
|
|
|
);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
_adjustment.signal_value_changed().connect (mem_fun (*this, &ArdourFader::adjustment_changed));
|
|
|
|
_adjustment.signal_changed().connect (mem_fun (*this, &ArdourFader::adjustment_changed));
|
|
|
|
signal_grab_broken_event ().connect (mem_fun (*this, &ArdourFader::on_grab_broken_event));
|
2014-01-03 23:29:06 -05:00
|
|
|
if (_orien == VERT) {
|
2014-10-27 21:18:46 -04:00
|
|
|
CairoWidget::set_size_request(_girth, _span);
|
2014-01-03 23:29:06 -05:00
|
|
|
} else {
|
2014-10-27 21:18:46 -04:00
|
|
|
CairoWidget::set_size_request(_span, _girth);
|
2014-01-03 23:29:06 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::~ArdourFader ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-08-30 14:58:03 -04:00
|
|
|
if (_parent_style_change) _parent_style_change.disconnect();
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_layout) _layout.clear (); // drop reference to existing layout
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2015-09-12 14:05:25 -04:00
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::flush_pattern_cache () {
|
2015-09-12 14:05:25 -04:00
|
|
|
for (list<FaderImage*>::iterator f = _patterns.begin(); f != _patterns.end(); ++f) {
|
|
|
|
cairo_pattern_destroy ((*f)->pattern);
|
|
|
|
}
|
|
|
|
_patterns.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_pattern_t*
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::find_pattern (double afr, double afg, double afb,
|
2014-09-01 16:02:51 -04:00
|
|
|
double abr, double abg, double abb,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
for (list<FaderImage*>::iterator f = _patterns.begin(); f != _patterns.end(); ++f) {
|
|
|
|
if ((*f)->matches (afr, afg, afb, abr, abg, abb, w, h)) {
|
|
|
|
return (*f)->pattern;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::create_patterns ()
|
2014-09-01 16:02:51 -04:00
|
|
|
{
|
|
|
|
Gdk::Color c = get_style()->get_fg (get_state());
|
|
|
|
float fr, fg, fb;
|
|
|
|
float br, bg, bb;
|
|
|
|
|
|
|
|
fr = c.get_red_p ();
|
|
|
|
fg = c.get_green_p ();
|
|
|
|
fb = c.get_blue_p ();
|
|
|
|
|
|
|
|
c = get_style()->get_bg (get_state());
|
|
|
|
|
|
|
|
br = c.get_red_p ();
|
|
|
|
bg = c.get_green_p ();
|
|
|
|
bb = c.get_blue_p ();
|
|
|
|
|
|
|
|
cairo_surface_t* surface;
|
|
|
|
cairo_t* tc = 0;
|
|
|
|
|
|
|
|
if (get_width() <= 1 || get_height() <= 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if ((_pattern = find_pattern (fr, fg, fb, br, bg, bb, get_width(), get_height())) != 0) {
|
2014-09-01 16:02:51 -04:00
|
|
|
/* found it - use it */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_orien == VERT) {
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, get_width(), get_height() * 2.0);
|
|
|
|
tc = cairo_create (surface);
|
|
|
|
|
|
|
|
/* paint background + border */
|
|
|
|
|
|
|
|
cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, get_width(), 0);
|
2014-09-02 16:58:55 -04:00
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, br*0.4,bg*0.4,bb*0.4, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0.25, br*0.6,bg*0.6,bb*0.6, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, br*0.8,bg*0.8,bb*0.8, 1.0);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_set_source (tc, shade_pattern);
|
|
|
|
cairo_rectangle (tc, 0, 0, get_width(), get_height() * 2.0);
|
|
|
|
cairo_fill (tc);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
|
|
|
/* paint lower shade */
|
|
|
|
|
|
|
|
shade_pattern = cairo_pattern_create_linear (0.0, 0.0, get_width() - 2 - CORNER_OFFSET , 0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, fr*0.8,fg*0.8,fb*0.8, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, fr*0.6,fg*0.6,fb*0.6, 1.0);
|
|
|
|
cairo_set_source (tc, shade_pattern);
|
|
|
|
Gtkmm2ext::rounded_top_half_rectangle (tc, CORNER_OFFSET, get_height() + CORNER_OFFSET,
|
|
|
|
get_width() - CORNER_SIZE, get_height(), CORNER_RADIUS);
|
|
|
|
cairo_fill (tc);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
_pattern = cairo_pattern_create_for_surface (surface);
|
2014-09-01 16:02:51 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, get_width() * 2.0, get_height());
|
|
|
|
tc = cairo_create (surface);
|
|
|
|
|
|
|
|
/* paint right shade (background section)*/
|
|
|
|
|
|
|
|
cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height());
|
2014-09-02 16:58:55 -04:00
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, br*0.4,bg*0.4,bb*0.4, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0.25, br*0.6,bg*0.6,bb*0.6, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, br*0.8,bg*0.8,bb*0.8, 1.0);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_set_source (tc, shade_pattern);
|
|
|
|
cairo_rectangle (tc, 0, 0, get_width() * 2.0, get_height());
|
|
|
|
cairo_fill (tc);
|
|
|
|
|
|
|
|
/* paint left shade (active section/foreground) */
|
|
|
|
|
|
|
|
shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, get_height());
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, fr*0.8,fg*0.8,fb*0.8, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, fr*0.6,fg*0.6,fb*0.6, 1.0);
|
|
|
|
cairo_set_source (tc, shade_pattern);
|
|
|
|
Gtkmm2ext::rounded_right_half_rectangle (tc, CORNER_OFFSET, CORNER_OFFSET,
|
|
|
|
get_width() - CORNER_OFFSET, get_height() - CORNER_SIZE, CORNER_RADIUS);
|
|
|
|
cairo_fill (tc);
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
_pattern = cairo_pattern_create_for_surface (surface);
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cache it for others to use */
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
_patterns.push_back (new FaderImage (_pattern, fr, fg, fb, br, bg, bb, get_width(), get_height()));
|
2014-09-01 16:02:51 -04:00
|
|
|
|
|
|
|
cairo_destroy (tc);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
2014-10-27 21:18:46 -04:00
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* area)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2017-03-20 12:11:56 -04:00
|
|
|
cairo_t* cr = ctx->cobj();
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if (!_pattern) {
|
2014-09-01 16:02:51 -04:00
|
|
|
create_patterns();
|
|
|
|
}
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if (!_pattern) {
|
2014-09-01 16:02:51 -04:00
|
|
|
/* this isn't supposed to be happen, but some wackiness whereby
|
|
|
|
* the pixfader ends up with a 1xN or Nx1 size allocation
|
|
|
|
* leads to it. the basic wackiness needs fixing but we
|
|
|
|
* shouldn't crash. just fill in the expose area with
|
|
|
|
* our bg color.
|
|
|
|
*/
|
2014-08-29 22:16:18 -04:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_bg (get_state()), 1);
|
2014-10-27 21:18:46 -04:00
|
|
|
cairo_rectangle (cr, area->x, area->y, area->width, area->height);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_fill (cr);
|
2014-10-27 21:18:46 -04:00
|
|
|
return;
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
2013-01-24 08:15:20 -05:00
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
OnExpose();
|
2014-09-01 16:02:51 -04:00
|
|
|
int ds = display_span ();
|
|
|
|
const float w = get_width();
|
|
|
|
const float h = get_height();
|
2012-12-07 17:38:49 -05:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, get_parent_bg(), 1);
|
2014-01-05 07:07:31 -05:00
|
|
|
cairo_rectangle (cr, 0, 0, w, h);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
2014-09-02 10:00:24 -04:00
|
|
|
cairo_set_line_width (cr, 2);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 1.0);
|
|
|
|
|
|
|
|
cairo_matrix_t matrix;
|
2014-09-03 14:01:11 -04:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET, w-CORNER_SIZE, h-CORNER_SIZE, CORNER_RADIUS);
|
2014-09-02 10:00:24 -04:00
|
|
|
// we use a 'trick' here: The stoke is off by .5px but filling the interior area
|
|
|
|
// after a stroke of 2px width results in an outline of 1px
|
2014-09-03 14:01:11 -04:00
|
|
|
cairo_stroke_preserve(cr);
|
2009-12-04 12:45:11 -05:00
|
|
|
|
|
|
|
if (_orien == VERT) {
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
if (ds > h - FADER_RESERVE - CORNER_OFFSET) {
|
|
|
|
ds = h - FADER_RESERVE - CORNER_OFFSET;
|
2014-08-27 12:58:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CairoWidget::flat_buttons() ) {
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_set_source (cr, _pattern);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_matrix_init_translate (&matrix, 0, (h - ds));
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_pattern_set_matrix (_pattern, &matrix);
|
2014-09-01 16:02:51 -04:00
|
|
|
} else {
|
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_bg (get_state()), 1);
|
2014-08-27 12:58:09 -04:00
|
|
|
cairo_fill (cr);
|
2014-09-01 16:02:51 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_fg (get_state()), 1);
|
|
|
|
Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, ds + CORNER_OFFSET,
|
|
|
|
w - CORNER_SIZE, h - ds - CORNER_SIZE, CORNER_RADIUS);
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2009-12-04 12:45:11 -05:00
|
|
|
} else {
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
if (ds < FADER_RESERVE) {
|
|
|
|
ds = FADER_RESERVE;
|
2014-08-27 12:58:09 -04:00
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
assert(ds <= w);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if ds == w, the pattern does not need to be translated
|
|
|
|
* if ds == 0 (or FADER_RESERVE), the pattern needs to be moved
|
|
|
|
* w to the left, which is -w in pattern space, and w in user space
|
|
|
|
* if ds == 10, then the pattern needs to be moved w - 10
|
|
|
|
* to the left, which is -(w-10) in pattern space, which
|
|
|
|
* is (w - 10) in user space
|
|
|
|
* thus: translation = (w - ds)
|
|
|
|
*/
|
2014-08-27 12:58:09 -04:00
|
|
|
|
|
|
|
if (!CairoWidget::flat_buttons() ) {
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_set_source (cr, _pattern);
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_matrix_init_translate (&matrix, w - ds, 0);
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_pattern_set_matrix (_pattern, &matrix);
|
2014-09-01 16:02:51 -04:00
|
|
|
} else {
|
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_bg (get_state()), 1);
|
2014-08-27 12:58:09 -04:00
|
|
|
cairo_fill (cr);
|
2014-09-01 16:02:51 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_fg (get_state()), 1);
|
|
|
|
Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET,
|
2014-09-02 10:00:24 -04:00
|
|
|
ds - CORNER_SIZE, h - CORNER_SIZE, CORNER_RADIUS);
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
cairo_fill (cr);
|
2012-12-07 17:38:49 -05:00
|
|
|
}
|
2014-08-27 12:58:09 -04:00
|
|
|
|
2012-12-10 15:08:36 -05:00
|
|
|
/* draw the unity-position line if it's not at either end*/
|
2014-09-04 20:24:19 -04:00
|
|
|
if (!(_tweaks & NoShowUnityLine) && _unity_loc > CORNER_RADIUS) {
|
2014-10-27 21:18:46 -04:00
|
|
|
cairo_set_line_width(cr, 1);
|
|
|
|
cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
|
2013-07-09 18:02:17 -04:00
|
|
|
Gdk::Color c = get_style()->get_fg (Gtk::STATE_ACTIVE);
|
2014-10-27 21:18:46 -04:00
|
|
|
cairo_set_source_rgba (cr, c.get_red_p() * 1.5, c.get_green_p() * 1.5, c.get_blue_p() * 1.5, 0.85);
|
2014-09-02 10:00:24 -04:00
|
|
|
if (_orien == VERT) {
|
|
|
|
if (_unity_loc < h - CORNER_RADIUS) {
|
2014-10-27 21:18:46 -04:00
|
|
|
cairo_move_to (cr, 1.5, _unity_loc + CORNER_OFFSET + .5);
|
|
|
|
cairo_line_to (cr, _girth - 1.5, _unity_loc + CORNER_OFFSET + .5);
|
|
|
|
cairo_stroke (cr);
|
2013-01-10 11:25:31 -05:00
|
|
|
}
|
2013-07-09 18:02:17 -04:00
|
|
|
} else {
|
2014-09-02 10:00:24 -04:00
|
|
|
if (_unity_loc < w - CORNER_RADIUS) {
|
2014-10-27 21:18:46 -04:00
|
|
|
cairo_move_to (cr, _unity_loc - CORNER_OFFSET + .5, 1.5);
|
|
|
|
cairo_line_to (cr, _unity_loc - CORNER_OFFSET + .5, _girth - 1.5);
|
|
|
|
cairo_stroke (cr);
|
2013-01-10 11:25:31 -05:00
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-08-27 12:58:09 -04:00
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_layout && !_text.empty() && _orien == HORIZ) {
|
|
|
|
cairo_save (cr);
|
|
|
|
if (_centered_text) {
|
|
|
|
/* center text */
|
|
|
|
cairo_move_to (cr, (w - _text_width)/2.0, h/2.0 - _text_height/2.0);
|
|
|
|
} else if (ds > .5 * w) {
|
|
|
|
cairo_move_to (cr, CORNER_OFFSET + 3, h/2.0 - _text_height/2.0);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_XOR);
|
|
|
|
} else {
|
|
|
|
cairo_move_to (cr, w - _text_width - CORNER_OFFSET - 3, h/2.0 - _text_height/2.0);
|
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, get_style()->get_text (get_state()), 1);
|
2012-12-10 15:08:36 -05:00
|
|
|
pango_cairo_show_layout (cr, _layout->gobj());
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_restore (cr);
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
|
|
|
|
2013-07-12 13:07:07 -04:00
|
|
|
if (!get_sensitive()) {
|
2014-01-05 07:07:31 -05:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET, w-CORNER_SIZE, h-CORNER_SIZE, CORNER_RADIUS);
|
2013-07-12 13:07:07 -04:00
|
|
|
cairo_set_source_rgba (cr, 0.505, 0.517, 0.525, 0.4);
|
|
|
|
cairo_fill (cr);
|
2015-01-27 20:22:52 -05:00
|
|
|
} else if (_hovering && CairoWidget::widget_prelight()) {
|
2014-01-05 07:07:31 -05:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET, w-CORNER_SIZE, h-CORNER_SIZE, CORNER_RADIUS);
|
2013-07-12 13:07:07 -04:00
|
|
|
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.1);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_size_request (GtkRequisition* req)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2013-01-10 10:25:11 -05:00
|
|
|
if (_orien == VERT) {
|
2014-09-02 10:00:24 -04:00
|
|
|
req->width = (_min_girth ? _min_girth : -1);
|
|
|
|
req->height = (_min_span ? _min_span : -1);
|
2013-01-10 10:25:11 -05:00
|
|
|
} else {
|
2014-09-02 10:00:24 -04:00
|
|
|
req->height = (_min_girth ? _min_girth : -1);
|
|
|
|
req->width = (_min_span ? _min_span : -1);
|
2013-01-10 10:25:11 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_size_allocate (Gtk::Allocation& alloc)
|
2012-12-07 17:38:49 -05:00
|
|
|
{
|
2016-02-28 11:15:53 -05:00
|
|
|
int old_girth = _girth;
|
|
|
|
int old_span = _span;
|
|
|
|
|
2014-10-27 21:18:46 -04:00
|
|
|
CairoWidget::on_size_allocate(alloc);
|
2013-01-10 10:25:11 -05:00
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
if (_orien == VERT) {
|
2014-09-01 22:46:34 -04:00
|
|
|
_girth = alloc.get_width ();
|
|
|
|
_span = alloc.get_height ();
|
2012-12-07 17:38:49 -05:00
|
|
|
} else {
|
2014-09-01 22:46:34 -04:00
|
|
|
_girth = alloc.get_height ();
|
|
|
|
_span = alloc.get_width ();
|
2012-12-07 17:38:49 -05:00
|
|
|
}
|
|
|
|
|
2016-02-28 11:15:53 -05:00
|
|
|
if (is_realized() && ((old_girth != _girth) || (old_span != _span))) {
|
2014-09-01 16:02:51 -04:00
|
|
|
/* recreate patterns in case we've changed size */
|
|
|
|
create_patterns ();
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
update_unity_position ();
|
|
|
|
}
|
|
|
|
|
2015-06-07 09:07:56 -04:00
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_grab_broken_event (GdkEventGrabBroken* ev)
|
2015-06-07 09:07:56 -04:00
|
|
|
{
|
|
|
|
if (_dragging) {
|
|
|
|
remove_modal_grab();
|
|
|
|
_dragging = false;
|
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
StopGesture ();
|
|
|
|
}
|
|
|
|
return (_tweaks & NoButtonForward) ? true : false;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_button_press_event (GdkEventButton* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-01-10 19:03:12 -05:00
|
|
|
if (ev->type != GDK_BUTTON_PRESS) {
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_dragging) {
|
|
|
|
remove_modal_grab();
|
|
|
|
_dragging = false;
|
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
|
|
|
StopGesture ();
|
|
|
|
}
|
2014-09-04 20:24:19 -04:00
|
|
|
return (_tweaks & NoButtonForward) ? true : false;
|
2011-01-10 19:03:12 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2011-01-29 20:39:57 -05:00
|
|
|
if (ev->button != 1 && ev->button != 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_modal_grab ();
|
2014-09-01 22:46:34 -04:00
|
|
|
StartGesture ();
|
|
|
|
_grab_loc = (_orien == VERT) ? ev->y : ev->x;
|
|
|
|
_grab_start = (_orien == VERT) ? ev->y : ev->x;
|
|
|
|
_grab_window = ev->window;
|
|
|
|
_dragging = true;
|
2013-01-04 11:02:12 -05:00
|
|
|
gdk_pointer_grab(ev->window,false,
|
|
|
|
GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
|
|
|
|
NULL,NULL,ev->time);
|
2011-01-29 20:39:57 -05:00
|
|
|
|
|
|
|
if (ev->button == 2) {
|
|
|
|
set_adjustment_from_event (ev);
|
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2014-09-04 20:24:19 -04:00
|
|
|
return (_tweaks & NoButtonForward) ? true : false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_button_release_event (GdkEventButton* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-02 10:00:24 -04:00
|
|
|
double ev_pos = (_orien == VERT) ? ev->y : ev->x;
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_dragging) {
|
2008-06-02 17:41:35 -04:00
|
|
|
remove_modal_grab();
|
2014-09-01 22:46:34 -04:00
|
|
|
_dragging = false;
|
2013-01-04 11:02:12 -05:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
2014-09-01 22:46:34 -04:00
|
|
|
StopGesture ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-12-10 16:52:55 -05:00
|
|
|
if (!_hovering) {
|
2014-09-06 06:46:03 -04:00
|
|
|
if (!(_tweaks & NoVerticalScroll)) {
|
|
|
|
Keyboard::magic_widget_drop_focus();
|
|
|
|
}
|
2012-12-10 16:52:55 -05:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if (ev_pos == _grab_start) {
|
2008-06-02 17:41:35 -04:00
|
|
|
/* no motion - just a click */
|
2014-09-02 10:00:24 -04:00
|
|
|
ev_pos = rint(ev_pos);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-10 18:01:45 -05:00
|
|
|
if (ev->state & Keyboard::TertiaryModifier) {
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (_default_value);
|
2012-05-31 14:04:47 -04:00
|
|
|
} else if (ev->state & Keyboard::GainFineScaleModifier) {
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (_adjustment.get_lower());
|
2014-11-29 11:31:41 -05:00
|
|
|
#if 0 // ignore clicks
|
2014-09-02 10:00:24 -04:00
|
|
|
} else if (ev_pos == slider_pos) {
|
2014-09-01 22:46:34 -04:00
|
|
|
; // click on current position, no move.
|
2014-09-02 10:00:24 -04:00
|
|
|
} else if ((_orien == VERT && ev_pos < slider_pos) || (_orien == HORIZ && ev_pos > slider_pos)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
/* above the current display height, remember X Window coords */
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (_adjustment.get_value() + _adjustment.get_step_increment());
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (_adjustment.get_value() - _adjustment.get_step_increment());
|
2014-11-29 11:31:41 -05:00
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 21:41:11 -05:00
|
|
|
return true;
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
case 2:
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_dragging) {
|
2008-06-02 17:41:35 -04:00
|
|
|
remove_modal_grab();
|
2014-09-01 22:46:34 -04:00
|
|
|
_dragging = false;
|
|
|
|
StopGesture ();
|
2011-01-29 20:39:57 -05:00
|
|
|
set_adjustment_from_event (ev);
|
2013-01-04 11:02:12 -05:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
2013-01-16 21:41:11 -05:00
|
|
|
return true;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_scroll_event (GdkEventScroll* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2017-09-24 15:20:20 -04:00
|
|
|
double increment = 0;
|
2012-05-31 14:04:47 -04:00
|
|
|
if (ev->state & Keyboard::GainFineScaleModifier) {
|
|
|
|
if (ev->state & Keyboard::GainExtraFineScaleModifier) {
|
2017-09-24 15:20:20 -04:00
|
|
|
increment = 0.05 * _adjustment.get_step_increment();
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
2017-09-24 15:20:20 -04:00
|
|
|
increment = _adjustment.get_step_increment();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
} else {
|
2017-09-24 15:20:20 -04:00
|
|
|
increment = _adjustment.get_page_increment();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2017-09-24 15:37:19 -04:00
|
|
|
bool vertical = false;
|
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
vertical = !(ev->state & Keyboard::ScrollHorizontalModifier);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((_orien == VERT && !vertical) ||
|
|
|
|
((_tweaks & NoVerticalScroll) && vertical)) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-09-24 15:37:19 -04:00
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
case GDK_SCROLL_RIGHT:
|
|
|
|
_adjustment.set_value (_adjustment.get_value() + increment);
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
case GDK_SCROLL_LEFT:
|
|
|
|
_adjustment.set_value (_adjustment.get_value() - increment);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2017-09-24 15:37:19 -04:00
|
|
|
|
|
|
|
return true;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_motion_notify_event (GdkEventMotion* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_dragging) {
|
2011-01-29 20:39:47 -05:00
|
|
|
double scale = 1.0;
|
|
|
|
double const ev_pos = (_orien == VERT) ? ev->y : ev->x;
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
if (ev->window != _grab_window) {
|
|
|
|
_grab_loc = ev_pos;
|
|
|
|
_grab_window = ev->window;
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2012-05-31 14:04:47 -04:00
|
|
|
if (ev->state & Keyboard::GainFineScaleModifier) {
|
|
|
|
if (ev->state & Keyboard::GainExtraFineScaleModifier) {
|
2014-11-30 15:26:55 -05:00
|
|
|
scale = 0.005;
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
|
|
|
scale = 0.1;
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 20:39:47 -05:00
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
double const delta = ev_pos - _grab_loc;
|
|
|
|
_grab_loc = ev_pos;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-12-01 11:36:17 -05:00
|
|
|
const double off = FADER_RESERVE + ((_orien == VERT) ? CORNER_OFFSET : 0);
|
|
|
|
const double span = _span - off;
|
|
|
|
double fract = (delta / span);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
fract = min (1.0, fract);
|
|
|
|
fract = max (-1.0, fract);
|
|
|
|
|
|
|
|
// X Window is top->bottom for 0..Y
|
2014-09-01 16:02:51 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (_orien == VERT) {
|
|
|
|
fract = -fract;
|
|
|
|
}
|
|
|
|
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (_adjustment.get_value() + scale * fract * (_adjustment.get_upper() - _adjustment.get_lower()));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::adjustment_changed ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-12-05 15:16:54 -05:00
|
|
|
queue_draw ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-12-04 12:45:11 -05:00
|
|
|
/** @return pixel offset of the current value from the right or bottom of the fader */
|
2014-09-01 16:02:51 -04:00
|
|
|
int
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::display_span ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-09-04 20:24:19 -04:00
|
|
|
float fract = (_adjustment.get_value () - _adjustment.get_lower()) / ((_adjustment.get_upper() - _adjustment.get_lower()));
|
2014-09-01 16:02:51 -04:00
|
|
|
int ds;
|
|
|
|
if (_orien == VERT) {
|
2014-12-01 11:36:17 -05:00
|
|
|
const double off = FADER_RESERVE + CORNER_OFFSET;
|
|
|
|
const double span = _span - off;
|
|
|
|
ds = (int)rint (span * (1.0 - fract));
|
2014-09-01 16:02:51 -04:00
|
|
|
} else {
|
2014-12-01 11:36:17 -05:00
|
|
|
const double off = FADER_RESERVE;
|
|
|
|
const double span = _span - off;
|
|
|
|
ds = (int)rint (span * fract + off);
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ds;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-08-03 14:41:16 -04:00
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::update_unity_position ()
|
2011-08-03 14:41:16 -04:00
|
|
|
{
|
|
|
|
if (_orien == VERT) {
|
2014-12-01 11:36:17 -05:00
|
|
|
const double span = _span - FADER_RESERVE - CORNER_OFFSET;
|
|
|
|
_unity_loc = (int) rint (span * (1 - ((_default_value - _adjustment.get_lower()) / (_adjustment.get_upper() - _adjustment.get_lower())))) - 1;
|
2011-08-03 14:41:16 -04:00
|
|
|
} else {
|
2014-12-01 11:36:17 -05:00
|
|
|
const double span = _span - FADER_RESERVE;
|
|
|
|
_unity_loc = (int) rint (FADER_RESERVE + (_default_value - _adjustment.get_lower()) * span / (_adjustment.get_upper() - _adjustment.get_lower()));
|
2009-12-04 12:45:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
2009-12-10 18:01:45 -05:00
|
|
|
|
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_enter_notify_event (GdkEventCrossing*)
|
2009-12-10 18:01:45 -05:00
|
|
|
{
|
2012-12-07 17:38:49 -05:00
|
|
|
_hovering = true;
|
2014-09-06 06:46:03 -04:00
|
|
|
if (!(_tweaks & NoVerticalScroll)) {
|
|
|
|
Keyboard::magic_widget_grab_focus ();
|
|
|
|
}
|
2012-12-07 17:38:49 -05:00
|
|
|
queue_draw ();
|
2009-12-10 18:01:45 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_leave_notify_event (GdkEventCrossing*)
|
2009-12-10 18:01:45 -05:00
|
|
|
{
|
2014-09-01 22:46:34 -04:00
|
|
|
if (!_dragging) {
|
2012-12-10 16:52:55 -05:00
|
|
|
_hovering = false;
|
2014-09-06 06:46:03 -04:00
|
|
|
if (!(_tweaks & NoVerticalScroll)) {
|
|
|
|
Keyboard::magic_widget_drop_focus();
|
|
|
|
}
|
2012-12-10 16:52:55 -05:00
|
|
|
queue_draw ();
|
|
|
|
}
|
2009-12-10 18:01:45 -05:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-29 20:39:57 -05:00
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::set_adjustment_from_event (GdkEventButton* ev)
|
2011-01-29 20:39:57 -05:00
|
|
|
{
|
2014-12-01 11:36:17 -05:00
|
|
|
const double off = FADER_RESERVE + ((_orien == VERT) ? CORNER_OFFSET : 0);
|
|
|
|
const double span = _span - off;
|
|
|
|
double fract = (_orien == VERT) ? (1.0 - ((ev->y - off) / span)) : ((ev->x - off) / span);
|
2011-01-29 20:39:57 -05:00
|
|
|
|
|
|
|
fract = min (1.0, fract);
|
|
|
|
fract = max (0.0, fract);
|
|
|
|
|
2014-09-04 20:24:19 -04:00
|
|
|
_adjustment.set_value (fract * (_adjustment.get_upper () - _adjustment.get_lower ()));
|
2011-01-29 20:39:57 -05:00
|
|
|
}
|
2011-08-03 14:41:16 -04:00
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::set_default_value (float d)
|
2011-08-03 14:41:16 -04:00
|
|
|
{
|
2014-09-01 22:46:34 -04:00
|
|
|
_default_value = d;
|
2011-08-03 14:41:16 -04:00
|
|
|
update_unity_position ();
|
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::set_tweaks (Tweaks t)
|
2014-09-02 10:00:24 -04:00
|
|
|
{
|
2014-09-04 20:24:19 -04:00
|
|
|
bool need_redraw = false;
|
|
|
|
if ((_tweaks & NoShowUnityLine) ^ (t & NoShowUnityLine)) {
|
|
|
|
need_redraw = true;
|
|
|
|
}
|
|
|
|
_tweaks = t;
|
|
|
|
if (need_redraw) {
|
|
|
|
queue_draw();
|
|
|
|
}
|
2014-09-02 10:00:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::set_text (const std::string& str, bool centered, bool expose)
|
2012-12-10 15:08:36 -05:00
|
|
|
{
|
2014-09-01 22:46:34 -04:00
|
|
|
if (_layout && _text == str) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_layout && !str.empty()) {
|
2012-12-10 15:08:36 -05:00
|
|
|
_layout = Pango::Layout::create (get_pango_context());
|
2014-09-01 16:02:51 -04:00
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
|
2014-09-01 22:46:34 -04:00
|
|
|
_text = str;
|
|
|
|
_centered_text = centered;
|
2012-12-10 15:08:36 -05:00
|
|
|
if (_layout) {
|
|
|
|
_layout->set_text (str);
|
2013-01-17 17:33:08 -05:00
|
|
|
_layout->get_pixel_size (_text_width, _text_height);
|
2014-09-02 10:00:24 -04:00
|
|
|
// queue_resize ();
|
|
|
|
if (expose) queue_draw ();
|
2012-12-10 15:08:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_state_changed (Gtk::StateType old_state)
|
2013-01-11 13:33:57 -05:00
|
|
|
{
|
|
|
|
Widget::on_state_changed (old_state);
|
2014-09-01 16:02:51 -04:00
|
|
|
create_patterns ();
|
2014-01-05 07:07:31 -05:00
|
|
|
queue_draw ();
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2013-01-21 11:10:39 -05:00
|
|
|
|
|
|
|
void
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
|
2013-01-21 11:10:39 -05:00
|
|
|
{
|
|
|
|
if (_layout) {
|
|
|
|
std::string txt = _layout->get_text();
|
|
|
|
_layout.clear (); // drop reference to existing layout
|
2014-09-01 22:46:34 -04:00
|
|
|
_text = "";
|
2014-09-02 10:00:24 -04:00
|
|
|
set_text (txt, _centered_text, false);
|
2013-01-21 11:10:39 -05:00
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
/* patterns are cached and re-created as needed
|
2014-09-01 16:02:51 -04:00
|
|
|
* during 'expose' in the GUI thread */
|
2014-09-01 22:46:34 -04:00
|
|
|
_pattern = 0;
|
2014-01-05 07:07:31 -05:00
|
|
|
queue_draw ();
|
2013-01-21 11:10:39 -05:00
|
|
|
}
|
2014-08-29 22:16:18 -04:00
|
|
|
|
|
|
|
Gdk::Color
|
2017-07-16 16:13:46 -04:00
|
|
|
ArdourFader::get_parent_bg ()
|
2014-08-29 22:16:18 -04:00
|
|
|
{
|
2014-09-01 16:02:51 -04:00
|
|
|
Widget* parent = get_parent ();
|
2014-08-29 22:16:18 -04:00
|
|
|
|
|
|
|
while (parent) {
|
2014-09-01 16:02:51 -04:00
|
|
|
if (parent->get_has_window()) {
|
2014-08-29 22:16:18 -04:00
|
|
|
break;
|
|
|
|
}
|
2014-09-01 16:02:51 -04:00
|
|
|
parent = parent->get_parent();
|
2014-08-29 22:16:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent && parent->get_has_window()) {
|
|
|
|
if (_current_parent != parent) {
|
|
|
|
if (_parent_style_change) _parent_style_change.disconnect();
|
|
|
|
_current_parent = parent;
|
2017-07-16 16:13:46 -04:00
|
|
|
_parent_style_change = parent->signal_style_changed().connect (mem_fun (*this, &ArdourFader::on_style_changed));
|
2014-08-29 22:16:18 -04:00
|
|
|
}
|
|
|
|
return parent->get_style ()->get_bg (parent->get_state());
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_style ()->get_bg (get_state());
|
|
|
|
}
|