13
0

better detent handling, and dbl-click behaviour for lower half improvements

git-svn-id: svn://localhost/ardour2/branches/3.0@8391 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-12-30 18:59:09 +00:00
parent f669a4b581
commit 55ec9b3a18

View File

@ -64,6 +64,7 @@ StereoPanner::StereoPanner (boost::shared_ptr<PBD::Controllable> position, boost
, drag_start_x (0)
, last_drag_x (0)
, accumulated_delta (0)
, detented (false)
, drag_data_window (0)
, drag_data_label (0)
{
@ -289,7 +290,59 @@ StereoPanner::on_button_press_event (GdkEventButton* ev)
dragging_position = false;
dragging_left = false;
dragging_right = false;
dragging = false;
accumulated_delta = 0;
detented = false;
if (ev->type == GDK_2BUTTON_PRESS) {
int width = get_width();
if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
/* handled by button release */
return true;
}
if (ev->y < 20) {
/* lower section: adjusts position, constrained by width */
if (ev->x >= width/2 - 10 && ev->x <= width/2 + 10) {
/* double click near center, reset position to center */
position_control->set_value (0.5);
} else {
if (ev->x < width/2) {
/* double click on left, collapse to hard left */
width_control->set_value (0);
position_control->set_value (0);
} else {
/* double click on right, collapse to hard right */
width_control->set_value (0);
position_control->set_value (1.0);
}
}
} else {
/* lower section: adjusts width, constrained by position */
if (ev->x <= width/3) {
/* left side dbl click */
width_control->set_value (1.0); // reset width to 100%
} else if (ev->x > 2*width/3) {
/* right side dbl click */
width_control->set_value (-1.0); // reset width to inverted 100%
} else {
/* center dbl click */
width_control->set_value (0); // collapse width to 0%
}
}
dragging = false;
} else if (ev->type == GDK_BUTTON_PRESS) {
if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
/* handled by button release */
return true;
}
if (ev->y < 20) {
/* top section of widget is for position drags */
@ -314,37 +367,6 @@ StereoPanner::on_button_press_event (GdkEventButton* ev)
}
if (ev->type == GDK_2BUTTON_PRESS) {
if (dragging_position) {
int width = get_width();
if (ev->x >= width/2 - 10 && ev->x <= width/2 + 10) {
/* double click near center, reset position to center */
position_control->set_value (0.5);
} else {
if (ev->x < width/2) {
/* double click on left, collapse to hard left */
width_control->set_value (0);
position_control->set_value (0);
} else {
/* double click on right, collapse to hard right */
width_control->set_value (0);
position_control->set_value (1.0);
}
}
} else {
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 (0); // collapse width to 0%
}
}
dragging = false;
} else {
dragging = true;
}
@ -359,11 +381,18 @@ StereoPanner::on_button_release_event (GdkEventButton* ev)
dragging_left = false;
dragging_right = false;
accumulated_delta = 0;
detented = false;
if (drag_data_window) {
drag_data_window->hide ();
}
if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
/* reset to default */
position_control->set_value (0.5);
width_control->set_value (1.0);
}
set_tooltip ();
return true;
@ -452,16 +481,24 @@ StereoPanner::on_motion_notify_event (GdkEventMotion* ev)
/* 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 {
if (!detented && fabs (current_width) < 0.02) {
detented = true;
/* snap to zero */
width_control->set_value (0);
}
if (detented) {
accumulated_delta += delta;
/* have we pulled far enough to escape ? */
if (fabs (accumulated_delta) >= 0.1) {
width_control->set_value (current_width + accumulated_delta);
detented = false;
accumulated_delta = false;
}
} else {
width_control->set_value (current_width + delta);
}