Plot video and subtitle on one track and audio on the rest in the timeline.
[dcpomatic.git] / src / wx / timeline_reels_view.cc
1 /*
2     Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "timeline_reels_view.h"
21 #include "timeline.h"
22 #include <wx/wx.h>
23 #include <wx/graphics.h>
24 #include <boost/foreach.hpp>
25
26 using std::min;
27 using std::list;
28
29 TimelineReelsView::TimelineReelsView (Timeline& tl, int y)
30         : TimelineView (tl)
31         , _y (y)
32 {
33
34 }
35
36 dcpomatic::Rect<int>
37 TimelineReelsView::bbox () const
38 {
39         return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
40 }
41
42 void
43 TimelineReelsView::set_y (int y)
44 {
45         _y = y;
46         force_redraw ();
47 }
48
49 void
50 TimelineReelsView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
51 {
52         if (!_timeline.pixels_per_second()) {
53                 return;
54         }
55
56         double const pps = _timeline.pixels_per_second().get ();
57
58         gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 255), 1, wxPENSTYLE_SOLID));
59
60         wxGraphicsPath path = gc->CreatePath ();
61         path.MoveToPoint (time_x (DCPTime (0)), _y);
62         path.AddLineToPoint (time_x (_timeline.film()->length()), _y);
63         gc->StrokePath (path);
64
65         gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, wxColour (0, 0, 255)));
66
67         int reel = 1;
68         BOOST_FOREACH (DCPTimePeriod i, _timeline.film()->reels()) {
69                 int const size = min (8.0, i.duration().seconds() * pps / 2);
70
71                 wxGraphicsPath path = gc->CreatePath ();
72                 path.MoveToPoint (time_x (i.from) + size, _y + size / 2);
73                 path.AddLineToPoint (time_x (i.from), _y);
74                 path.AddLineToPoint (time_x (i.from) + size, _y - size / 2);
75                 gc->StrokePath (path);
76
77                 path = gc->CreatePath ();
78                 path.MoveToPoint (time_x (i.to) - size, _y + size / 2);
79                 path.AddLineToPoint (time_x (i.to), _y);
80                 path.AddLineToPoint (time_x (i.to) - size, _y - size / 2);
81                 gc->StrokePath (path);
82
83                 wxString str = wxString::Format (_("Reel %d"), reel++);
84                 wxDouble str_width;
85                 wxDouble str_height;
86                 wxDouble str_descent;
87                 wxDouble str_leading;
88                 gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
89
90                 int const available_width = time_x (DCPTime (i.to.get() - i.from.get()));
91
92                 if (available_width > str_width) {
93                         gc->DrawText (str, time_x (DCPTime (i.from.get())) + (available_width - str_width) / 2, _y + 4);
94                 }
95         }
96 }