Click on the timeline time axis view moves the playhead (#2369).
[dcpomatic.git] / src / wx / timeline.cc
index b39a8aebef53319622d17a8efb88cd1ebffe4dbf..2a8555e7ce0b3fd8abcedd14dc369e2c7e43712d 100644 (file)
 #include "lib/text_content.h"
 #include "lib/timer.h"
 #include "lib/video_content.h"
-#include "lib/warnings.h"
-DCPOMATIC_DISABLE_WARNINGS
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/graphics.h>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #include <iterator>
 #include <list>
 
@@ -67,7 +67,7 @@ double const Timeline::_minimum_pixels_per_second = 640.0 / (60 * 60 * 3);
 int const Timeline::_minimum_pixels_per_track = 16;
 
 
-Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
+Timeline::Timeline(wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, FilmViewer& viewer)
        : wxPanel (parent, wxID_ANY)
        , _labels_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
        , _main_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
@@ -81,7 +81,7 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, w
        , _left_down (false)
        , _down_view_position (0)
        , _first_move (false)
-       , _menu (this)
+       , _menu (this, viewer)
        , _snap (true)
        , _tool (SELECT)
        , _x_scroll_rate (16)
@@ -159,7 +159,7 @@ Timeline::paint_labels ()
        _labels_canvas->GetViewStart (&vsx, &vsy);
        gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate + tracks_y_offset());
 
-       _labels_view->paint (gc, list<dcpomatic::Rect<int> >());
+       _labels_view->paint (gc, {});
 
        delete gc;
 }
@@ -207,7 +207,7 @@ Timeline::paint_main ()
        if (_zoom_point) {
                /* Translate back as _down_point and _zoom_point do not take scroll into account */
                gc->Translate (vsx * _x_scroll_rate, vsy * _y_scroll_rate);
-               gc->SetPen (*wxBLACK_PEN);
+               gc->SetPen(gui_is_dark() ? *wxWHITE_PEN : *wxBLACK_PEN);
                gc->SetBrush (*wxTRANSPARENT_BRUSH);
                gc->DrawRectangle (
                        min (_down_point.x, _zoom_point->x),
@@ -219,12 +219,9 @@ Timeline::paint_main ()
 
        /* Playhead */
 
-       auto vp = _viewer.lock ();
-       DCPOMATIC_ASSERT (vp);
-
        gc->SetPen (*wxRED_PEN);
        auto path = gc->CreatePath ();
-       double const ph = vp->position().seconds() * pixels_per_second().get_value_or(0);
+       double const ph = _viewer.position().seconds() * pixels_per_second().get_value_or(0);
        path.MoveToPoint (ph, 0);
        path.AddLineToPoint (ph, pixels_per_track() * _tracks + 32);
        gc->StrokePath (path);
@@ -479,7 +476,6 @@ Timeline::event_to_view (wxMouseEvent& ev)
        Position<int> const p (ev.GetX() + vsx * _x_scroll_rate, ev.GetY() + vsy * _y_scroll_rate);
 
        while (i != _views.rend() && !(*i)->bbox().contains (p)) {
-               auto cv = dynamic_pointer_cast<TimelineContentView>(*i);
                ++i;
        }
 
@@ -524,6 +520,12 @@ Timeline::left_down_select (wxMouseEvent& ev)
                _down_view_position = content_view->content()->position ();
        }
 
+       if (dynamic_pointer_cast<TimelineTimeAxisView>(view)) {
+               int vsx, vsy;
+               _main_canvas->GetViewStart(&vsx, &vsy);
+               _viewer.seek(DCPTime::from_seconds((ev.GetPosition().x + vsx * _x_scroll_rate) / _pixels_per_second.get_value_or(1)), true);
+       }
+
        for (auto i: _views) {
                auto cv = dynamic_pointer_cast<TimelineContentView>(i);
                if (!cv) {