Supporters update.
[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.h"
23 #include "timeline_reels_view.h"
24 #include "wx_util.h"
25 #include "lib/film.h"
26 #include <dcp/warnings.h>
27 LIBDCP_DISABLE_WARNINGS
28 #include <wx/graphics.h>
29 #include <wx/wx.h>
30 LIBDCP_ENABLE_WARNINGS
31
32
33 using std::min;
34 using std::list;
35 using namespace dcpomatic;
36
37
38 TimelineReelsView::TimelineReelsView (Timeline& tl, int y)
39         : TimelineView (tl)
40         , _y (y)
41 {
42
43 }
44
45
46 dcpomatic::Rect<int>
47 TimelineReelsView::bbox () const
48 {
49         return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
50 }
51
52
53 void
54 TimelineReelsView::set_y (int y)
55 {
56         _y = y;
57         force_redraw ();
58 }
59
60
61 void
62 TimelineReelsView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>>)
63 {
64         if (!_timeline.pixels_per_second()) {
65                 return;
66         }
67
68         double const pps = _timeline.pixels_per_second().get ();
69
70         wxColour const colour = gui_is_dark() ? wxColour(182, 204, 240) : wxColour(0, 0, 255);
71         gc->SetPen(*wxThePenList->FindOrCreatePen(colour, 1, wxPENSTYLE_SOLID));
72
73         auto path = gc->CreatePath ();
74         path.MoveToPoint (time_x (DCPTime (0)), _y);
75         path.AddLineToPoint (time_x (_timeline.film()->length()), _y);
76         gc->StrokePath (path);
77
78         gc->SetFont(gc->CreateFont(*wxNORMAL_FONT, colour));
79
80         int reel = 1;
81         for (auto i: _timeline.film()->reels()) {
82                 int const size = min (8.0, i.duration().seconds() * pps / 2);
83
84                 auto path = gc->CreatePath ();
85                 path.MoveToPoint (time_x (i.from) + size, _y + size / 2);
86                 path.AddLineToPoint (time_x (i.from), _y);
87                 path.AddLineToPoint (time_x (i.from) + size, _y - size / 2);
88                 gc->StrokePath (path);
89
90                 path = gc->CreatePath ();
91                 path.MoveToPoint (time_x (i.to) - size, _y + size / 2);
92                 path.AddLineToPoint (time_x (i.to), _y);
93                 path.AddLineToPoint (time_x (i.to) - size, _y - size / 2);
94                 gc->StrokePath (path);
95
96                 auto str = wxString::Format (_("Reel %d"), reel++);
97                 wxDouble str_width;
98                 wxDouble str_height;
99                 wxDouble str_descent;
100                 wxDouble str_leading;
101                 gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
102
103                 int const available_width = time_x(DCPTime(i.to.get())) - time_x(DCPTime(i.from.get()));
104
105                 if (available_width > str_width) {
106                         gc->DrawText (str, time_x(DCPTime(i.from.get())) + (available_width - str_width) / 2, _y + 4);
107                 }
108         }
109 }