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