#include <algorithm>
-#include <cairo/cairo.h>
+#include <cairo.h>
#include "ardour/ardour.h"
#include "ardour/audioengine.h"
#include "gtkmm2ext/keyboard.h"
#include "gtkmm2ext/gui_thread.h"
+#include "gtkmm2ext/cairocell.h"
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/rgb_macros.h"
+#include "actions.h"
#include "ardour_ui.h"
#include "rgb_macros.h"
#include "shuttle_control.h"
ARDOUR_UI::instance()->set_tip (*this, _("Shuttle speed control (Context-click for options)"));
pattern = 0;
+ shine_pattern = 0;
last_shuttle_request = 0;
last_speed_displayed = -99999999;
shuttle_grabbed = false;
shuttle_style_menu = 0;
shuttle_unit_menu = 0;
shuttle_context_menu = 0;
+ _hovering = false;
set_flags (CAN_FOCUS);
add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK|Gdk::SCROLL_MASK);
- set_size_request (100, 15);
+ set_size_request (85, 20);
set_name (X_("ShuttleControl"));
Config->ParameterChanged.connect (parameter_connection, MISSING_INVALIDATOR, boost::bind (&ShuttleControl::parameter_changed, this, _1), gui_context());
ShuttleControl::~ShuttleControl ()
{
cairo_pattern_destroy (pattern);
+ cairo_pattern_destroy (shine_pattern);
}
void
if (pattern) {
cairo_pattern_destroy (pattern);
pattern = 0;
+ cairo_pattern_destroy (shine_pattern);
+ shine_pattern = 0;
}
- pattern = cairo_pattern_create_linear (0, 0, alloc.get_width(), alloc.get_height());
-
- /* add 3 color stops */
+ CairoWidget::on_size_allocate ( alloc);
+ //background
+ pattern = cairo_pattern_create_linear (0, 0, 0, alloc.get_height());
uint32_t col = ARDOUR_UI::config()->canvasvar_Shuttle.get();
-
int r,b,g,a;
UINT_TO_RGBA(col, &r, &g, &b, &a);
-
- cairo_pattern_add_color_stop_rgb (pattern, 0.0, 0, 0, 0);
- cairo_pattern_add_color_stop_rgb (pattern, 0.5, r/255.0, g/255.0, b/255.0);
- cairo_pattern_add_color_stop_rgb (pattern, 1.0, 0, 0, 0);
-
- DrawingArea::on_size_allocate (alloc);
+ cairo_pattern_add_color_stop_rgb (pattern, 0.0, r/400.0, g/400.0, b/400.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 0.4, r/255.0, g/255.0, b/255.0);
+ cairo_pattern_add_color_stop_rgb (pattern, 1.0, r/512.0, g/512.0, b/512.0);
+
+ //reflection
+ shine_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, 10);
+ cairo_pattern_add_color_stop_rgba (shine_pattern, 0, 1,1,1,0.0);
+ cairo_pattern_add_color_stop_rgba (shine_pattern, 0.2, 1,1,1,0.4);
+ cairo_pattern_add_color_stop_rgba (shine_pattern, 1, 1,1,1,0.1);
}
void
switch (ev->button) {
case 1:
- add_modal_grab ();
- shuttle_grabbed = true;
- shuttle_speed_on_grab = _session->transport_speed ();
- mouse_shuttle (ev->x, true);
+ if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
+ if (_session->transport_rolling()) {
+ _session->request_transport_speed (1.0);
+ }
+ } else {
+ add_modal_grab ();
+ shuttle_grabbed = true;
+ shuttle_speed_on_grab = _session->transport_speed ();
+ mouse_shuttle (ev->x, true);
+ gdk_pointer_grab(ev->window,false,
+ GdkEventMask( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK |Gdk::BUTTON_RELEASE_MASK),
+ NULL,NULL,ev->time);
+ }
break;
case 2:
switch (ev->button) {
case 1:
- shuttle_grabbed = false;
- remove_modal_grab ();
-
- if (Config->get_shuttle_behaviour() == Sprung) {
- _session->request_transport_speed (shuttle_speed_on_grab);
- } else {
- mouse_shuttle (ev->x, true);
+ if (shuttle_grabbed) {
+ shuttle_grabbed = false;
+ remove_modal_grab ();
+ gdk_pointer_ungrab (GDK_CURRENT_TIME);
+
+ if (Config->get_shuttle_behaviour() == Sprung) {
+ if (shuttle_speed_on_grab == 0 ) {
+ _session->request_transport_speed (1.0);
+ }
+ _session->request_transport_speed (shuttle_speed_on_grab);
+ } else {
+ mouse_shuttle (ev->x, true);
+ }
}
-
return true;
case 2:
if (_session->transport_rolling()) {
- _session->request_transport_speed (1.0);
+ _session->request_transport_speed (1.0, Config->get_shuttle_behaviour() == Wheel);
}
return true;
}
void
-ShuttleControl::set_shuttle_fract (double f)
+ShuttleControl::set_shuttle_fract (double f, bool zero_ok)
{
shuttle_fract = f;
- use_shuttle_fract (false);
+ use_shuttle_fract (false, zero_ok);
}
int
}
void
-ShuttleControl::use_shuttle_fract (bool force)
+ShuttleControl::use_shuttle_fract (bool force, bool zero_ok)
{
microseconds_t now = get_microseconds();
speed = shuttle_max_speed * shuttle_fract;
}
- _session->request_transport_speed_nonzero (speed);
+ if (zero_ok) {
+ _session->request_transport_speed (speed, Config->get_shuttle_behaviour() == Wheel);
+ } else {
+ _session->request_transport_speed_nonzero (speed, Config->get_shuttle_behaviour() == Wheel);
+ }
}
-bool
-ShuttleControl::on_expose_event (GdkEventExpose*)
+void
+ShuttleControl::render (cairo_t* cr)
{
cairo_text_extents_t extents;
- Glib::RefPtr<Gdk::Window> win (get_window());
- Glib::RefPtr<Gtk::Style> style (get_style());
-
- cairo_t* cr = gdk_cairo_create (win->gobj());
- cairo_set_source (cr, pattern);
- cairo_rectangle (cr, 0.0, 0.0, get_width(), get_height());
- cairo_fill_preserve (cr);
-
- cairo_set_source_rgb (cr, 0, 0, 0.0);
- cairo_stroke (cr);
+ //black border
+ cairo_set_source_rgb (cr, 0, 0.0, 0.0);
+ rounded_rectangle (cr, 0, 0, get_width(), get_height(), 4);
+// cairo_fill_preserve (cr);
+// cairo_stroke (cr);
+ cairo_fill (cr);
float speed = 0.0;
}
/* Marker */
-
- double visual_fraction = std::min (1.0f, speed/shuttle_max_speed);
- double x = (get_width() / 2.0) + (0.5 * (get_width() * visual_fraction));
- cairo_move_to (cr, x, 1);
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- cairo_line_to (cr, x, get_height()-1);
+ float visual_fraction = std::min (1.0f, speed/shuttle_max_speed);
+ float marker_size = get_height()-4;
+ float avail_width = get_width() - marker_size;
+ float x = get_width()*0.5 + visual_fraction * avail_width*0.5;
+ float offset = x - marker_size*0.5;
+// cairo_set_source_rgb (cr, 0, 1, 0.0);
+ cairo_set_source (cr, pattern);
+ if (speed == 1.0) {
+ cairo_move_to( cr, offset-4, 2);
+ cairo_line_to( cr, offset+4, 2+marker_size*0.5);
+ cairo_line_to( cr, offset-4, 2+marker_size);
+ cairo_line_to( cr, offset-4, 2);
+ } else if ( speed ==0.0 )
+ rounded_rectangle (cr, offset, 4, marker_size-2, marker_size-2, 1);
+ else
+ cairo_arc (cr, offset + marker_size*0.5, 2 + marker_size*0.5, marker_size*0.5, 0, 360);
+ cairo_set_line_width (cr, 2);
cairo_stroke (cr);
/* speed text */
last_speed_displayed = speed;
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_set_source_rgb (cr, 0.6, 0.6, 0.6);
cairo_text_extents (cr, buf, &extents);
- cairo_move_to (cr, 10, extents.height + 2);
+ cairo_move_to (cr, 10, extents.height + 4);
+ cairo_set_font_size (cr, 13.0);
cairo_show_text (cr, buf);
/* style text */
}
cairo_text_extents (cr, buf, &extents);
-
- cairo_move_to (cr, get_width() - (fabs(extents.x_advance) + 5), extents.height + 2);
+ cairo_move_to (cr, get_width() - (fabs(extents.x_advance) + 5), extents.height + 4);
cairo_show_text (cr, buf);
- cairo_destroy (cr);
+ float _corner_radius = 4.0;
- return true;
+/* //reflection
+ float rheight = 10.0;
+ Gtkmm2ext::rounded_rectangle (cr, 2, 1, get_width()-4, rheight, _corner_radius);
+ cairo_set_source (cr, shine_pattern);
+ cairo_fill (cr);
+*/
+ if (ARDOUR::Config->get_widget_prelight()) {
+ if (_hovering) {
+ rounded_rectangle (cr, 1, 1, get_width()-2, get_height()-2, _corner_radius);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.2);
+ cairo_fill (cr);
+ }
+ }
}
void
void
ShuttleControl::ShuttleControllable::set_value (double val)
{
- double fract;
-
- if (val == 0.5) {
- fract = 0.0;
- } else {
- if (val < 0.5) {
- fract = -((0.5 - val)/0.5);
- } else {
- fract = ((val - 0.5)/0.5);
- }
- }
-
- sc.set_shuttle_fract (fract);
+ sc.set_shuttle_fract ((val - lower()) / (upper() - lower()), true);
}
double
ShuttleControl::ShuttleControllable::get_value () const
{
- return sc.get_shuttle_fract ();
+ return lower() + (sc.get_shuttle_fract () * (upper() - lower()));
}
void
if (_session->transport_speed() == 1.0) {
queue_draw ();
} else {
+ /* reset current speed and
+ revert to 1.0 as the default
+ */
_session->request_transport_speed (1.0);
/* redraw when speed changes */
}
queue_draw ();
}
}
+
+
+bool
+ShuttleControl::on_enter_notify_event (GdkEventCrossing* ev)
+{
+ _hovering = true;
+
+ if (ARDOUR::Config->get_widget_prelight()) {
+ queue_draw ();
+ }
+
+ return CairoWidget::on_enter_notify_event (ev);
+}
+
+bool
+ShuttleControl::on_leave_notify_event (GdkEventCrossing* ev)
+{
+ _hovering = false;
+
+ if (ARDOUR::Config->get_widget_prelight()) {
+ queue_draw ();
+ }
+
+ return CairoWidget::on_leave_notify_event (ev);
+}