No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / timeline_reels_view.cc
1 /*
2     Copyright (C) 2015-2016 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 #include "timeline_reels_view.h"
22 #include "timeline.h"
23 #include <wx/wx.h>
24 #include <wx/graphics.h>
25 #include <boost/foreach.hpp>
26
27 using std::min;
28 using std::list;
29
30 TimelineReelsView::TimelineReelsView (Timeline& tl, int y)
31         : TimelineView (tl)
32         , _y (y)
33 {
34
35 }
36
37 dcpomatic::Rect<int>
38 TimelineReelsView::bbox () const
39 {
40         return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
41 }
42
43 void
44 TimelineReelsView::set_y (int y)
45 {
46         _y = y;
47         force_redraw ();
48 }
49
50 void
51 TimelineReelsView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> >)
52 {
53         if (!_timeline.pixels_per_second()) {
54                 return;
55         }
56
57         double const pps = _timeline.pixels_per_second().get ();
58
59         gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 255), 1, wxPENSTYLE_SOLID));
60
61         wxGraphicsPath path = gc->CreatePath ();
62         path.MoveToPoint (time_x (DCPTime (0)), _y);
63         path.AddLineToPoint (time_x (_timeline.film()->length()), _y);
64         gc->StrokePath (path);
65
66         gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, wxColour (0, 0, 255)));
67
68         int reel = 1;
69         BOOST_FOREACH (DCPTimePeriod i, _timeline.film()->reels()) {
70                 int const size = min (8.0, i.duration().seconds() * pps / 2);
71
72                 wxGraphicsPath path = gc->CreatePath ();
73                 path.MoveToPoint (time_x (i.from) + size, _y + size / 2);
74                 path.AddLineToPoint (time_x (i.from), _y);
75                 path.AddLineToPoint (time_x (i.from) + size, _y - size / 2);
76                 gc->StrokePath (path);
77
78                 path = gc->CreatePath ();
79                 path.MoveToPoint (time_x (i.to) - size, _y + size / 2);
80                 path.AddLineToPoint (time_x (i.to), _y);
81                 path.AddLineToPoint (time_x (i.to) - size, _y - size / 2);
82                 gc->StrokePath (path);
83
84                 wxString str = wxString::Format (_("Reel %d"), reel++);
85                 wxDouble str_width;
86                 wxDouble str_height;
87                 wxDouble str_descent;
88                 wxDouble str_leading;
89                 gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
90
91                 int const available_width = time_x (DCPTime (i.to.get())) - time_x (DCPTime (i.from.get()));
92
93                 if (available_width > str_width) {
94                         gc->DrawText (str, time_x (DCPTime (i.from.get())) + (available_width - str_width) / 2, _y + 4);
95                 }
96         }
97 }