, drag_start_x (0)
, last_drag_x (0)
, accumulated_delta (0)
+ , drag_data_window (0)
+ , drag_data_label (0)
{
if (!have_colors) {
set_colors ();
position_control->Changed.connect (connections, invalidator(*this), boost::bind (&StereoPanner::value_change, this), gui_context());
width_control->Changed.connect (connections, invalidator(*this), boost::bind (&StereoPanner::value_change, this), gui_context());
- set_tooltip ();
+ set_tooltip ();
set_flags (Gtk::CAN_FOCUS);
add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|
StereoPanner::~StereoPanner ()
{
+ delete drag_data_window;
}
void
StereoPanner::set_tooltip ()
{
+ Gtkmm2ext::UI::instance()->set_tip (this,
+ string_compose (_("0 -> set width to zero (mono)\n%1-uparrow -> set width to 100\n%1-downarrow -> set width to -100"),
+
+ Keyboard::secondary_modifier_name()).c_str());
+}
+
+void
+StereoPanner::unset_tooltip ()
+{
+ Gtkmm2ext::UI::instance()->set_tip (this, "");
+}
+
+void
+StereoPanner::set_drag_data ()
+{
+ if (!drag_data_label) {
+ return;
+ }
+
double pos = position_control->get_value(); // 0..1
/* We show the position of the center of the image relative to the left & right.
the center of the USA isn't Kansas, its (50LA, 50NY) and it will all make sense.
*/
- Gtkmm2ext::UI::instance()->set_tip (this,
- string_compose (_("L:%1 R:%2 Width: %3%%\n\n0 -> set width to zero\n%4-uparrow -> set width to 100\n%4-downarrow -> set width to -100"),
- (int) rint (100.0 * (1.0 - pos)),
- (int) rint (100.0 * pos),
- (int) floor (100.0 * width_control->get_value()),
- Keyboard::secondary_modifier_name()).c_str());
+ drag_data_label->set_markup (string_compose (_("L:%1 R:%2 Width: %3%%"),
+ (int) rint (100.0 * (1.0 - pos)),
+ (int) rint (100.0 * pos),
+ (int) floor (100.0 * width_control->get_value())));
}
void
StereoPanner::value_change ()
{
- set_tooltip ();
+ set_drag_data ();
queue_draw ();
}
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
+ /* the usable width is reduced from the real width, because we need space for
+ the two halves of LR boxes that will extend past the actual left/right
+ positions (indicated by the vertical line segment above them).
+ */
+
double usable_width = width - lr_box_size;
/* compute the centers of the L/R boxes based on the current stereo width */
int right;
left = center - pan_spread; // center of left box
- right = center + pan_spread; // right of right box
+ right = center + pan_spread; // center of right box
/* compute & draw the line through the box */
cairo_rectangle (cr,
left - half_lr_box,
- (lr_box_size/2)+step_down,
+ half_lr_box+step_down,
lr_box_size, lr_box_size);
cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(o), UINT_RGBA_G_FLT(o), UINT_RGBA_B_FLT(o), UINT_RGBA_A_FLT(o));
cairo_stroke_preserve (cr);
cairo_rectangle (cr,
right - half_lr_box,
- (lr_box_size/2)+step_down,
+ half_lr_box+step_down,
lr_box_size, lr_box_size);
cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(o), UINT_RGBA_G_FLT(o), UINT_RGBA_B_FLT(o), UINT_RGBA_A_FLT(o));
cairo_stroke_preserve (cr);
}
}
} else {
- if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
- width_control->set_value (-1.0); // reset position to reversed full, LR
+ if (dragging_left) {
+ width_control->set_value (1.0); // reset width to 100%
+ } else if (dragging_right) {
+ width_control->set_value (-1.0); // reset width to inverted 100%
} else {
- width_control->set_value (1.0); // reset position to full, LR
+ width_control->set_value (0); // collapse width to 0%
}
+
}
+
dragging = false;
+
} else {
dragging = true;
}
dragging_left = false;
dragging_right = false;
accumulated_delta = 0;
+
+ if (drag_data_window) {
+ drag_data_window->hide ();
+ }
+
+ set_tooltip ();
+
return true;
}
return false;
}
+ if (!drag_data_window) {
+ drag_data_window = new Window (WINDOW_POPUP);
+ drag_data_window->set_position (WIN_POS_MOUSE);
+ drag_data_window->set_decorated (false);
+
+ drag_data_label = manage (new Label);
+ drag_data_label->set_use_markup (true);
+
+ drag_data_window->set_border_width (6);
+ drag_data_window->add (*drag_data_label);
+ drag_data_label->show ();
+
+ Window* toplevel = dynamic_cast<Window*> (get_toplevel());
+ if (toplevel) {
+ drag_data_window->set_transient_for (*toplevel);
+ }
+ }
+
+ if (!drag_data_window->is_visible ()) {
+ /* move the window a little away from the mouse */
+ drag_data_window->move (ev->x_root+30, ev->y_root+30);
+ drag_data_window->present ();
+ unset_tooltip ();
+ }
+
int w = get_width();
double delta = (ev->x - last_drag_x) / (double) w;
double current_width = width_control->get_value ();
+ /* create a detent close to the center */
+
if (fabs (current_width) < 0.1) {
accumulated_delta += delta;
/* in the detent - have we pulled far enough to escape ? */
if (fabs (accumulated_delta) >= 0.1) {
width_control->set_value (current_width + accumulated_delta);
accumulated_delta = 0;
+ } else {
+ /* snap to zero */
+ width_control->set_value (0);
}
} else {
width_control->set_value (current_width + delta);