2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "timeline_content_view.h"
23 #include "lib/content.h"
24 #include <wx/graphics.h>
25 #include <boost/foreach.hpp>
28 using boost::shared_ptr;
30 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
35 _content_connection = c->Changed.connect (bind (&TimelineContentView::content_changed, this, _2));
39 TimelineContentView::bbox () const
41 DCPOMATIC_ASSERT (_track);
43 shared_ptr<const Film> film = _timeline.film ();
44 shared_ptr<const Content> content = _content.lock ();
45 if (!film || !content) {
46 return dcpomatic::Rect<int> ();
49 return dcpomatic::Rect<int> (
50 time_x (content->position ()),
52 content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0),
53 _timeline.track_height()
58 TimelineContentView::set_selected (bool s)
65 TimelineContentView::selected () const
71 TimelineContentView::content () const
73 return _content.lock ();
77 TimelineContentView::set_track (int t)
83 TimelineContentView::unset_track ()
85 _track = boost::optional<int> ();
89 TimelineContentView::track () const
95 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
97 DCPOMATIC_ASSERT (_track);
99 shared_ptr<const Film> film = _timeline.film ();
100 shared_ptr<const Content> cont = content ();
101 if (!film || !cont) {
105 DCPTime const position = cont->position ();
106 DCPTime const len = cont->length_after_trim ();
108 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
110 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
112 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
114 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
118 wxGraphicsPath path = gc->CreatePath ();
119 path.MoveToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
120 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
121 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
122 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get() + 1) - 4);
123 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
124 gc->StrokePath (path);
127 /* Reel split points */
128 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
129 BOOST_FOREACH (DCPTime i, cont->reel_split_points ()) {
130 path = gc->CreatePath ();
131 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
132 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
133 gc->StrokePath (path);
137 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
138 for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
139 gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
143 wxString name = std_to_wx (cont->summary());
145 wxDouble name_height;
146 wxDouble name_descent;
147 wxDouble name_leading;
148 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
149 gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
150 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
151 gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
156 TimelineContentView::y_pos (int t) const
158 return _timeline.tracks_position().y + t * _timeline.track_height();
162 TimelineContentView::content_changed (int p)
166 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {