2010-03-10 12:31:58 -05:00
|
|
|
/*
|
2011-06-17 17:47:20 -04:00
|
|
|
Copyright (C) 2010-2011 Paul Davis
|
|
|
|
|
2010-03-10 12:31:58 -05: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: motionfeedback.cc,v 1.5 2004/03/01 03:44:19 pauld Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cmath>
|
2010-05-26 11:18:04 -04:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <algorithm>
|
2010-03-10 12:31:58 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h> /* for snprintf, grrr */
|
|
|
|
|
2015-09-17 08:37:57 -04:00
|
|
|
#include <pbd/gstdio_compat.h>
|
2013-07-15 14:29:00 -04:00
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtkmm.h>
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
#include "pbd/controllable.h"
|
2014-03-17 10:16:45 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "pbd/error.h"
|
2011-06-17 17:47:20 -04:00
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
#include "gtkmm2ext/motionfeedback.h"
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2010-05-06 17:02:08 -04:00
|
|
|
#include "gtkmm2ext/prolooks-helpers.h"
|
2011-06-17 17:47:20 -04:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
2010-03-10 12:31:58 -05:00
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace sigc;
|
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
using PBD::error;
|
|
|
|
|
2011-10-29 11:53:22 -04:00
|
|
|
Gdk::Color* MotionFeedback::base_color;
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
MotionFeedback::MotionFeedback (Glib::RefPtr<Gdk::Pixbuf> pix,
|
|
|
|
Type t,
|
2011-06-17 17:47:20 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> c,
|
|
|
|
double default_val,
|
|
|
|
double step_increment,
|
|
|
|
double page_increment,
|
2010-03-10 12:31:58 -05:00
|
|
|
const char *widget_name,
|
2010-05-25 12:45:21 -04:00
|
|
|
bool with_numeric_display,
|
|
|
|
int subw,
|
|
|
|
int subh)
|
2011-06-17 17:47:20 -04:00
|
|
|
: _controllable (c)
|
2010-03-10 12:31:58 -05:00
|
|
|
, value (0)
|
2011-06-17 17:47:20 -04:00
|
|
|
, default_value (default_val)
|
|
|
|
, step_inc (step_increment)
|
|
|
|
, page_inc (page_increment)
|
|
|
|
, type (t)
|
|
|
|
, value_packer (0)
|
2010-03-10 12:31:58 -05:00
|
|
|
, pixbuf (pix)
|
|
|
|
, subwidth (subw)
|
|
|
|
, subheight (subh)
|
|
|
|
{
|
2011-10-29 11:53:22 -04:00
|
|
|
if (!base_color) {
|
|
|
|
base_color = new Gdk::Color ("#1a5274");
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
char value_name[1024];
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
print_func = default_printer;
|
|
|
|
print_arg = 0;
|
2010-03-10 12:31:58 -05:00
|
|
|
|
2010-03-19 17:40:23 -04:00
|
|
|
|
2010-03-19 16:53:22 -04:00
|
|
|
HBox* hpacker = manage (new HBox);
|
2011-06-17 17:47:20 -04:00
|
|
|
hpacker->pack_start (pixwin, true, true);
|
2010-03-19 16:53:22 -04:00
|
|
|
hpacker->show ();
|
|
|
|
pack_start (*hpacker, false, false);
|
2010-03-10 12:31:58 -05:00
|
|
|
pixwin.show ();
|
|
|
|
|
|
|
|
if (with_numeric_display) {
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
value_packer = new EventBox;
|
|
|
|
value_packer->set_name ("MotionControllerValue");
|
|
|
|
value_packer->show ();
|
|
|
|
value_packer->set_border_width (6);
|
|
|
|
|
|
|
|
value = new Label;
|
|
|
|
value->set_justify (Gtk::JUSTIFY_RIGHT);
|
|
|
|
value->show ();
|
2010-03-10 12:31:58 -05:00
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
value_packer->add (*value);
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
hpacker = manage (new HBox);
|
|
|
|
hpacker->pack_start (*value_packer, true, false);
|
|
|
|
hpacker->show ();
|
2013-02-05 13:18:35 -05:00
|
|
|
hpacker->set_border_width (6);
|
2011-06-17 17:47:20 -04:00
|
|
|
|
|
|
|
pack_start (*hpacker, false, false);
|
2010-03-10 12:31:58 -05:00
|
|
|
|
|
|
|
if (widget_name) {
|
|
|
|
snprintf (value_name, sizeof(value_name), "%sValue", widget_name);
|
|
|
|
value->set_name (value_name);
|
|
|
|
}
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
if (_controllable) {
|
|
|
|
char buf[32];
|
|
|
|
print_func (buf, _controllable, print_arg);
|
|
|
|
value->set_text (buf);
|
|
|
|
}
|
2010-03-10 12:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pixwin.set_events (Gdk::BUTTON_PRESS_MASK|
|
|
|
|
Gdk::BUTTON_RELEASE_MASK|
|
|
|
|
Gdk::POINTER_MOTION_MASK|
|
|
|
|
Gdk::ENTER_NOTIFY_MASK|
|
|
|
|
Gdk::LEAVE_NOTIFY_MASK|
|
|
|
|
Gdk::SCROLL_MASK|
|
|
|
|
Gdk::KEY_PRESS_MASK|
|
|
|
|
Gdk::KEY_RELEASE_MASK);
|
|
|
|
|
|
|
|
pixwin.set_flags (CAN_FOCUS);
|
|
|
|
|
|
|
|
/* Proxy all important events on the pixwin to ourselves */
|
|
|
|
|
|
|
|
pixwin.signal_button_press_event().connect(mem_fun (*this,&MotionFeedback::pixwin_button_press_event));
|
|
|
|
pixwin.signal_button_release_event().connect(mem_fun (*this,&MotionFeedback::pixwin_button_release_event));
|
|
|
|
pixwin.signal_motion_notify_event().connect(mem_fun (*this,&MotionFeedback::pixwin_motion_notify_event));
|
|
|
|
pixwin.signal_enter_notify_event().connect(mem_fun (*this,&MotionFeedback::pixwin_enter_notify_event));
|
|
|
|
pixwin.signal_leave_notify_event().connect(mem_fun (*this,&MotionFeedback::pixwin_leave_notify_event));
|
|
|
|
pixwin.signal_key_press_event().connect(mem_fun (*this,&MotionFeedback::pixwin_key_press_event));
|
|
|
|
pixwin.signal_scroll_event().connect(mem_fun (*this,&MotionFeedback::pixwin_scroll_event));
|
|
|
|
pixwin.signal_expose_event().connect(mem_fun (*this,&MotionFeedback::pixwin_expose_event), true);
|
|
|
|
pixwin.signal_size_request().connect(mem_fun (*this,&MotionFeedback::pixwin_size_request));
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionFeedback::~MotionFeedback()
|
|
|
|
{
|
|
|
|
delete value;
|
|
|
|
delete value_packer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MotionFeedback::pixwin_button_press_event (GdkEventButton *ev)
|
|
|
|
{
|
2010-04-06 12:57:35 -04:00
|
|
|
if (binding_proxy.button_press_handler (ev)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
grab_is_fine = false;
|
|
|
|
break;
|
2011-06-19 19:02:55 -04:00
|
|
|
case 2:
|
2010-03-10 12:31:58 -05:00
|
|
|
grab_is_fine = true;
|
|
|
|
break;
|
2011-06-19 19:02:55 -04:00
|
|
|
case 3:
|
|
|
|
return false;
|
2010-03-10 12:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_grab_add(GTK_WIDGET(pixwin.gobj()));
|
2011-06-19 19:02:55 -04:00
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
grabbed_y = ev->y_root;
|
|
|
|
grabbed_x = ev->x_root;
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
return false;
|
2010-03-10 12:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MotionFeedback::pixwin_button_release_event (GdkEventButton *ev)
|
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
if (!_controllable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
if (pixwin.has_grab()) {
|
|
|
|
if (!grab_is_fine) {
|
|
|
|
gtk_grab_remove
|
|
|
|
(GTK_WIDGET(pixwin.gobj()));
|
|
|
|
}
|
|
|
|
}
|
2010-03-19 17:40:23 -04:00
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
|
|
|
|
/* shift click back to the default */
|
2011-06-17 17:47:20 -04:00
|
|
|
_controllable->set_value (default_value);
|
2010-03-19 17:40:23 -04:00
|
|
|
return true;
|
2012-05-31 14:04:54 -04:00
|
|
|
} else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
|
|
|
/* ctrl click back to the minimum value */
|
|
|
|
_controllable->set_value (_controllable->lower ());
|
|
|
|
}
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (pixwin.has_grab()) {
|
|
|
|
if (grab_is_fine) {
|
|
|
|
gtk_grab_remove
|
|
|
|
(GTK_WIDGET(pixwin.gobj()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VBox::on_button_release_event (ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MotionFeedback::pixwin_motion_notify_event (GdkEventMotion *ev)
|
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
if (!_controllable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
gfloat multiplier;
|
|
|
|
gfloat x_delta;
|
|
|
|
gfloat y_delta;
|
|
|
|
|
2010-05-07 12:33:25 -04:00
|
|
|
if (!pixwin.has_grab()) {
|
2010-03-10 12:31:58 -05:00
|
|
|
return VBox::on_motion_notify_event (ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
multiplier = ((ev->state & Keyboard::TertiaryModifier) ? 100 : 1) *
|
2011-06-17 17:47:20 -04:00
|
|
|
((ev->state & Keyboard::PrimaryModifier) ? 10 : 1) *
|
|
|
|
((ev->state & Keyboard::SecondaryModifier) ? 0.1 : 1);
|
2010-03-10 12:31:58 -05:00
|
|
|
|
2010-05-07 12:33:25 -04:00
|
|
|
if (ev->state & Gdk::BUTTON1_MASK) {
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
/* vertical control */
|
|
|
|
|
2010-05-07 12:33:25 -04:00
|
|
|
y_delta = grabbed_y - ev->y_root;
|
|
|
|
grabbed_y = ev->y_root;
|
|
|
|
|
|
|
|
x_delta = ev->x_root - grabbed_x;
|
|
|
|
|
|
|
|
if (y_delta == 0) return TRUE;
|
|
|
|
|
|
|
|
y_delta *= 1 + (x_delta/100);
|
|
|
|
y_delta *= multiplier;
|
|
|
|
y_delta /= 10;
|
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
_controllable->set_value (adjust ((grab_is_fine ? step_inc : page_inc) * y_delta));
|
2010-05-07 12:33:25 -04:00
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
} else if (ev->state & Gdk::BUTTON2_MASK) {
|
|
|
|
|
|
|
|
/* rotary control */
|
2010-05-07 12:33:25 -04:00
|
|
|
|
|
|
|
double x = ev->x - subwidth/2;
|
|
|
|
double y = - ev->y + subwidth/2;
|
|
|
|
double angle = std::atan2 (y, x) / M_PI;
|
|
|
|
|
|
|
|
if (angle < -0.5) {
|
|
|
|
angle += 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
angle = -(2.0/3.0) * (angle - 1.25);
|
|
|
|
angle *= multiplier;
|
2011-06-17 17:47:20 -04:00
|
|
|
|
|
|
|
_controllable->set_value (to_control_value (angle));
|
2010-05-07 12:33:25 -04:00
|
|
|
}
|
2010-03-10 12:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-30 13:55:14 -04:00
|
|
|
MotionFeedback::pixwin_enter_notify_event (GdkEventCrossing*)
|
2010-03-10 12:31:58 -05:00
|
|
|
{
|
|
|
|
pixwin.grab_focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-30 13:55:14 -04:00
|
|
|
MotionFeedback::pixwin_leave_notify_event (GdkEventCrossing*)
|
2010-03-10 12:31:58 -05:00
|
|
|
{
|
|
|
|
pixwin.unset_flags (HAS_FOCUS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MotionFeedback::pixwin_key_press_event (GdkEventKey *ev)
|
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
if (!_controllable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
bool retval = false;
|
2011-06-17 17:47:20 -04:00
|
|
|
double multiplier;
|
2010-03-10 12:31:58 -05:00
|
|
|
|
2011-06-19 19:02:55 -04:00
|
|
|
multiplier = ((ev->state & Keyboard::TertiaryModifier) ? 100.0 : 1.0) *
|
|
|
|
((ev->state & Keyboard::SecondaryModifier) ? 10.0 : 1.0) *
|
|
|
|
((ev->state & Keyboard::PrimaryModifier) ? 2.0 : 1.0);
|
2010-03-10 12:31:58 -05:00
|
|
|
|
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_Page_Up:
|
|
|
|
retval = true;
|
2011-06-19 19:02:55 -04:00
|
|
|
_controllable->set_value (adjust (multiplier * page_inc));
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Page_Down:
|
|
|
|
retval = true;
|
2013-08-31 14:37:02 -04:00
|
|
|
_controllable->set_value (adjust (-multiplier * page_inc));
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Up:
|
|
|
|
retval = true;
|
2011-06-19 19:02:55 -04:00
|
|
|
_controllable->set_value (adjust (multiplier * step_inc));
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Down:
|
|
|
|
retval = true;
|
2013-08-31 14:37:02 -04:00
|
|
|
_controllable->set_value (adjust (-multiplier * step_inc));
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Home:
|
|
|
|
retval = true;
|
2011-06-17 17:47:20 -04:00
|
|
|
_controllable->set_value (_controllable->lower());
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_End:
|
|
|
|
retval = true;
|
2011-06-17 17:47:20 -04:00
|
|
|
_controllable->set_value (_controllable->upper());
|
2010-03-10 12:31:58 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
bool
|
2011-09-30 13:55:14 -04:00
|
|
|
MotionFeedback::pixwin_expose_event (GdkEventExpose*)
|
2011-06-17 17:47:20 -04:00
|
|
|
{
|
|
|
|
if (!_controllable) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkWindow *window = pixwin.get_window()->gobj();
|
|
|
|
double display_val = to_display_value (_controllable->get_value());
|
|
|
|
int32_t phase = lrint (display_val * 64.0);
|
|
|
|
|
|
|
|
// skip middle phase except for true middle value
|
|
|
|
|
|
|
|
if (type == Rotary && phase == 32) {
|
|
|
|
double pt = (display_val * 2.0) - 1.0;
|
|
|
|
if (pt < 0)
|
|
|
|
phase = 31;
|
|
|
|
if (pt > 0)
|
|
|
|
phase = 33;
|
|
|
|
}
|
|
|
|
|
|
|
|
// endless knob: skip 90deg highlights unless the value is really a multiple of 90deg
|
|
|
|
|
|
|
|
if (type == Endless && !(phase % 16)) {
|
|
|
|
if (phase == 64) {
|
|
|
|
phase = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double nom = phase / 64.0;
|
|
|
|
double diff = display_val - nom;
|
|
|
|
|
|
|
|
if (diff > 0.0001)
|
|
|
|
phase = (phase + 1) % 64;
|
|
|
|
if (diff < -0.0001)
|
|
|
|
phase = (phase + 63) % 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
phase = std::min (phase, (int32_t) 63);
|
|
|
|
|
|
|
|
GtkWidget* widget = GTK_WIDGET(pixwin.gobj());
|
|
|
|
gdk_draw_pixbuf (GDK_DRAWABLE(window), widget->style->fg_gc[0],
|
|
|
|
pixbuf->gobj(),
|
|
|
|
phase * subwidth, type * subheight,
|
|
|
|
/* center image in allocated area */
|
|
|
|
(get_width() - subwidth)/2,
|
|
|
|
0,
|
|
|
|
subwidth, subheight, GDK_RGB_DITHER_NORMAL, 0, 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MotionFeedback::pixwin_scroll_event (GdkEventScroll* ev)
|
|
|
|
{
|
|
|
|
double scale;
|
|
|
|
|
|
|
|
if (!_controllable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-31 14:04:47 -04:00
|
|
|
if (ev->state & Keyboard::GainFineScaleModifier) {
|
|
|
|
if (ev->state & Keyboard::GainExtraFineScaleModifier) {
|
|
|
|
scale = 0.01;
|
|
|
|
} else {
|
2013-08-31 21:19:13 -04:00
|
|
|
scale = 0.10;
|
2012-05-31 14:04:47 -04:00
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
} else {
|
2013-08-31 21:19:13 -04:00
|
|
|
scale = 0.20;
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
case GDK_SCROLL_RIGHT:
|
2012-05-31 14:04:47 -04:00
|
|
|
_controllable->set_value (adjust (scale * page_inc));
|
2011-06-17 17:47:20 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
case GDK_SCROLL_LEFT:
|
2012-05-31 14:04:47 -04:00
|
|
|
_controllable->set_value (adjust (-scale * page_inc));
|
2011-06-17 17:47:20 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
void
|
2011-06-17 17:47:20 -04:00
|
|
|
MotionFeedback::pixwin_size_request (GtkRequisition* req)
|
2010-03-10 12:31:58 -05:00
|
|
|
{
|
2011-06-17 17:47:20 -04:00
|
|
|
req->width = subwidth;
|
|
|
|
req->height = subheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MotionFeedback::controllable_value_changed ()
|
|
|
|
{
|
|
|
|
if (value) {
|
|
|
|
char buf[32];
|
|
|
|
print_func (buf, _controllable, print_arg);
|
|
|
|
value->set_text (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixwin.queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MotionFeedback::set_controllable (boost::shared_ptr<PBD::Controllable> c)
|
|
|
|
{
|
|
|
|
_controllable = c;
|
|
|
|
binding_proxy.set_controllable (c);
|
|
|
|
controller_connection.disconnect ();
|
|
|
|
|
|
|
|
if (c) {
|
|
|
|
c->Changed.connect (controller_connection, MISSING_INVALIDATOR, boost::bind (&MotionFeedback::controllable_value_changed, this), gui_context());
|
|
|
|
|
|
|
|
char buf[32];
|
|
|
|
print_func (buf, _controllable, print_arg);
|
|
|
|
value->set_text (buf);
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:31:58 -05:00
|
|
|
pixwin.queue_draw ();
|
|
|
|
}
|
|
|
|
|
2011-06-17 17:47:20 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable>
|
|
|
|
MotionFeedback::controllable () const
|
|
|
|
{
|
|
|
|
return _controllable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MotionFeedback::default_printer (char buf[32], const boost::shared_ptr<PBD::Controllable>& c, void *)
|
|
|
|
{
|
|
|
|
if (c) {
|
|
|
|
sprintf (buf, "%.2f", c->get_value());
|
|
|
|
} else {
|
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::RefPtr<Gdk::Pixbuf>
|
|
|
|
MotionFeedback::render_pixbuf (int size)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
|
2013-07-11 15:15:40 -04:00
|
|
|
char *path;
|
2011-06-17 17:47:20 -04:00
|
|
|
int fd;
|
2014-03-17 10:16:45 -04:00
|
|
|
GError *gerror = NULL;
|
2011-06-17 17:47:20 -04:00
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
fd = g_file_open_tmp ("mfimgXXXXXX", &path, &gerror);
|
2013-07-11 15:15:40 -04:00
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
if (gerror) {
|
|
|
|
error << string_compose (_("motionfeedback: failed to open a temporary file for writing: %1"), gerror->message) << endmsg;
|
|
|
|
g_error_free (gerror);
|
2011-06-17 17:47:20 -04:00
|
|
|
return pixbuf;
|
2014-03-15 10:42:20 -04:00
|
|
|
} else {
|
2014-03-17 10:16:45 -04:00
|
|
|
::close (fd);
|
2013-07-11 15:15:40 -04:00
|
|
|
}
|
2011-06-17 17:47:20 -04:00
|
|
|
|
2014-03-15 10:42:20 -04:00
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
GdkColor col2 = {0,0,0,0};
|
|
|
|
GdkColor col3 = {0,0,0,0};
|
|
|
|
GdkColor dark;
|
|
|
|
GdkColor bright;
|
|
|
|
ProlooksHSV* hsv;
|
|
|
|
|
|
|
|
hsv = prolooks_hsv_new_for_gdk_color (base_color->gobj());
|
|
|
|
bright = (prolooks_hsv_to_gdk_color (hsv, &col2), col2);
|
|
|
|
prolooks_hsv_set_saturation (hsv, 0.66);
|
|
|
|
prolooks_hsv_set_value (hsv, 0.67);
|
|
|
|
dark = (prolooks_hsv_to_gdk_color (hsv, &col3), col3);
|
|
|
|
|
|
|
|
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size * 64, size);
|
|
|
|
cairo_t* cr = cairo_create (surface);
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
cairo_save (cr);
|
|
|
|
core_draw (cr, i, size, 20, size*i, 0, &bright, &dark);
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cairo_surface_write_to_png (surface, path) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
error << string_compose (_("motionfeedback: could not save image set to %1"), path) << endmsg;
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
try {
|
|
|
|
pixbuf = Gdk::Pixbuf::create_from_file (path);
|
|
|
|
} catch (const Gdk::PixbufError &e) {
|
|
|
|
error << string_compose (_("motionfeedback: caught PixbufError: %1"), e.what()) << endmsg;
|
|
|
|
} catch (...) {
|
|
|
|
error << _("motionfeedback: unknown exception") << endmsg;
|
2014-03-15 10:42:20 -04:00
|
|
|
}
|
2013-07-11 15:15:40 -04:00
|
|
|
|
2014-03-17 10:16:45 -04:00
|
|
|
g_unlink (path);
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
return pixbuf;
|
2011-06-17 17:47:20 -04:00
|
|
|
}
|
|
|
|
|
2010-05-06 17:02:08 -04:00
|
|
|
void
|
2010-05-26 11:18:04 -04:00
|
|
|
MotionFeedback::core_draw (cairo_t* cr, int phase, double size, double progress_width, double xorigin, double yorigin,
|
|
|
|
const GdkColor* bright, const GdkColor* dark)
|
2010-05-06 17:02:08 -04:00
|
|
|
{
|
|
|
|
double xc;
|
|
|
|
double yc;
|
|
|
|
double start_angle;
|
|
|
|
double end_angle;
|
|
|
|
double value_angle;
|
|
|
|
double value;
|
|
|
|
double value_x;
|
|
|
|
double value_y;
|
|
|
|
double start_angle_x;
|
|
|
|
double start_angle_y;
|
|
|
|
double end_angle_x;
|
|
|
|
double end_angle_y;
|
|
|
|
double progress_radius;
|
|
|
|
double progress_radius_inner;
|
|
|
|
double progress_radius_outer;
|
|
|
|
|
|
|
|
g_return_if_fail (cr != NULL);
|
2010-05-26 11:18:04 -04:00
|
|
|
|
|
|
|
progress_radius = 40.0;
|
|
|
|
progress_radius_inner = progress_radius - (progress_width / 2.0);
|
|
|
|
progress_radius_outer = progress_radius + (progress_width / 2.0);
|
2010-05-06 17:02:08 -04:00
|
|
|
|
2014-08-31 17:45:20 -04:00
|
|
|
const double pad = 2.0; /* line width for boundary of progress ring */
|
|
|
|
const double actual_width = ((2.0 * pad) + (2.0 * progress_radius_outer));
|
|
|
|
const double scale_factor = size / actual_width;
|
2010-05-26 11:18:04 -04:00
|
|
|
|
2014-08-31 17:45:20 -04:00
|
|
|
/* knob center is at middle of the area bounded by (xorigin,yorigin) and (xorigin+size, yorigin+size)
|
|
|
|
but the coordinates will be scaled by the scale factor when cairo uses them so first
|
|
|
|
adjust them by the reciprocal of the scale factor.
|
|
|
|
*/
|
2010-05-26 11:18:04 -04:00
|
|
|
|
|
|
|
xc = (xorigin + (size / 2.0)) * (1.0/scale_factor);
|
2014-08-31 17:45:20 -04:00
|
|
|
yc = (yorigin + (size / 2.0)) * (1.0/scale_factor);
|
2010-05-06 17:02:08 -04:00
|
|
|
|
|
|
|
value = (phase * 1.0) / (65 - 1);
|
|
|
|
|
2014-08-31 17:45:20 -04:00
|
|
|
start_angle = ((180 - 65) * G_PI) / 180;
|
|
|
|
end_angle = ((360 + 65) * G_PI) / 180;
|
2010-05-06 17:02:08 -04:00
|
|
|
|
|
|
|
value_angle = start_angle + (value * (end_angle - start_angle));
|
|
|
|
value_x = cos (value_angle);
|
|
|
|
value_y = sin (value_angle);
|
|
|
|
start_angle_x = cos (start_angle);
|
|
|
|
start_angle_y = sin (start_angle);
|
|
|
|
end_angle_x = cos (end_angle);
|
|
|
|
end_angle_y = sin (end_angle);
|
|
|
|
|
2010-05-26 11:18:04 -04:00
|
|
|
cairo_scale (cr, scale_factor, scale_factor);
|
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//dark arc background
|
|
|
|
cairo_set_source_rgb (cr, 0.3, 0.3, 0.3 );
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_set_line_width (cr, progress_width);
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius, start_angle, end_angle);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
|
|
|
|
float r = (value) * (((float)bright->red)/G_MAXUINT16) + (1.0-value)*(((float)dark->red)/G_MAXUINT16);
|
|
|
|
float g = (value) * (((float)bright->green)/G_MAXUINT16) + (1.0-value)*(((float)dark->green)/G_MAXUINT16);
|
|
|
|
float b = (value) * (((float)bright->blue)/G_MAXUINT16) + (1.0-value)*(((float)dark->blue)/G_MAXUINT16);
|
|
|
|
|
|
|
|
//colored arc
|
|
|
|
cairo_set_source_rgb (cr, r,g,b);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_set_line_width (cr, progress_width);
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius, start_angle, value_angle);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//overall shade
|
|
|
|
cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, progress_radius_outer);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, 1,1,1, 0.3);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, 1,1,1, 0.0);
|
|
|
|
cairo_set_source (cr, shade_pattern);
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_outer-1, 0, 2.0*G_PI);
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
|
|
|
//black border
|
|
|
|
cairo_set_source_rgb (cr, 0, 0, 0 );
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
2014-07-15 15:58:25 -04:00
|
|
|
cairo_set_line_width (cr, 1.0/scale_factor);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_move_to (cr, xc + (progress_radius_outer * start_angle_x), yc + (progress_radius_outer * start_angle_y));
|
|
|
|
cairo_line_to (cr, xc + (progress_radius_inner * start_angle_x), yc + (progress_radius_inner * start_angle_y));
|
|
|
|
cairo_stroke (cr);
|
|
|
|
cairo_move_to (cr, xc + (progress_radius_outer * end_angle_x), yc + (progress_radius_outer * end_angle_y));
|
|
|
|
cairo_line_to (cr, xc + (progress_radius_inner * end_angle_x), yc + (progress_radius_inner * end_angle_y));
|
|
|
|
cairo_stroke (cr);
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_outer, start_angle, end_angle);
|
|
|
|
cairo_stroke (cr);
|
2014-07-15 15:58:25 -04:00
|
|
|
cairo_arc (cr, xc, yc, progress_radius_inner, start_angle, end_angle);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//knob shadow
|
|
|
|
cairo_save(cr);
|
|
|
|
cairo_translate(cr, 6, 6 );
|
|
|
|
cairo_set_source_rgba (cr, 0,0,0,0.1 );
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_fill (cr);
|
2014-07-15 15:58:25 -04:00
|
|
|
cairo_restore(cr);
|
2010-05-06 17:02:08 -04:00
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//inner circle
|
|
|
|
cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1 );
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_fill (cr);
|
2014-07-15 15:58:25 -04:00
|
|
|
|
|
|
|
//knob shade
|
|
|
|
shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, progress_radius_outer);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 0, 1,1,1, 0.5);
|
|
|
|
cairo_pattern_add_color_stop_rgba (shade_pattern, 1, 0,0,0, 0.3);
|
|
|
|
cairo_set_source (cr, shade_pattern);
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_fill (cr);
|
2014-07-15 15:58:25 -04:00
|
|
|
cairo_pattern_destroy (shade_pattern);
|
|
|
|
|
|
|
|
//inner circle
|
|
|
|
cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.5 );
|
|
|
|
cairo_arc (cr, xc, yc, progress_radius_inner-5, 0, 2.0*G_PI);
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//line
|
|
|
|
cairo_save(cr);
|
|
|
|
cairo_translate(cr, 2, 2 );
|
|
|
|
cairo_set_source_rgba (cr, 0,0,0,0.5 );
|
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_line_width (cr, 4);
|
|
|
|
cairo_move_to (cr, xc + (progress_radius_inner * value_x), yc + (progress_radius_inner * value_y));
|
|
|
|
cairo_line_to (cr, xc + ((progress_radius_inner*0.4) * value_x), yc + ((progress_radius_inner*0.4) * value_y));
|
2010-05-06 17:02:08 -04:00
|
|
|
cairo_stroke (cr);
|
2014-07-15 15:58:25 -04:00
|
|
|
cairo_restore(cr);
|
|
|
|
cairo_set_source_rgba (cr, 1,1,1,0.7 );
|
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_line_width (cr, 4.0);
|
|
|
|
cairo_move_to (cr, xc + (progress_radius_inner * value_x), yc + (progress_radius_inner * value_y));
|
|
|
|
cairo_line_to (cr, xc + ((progress_radius_inner*0.4) * value_x), yc + ((progress_radius_inner*0.4) * value_y));
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2010-05-06 17:02:08 -04:00
|
|
|
|
2014-07-15 15:58:25 -04:00
|
|
|
//highlight if focused (damn, this is a cached image which doesn't (yet) have a "focused" state
|
|
|
|
// if (pixwin.has_focus()) {
|
|
|
|
// cairo_set_source_rgba (cr, 1,1,1, 0.5 );
|
|
|
|
// cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
|
|
|
|
// cairo_fill (cr);
|
|
|
|
// }
|
2010-05-06 17:02:08 -04:00
|
|
|
}
|
2011-10-29 11:53:22 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
MotionFeedback::set_lamp_color (const std::string& str)
|
|
|
|
{
|
|
|
|
if (base_color) {
|
|
|
|
*base_color = Gdk::Color (str);
|
|
|
|
} else {
|
|
|
|
base_color = new Gdk::Color (str);
|
|
|
|
}
|
|
|
|
}
|