Basics of timeline track labels.
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Feb 2016 22:24:39 +0000 (22:24 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 25 Feb 2016 22:24:39 +0000 (22:24 +0000)
src/wx/timeline.cc
src/wx/timeline.h
src/wx/timeline_labels_view.cc [new file with mode: 0644]
src/wx/timeline_labels_view.h [new file with mode: 0644]
src/wx/timeline_reels_view.h
src/wx/timeline_time_axis_view.cc
src/wx/timeline_time_axis_view.h
src/wx/wscript

index de20705316d04419df7c389e04d02b28735f97f5..a7b41eb983d7516b3e12898e53bd47a9b0464167 100644 (file)
@@ -21,6 +21,7 @@
 #include "timeline.h"
 #include "timeline_time_axis_view.h"
 #include "timeline_reels_view.h"
+#include "timeline_labels_view.h"
 #include "timeline_video_content_view.h"
 #include "timeline_audio_content_view.h"
 #include "timeline_subtitle_content_view.h"
@@ -53,6 +54,7 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film)
        , _film (film)
        , _time_axis_view (new TimelineTimeAxisView (*this, 64))
        , _reels_view (new TimelineReelsView (*this, 32))
+       , _labels_view (new TimelineLabelsView (*this))
        , _tracks (0)
        , _left_down (false)
        , _down_view_position (0)
@@ -75,6 +77,8 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film)
 
        SetMinSize (wxSize (640, tracks() * track_height() + 96));
 
+       _tracks_position = Position<int> (_labels_view->bbox().width, 8);
+
        _film_changed_connection = film->Changed.connect (bind (&Timeline::film_changed, this, _1));
        _film_content_changed_connection = film->ContentChanged.connect (bind (&Timeline::film_content_changed, this, _2, _3));
 }
@@ -136,6 +140,7 @@ Timeline::recreate_views ()
        _views.clear ();
        _views.push_back (_time_axis_view);
        _views.push_back (_reels_view);
+       _views.push_back (_labels_view);
 
        BOOST_FOREACH (shared_ptr<Content> i, film->content ()) {
                if (dynamic_pointer_cast<VideoContent> (i)) {
@@ -255,7 +260,7 @@ Timeline::setup_pixels_per_second ()
                return;
        }
 
-       _pixels_per_second = static_cast<double>(width() - x_offset() * 2) / film->length().seconds ();
+       _pixels_per_second = static_cast<double>(width() - tracks_position().x * 2) / film->length().seconds ();
 }
 
 shared_ptr<TimelineView>
index c0a18ab0dd107065be62902aae3e40458f28771d..519f00afbd1abb9a6efe26dfa7efab5d67e4240c 100644 (file)
@@ -32,6 +32,7 @@ class ContentPanel;
 class TimelineView;
 class TimelineTimeAxisView;
 class TimelineReelsView;
+class TimelineLabelsView;
 
 class Timeline : public wxPanel
 {
@@ -42,10 +43,6 @@ public:
 
        void force_redraw (dcpomatic::Rect<int> const &);
 
-       int x_offset () const {
-               return 8;
-       }
-
        int width () const {
                return GetSize().GetWidth ();
        }
@@ -59,7 +56,7 @@ public:
        }
 
        Position<int> tracks_position () const {
-               return Position<int> (8, 8);
+               return _tracks_position;
        }
 
        int tracks () const;
@@ -100,6 +97,7 @@ private:
        TimelineViewList _views;
        boost::shared_ptr<TimelineTimeAxisView> _time_axis_view;
        boost::shared_ptr<TimelineReelsView> _reels_view;
+       boost::shared_ptr<TimelineLabelsView> _labels_view;
        int _tracks;
        boost::optional<double> _pixels_per_second;
        bool _left_down;
@@ -111,6 +109,7 @@ private:
        bool _snap;
        std::list<DCPTime> _start_snaps;
        std::list<DCPTime> _end_snaps;
