2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006 Paul Davis
|
|
|
|
|
|
|
|
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>
|
2013-01-16 21:32:48 -05:00
|
|
|
|
2009-12-10 18:01:45 -05:00
|
|
|
#include "gtkmm2ext/pixfader.h"
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2011-02-08 14:19:55 -05: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
|
|
|
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
#define CORNER_RADIUS 4
|
|
|
|
#define FADER_RESERVE (2*CORNER_RADIUS)
|
|
|
|
|
2013-01-17 10:36:35 -05:00
|
|
|
std::list<PixFader::FaderImage*> PixFader::_patterns;
|
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int fader_girth)
|
2013-01-10 10:25:11 -05:00
|
|
|
: adjustment (adj)
|
2013-01-11 13:33:57 -05:00
|
|
|
, span (fader_length)
|
|
|
|
, girth (fader_girth)
|
2013-01-10 10:25:11 -05:00
|
|
|
, _orien (orientation)
|
2013-01-11 13:33:57 -05:00
|
|
|
, pattern (0)
|
|
|
|
, _hovering (false)
|
|
|
|
, last_drawn (-1)
|
|
|
|
, dragging (false)
|
2008-06-02 17:41:35 -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
|
|
|
|
2009-12-10 18:01:45 -05: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
|
|
|
|
|
|
|
adjustment.signal_value_changed().connect (mem_fun (*this, &PixFader::adjustment_changed));
|
|
|
|
adjustment.signal_changed().connect (mem_fun (*this, &PixFader::adjustment_changed));
|
|
|
|
}
|
|
|
|
|
|
|
|
PixFader::~PixFader ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-17 10:36:35 -05:00
|
|
|
cairo_pattern_t*
|
|
|
|
PixFader::find_pattern (double afr, double afg, double afb,
|
|
|
|
double abr, double abg, double abb,
|
|
|
|
int w, int h)
|
2011-02-08 14:19:55 -05:00
|
|
|
{
|
2013-01-17 10:36:35 -05:00
|
|
|
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;
|
|
|
|
}
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2013-01-17 10:36:35 -05:00
|
|
|
return 0;
|
2011-02-08 14:19:55 -05:00
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
void
|
|
|
|
PixFader::create_patterns ()
|
|
|
|
{
|
|
|
|
Gdk::Color c = get_style()->get_fg (get_state());
|
2013-01-11 20:37:27 -05:00
|
|
|
float fr, fg, fb;
|
|
|
|
float br, bg, bb;
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
fr = c.get_red_p ();
|
|
|
|
fg = c.get_green_p ();
|
|
|
|
fb = c.get_blue_p ();
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
c = get_style()->get_bg (get_state());
|
2012-12-07 17:38:49 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
br = c.get_red_p ();
|
|
|
|
bg = c.get_green_p ();
|
|
|
|
bb = c.get_blue_p ();
|
|
|
|
|
2013-01-17 17:33:08 -05:00
|
|
|
if ( !_text.empty()) {
|
|
|
|
_layout->get_pixel_size (_text_width, _text_height);
|
|
|
|
} else {
|
|
|
|
_text_width = 0;
|
|
|
|
_text_height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = get_style()->get_text (get_state());
|
|
|
|
|
|
|
|
text_r = c.get_red_p ();
|
|
|
|
text_g = c.get_green_p ();
|
|
|
|
text_b = c.get_blue_p ();
|
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
cairo_surface_t* surface;
|
2013-01-11 13:33:57 -05:00
|
|
|
cairo_t* tc = 0;
|
2013-01-11 20:37:27 -05:00
|
|
|
float radius = CORNER_RADIUS;
|
|
|
|
|
|
|
|
double w = get_width();
|
2013-01-21 11:10:39 -05:00
|
|
|
|
|
|
|
if (w <= 1 || get_height() <= 1) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-11 13:33:57 -05:00
|
|
|
|
2013-01-17 10:36:35 -05:00
|
|
|
if ((pattern = find_pattern (fr, fg, fb, br, bg, bb, get_width(), get_height())) != 0) {
|
|
|
|
/* found it - use it */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
if (_orien == VERT) {
|
2013-01-11 20:37:27 -05:00
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, get_width(), get_height() * 2.0);
|
|
|
|
tc = cairo_create (surface);
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
/* paint background + border */
|
|
|
|
|
|
|
|
cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, get_width(), 0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, br*0.8,bg*0.8,bb*0.8, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, br*0.6,bg*0.6,bb*0.6, 1.0);
|
|
|
|
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 */
|
|
|
|
|
|
|
|
w -= 2.0;
|
|
|
|
|
|
|
|
shade_pattern = cairo_pattern_create_linear (0.0, 0.0, w, 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, 1.0, get_height(), w, get_height(), radius-1.5);
|
|
|
|
cairo_fill (tc);
|
|
|
|
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
} else {
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
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());
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, br*0.8,bg*0.8,bb*0.8, 1.0);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, br*0.6,bg*0.6,bb*0.6, 1.0);
|
|
|
|
cairo_set_source (tc, shade_pattern);
|
|
|
|
cairo_rectangle (tc, 0, 0, get_width() * 2.0, get_height());
|
|
|
|
cairo_fill (tc);
|
2013-01-11 13:33:57 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
/* paint left shade (active section/foreground) */
|
2013-01-11 13:33:57 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
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, 0, 1, get_width(), get_height() - 2.0, radius-1.5);
|
|
|
|
cairo_fill (tc);
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
2012-12-07 17:38:49 -05:00
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
|
2013-01-17 10:36:35 -05:00
|
|
|
/* cache it for others to use */
|
|
|
|
|
|
|
|
_patterns.push_back (new FaderImage (pattern, fr, fg, fb, br, bg, bb, get_width(), get_height()));
|
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
cairo_destroy (tc);
|
|
|
|
cairo_surface_destroy (surface);
|
2012-12-07 17:38:49 -05:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool
|
2013-01-11 13:33:57 -05:00
|
|
|
PixFader::on_expose_event (GdkEventExpose* ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-12-07 17:38:49 -05:00
|
|
|
Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context();
|
|
|
|
cairo_t* cr = context->cobj();
|
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
if (!pattern) {
|
|
|
|
create_patterns();
|
|
|
|
}
|
2013-01-21 11:10:39 -05:00
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
int ds = display_span ();
|
|
|
|
float w = get_width();
|
|
|
|
float h = get_height();
|
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
cairo_matrix_t matrix;
|
2009-12-04 12:45:11 -05:00
|
|
|
|
|
|
|
if (_orien == VERT) {
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
if (ds > h - FADER_RESERVE) {
|
2012-12-07 17:38:49 -05:00
|
|
|
ds = h - FADER_RESERVE;
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2012-12-07 17:38:49 -05:00
|
|
|
|
|
|
|
cairo_set_source (cr, pattern);
|
2013-01-11 20:37:27 -05:00
|
|
|
cairo_matrix_init_translate (&matrix, 0, (h - ds));
|
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
2013-01-11 21:14:58 -05:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, w, h, CORNER_RADIUS-1.5);
|
2012-12-07 17:38:49 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2009-12-04 12:45:11 -05:00
|
|
|
} else {
|
2013-01-10 11:25:31 -05:00
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
if (ds < FADER_RESERVE) {
|
2012-12-07 17:38:49 -05:00
|
|
|
ds = FADER_RESERVE;
|
2013-01-11 13:33:57 -05:00
|
|
|
}
|
2011-02-08 14:19:55 -05:00
|
|
|
|
2013-01-11 20:37:27 -05:00
|
|
|
/*
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
cairo_set_source (cr, pattern);
|
2013-01-11 20:37:27 -05:00
|
|
|
cairo_matrix_init_translate (&matrix, w - ds, 0);
|
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
2013-01-11 21:14:58 -05:00
|
|
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, w, h, CORNER_RADIUS-1.5);
|
2012-12-07 17:38:49 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
2013-01-11 13:33:57 -05:00
|
|
|
|
2012-12-10 15:08:36 -05:00
|
|
|
/* draw the unity-position line if it's not at either end*/
|
|
|
|
if (unity_loc > 0) {
|
2013-01-10 11:25:31 -05:00
|
|
|
if ( _orien == VERT) {
|
|
|
|
if (unity_loc < h ) {
|
2012-12-10 15:08:36 -05:00
|
|
|
context->set_line_width (1);
|
|
|
|
context->set_source_rgb (0.0, 1.0, 0.0);
|
|
|
|
context->move_to (1, unity_loc);
|
2013-01-11 20:37:27 -05:00
|
|
|
context->line_to (girth - 2.0, unity_loc);
|
2012-12-10 15:08:36 -05:00
|
|
|
context->stroke ();
|
2013-01-10 11:25:31 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( unity_loc < w ){
|
|
|
|
context->set_line_width (1);
|
|
|
|
context->set_source_rgb (0.0, 1.0, 0.0);
|
|
|
|
context->move_to (unity_loc, 1);
|
2013-01-11 20:37:27 -05:00
|
|
|
context->line_to (unity_loc, girth - 2.0);
|
2013-01-10 11:25:31 -05:00
|
|
|
context->stroke ();
|
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
|
|
|
|
if ( !_text.empty() ) {
|
2011-02-08 14:19:55 -05:00
|
|
|
|
2012-12-10 15:08:36 -05:00
|
|
|
cairo_new_path (cr);
|
|
|
|
|
|
|
|
/* center text */
|
|
|
|
cairo_move_to (cr, (get_width() - _text_width)/2.0, get_height()/2.0 - _text_height/2.0);
|
|
|
|
cairo_set_source_rgba (cr, text_r, text_g, text_b, 0.9);
|
|
|
|
pango_cairo_show_layout (cr, _layout->gobj());
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
// if (Config->get_widget_prelight()) { //pixfader does not have access to config
|
|
|
|
if (_hovering) {
|
|
|
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, get_width(), get_height(), 3);
|
2013-01-11 20:37:27 -05:00
|
|
|
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.1);
|
2012-12-07 17:38:49 -05:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
last_drawn = ds;
|
2011-02-08 14:19:55 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::on_size_request (GtkRequisition* req)
|
|
|
|
{
|
2013-01-10 10:25:11 -05:00
|
|
|
if (_orien == VERT) {
|
|
|
|
req->width = girth;
|
|
|
|
req->height = span;
|
|
|
|
} else {
|
|
|
|
req->height = girth;
|
|
|
|
req->width = span;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
void
|
|
|
|
PixFader::on_size_allocate (Gtk::Allocation& alloc)
|
|
|
|
{
|
|
|
|
DrawingArea::on_size_allocate(alloc);
|
2013-01-10 10:25:11 -05:00
|
|
|
|
2012-12-07 17:38:49 -05:00
|
|
|
if (_orien == VERT) {
|
2013-01-11 13:33:57 -05:00
|
|
|
girth = alloc.get_width ();
|
2013-01-17 10:00:44 -05:00
|
|
|
span = alloc.get_height ();
|
2012-12-07 17:38:49 -05:00
|
|
|
} else {
|
2013-01-11 13:33:57 -05:00
|
|
|
girth = alloc.get_height ();
|
2013-01-17 10:00:44 -05:00
|
|
|
span = alloc.get_width ();
|
2012-12-07 17:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
update_unity_position ();
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
bool
|
|
|
|
PixFader::on_button_press_event (GdkEventButton* ev)
|
|
|
|
{
|
2011-01-10 19:03:12 -05:00
|
|
|
if (ev->type != GDK_BUTTON_PRESS) {
|
2011-10-24 19:46:00 -04:00
|
|
|
return true;
|
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 ();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PixFader::on_button_release_event (GdkEventButton* ev)
|
|
|
|
{
|
2011-01-29 20:39:57 -05:00
|
|
|
double const ev_pos = (_orien == VERT) ? ev->y : ev->x;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
if (dragging) {
|
|
|
|
remove_modal_grab();
|
|
|
|
dragging = false;
|
2013-01-04 11:02:12 -05:00
|
|
|
gdk_pointer_ungrab (GDK_CURRENT_TIME);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-12-10 16:52:55 -05:00
|
|
|
if (!_hovering) {
|
|
|
|
Keyboard::magic_widget_drop_focus();
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (ev_pos == grab_start) {
|
|
|
|
|
|
|
|
/* no motion - just a click */
|
|
|
|
|
2009-12-10 18:01:45 -05:00
|
|
|
if (ev->state & Keyboard::TertiaryModifier) {
|
2008-06-02 17:41:35 -04:00
|
|
|
adjustment.set_value (default_value);
|
2012-05-31 14:04:47 -04:00
|
|
|
} else if (ev->state & Keyboard::GainFineScaleModifier) {
|
2008-06-02 17:41:35 -04:00
|
|
|
adjustment.set_value (adjustment.get_lower());
|
2012-12-25 13:11:55 -05:00
|
|
|
} else if ((_orien == VERT && ev_pos < display_span()) || (_orien == HORIZ && ev_pos > display_span())) {
|
2008-06-02 17:41:35 -04:00
|
|
|
/* above the current display height, remember X Window coords */
|
|
|
|
adjustment.set_value (adjustment.get_value() + adjustment.get_step_increment());
|
|
|
|
} else {
|
|
|
|
adjustment.set_value (adjustment.get_value() - adjustment.get_step_increment());
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 21:41:11 -05:00
|
|
|
return true;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (dragging) {
|
|
|
|
remove_modal_grab();
|
|
|
|
dragging = false;
|
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
|
|
|
|
PixFader::on_scroll_event (GdkEventScroll* ev)
|
|
|
|
{
|
|
|
|
double scale;
|
|
|
|
bool ret = false;
|
|
|
|
|
2012-05-31 14:04:47 -04:00
|
|
|
if (ev->state & Keyboard::GainFineScaleModifier) {
|
|
|
|
if (ev->state & Keyboard::GainExtraFineScaleModifier) {
|
2008-06-02 17:41:35 -04:00
|
|
|
scale = 0.01;
|
|
|
|
} else {
|
|
|
|
scale = 0.05;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scale = 0.25;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_orien == VERT) {
|
|
|
|
|
|
|
|
/* should left/right scroll affect vertical faders ? */
|
|
|
|
|
|
|
|
switch (ev->direction) {
|
|
|
|
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
adjustment.set_value (adjustment.get_value() + (adjustment.get_page_increment() * scale));
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
adjustment.set_value (adjustment.get_value() - (adjustment.get_page_increment() * scale));
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* up/down scrolls should definitely affect horizontal faders
|
|
|
|
because they are so much easier to use
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (ev->direction) {
|
|
|
|
|
|
|
|
case GDK_SCROLL_RIGHT:
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
adjustment.set_value (adjustment.get_value() + (adjustment.get_page_increment() * scale));
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_LEFT:
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
adjustment.set_value (adjustment.get_value() - (adjustment.get_page_increment() * scale));
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PixFader::on_motion_notify_event (GdkEventMotion* ev)
|
|
|
|
{
|
|
|
|
if (dragging) {
|
2011-01-29 20:39:47 -05:00
|
|
|
double scale = 1.0;
|
|
|
|
double const ev_pos = (_orien == VERT) ? ev->y : ev->x;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (ev->window != grab_window) {
|
|
|
|
grab_loc = ev_pos;
|
|
|
|
grab_window = ev->window;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-31 14:04:47 -04:00
|
|
|
if (ev->state & Keyboard::GainFineScaleModifier) {
|
|
|
|
if (ev->state & Keyboard::GainExtraFineScaleModifier) {
|
2008-06-02 17:41:35 -04:00
|
|
|
scale = 0.05;
|
|
|
|
} else {
|
|
|
|
scale = 0.1;
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 20:39:47 -05:00
|
|
|
|
|
|
|
double const delta = ev_pos - grab_loc;
|
2008-06-02 17:41:35 -04:00
|
|
|
grab_loc = ev_pos;
|
|
|
|
|
2011-01-29 20:39:47 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
if (_orien == VERT) {
|
|
|
|
fract = -fract;
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustment.set_value (adjustment.get_value() + scale * fract * (adjustment.get_upper() - adjustment.get_lower()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::adjustment_changed ()
|
|
|
|
{
|
|
|
|
if (display_span() != last_drawn) {
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-04 12:45:11 -05:00
|
|
|
/** @return pixel offset of the current value from the right or bottom of the fader */
|
2008-06-02 17:41:35 -04:00
|
|
|
int
|
|
|
|
PixFader::display_span ()
|
|
|
|
{
|
2011-02-08 14:19:55 -05:00
|
|
|
float fract = (adjustment.get_value () - adjustment.get_lower()) / ((adjustment.get_upper() - adjustment.get_lower()));
|
2012-12-07 17:38:49 -05:00
|
|
|
int ds;
|
|
|
|
if (_orien == VERT) {
|
|
|
|
ds = (int)floor ( span * (1.0 - fract));
|
|
|
|
} else {
|
|
|
|
ds = (int)floor (span * fract);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ds;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-12-04 12:45:11 -05:00
|
|
|
void
|
|
|
|
PixFader::set_fader_length (int l)
|
|
|
|
{
|
2013-01-11 13:33:57 -05:00
|
|
|
span = l;
|
2011-08-03 14:41:16 -04:00
|
|
|
update_unity_position ();
|
2013-01-16 21:32:48 -05:00
|
|
|
queue_resize ();
|
2011-08-03 14:41:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::update_unity_position ()
|
|
|
|
{
|
|
|
|
if (_orien == VERT) {
|
2013-01-10 10:25:11 -05:00
|
|
|
unity_loc = (int) rint (span * (1 - (default_value / (adjustment.get_upper() - adjustment.get_lower())))) - 1;
|
2011-08-03 14:41:16 -04:00
|
|
|
} else {
|
2013-01-12 10:44:55 -05:00
|
|
|
unity_loc = (int) rint (default_value * 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
|
|
|
|
PixFader::on_enter_notify_event (GdkEventCrossing*)
|
|
|
|
{
|
2012-12-07 17:38:49 -05:00
|
|
|
_hovering = true;
|
2009-12-10 18:01:45 -05:00
|
|
|
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
|
|
|
|
PixFader::on_leave_notify_event (GdkEventCrossing*)
|
|
|
|
{
|
2012-12-10 16:52:55 -05:00
|
|
|
if (!dragging) {
|
|
|
|
_hovering = false;
|
|
|
|
Keyboard::magic_widget_drop_focus();
|
|
|
|
queue_draw ();
|
|
|
|
}
|
2009-12-10 18:01:45 -05:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-29 20:39:57 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::set_adjustment_from_event (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
double fract = (_orien == VERT) ? (1.0 - (ev->y / span)) : (ev->x / span);
|
|
|
|
|
|
|
|
fract = min (1.0, fract);
|
|
|
|
fract = max (0.0, fract);
|
|
|
|
|
|
|
|
adjustment.set_value (fract * (adjustment.get_upper () - adjustment.get_lower ()));
|
|
|
|
}
|
2011-08-03 14:41:16 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::set_default_value (float d)
|
|
|
|
{
|
|
|
|
default_value = d;
|
|
|
|
update_unity_position ();
|
|
|
|
}
|
2012-12-10 15:08:36 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::set_text (const std::string& str)
|
|
|
|
{
|
|
|
|
_text = str;
|
|
|
|
|
|
|
|
if (!_layout && !_text.empty()) {
|
|
|
|
_layout = Pango::Layout::create (get_pango_context());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_layout) {
|
|
|
|
_layout->set_text (str);
|
2013-01-17 17:33:08 -05:00
|
|
|
_layout->get_pixel_size (_text_width, _text_height);
|
2012-12-10 15:08:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
queue_resize ();
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:33:57 -05:00
|
|
|
void
|
|
|
|
PixFader::on_state_changed (Gtk::StateType old_state)
|
|
|
|
{
|
|
|
|
Widget::on_state_changed (old_state);
|
|
|
|
create_patterns ();
|
|
|
|
}
|
2013-01-21 11:10:39 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
PixFader::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
|
|
|
|
{
|
|
|
|
if (_layout) {
|
|
|
|
std::string txt = _layout->get_text();
|
|
|
|
_layout.clear (); // drop reference to existing layout
|
|
|
|
set_text (txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remember that all patterns are cached and not owned by an individual
|
|
|
|
pixfader. we will lazily create a new pattern when needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pattern = 0;
|
|
|
|
}
|