X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftimeline.cc;h=f67bf52dc4ffaf971129a0195a4a27af48843288;hb=efc6f0d2148441f3a30e2a66349d66461bb986f9;hp=c6ce1527b0aaa549fc9690f781ddc40e24ba1f3e;hpb=65895ac52ed072314080040f99978cdd77b5a5db;p=dcpomatic.git diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index c6ce1527b..f67bf52dc 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -35,10 +35,10 @@ #include "lib/film.h" #include "lib/image_content.h" #include "lib/playlist.h" -#include "lib/scope_guard.h" #include "lib/text_content.h" #include "lib/timer.h" #include "lib/video_content.h" +#include #include LIBDCP_DISABLE_WARNINGS #include @@ -109,6 +109,7 @@ Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr film, Fi _main_canvas->Bind (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down, this, _1)); _main_canvas->Bind (wxEVT_MOTION, boost::bind (&Timeline::mouse_moved, this, _1)); _main_canvas->Bind (wxEVT_SIZE, boost::bind (&Timeline::resized, this)); + _main_canvas->Bind (wxEVT_MOUSEWHEEL, boost::bind(&Timeline::mouse_wheel_turned, this, _1)); _main_canvas->Bind (wxEVT_SCROLLWIN_TOP, boost::bind (&Timeline::scrolled, this, _1)); _main_canvas->Bind (wxEVT_SCROLLWIN_BOTTOM, boost::bind (&Timeline::scrolled, this, _1)); _main_canvas->Bind (wxEVT_SCROLLWIN_LINEUP, boost::bind (&Timeline::scrolled, this, _1)); @@ -117,7 +118,7 @@ Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr film, Fi _main_canvas->Bind (wxEVT_SCROLLWIN_PAGEDOWN, boost::bind (&Timeline::scrolled, this, _1)); _main_canvas->Bind (wxEVT_SCROLLWIN_THUMBTRACK, boost::bind (&Timeline::scrolled, this, _1)); - film_change (ChangeType::DONE, Film::Property::CONTENT); + film_change(ChangeType::DONE, FilmProperty::CONTENT); SetMinSize (wxSize (640, 4 * pixels_per_track() + 96)); @@ -132,6 +133,43 @@ Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr film, Fi } +void +Timeline::mouse_wheel_turned(wxMouseEvent& event) +{ + if (event.ControlDown()) { + auto const rotation = event.GetWheelRotation(); + /* On my mouse one click of the scroll wheel is 120, and it's -ve when + * scrolling the wheel towards me. + */ + auto const scale = rotation > 0 ? + (1.0 / (rotation / 90.0)) : + (-rotation / 90.0); + + int before_start_x; + int before_start_y; + _main_canvas->GetViewStart(&before_start_x, &before_start_y); + + auto const before_pps = _pixels_per_second.get_value_or(1); + auto const before_pos = _last_mouse_wheel_x && *_last_mouse_wheel_x == event.GetX() ? + *_last_mouse_wheel_time : + (before_start_x * _x_scroll_rate + event.GetX()) / before_pps; + + set_pixels_per_second(before_pps * scale); + setup_scrollbars(); + + auto after_left = std::max(0.0, before_pos * _pixels_per_second.get_value_or(1) - event.GetX()); + _main_canvas->Scroll(after_left / _x_scroll_rate, before_start_y); + _labels_canvas->Scroll(0, before_start_y); + Refresh(); + + if (!_last_mouse_wheel_x || *_last_mouse_wheel_x != event.GetX()) { + _last_mouse_wheel_x = event.GetX(); + _last_mouse_wheel_time = before_pos; + } + } +} + + void Timeline::update_playhead () { @@ -161,7 +199,7 @@ Timeline::paint_labels () return; } - ScopeGuard sg = [gc]() { delete gc; }; + dcp::ScopeGuard sg = [gc]() { delete gc; }; int vsx, vsy; _labels_canvas->GetViewStart (&vsx, &vsy); @@ -175,6 +213,7 @@ void Timeline::paint_main () { wxPaintDC dc (_main_canvas); + dc.Clear(); auto film = _film.lock(); if (film->content().empty()) { @@ -188,7 +227,7 @@ Timeline::paint_main () return; } - ScopeGuard sg = [gc]() { delete gc; }; + dcp::ScopeGuard sg = [gc]() { delete gc; }; gc->SetAntialiasMode (wxANTIALIAS_DEFAULT); @@ -237,16 +276,16 @@ Timeline::paint_main () void -Timeline::film_change (ChangeType type, Film::Property p) +Timeline::film_change(ChangeType type, FilmProperty p) { if (type != ChangeType::DONE) { return; } - if (p == Film::Property::CONTENT || p == Film::Property::REEL_TYPE || p == Film::Property::REEL_LENGTH) { + if (p == FilmProperty::CONTENT || p == FilmProperty::REEL_TYPE || p == FilmProperty::REEL_LENGTH) { ensure_ui_thread (); recreate_views (); - } else if (p == Film::Property::CONTENT_ORDER) { + } else if (p == FilmProperty::CONTENT_ORDER) { Refresh (); } } @@ -320,6 +359,7 @@ place (shared_ptr film, TimelineViewList& views, int& tracks) } auto cv = dynamic_pointer_cast (i); + DCPOMATIC_ASSERT(cv); int t = base;