2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
23 #include "timeline_content_view.h"
25 #include "lib/content.h"
26 #include <dcp/warnings.h>
27 LIBDCP_DISABLE_WARNINGS
28 #include <wx/graphics.h>
29 LIBDCP_ENABLE_WARNINGS
33 using std::shared_ptr;
34 using namespace dcpomatic;
35 #if BOOST_VERSION >= 106100
36 using namespace boost::placeholders;
40 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
44 _content_connection = c->Change.connect (bind (&TimelineContentView::content_change, this, _1, _3));
49 TimelineContentView::bbox () const
51 DCPOMATIC_ASSERT (_track);
53 auto film = _timeline.film ();
54 auto content = _content.lock ();
55 if (!film || !content) {
59 return dcpomatic::Rect<int> (
60 time_x (content->position ()),
62 content->length_after_trim(film).seconds() * _timeline.pixels_per_second().get_value_or(0),
63 _timeline.pixels_per_track()
69 TimelineContentView::set_selected (bool s)
77 TimelineContentView::selected () const
84 TimelineContentView::content () const
86 return _content.lock ();
91 TimelineContentView::set_track (int t)
98 TimelineContentView::unset_track ()
100 _track = boost::optional<int>();
105 TimelineContentView::track () const
112 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>> overlaps)
114 DCPOMATIC_ASSERT (_track);
116 auto film = _timeline.film ();
117 auto cont = content ();
118 if (!film || !cont) {
122 auto const position = cont->position ();
123 auto const len = cont->length_after_trim (film);
125 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
127 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
129 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
131 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
135 auto path = gc->CreatePath ();
136 path.MoveToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
137 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
138 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
139 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get() + 1) - 4);
140 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
141 gc->StrokePath (path);
144 /* Reel split points */
145 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
146 for (auto i: cont->reel_split_points(film)) {
147 path = gc->CreatePath ();
148 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
149 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
150 gc->StrokePath (path);
154 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
155 for (auto const& i: overlaps) {
156 gc->DrawRectangle (i.x, i.y + 4, i.width, i.height - 8);
163 wxDouble lab_descent;
164 wxDouble lab_leading;
165 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
166 gc->GetTextExtent (lab, &lab_width, &lab_height, &lab_descent, &lab_leading);
168 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.pixels_per_track()));
169 gc->DrawText (lab, time_x (position) + 12, y_pos (_track.get() + 1) - lab_height - 4);
175 TimelineContentView::content_change (ChangeType type, int p)
177 if (type != ChangeType::DONE) {
183 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
190 TimelineContentView::label () const
192 return std_to_wx(content()->summary());