Build fixes for Boost >= 1.73
[dcpomatic.git] / src / wx / timeline_content_view.cc
1 /*
2     Copyright (C) 2013-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_content_view.h"
22 #include "timeline.h"
23 #include "wx_util.h"
24 #include "lib/content.h"
25 #include <wx/graphics.h>
26 #include <boost/foreach.hpp>
27
28 using std::list;
29 using boost::shared_ptr;
30 using namespace dcpomatic;
31 #if BOOST_VERSION >= 106100
32 using namespace boost::placeholders;
33 #endif
34
35 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
36         : TimelineView (tl)
37         , _content (c)
38         , _selected (false)
39 {
40         _content_connection = c->Change.connect (bind (&TimelineContentView::content_change, this, _1, _3));
41 }
42
43 dcpomatic::Rect<int>
44 TimelineContentView::bbox () const
45 {
46         DCPOMATIC_ASSERT (_track);
47
48         shared_ptr<const Film> film = _timeline.film ();
49         shared_ptr<const Content> content = _content.lock ();
50         if (!film || !content) {
51                 return dcpomatic::Rect<int> ();
52         }
53
54         return dcpomatic::Rect<int> (
55                 time_x (content->position ()),
56                 y_pos (_track.get()),
57                 content->length_after_trim(film).seconds() * _timeline.pixels_per_second().get_value_or(0),
58                 _timeline.pixels_per_track()
59                 );
60 }
61
62 void
63 TimelineContentView::set_selected (bool s)
64 {
65         _selected = s;
66         force_redraw ();
67 }
68
69 bool
70 TimelineContentView::selected () const
71 {
72         return _selected;
73 }
74
75 shared_ptr<Content>
76 TimelineContentView::content () const
77 {
78         return _content.lock ();
79 }
80
81 void
82 TimelineContentView::set_track (int t)
83 {
84         _track = t;
85 }
86
87 void
88 TimelineContentView::unset_track ()
89 {
90         _track = boost::optional<int> ();
91 }
92
93 boost::optional<int>
94 TimelineContentView::track () const
95 {
96         return _track;
97 }
98
99 void
100 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
101 {
102         DCPOMATIC_ASSERT (_track);
103
104         shared_ptr<const Film> film = _timeline.film ();
105         shared_ptr<const Content> cont = content ();
106         if (!film || !cont) {
107                 return;
108         }
109
110         DCPTime const position = cont->position ();
111         DCPTime const len = cont->length_after_trim (film);
112
113         wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
114
115         gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
116         if (_selected) {
117                 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
118         } else {
119                 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
120         }
121
122         /* Outline */
123         wxGraphicsPath path = gc->CreatePath ();
124         path.MoveToPoint    (time_x (position) + 2,           y_pos (_track.get()) + 4);
125         path.AddLineToPoint (time_x (position + len) - 1,     y_pos (_track.get()) + 4);
126         path.AddLineToPoint (time_x (position + len) - 1,     y_pos (_track.get() + 1) - 4);
127         path.AddLineToPoint (time_x (position) + 2,           y_pos (_track.get() + 1) - 4);
128         path.AddLineToPoint (time_x (position) + 2,           y_pos (_track.get()) + 4);
129         gc->StrokePath (path);
130         gc->FillPath (path);
131
132         /* Reel split points */
133         gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
134         BOOST_FOREACH (DCPTime i, cont->reel_split_points(film)) {
135                 path = gc->CreatePath ();
136                 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
137                 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
138                 gc->StrokePath (path);
139         }
140
141         /* Overlaps */
142         gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
143         for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
144                 gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
145         }
146
147         /* Label text */
148         wxString lab = label ();
149         wxDouble lab_width;
150         wxDouble lab_height;
151         wxDouble lab_descent;
152         wxDouble lab_leading;
153         gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
154         gc->GetTextExtent (lab, &lab_width, &lab_height, &lab_descent, &lab_leading);
155         gc->PushState ();
156         gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.pixels_per_track()));
157         gc->DrawText (lab, time_x (position) + 12, y_pos (_track.get() + 1) - lab_height - 4);
158         gc->PopState ();
159 }
160
161 int
162 TimelineContentView::y_pos (int t) const
163 {
164         return t * _timeline.pixels_per_track() + _timeline.tracks_y_offset();
165 }
166
167 void
168 TimelineContentView::content_change (ChangeType type, int p)
169 {
170         if (type != CHANGE_TYPE_DONE) {
171                 return;
172         }
173
174         ensure_ui_thread ();
175
176         if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
177                 force_redraw ();
178         }
179 }
180
181 wxString
182 TimelineContentView::label () const
183 {
184         return std_to_wx(content()->summary());
185 }