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>
27 using boost::shared_ptr;
29 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
34 _content_connection = c->Changed.connect (bind (&TimelineContentView::content_changed, this, _2, _3));
38 TimelineContentView::bbox () const
40 DCPOMATIC_ASSERT (_track);
42 shared_ptr<const Film> film = _timeline.film ();
43 shared_ptr<const Content> content = _content.lock ();
44 if (!film || !content) {
45 return dcpomatic::Rect<int> ();
48 return dcpomatic::Rect<int> (
49 time_x (content->position ()),
51 content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0),
52 _timeline.track_height()
57 TimelineContentView::set_selected (bool s)
64 TimelineContentView::selected () const
70 TimelineContentView::content () const
72 return _content.lock ();
76 TimelineContentView::set_track (int t)
82 TimelineContentView::unset_track ()
84 _track = boost::optional<int> ();
88 TimelineContentView::track () const
94 TimelineContentView::do_paint (wxGraphicsContext* gc)
96 DCPOMATIC_ASSERT (_track);
98 shared_ptr<const Film> film = _timeline.film ();
99 shared_ptr<const Content> cont = content ();
100 if (!film || !cont) {
104 DCPTime const position = cont->position ();
105 DCPTime const len = cont->length_after_trim ();
107 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
109 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
111 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
113 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
117 wxGraphicsPath path = gc->CreatePath ();
118 path.MoveToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
119 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
120 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
121 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get() + 1) - 4);
122 path.AddLineToPoint (time_x (position) + 1, y_pos (_track.get()) + 4);
123 gc->StrokePath (path);
126 /* Reel split points */
127 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
128 BOOST_FOREACH (DCPTime i, cont->reel_split_points ()) {
129 path = gc->CreatePath ();
130 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
131 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
132 gc->StrokePath (path);
136 wxString name = std_to_wx (cont->summary());
138 wxDouble name_height;
139 wxDouble name_descent;
140 wxDouble name_leading;
141 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
142 gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
143 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
144 gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
149 TimelineContentView::y_pos (int t) const
151 return _timeline.tracks_position().y + t * _timeline.track_height();
155 TimelineContentView::content_changed (int p, bool frequent)
159 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
164 _timeline.setup_pixels_per_second ();
165 _timeline.Refresh ();