2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 2006 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2017 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2014-09-01 16:02:51 -04:00
|
|
|
#include <assert.h>
|
2013-01-16 21:32:48 -05:00
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2020-04-09 19:12:40 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
2009-12-10 18:01:45 -05:00
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2020-04-09 19:12:40 -04:00
|
|
|
#include "gtkmm2ext/rgb_macros.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"
|
2023-12-08 10:44:08 -05:00
|
|
|
#include "widgets/ui_config.h"
|
2017-07-16 16:13:46 -04:00
|
|
|
|
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)
|
2024-05-14 14:40:12 -04:00
|
|
|
: FaderWidget (adj, orientation)
|
|
|
|
, _layout (0)
|
2014-09-04 20:24:19 -04:00
|
|
|
, _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)
|
2014-09-01 22:46:34 -04:00
|
|
|
, _pattern (0)
|
|
|
|
, _centered_text (true)
|
2014-08-29 22:16:18 -04:00
|
|
|
, _current_parent (0)
|
2022-08-10 20:15:39 -04:00
|
|
|
, have_explicit_bg (false)
|
|
|
|
, have_explicit_fg (false)
|
2023-12-08 10:44:08 -05:00
|
|
|
, outline_color (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2013-01-11 13:33:57 -05:00
|
|
|
update_unity_position ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
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
|
|
|
}
|
2023-12-08 10:44:08 -05:00
|
|
|
|
2023-12-13 13:14:02 -05:00
|
|
|
outline_color = UIConfigurationBase::instance().color ("fader outline");
|
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
|
|
|
{
|
2022-08-11 02:07:30 -04:00
|
|
|
Gdk::Color c = fg_color (get_state());
|
2014-09-01 16:02:51 -04:00
|
|
|
float fr, fg, fb;
|
|
|
|
float br, bg, bb;
|
|
|
|
|
|
|
|
fr = c.get_red_p ();
|
|
|
|
fg = c.get_green_p ();
|
|
|
|
fb = c.get_blue_p ();
|
|
|
|
|
2022-08-11 02:07:30 -04:00
|
|
|
c = bg_color (get_state());
|
2014-09-01 16:02:51 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-08-10 20:15:39 -04:00
|
|
|
Gdk::Color
|
|
|
|
ArdourFader::bg_color (Gtk::StateType s)
|
|
|
|
{
|
2022-08-11 00:32:42 -04:00
|
|
|
if (have_explicit_bg) {
|
|
|
|
return gdk_color_from_rgba (explicit_bg);
|
|
|
|
}
|
2022-08-10 20:15:39 -04:00
|
|
|
return get_style()->get_bg (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gdk::Color
|
|
|
|
ArdourFader::fg_color (Gtk::StateType s)
|
|
|
|
{
|
2022-08-11 00:32:42 -04:00
|
|
|
if (have_explicit_fg) {
|
2022-08-11 02:07:30 -04:00
|
|
|
Gtkmm2ext::HSV hsv;
|
|
|
|
|
|
|
|
if (_hovering || (s == Gtk::STATE_PRELIGHT)) {
|
|
|
|
hsv = HSV (explicit_fg);
|
|
|
|
hsv.s *= 0.50;
|
|
|
|
return gdk_color_from_rgba (hsv.color());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (s) {
|
|
|
|
case Gtk::STATE_NORMAL:
|
|
|
|
return gdk_color_from_rgba (explicit_fg);
|
|
|
|
return gdk_color_from_rgba (hsv.color());
|
|
|
|
case Gtk::STATE_SELECTED:
|
|
|
|
return gdk_color_from_rgba (explicit_fg);
|
|
|
|
case Gtk::STATE_ACTIVE:
|
|
|
|
return gdk_color_from_rgba (explicit_fg);
|
|
|
|
case Gtk::STATE_INSENSITIVE:
|
|
|
|
return get_style()->get_fg (s);
|
|
|
|
case Gtk::STATE_PRELIGHT:
|
|
|
|
break;
|
|
|
|
}
|
2022-08-11 00:32:42 -04:00
|
|
|
}
|
2022-08-11 02:07:30 -04:00
|
|
|
|
2022-08-10 20:15:39 -04:00
|
|
|
return get_style()->get_fg (s);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-08-11 02:07:30 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, bg_color (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);
|
2023-12-08 10:44:08 -05:00
|
|
|
Gtkmm2ext::set_source_rgba (cr, outline_color);
|
|
|
|
|
2014-09-01 16:02:51 -04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-11 02:07:30 -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 {
|
2022-08-10 20:15:39 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, bg_color (get_state()), 1);
|
2014-08-27 12:58:09 -04:00
|
|
|
cairo_fill (cr);
|
2022-08-10 20:15:39 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, fg_color (get_state()), 1);
|
2014-09-01 16:02:51 -04:00
|
|
|
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 {
|
2022-08-10 20:15:39 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, bg_color (get_state()), 1);
|
2014-08-27 12:58:09 -04:00
|
|
|
cairo_fill (cr);
|
2022-08-10 20:15:39 -04:00
|
|
|
CairoWidget::set_source_rgb_a (cr, fg_color (get_state()), 1);
|
2014-09-01 16:02:51 -04:00
|
|
|
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);
|
2022-08-11 02:07:30 -04:00
|
|
|
Gdk::Color c = fg_color (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) {
|
2022-08-11 02:07:30 -04:00
|
|
|
Gdk::Color bg_col;
|
2014-09-01 22:46:34 -04:00
|
|
|
cairo_save (cr);
|
|
|
|
if (_centered_text) {
|
|
|
|
/* center text */
|
|
|
|
cairo_move_to (cr, (w - _text_width)/2.0, h/2.0 - _text_height/2.0);
|
2022-08-11 02:07:30 -04:00
|
|
|
bg_col = bg_color (get_state());
|
2014-09-01 22:46:34 -04:00
|
|
|
} else if (ds > .5 * w) {
|
|
|
|
cairo_move_to (cr, CORNER_OFFSET + 3, h/2.0 - _text_height/2.0);
|
2022-08-11 02:07:30 -04:00
|
|
|
bg_col = fg_color (get_state());
|
2014-09-01 22:46:34 -04:00
|
|
|
} else {
|
|
|
|
cairo_move_to (cr, w - _text_width - CORNER_OFFSET - 3, h/2.0 - _text_height/2.0);
|
2022-08-11 02:07:30 -04:00
|
|
|
bg_col = bg_color (get_state());
|
2014-09-01 22:46:34 -04:00
|
|
|
}
|
2020-04-09 19:12:40 -04:00
|
|
|
|
2022-08-11 02:07:30 -04:00
|
|
|
const uint32_t r = bg_col.get_red_p () * 255.0;
|
|
|
|
const uint32_t g = bg_col.get_green_p () * 255.0;
|
|
|
|
const uint32_t b = bg_col.get_blue_p () * 255.0;
|
2020-04-09 19:12:40 -04:00
|
|
|
const uint32_t a = 0xff;
|
|
|
|
uint32_t rgba = RGBA_TO_UINT (r, g, b, a);
|
|
|
|
rgba = contrasting_text_color (rgba);
|
|
|
|
Gdk::Color text_color;
|
|
|
|
text_color.set_rgb ((rgba >> 24)*256, ((rgba & 0xff0000) >> 16)*256, ((rgba & 0xff00) >> 8)*256);
|
|
|
|
CairoWidget::set_source_rgb_a (cr, text_color, 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);
|
2022-08-11 02:07:30 -04:00
|
|
|
} else if (_hovering && CairoWidget::widget_prelight() && !have_explicit_fg) {
|
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
|
|
|
}
|
|
|
|
|
2022-01-26 15:22:00 -05:00
|
|
|
if (get_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 ();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
2021-01-29 20:18:56 -05:00
|
|
|
ArdourFader::on_style_changed (const Glib::RefPtr<Gtk::Style>& style)
|
2013-01-21 11:10:39 -05:00
|
|
|
{
|
2021-01-29 20:18:56 -05:00
|
|
|
CairoWidget::on_style_changed (style);
|
2021-02-03 14:14:22 -05:00
|
|
|
if (_layout) {
|
|
|
|
std::string txt = _layout->get_text();
|
|
|
|
_layout.clear (); // drop reference to existing layout
|
|
|
|
_text = "";
|
|
|
|
set_text (txt, _centered_text, false);
|
2021-01-29 20:18:56 -05:00
|
|
|
queue_resize ();
|
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());
|
|
|
|
}
|
2022-08-10 20:26:49 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
ArdourFader::set_bg (Gtkmm2ext::Color c)
|
|
|
|
{
|
|
|
|
explicit_bg = c;
|
|
|
|
have_explicit_bg = true;
|
2022-08-11 02:07:30 -04:00
|
|
|
_pattern = 0;
|
2022-08-11 00:32:42 -04:00
|
|
|
queue_draw ();
|
2022-08-10 20:26:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArdourFader::set_fg (Gtkmm2ext::Color c)
|
|
|
|
{
|
|
|
|
explicit_fg = c;
|
|
|
|
have_explicit_fg = true;
|
2022-08-11 02:07:30 -04:00
|
|
|
_pattern = 0;
|
2022-08-11 00:32:42 -04:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArdourFader::unset_bg ()
|
|
|
|
{
|
|
|
|
if (have_explicit_bg) {
|
|
|
|
have_explicit_bg = false;
|
2022-08-11 02:07:30 -04:00
|
|
|
_pattern = 0;
|
2022-08-11 00:32:42 -04:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArdourFader::unset_fg ()
|
|
|
|
{
|
|
|
|
if (have_explicit_fg) {
|
|
|
|
have_explicit_fg = false;
|
2022-08-11 02:07:30 -04:00
|
|
|
_pattern = 0;
|
2022-08-11 00:32:42 -04:00
|
|
|
queue_draw ();
|
|
|
|
}
|
2022-08-10 20:26:49 -04:00
|
|
|
}
|