+       Position<int> _tracks_position;
 
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _film_content_changed_connection;
diff --git a/src/wx/timeline_labels_view.cc b/src/wx/timeline_labels_view.cc
new file mode 100644 (file)
index 0000000..e5827f9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+
+#include "timeline_labels_view.h"
+#include "timeline.h"
+#include <wx/wx.h>
+#include <wx/graphics.h>
+
+using std::list;
+using std::max;
+
+TimelineLabelsView::TimelineLabelsView (Timeline& tl)
+       : TimelineView (tl)
+{
+       wxString labels[] = {
+               _("Video"),
+               _("Audio"),
+               _("Subtitles")
+       };
+
+       _width = 0;
+
+        wxClientDC dc (&_timeline);
+       for (int i = 0; i < 3; ++i) {
+               wxSize size = dc.GetTextExtent (labels[i]);
+               _width = max (_width, size.GetWidth());
+       }
+
+       _width += 16;
+}
+
+dcpomatic::Rect<int>
+TimelineLabelsView::bbox () const
+{
+       return dcpomatic::Rect<int> (0, 0, _width, _timeline.tracks() * _timeline.track_height());
+}
+
+void
+TimelineLabelsView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
+{
+       int const h = _timeline.track_height ();
+       gc->SetFont (gc->CreateFont(*wxNORMAL_FONT, wxColour (0, 0, 0)));
+       gc->DrawText (_("Video"), 0, h / 2);
+       gc->DrawText (_("Subtitles"), 0, 3 * h / 2);
+       gc->DrawText (_("Audio"), 0, h + _timeline.tracks() * h / 2);
+}
diff --git a/src/wx/timeline_labels_view.h b/src/wx/timeline_labels_view.h
new file mode 100644 (file)
index 0000000..96dd692
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "timeline_view.h"
+
+class wxWindow;
+
+class TimelineLabelsView : public TimelineView
+{
+public:
+       TimelineLabelsView (Timeline& tl);
+
+       dcpomatic::Rect<int> bbox () const;
+
+private:
+       void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
+
+       int _width;
+};
index 5f8ae1d387966d15496b32e0fdec2cef06a0e509..7ef16d496af2bbcbdbcfc18804fc442ed43b8184 100644 (file)
@@ -30,6 +30,5 @@ public:
 private:
        void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
 
-private:
        int _y;
 };
index bbaf5fde2847422114088407f56d4ef684eb83fb..ce37ec659e3f7561ea85be7fe94d3077d6080de0 100644 (file)
@@ -34,7 +34,7 @@ TimelineTimeAxisView::TimelineTimeAxisView (Timeline& tl, int y)
 dcpomatic::Rect<int>
 TimelineTimeAxisView::bbox () const
 {
-       return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
+       return dcpomatic::Rect<int> (_timeline.tracks_position().x, _y - 4, _timeline.width(), 24);
 }
 
 void
@@ -74,7 +74,7 @@ TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>
        }
 
        wxGraphicsPath path = gc->CreatePath ();
-       path.MoveToPoint (_timeline.x_offset(), _y);
+       path.MoveToPoint (_timeline.tracks_position().x, _y);
        path.AddLineToPoint (_timeline.width(), _y);
        gc->StrokePath (path);
 
@@ -102,7 +102,7 @@ TimelineTimeAxisView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>
                wxDouble str_leading;
                gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
 
-               int const tx = _timeline.x_offset() + t.seconds() * pps;
+               int const tx = _timeline.tracks_position().x + t.seconds() * pps;
                if ((tx + str_width) < _timeline.width()) {
                        gc->DrawText (str, time_x (t), _y + 16);
                }
index fbd7c5de9a81245dcc13da4a5a9b2bf269f2129c..d57d7b7491d92bb1d465a90fdaa5b9fc847d1141 100644 (file)
@@ -30,7 +30,6 @@ public:
 private:
        void do_paint (wxGraphicsContext* gc, std::list<dcpomatic::Rect<int> > overlaps);
 
-private:
        int _y;
 };
 
index b78ccc9282adb546ecd4f2e06833941263de4f03..2198a401aaed6ea9937c998b1b1d4e12170f148b 100644 (file)
@@ -83,6 +83,7 @@ sources = """
           timeline_content_view.cc
           timeline_dialog.cc
           timeline_audio_content_view.cc
+          timeline_labels_view.cc
           timeline_subtitle_content_view.cc
           timeline_reels_view.cc
           timeline_time_axis_view.cc