13
0

Resolve potential ambiguity between the constraint modifier and the copy modifier when beginning a drag.

This commit is contained in:
nick_m 2016-08-14 01:50:51 +10:00
parent c62026b567
commit 4eba9b8638
5 changed files with 42 additions and 10 deletions

View File

@ -237,6 +237,7 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only)
, _grab_frame (0)
, _last_pointer_frame (0)
, _snap_delta (0)
, _constraint_pressed (false)
{
}
@ -261,6 +262,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
{
/* we set up x/y dragging constraints on first move */
_constraint_pressed = ArdourKeyboard::indicates_constraint (event->button.state);
_raw_grab_frame = _editor->canvas_event_sample (event, &_grab_x, &_grab_y);
@ -420,14 +422,14 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
if (Config->get_edit_mode() != Lock) {
if (event->motion.state & Gdk::BUTTON2_MASK) {
// if dragging with button2, the motion is x constrained, with constraint modifier it is y constrained
if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
if (_constraint_pressed) {
_x_constrained = false;
_y_constrained = true;
} else {
_x_constrained = true;
_y_constrained = false;
}
} else if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
} else if (_constraint_pressed) {
// if dragging normally, the motion is constrained to the first direction of movement.
if (_initially_vertical) {
_x_constrained = true;
@ -3343,7 +3345,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
}
if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier ())) {
if (ArdourKeyboard::indicates_constraint (event->button.state)) {
/* use vertical movement to alter tempo .. should be log */
double new_bpm = _real_section->beats_per_minute() + ((last_pointer_y() - current_pointer_y()) / 5.0);
stringstream strs;
@ -3469,7 +3471,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
pf = adjusted_current_frame (event);
}
if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
if (ArdourKeyboard::indicates_constraint (event->button.state)) {
/* adjust previous tempo to match pointer frame */
_editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_pulse (_pulse), pf, _pulse);
}

View File

@ -282,6 +282,7 @@ private:
*/
ARDOUR::frameoffset_t _snap_delta;
CursorContext::Handle _cursor_ctx; ///< cursor change context
bool _constraint_pressed; ///< if the keyboard indicated constraint modifier was pressed on start_grab()
};
class RegionDrag;

View File

@ -684,7 +684,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
new TempoMarkerDrag (
this,
item,
Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)
ArdourKeyboard::indicates_copy (event->button.state)
),
event
);
@ -697,7 +697,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
new MeterMarkerDrag (
this,
item,
Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)
ArdourKeyboard::indicates_copy (event->button.state)
),
event
);
@ -718,9 +718,9 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case MinsecRulerItem:
case BBTRulerItem:
if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)
&& !Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
&& !ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new CursorDrag (this, *playhead_cursor, false), event);
} else if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
} else if (ArdourKeyboard::indicates_constraint (event->button.state)) {
_drags->set (new BBTRulerDrag (this, item), event);
}
return true;
@ -963,7 +963,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
}
/* click on a normal region view */
if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
if (ArdourKeyboard::indicates_copy (event->button.state)) {
add_region_copy_drag (item, event, clicked_regionview);
} else if (Keyboard::the_keyboard().key_is_down (GDK_b)) {
add_region_brush_drag (item, event, clicked_regionview);
@ -1164,7 +1164,7 @@ Editor::button_press_handler_2 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case MouseObject:
switch (item_type) {
case RegionItem:
if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) {
if (ArdourKeyboard::indicates_copy (event->button.state)) {
add_region_copy_drag (item, event, clicked_regionview);
} else {
add_region_drag (item, event, clicked_regionview);

View File

@ -300,6 +300,25 @@ ArdourKeyboard::indicates_snap_delta (guint state)
return (contains_d && ((contains_s && d_contains_s) || !contains_s));
}
/* Constraint and copy modifiers are both in effect at the beginning of some drags, and may be set ambiguously */
bool
ArdourKeyboard::indicates_copy (guint state)
{
const bool contains_c = Keyboard::modifier_state_contains (state, Keyboard::CopyModifier);
const bool equals_cs = Keyboard::modifier_state_equals (state, constraint_modifier ());
return contains_c && !equals_cs;
}
bool
ArdourKeyboard::indicates_constraint (guint state)
{
const bool contains_cs = Keyboard::modifier_state_contains (state, constraint_modifier ());
const bool equals_c = Keyboard::modifier_state_equals (state, Keyboard::CopyModifier);
return contains_cs && !equals_c;
}
void
ArdourKeyboard::set_constraint_modifier (guint mod)
{

View File

@ -56,6 +56,16 @@ class ArdourKeyboard : public Gtkmm2ext::Keyboard
*/
static bool indicates_snap_delta (guint state);
/** @param state The button state from a GdkEvent.
* @return true if the modifier state indicates copy modifier
*/
static bool indicates_copy (guint state);
/** @param state The button state from a GdkEvent.
* @return true if the modifier state indicates constraint modifier
*/
static bool indicates_constraint (guint state);
static void set_constraint_modifier (guint);
/** @return Modifier mask to constrain drags in a particular direction;
*/