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;
30 using namespace dcpomatic;
32 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
37 _content_connection = c->Change.connect (bind (&TimelineContentView::content_change, this, _1, _3));
41 TimelineContentView::bbox () const
43 DCPOMATIC_ASSERT (_track);
45 shared_ptr<const Film> film = _timeline.film ();
46 shared_ptr<const Content> content = _content.lock ();
47 if (!film || !content) {
48 return dcpomatic::Rect<int> ();
51 return dcpomatic::Rect<int> (
52 time_x (content->position ()),
54 content->length_after_trim(film).seconds() * _timeline.pixels_per_second().get_value_or(0),
55 _timeline.pixels_per_track()
60 TimelineContentView::set_selected (bool s)
67 TimelineContentView::selected () const
73 TimelineContentView::content () const
75 return _content.lock ();
79 TimelineContentView::set_track (int t)
85 TimelineContentView::unset_track ()
87 _track = boost::optional<int> ();
91 TimelineContentView::track () const
97 TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
99 DCPOMATIC_ASSERT (_track);
101 shared_ptr<const Film> film = _timeline.film ();
102 shared_ptr<const Content> cont = content ();
103 if (!film || !cont) {
107 DCPTime const position = cont->position ();
108 DCPTime const len = cont->length_after_trim (film);
110 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
112 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
114 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
116 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
120 wxGraphicsPath path = gc->CreatePath ();
121 path.MoveToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
122 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get()) + 4);
123 path.AddLineToPoint (time_x (position + len) - 1, y_pos (_track.get() + 1) - 4);
124 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get() + 1) - 4);
125 path.AddLineToPoint (time_x (position) + 2, y_pos (_track.get()) + 4);
126 gc->StrokePath (path);
129 /* Reel split points */
130 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
131 BOOST_FOREACH (DCPTime i, cont->reel_split_points(film)) {
132 path = gc->CreatePath ();
133 path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
134 path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
135 gc->StrokePath (path);
139 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
140 for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
141 gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
145 wxString lab = label ();
148 wxDouble lab_descent;
149 wxDouble lab_leading;
150 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
151 gc->GetTextExtent (lab, &lab_width, &lab_height, &lab_descent, &lab_leading);
152 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.pixels_per_track()));
153 gc->DrawText (lab, time_x (position) + 12, y_pos (_track.get() + 1) - lab_height - 4);
158 TimelineContentView::y_pos (int t) const
160 return t * _timeline.pixels_per_track() + _timeline.tracks_y_offset();
164 TimelineContentView::content_change (ChangeType type, int p)
166 if (type != CHANGE_TYPE_DONE) {
172 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
178 TimelineContentView::label () const
180 return std_to_wx(content()->summary());