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 <wx/graphics.h>
30 using std::shared_ptr;
31 using namespace dcpomatic;
32 #if BOOST_VERSION >= 106100
33 using namespace boost::placeholders;
37 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
41 _content_connection = c->Change.connect (bind (&TimelineContentView::content_change, this, _1, _3));
46 TimelineContentView::bbox () const
48 DCPOMATIC_ASSERT (_track);
50 auto film = _timeline.film ();
51 auto content = _content.lock ();
52 if (!film || !content) {
56 return dcpomatic::Rect<int> (
57 time_x (content->position ()),
59 content->length_after_trim(film).seconds() * _timeline.pixels_per_second().get_value_or(0),
60 _timeline.pixels_per_track()
66 TimelineContentView::set_selected (bool s)
74 TimelineContentView::selected () const
81 TimelineContentView::content () const
83 return _content.lock ();
88 TimelineContentView::set_track (int t)
95 TimelineContentView::unset_track ()
97 _track = boost::optional<int>();
102 TimelineContentView::track () const
109 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>> overlaps)
111 DCPOMATIC_ASSERT (_track);
113 auto film = _timeline.film ();
114 auto cont = content ();
115 if (!film || !cont) {
119 auto const position = cont->position ();
120 auto const len = cont->length_after_trim (film);
122 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
124 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
126 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
128 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
132 auto path = gc->CreatePath ();
133 path.MoveToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
134 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
135 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
136 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get() + 1) - 4);
137 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
138 gc->StrokePath (path);
141 /* Reel split points */
142 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
143 for (auto i: cont->reel_split_points(film)) {
144 path = gc->CreatePath ();
145 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
146 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
147 gc->StrokePath (path);
151 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
152 for (auto const& i: overlaps) {
153 gc->DrawRectangle (i.x, i.y + 4, i.width, i.height - 8);
160 wxDouble lab_descent;
161 wxDouble lab_leading;
162 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
163 gc->GetTextExtent (lab, &lab_width, &lab_height, &lab_descent, &lab_leading);
165 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.pixels_per_track()));
166 gc->DrawText (lab, time_x (position) + 12, y_pos (_track.get() + 1) - lab_height - 4);
172 TimelineContentView::y_pos (int t) const
174 return t * _timeline.pixels_per_track() + _timeline.tracks_y_offset();
179 TimelineContentView::content_change (ChangeType type, int p)
181 if (type != ChangeType::DONE) {
187 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
194 TimelineContentView::label () const
196 return std_to_wx(content()->summary());