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