diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2006-05-25 20:30:32 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2006-05-25 20:30:32 +0000 |
commit | b7757ddd7007b6382fbd89ba02ddc525b3a57543 (patch) | |
tree | b1d5a2f1b907b30649d9c701982100b96e8c42d2 /gtk2_ardour | |
parent | ce6c41c060c700489a9ac9fc5080bf2920c17ae2 (diff) |
changes to autoscroll behaviour. not perfect, but probably better
git-svn-id: svn://localhost/trunk/ardour2@533 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/editor.cc | 120 | ||||
-rw-r--r-- | gtk2_ardour/editor_canvas.cc | 159 | ||||
-rw-r--r-- | gtk2_ardour/editor_mouse.cc | 29 |
3 files changed, 162 insertions, 146 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index de58b60f86..5caef7fc19 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -815,15 +815,6 @@ Editor::set_entered_track (TimeAxisView* tav) } } -gint -Editor::left_track_canvas (GdkEventCrossing *ev) -{ - set_entered_track (0); - set_entered_regionview (0); - return FALSE; -} - - void Editor::show_window () { @@ -2838,117 +2829,6 @@ Editor::setup_toolbar () toolbar_frame.add (toolbar_base); } -gint -Editor::_autoscroll_canvas (void *arg) -{ - return ((Editor *) arg)->autoscroll_canvas (); -} - -gint -Editor::autoscroll_canvas () -{ - jack_nframes_t new_frame; - bool keep_calling = true; - jack_nframes_t limit = max_frames - current_page_frames(); - GdkEventMotion ev; - - autoscroll_distance = current_page_frames() * 3 / 4; - - if (autoscroll_direction < 0) { - if (leftmost_frame < autoscroll_distance) { - new_frame = 0; - } else { - new_frame = leftmost_frame - autoscroll_distance; - } - ev.x = drag_info.current_pointer_x - autoscroll_distance; - } else { - if (leftmost_frame > limit - autoscroll_distance) { - new_frame = limit; - } else { - new_frame = leftmost_frame + autoscroll_distance; - } - ev.x = drag_info.current_pointer_x + autoscroll_distance; - } - - if (new_frame != leftmost_frame) { - cerr << "move to " << new_frame << " which is " << autoscroll_distance << " away" << endl; - reposition_x_origin (new_frame); - } - - /* now fake a motion event to get the object that is being dragged to move too */ - - ev.type = GDK_MOTION_NOTIFY; - ev.x = frame_to_unit (ev.x); - ev.y = frame_to_unit (drag_info.current_pointer_y); - motion_handler (drag_info.item, (GdkEvent*) &ev, drag_info.item_type, true); - - if (new_frame == 0 || new_frame == limit) { - /* we are done */ - return false; - } - - return false; - - autoscroll_cnt++; - - if (autoscroll_cnt == 1) { - - /* connect the timeout so that we get called repeatedly */ - - autoscroll_timeout_tag = gtk_timeout_add (20, _autoscroll_canvas, this); - keep_calling = false; - - } else if (autoscroll_cnt == 50) { /* 0.5 seconds */ - - /* after about a while, speed up a bit by changing the timeout interval */ - - autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/50.0f); - cerr << "change distance to " << autoscroll_distance << endl; - - } else if (autoscroll_cnt == 75) { /* 1.0 seconds */ - - autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/20.0f); - cerr << "change distance to " << autoscroll_distance << endl; - - } else if (autoscroll_cnt == 100) { /* 1.5 seconds */ - - /* after about another while, speed up by increasing the shift per callback */ - - autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/10.0f); - cerr << "change distance to " << autoscroll_distance << endl; - - } - - return keep_calling; -} - -void -Editor::start_canvas_autoscroll (int dir) -{ - if (!session) { - return; - } - - stop_canvas_autoscroll (); - - autoscroll_direction = dir; - autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/100.0); - autoscroll_cnt = 0; - - /* do it right now, which will start the repeated callbacks */ - - autoscroll_canvas (); -} - -void -Editor::stop_canvas_autoscroll () -{ - if (autoscroll_timeout_tag >= 0) { - gtk_timeout_remove (autoscroll_timeout_tag); - autoscroll_timeout_tag = -1; - } -} - int Editor::convert_drop_to_paths (vector<ustring>& paths, const RefPtr<Gdk::DragContext>& context, diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index b636fccc9c..73aeef79b2 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -495,3 +495,162 @@ Editor::drop_regions (const RefPtr<Gdk::DragContext>& context, context->drag_finish (true, false, time); } +void +Editor::maybe_autoscroll (GdkEvent* event) +{ + jack_nframes_t rightmost_frame = leftmost_frame + current_page_frames(); + jack_nframes_t frame = drag_info.current_pointer_frame; + bool startit = false; + + static int last_autoscroll_direction = 0; + + if (frame > rightmost_frame) { + + if (rightmost_frame < max_frames) { + autoscroll_direction = 1; + startit = true; + } + + } else if (frame < leftmost_frame) { + + if (leftmost_frame > 0) { + autoscroll_direction = -1; + startit = true; + } + + } else { + + if (drag_info.last_pointer_frame > drag_info.current_pointer_frame) { + autoscroll_direction = -1; + } else { + autoscroll_direction = 1; + } + } + + + if (autoscroll_direction != last_autoscroll_direction) { + stop_canvas_autoscroll (); + } + + if (startit && autoscroll_timeout_tag < 0) { + start_canvas_autoscroll (autoscroll_direction); + } + + last_autoscroll_direction = autoscroll_direction; + drag_info.last_pointer_frame = drag_info.current_pointer_frame; +} + +gint +Editor::_autoscroll_canvas (void *arg) +{ + return ((Editor *) arg)->autoscroll_canvas (); +} + +gint +Editor::autoscroll_canvas () +{ + jack_nframes_t new_frame; + bool keep_calling = true; + jack_nframes_t limit = max_frames - current_page_frames(); + GdkEventMotion ev; + jack_nframes_t target_frame; + + if (autoscroll_direction < 0) { + if (leftmost_frame < autoscroll_distance) { + new_frame = 0; + } else { + new_frame = leftmost_frame - autoscroll_distance; + } + target_frame = drag_info.current_pointer_frame - autoscroll_distance; + } else { + if (leftmost_frame > limit - autoscroll_distance) { + new_frame = limit; + } else { + new_frame = leftmost_frame + autoscroll_distance; + } + target_frame = drag_info.current_pointer_frame + autoscroll_distance; + } + + if (new_frame != leftmost_frame) { + reposition_x_origin (new_frame); + } + + /* now fake a motion event to get the object that is being dragged to move too */ + + ev.type = GDK_MOTION_NOTIFY; + ev.state &= Gdk::BUTTON1_MASK; + ev.x = frame_to_unit (target_frame); + ev.y = drag_info.current_pointer_y; + motion_handler (drag_info.item, (GdkEvent*) &ev, drag_info.item_type, true); + + if (new_frame == 0 || new_frame == limit) { + /* we are done */ + return false; + } + + autoscroll_cnt++; + + if (autoscroll_cnt == 1) { + + /* connect the timeout so that we get called repeatedly */ + + autoscroll_timeout_tag = gtk_timeout_add (20, _autoscroll_canvas, this); + keep_calling = false; + + } else if (autoscroll_cnt == 50) { /* 0.5 seconds */ + + /* after about a while, speed up a bit by changing the timeout interval */ + + autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/50.0f); + + } else if (autoscroll_cnt == 75) { /* 1.0 seconds */ + + autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/20.0f); + + } else if (autoscroll_cnt == 100) { /* 1.5 seconds */ + + /* after about another while, speed up by increasing the shift per callback */ + + autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/10.0f); + + } + + return keep_calling; +} + +void +Editor::start_canvas_autoscroll (int dir) +{ + if (!session) { + return; + } + + stop_canvas_autoscroll (); + + autoscroll_direction = dir; + autoscroll_distance = (jack_nframes_t) floor (current_page_frames()/100.0); + autoscroll_cnt = 0; + + /* do it right now, which will start the repeated callbacks */ + + autoscroll_canvas (); +} + +void +Editor::stop_canvas_autoscroll () +{ + if (autoscroll_timeout_tag >= 0) { + gtk_timeout_remove (autoscroll_timeout_tag); + autoscroll_timeout_tag = -1; + } +} + +gint +Editor::left_track_canvas (GdkEventCrossing *ev) +{ + set_entered_track (0); + set_entered_regionview (0); + return FALSE; +} + + diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 50527f51d6..1409da77a9 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1104,28 +1104,6 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT return false; } -void -Editor::maybe_autoscroll (GdkEvent* event) -{ - jack_nframes_t rightmost_frame = leftmost_frame + current_page_frames(); - - jack_nframes_t frame = drag_info.current_pointer_frame; - - cerr << "maybe autoscroll @ " << frame << " left = " << leftmost_frame << " right = " << rightmost_frame << endl; - - if (frame > rightmost_frame) { - if (rightmost_frame < max_frames) { - autoscroll_direction = 1; - autoscroll_canvas (); - } - } else if (frame < leftmost_frame) { - if (leftmost_frame > 0) { - autoscroll_direction = -1; - autoscroll_canvas (); - } - } -} - bool Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { @@ -1497,13 +1475,14 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item &drag_info.current_pointer_y); if (!from_autoscroll && drag_info.item) { - /* item != 0 is the best test i can think of for - dragging. + /* item != 0 is the best test i can think of for dragging. */ if (!drag_info.move_threshold_passsed) { + drag_info.move_threshold_passsed = (abs ((int) (drag_info.current_pointer_x - drag_info.grab_x)) > 4); // and change the initial grab loc/frame if this drag info wants us to + if (drag_info.want_move_threshold && drag_info.move_threshold_passsed) { drag_info.grab_frame = drag_info.current_pointer_frame; drag_info.grab_x = drag_info.current_pointer_x; @@ -2785,8 +2764,6 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) vector<int32_t> height_list(512) ; vector<int32_t>::iterator j; - cerr << "region motion to " << drag_info.current_pointer_frame << endl; - /* Which trackview is this ? */ TimeAxisView* tvp = trackview_by_y_position (drag_info.current_pointer_y); |