-public:
- ContentView (Timeline& tl, shared_ptr<Content> c)
- : View (tl)
- , _content (c)
- , _selected (false)
- {
- _content_connection = c->Changed.connect (bind (&ContentView::content_changed, this, _2, _3));
- }
-
- dcpomatic::Rect<int> bbox () const
- {
- assert (_track);
-
- shared_ptr<const Film> film = _timeline.film ();
- shared_ptr<const Content> content = _content.lock ();
- if (!film || !content) {
- return dcpomatic::Rect<int> ();
- }
-
- return dcpomatic::Rect<int> (
- time_x (content->position ()) - 8,
- y_pos (_track.get()) - 8,
- content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0) + 16,
- _timeline.track_height() + 16
- );
- }
-
- void set_selected (bool s) {
- _selected = s;
- force_redraw ();
- }
-
- bool selected () const {
- return _selected;
- }
-
- shared_ptr<Content> content () const {
- return _content.lock ();
- }
-
- void set_track (int t) {
- _track = t;
- }
-
- void unset_track () {
- _track = boost::optional<int> ();
- }
-
- optional<int> track () const {
- return _track;
- }
-
- virtual wxString type () const = 0;
- virtual wxColour background_colour () const = 0;
- virtual wxColour foreground_colour () const = 0;
-
-private:
-
- void do_paint (wxGraphicsContext* gc)
- {
- assert (_track);
-
- shared_ptr<const Film> film = _timeline.film ();
- shared_ptr<const Content> cont = content ();
- if (!film || !cont) {
- return;
- }
-
- DCPTime const position = cont->position ();
- DCPTime const len = cont->length_after_trim ();
-
- wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
-
- gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
- if (_selected) {
- gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
- } else {
- gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
- }
-
- wxGraphicsPath path = gc->CreatePath ();
- path.MoveToPoint (time_x (position), y_pos (_track.get()) + 4);
- path.AddLineToPoint (time_x (position + len), y_pos (_track.get()) + 4);
- path.AddLineToPoint (time_x (position + len), y_pos (_track.get() + 1) - 4);
- path.AddLineToPoint (time_x (position), y_pos (_track.get() + 1) - 4);
- path.AddLineToPoint (time_x (position), y_pos (_track.get()) + 4);
- gc->StrokePath (path);
- gc->FillPath (path);
-
- wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->summary()).data(), type().data());
- wxDouble name_width;
- wxDouble name_height;
- wxDouble name_descent;
- wxDouble name_leading;
- gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
-
- gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
- gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
- gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
- gc->ResetClip ();
- }
-
- int y_pos (int t) const
- {
- return _timeline.tracks_position().y + t * _timeline.track_height();
- }
-
- void content_changed (int p, bool frequent)
- {
- ensure_ui_thread ();
-
- if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
- force_redraw ();
- }
-
- if (!frequent) {
- _timeline.setup_pixels_per_second ();
- _timeline.Refresh ();
- }
- }
-
- boost::weak_ptr<Content> _content;
- optional<int> _track;
- bool _selected;
-
- boost::signals2::scoped_connection _content_connection;
-};
+#ifndef __WXOSX__
+ _labels_canvas->SetDoubleBuffered (true);
+ _main_canvas->SetDoubleBuffered (true);
+#endif
+
+ wxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+ sizer->Add (_labels_canvas, 0, wxEXPAND);
+ _labels_canvas->SetMinSize (wxSize (_labels_view->bbox().width, -1));
+ sizer->Add (_main_canvas, 1, wxEXPAND);
+ SetSizer (sizer);
+
+ _labels_canvas->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_labels, this));
+ _main_canvas->Bind (wxEVT_PAINT, boost::bind (&Timeline::paint_main, this));
+ _main_canvas->Bind (wxEVT_LEFT_DOWN, boost::bind (&Timeline::left_down, this, _1));
+ _main_canvas->Bind (wxEVT_LEFT_UP, boost::bind (&Timeline::left_up, this, _1));
+ _main_canvas->Bind (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down, this, _1));
+ _main_canvas->Bind (wxEVT_MOTION, boost::bind (&Timeline::mouse_moved, this, _1));
+ _main_canvas->Bind (wxEVT_SIZE, boost::bind (&Timeline::resized, this));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_TOP, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_BOTTOM, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_LINEUP, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_LINEDOWN, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_PAGEUP, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_PAGEDOWN, boost::bind (&Timeline::scrolled, this, _1));
+ _main_canvas->Bind (wxEVT_SCROLLWIN_THUMBTRACK, boost::bind (&Timeline::scrolled, this, _1));
+
+ film_changed (Film::CONTENT);
+
+ SetMinSize (wxSize (640, 4 * pixels_per_track() + 96));
+
+ _film_changed_connection = film->Changed.connect (bind (&Timeline::film_changed, this, _1));
+ _film_content_changed_connection = film->ContentChanged.connect (bind (&Timeline::film_content_changed, this, _2, _3));
+
+ setup_scrollbars ();
+ _labels_canvas->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
+}