CursorZoomDrag rework:

* If the use-time-rulers-to-zoom option is enabled, -all- cursor drags can zoom.
* Behavior has been tweaked so it is easy to scroll without zooming, if you want to.
This commit is contained in:
Ben Loftis 2017-07-20 09:51:26 -05:00
parent 3b47a42127
commit 40e2f9a68a
4 changed files with 41 additions and 82 deletions

View File

@ -2315,7 +2315,6 @@ private:
friend class ControlPointDrag;
friend class LineDrag;
friend class RubberbandSelectDrag;
friend class RulerZoomDrag;
friend class EditorRubberbandSelectDrag;
friend class TimeFXDrag;
friend class ScrubDrag;

View File

@ -1080,18 +1080,6 @@ Editor::canvas_ruler_event (GdkEvent *event, ArdourCanvas::Item* item, ItemType
return handled;
}
switch (event->type) {
case GDK_BUTTON_PRESS:
if (UIConfiguration::instance ().get_use_time_rulers_to_zoom_with_vertical_drag () &&
Keyboard::no_modifier_keys_pressed (&event->button) && event->button.button == 1) {
_drags->set(new RulerZoomDrag(this, item), event);
return true;
}
break;
default:
break;
}
return typed_event (item, event, type);
}

View File

@ -3981,6 +3981,8 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
}
fake_locate (where.frame - snap_delta (event->button.state));
_last_y_delta = 0;
}
void
@ -3993,6 +3995,39 @@ CursorDrag::motion (GdkEvent* event, bool)
if (where.frame != last_pointer_frame()) {
fake_locate (where.frame - snap_delta (event->button.state));
}
//maybe do zooming, too, if the option is enabled
if (UIConfiguration::instance ().get_use_time_rulers_to_zoom_with_vertical_drag () ) {
//To avoid accidental zooming, the mouse must move exactly vertical, not diagonal, to trigger a zoom step
//we use screen coordinates for this, not canvas-based grab_x
double mx = event->button.x;
double dx = fabs(mx - _last_mx);
double my = event->button.y;
double dy = fabs(my - _last_my);
{
//do zooming in windowed "steps" so it feels more reversible
const int stepsize = 4;
int y_delta = grab_y() - current_pointer_y();
y_delta = y_delta / stepsize;
//if all requirements are met, do the actual zoom
const double scale = 1.4;
if ( (dy>dx) && (_last_dx ==0) && (y_delta != _last_y_delta) ) {
if ( _last_y_delta > y_delta ) {
_editor->temporal_zoom_step_mouse_focus_scale (true, scale);
} else {
_editor->temporal_zoom_step_mouse_focus_scale (false, scale);
}
_last_y_delta = y_delta;
}
}
_last_my = my;
_last_mx = mx;
_last_dx = dx;
}
}
void
@ -6965,56 +7000,3 @@ void
RegionCutDrag::aborted (bool)
{
}
RulerZoomDrag::RulerZoomDrag (Editor* e, ArdourCanvas::Item* item)
: Drag (e, item, true)
{
}
void
RulerZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
{
Drag::start_grab (event, c);
framepos_t where = _editor->canvas_event_sample(event);
_editor->_dragging_playhead = true;
_editor->playhead_cursor->set_position (where);
}
void
RulerZoomDrag::motion (GdkEvent* event, bool)
{
framepos_t where = _editor->canvas_event_sample(event);
_editor->playhead_cursor->set_position (where);
const double movement_limit = 20.0;
const double scale = 1.12;
const double y_delta = last_pointer_y() - current_pointer_y();
if (y_delta > 0 && y_delta < movement_limit) {
_editor->temporal_zoom_step_mouse_focus_scale (true, scale);
} else if (y_delta < 0 && y_delta > -movement_limit) {
_editor->temporal_zoom_step_mouse_focus_scale (false, scale);
}
}
void
RulerZoomDrag::finished (GdkEvent*, bool)
{
_editor->_dragging_playhead = false;
Session* s = _editor->session ();
if (s) {
s->request_locate (_editor->playhead_cursor->current_frame (), _was_rolling);
_editor->_pending_locate_request = true;
}
}
void
RulerZoomDrag::aborted (bool)
{
}

View File

@ -907,6 +907,12 @@ private:
EditorCursor& _cursor;
bool _stop; ///< true to stop the transport on starting the drag, otherwise false
double _grab_zoom; ///< editor frames per unit when our grab started
//used for zooming
int _last_mx;
int _last_my;
int _last_dx;
int _last_y_delta;
};
/** Region fade-in drag */
@ -1295,21 +1301,5 @@ private:
bool start;
};
class RulerZoomDrag : public Drag
{
public:
RulerZoomDrag (Editor*, ArdourCanvas::Item*);
void start_grab (GdkEvent*, Gdk::Cursor* c = 0);
void motion (GdkEvent *, bool);
void finished (GdkEvent*, bool);
void aborted (bool);
virtual bool allow_vertical_autoscroll () const {
return false;
}
};
#endif /* __gtk2_ardour_editor_drag_h_ */