Updated zh_CN translation from Danbo Song.
[dcpomatic.git] / src / wx / timeline.cc
index 2a8555e7ce0b3fd8abcedd14dc369e2c7e43712d..2b8fba6fd50468766c09a36e3c05646df1d0a5a5 100644 (file)
@@ -35,6 +35,7 @@
 #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"
@@ -150,18 +151,23 @@ Timeline::paint_labels ()
 {
        wxPaintDC dc (_labels_canvas);
 
+       auto film = _film.lock();
+       if (film->content().empty()) {
+               return;
+       }
+
        auto gc = wxGraphicsContext::Create (dc);
        if (!gc) {
                return;
        }
 
+       ScopeGuard sg = [gc]() { delete gc; };
+
        int vsx, vsy;
        _labels_canvas->GetViewStart (&vsx, &vsy);
        gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate + tracks_y_offset());
 
        _labels_view->paint (gc, {});
-
-       delete gc;
 }
 
 
@@ -169,6 +175,12 @@ void
 Timeline::paint_main ()
 {
        wxPaintDC dc (_main_canvas);
+
+       auto film = _film.lock();
+       if (film->content().empty()) {
+               return;
+       }
+
        _main_canvas->DoPrepareDC (dc);
 
        auto gc = wxGraphicsContext::Create (dc);
@@ -176,6 +188,8 @@ Timeline::paint_main ()
                return;
        }
 
+       ScopeGuard sg = [gc]() { delete gc; };
+
        int vsx, vsy;
        _main_canvas->GetViewStart (&vsx, &vsy);
        gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate);
@@ -225,8 +239,6 @@ Timeline::paint_main ()
        path.MoveToPoint (ph, 0);
        path.AddLineToPoint (ph, pixels_per_track() * _tracks + 32);
        gc->StrokePath (path);
-
-       delete gc;
 }
 
 
@@ -318,7 +330,7 @@ place (shared_ptr<const Film> film, TimelineViewList& views, int& tracks)
                int t = base;
 
                auto content = cv->content();
-               DCPTimePeriod const content_period (content->position(), content->end(film));
+               DCPTimePeriod const content_period = content->period(film);
 
                while (true) {
                        auto j = views.begin();
@@ -332,7 +344,8 @@ place (shared_ptr<const Film> film, TimelineViewList& views, int& tracks)
                                auto test_content = test->content();
                                if (
                                        test->track() && test->track().get() == t &&
-                                       content_period.overlap(DCPTimePeriod(test_content->position(), test_content->end(film)))) {
+                                       content_period.overlap(test_content->period(film))
+                                  ) {
                                        /* we have an overlap on track `t' */
                                        ++t;
                                        break;
@@ -949,3 +962,14 @@ Timeline::zoom_all ()
        _labels_canvas->Scroll (0, 0);
        Refresh ();
 }
+
+
+void
+Timeline::keypress(wxKeyEvent const& event)
+{
+       if (event.GetKeyCode() == WXK_DELETE) {
+               auto film = _film.lock();
+               film->remove_content(selected_content());
+       }
+}
+