2 Copyright (C) 2013-2015 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>
26 using boost::shared_ptr;
28 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
33 _content_connection = c->Changed.connect (bind (&TimelineContentView::content_changed, this, _2, _3));
37 TimelineContentView::bbox () const
39 DCPOMATIC_ASSERT (_track);
41 shared_ptr<const Film> film = _timeline.film ();
42 shared_ptr<const Content> content = _content.lock ();
43 if (!film || !content) {
44 return dcpomatic::Rect<int> ();
47 return dcpomatic::Rect<int> (
48 time_x (content->position ()),
50 content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0),
51 _timeline.track_height()
56 TimelineContentView::set_selected (bool s)
63 TimelineContentView::selected () const
69 TimelineContentView::content () const
71 return _content.lock ();
75 TimelineContentView::set_track (int t)
81 TimelineContentView::unset_track ()
83 _track = boost::optional<int> ();
87 TimelineContentView::track () const
93 TimelineContentView::do_paint (wxGraphicsContext* gc)
95 DCPOMATIC_ASSERT (_track);
97 shared_ptr<const Film> film = _timeline.film ();
98 shared_ptr<const Content> cont = content ();
103 DCPTime const position = cont->position ();
104 DCPTime const len = cont->length_after_trim ();
106 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
108 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
110 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
112 gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
115 wxGraphicsPath path = gc->CreatePath ();
116 path.MoveToPoint (time_x (position), y_pos (_track.get()) + 4);
117 path.AddLineToPoint (time_x (position + len), y_pos (_track.get()) + 4);
118 path.AddLineToPoint (time_x (position + len), y_pos (_track.get() + 1) - 4);
119 path.AddLineToPoint (time_x (position), y_pos (_track.get() + 1) - 4);
120 path.AddLineToPoint (time_x (position), y_pos (_track.get()) + 4);
121 gc->StrokePath (path);
124 wxString name = std_to_wx (cont->summary());
126 wxDouble name_height;
127 wxDouble name_descent;
128 wxDouble name_leading;
129 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
130 gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
131 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
132 gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
137 TimelineContentView::y_pos (int t) const
139 return _timeline.tracks_position().y + t * _timeline.track_height();
143 TimelineContentView::content_changed (int p, bool frequent)
147 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
152 _timeline.setup_pixels_per_second ();
153 _timeline.Refresh ();