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/>.
21 #include "timeline_content_view.h"
24 #include "lib/content.h"
25 #include <wx/graphics.h>
26 #include <boost/foreach.hpp>
29 using boost::shared_ptr;
31 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
36 _content_connection = c->Changed.connect (bind (&TimelineContentView::content_changed, this, _2));
40 TimelineContentView::bbox () const
42 DCPOMATIC_ASSERT (_track);
44 shared_ptr<const Film> film = _timeline.film ();
45 shared_ptr<const Content> content = _content.lock ();
46 if (!film || !content) {
47 return dcpomatic::Rect<int> ();
50 return dcpomatic::Rect<int> (
51 time_x (content->position ()),
53 content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0),
54 _timeline.track_height()
59 TimelineContentView::set_selected (bool s)
66 TimelineContentView::selected () const
72 TimelineContentView::content () const
74 return _content.lock ();
78 TimelineContentView::set_track (int t)
84 TimelineContentView::unset_track ()
86 _track = boost::optional<int> ();
90 TimelineContentView::track () const
96 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
98 DCPOMATIC_ASSERT (_track);
100 shared_ptr<const Film> film = _timeline.film ();
101 shared_ptr<const Content> cont = content ();
102 if (!film || !cont) {
106 DCPTime const position = cont->position ();
107 DCPTime const len = cont->length_after_trim ();
109 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
111 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
113 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
115 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
119 wxGraphicsPath path = gc->CreatePath ();
120 path.MoveToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
121 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
122 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
123 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get() + 1) - 4);
124 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
125 gc->StrokePath (path);
128 /* Reel split points */
129 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
130 BOOST_FOREACH (DCPTime i, cont->reel_split_points ()) {
131 path = gc->CreatePath ();
132 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
133 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
134 gc->StrokePath (path);
138 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
139 for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
140 gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
144 wxString name = std_to_wx (cont->summary());
146 wxDouble name_height;
147 wxDouble name_descent;
148 wxDouble name_leading;
149 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
150 gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
151 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
152 gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
157 TimelineContentView::y_pos (int t) const
159 return _timeline.tracks_position().y + t * _timeline.track_height();
163 TimelineContentView::content_changed (int p)
167 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {