Move y_pos to TimelineView.
[dcpomatic.git] / src / wx / timeline_content_view.cc
index 69f1723cee28b6ea055ab647a1833882fa7a0e67..5d039d0d3f0a2e82d252da234f63519b8eb4864e 100644 (file)
 
 */
 
-#include "timeline_content_view.h"
+
 #include "timeline.h"
+#include "timeline_content_view.h"
 #include "wx_util.h"
 #include "lib/content.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/graphics.h>
-#include <boost/foreach.hpp>
+LIBDCP_ENABLE_WARNINGS
+
 
 using std::list;
-using boost::shared_ptr;
+using std::shared_ptr;
+using namespace dcpomatic;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
+
 
 TimelineContentView::TimelineContentView (Timeline& tl, shared_ptr<Content> c)
        : TimelineView (tl)
        , _content (c)
-       , _selected (false)
 {
        _content_connection = c->Change.connect (bind (&TimelineContentView::content_change, this, _1, _3));
 }
 
+
 dcpomatic::Rect<int>
 TimelineContentView::bbox () const
 {
        DCPOMATIC_ASSERT (_track);
 
-       shared_ptr<const Film> film = _timeline.film ();
-       shared_ptr<const Content> content = _content.lock ();
+       auto film = _timeline.film ();
+       auto content = _content.lock ();
        if (!film || !content) {
-               return dcpomatic::Rect<int> ();
+               return {};
        }
 
        return dcpomatic::Rect<int> (
@@ -55,6 +64,7 @@ TimelineContentView::bbox () const
                );
 }
 
+
 void
 TimelineContentView::set_selected (bool s)
 {
@@ -62,49 +72,55 @@ TimelineContentView::set_selected (bool s)
        force_redraw ();
 }
 
+
 bool
 TimelineContentView::selected () const
 {
        return _selected;
 }
 
+
 shared_ptr<Content>
 TimelineContentView::content () const
 {
        return _content.lock ();
 }
 
+
 void
 TimelineContentView::set_track (int t)
 {
        _track = t;
 }
 
+
 void
 TimelineContentView::unset_track ()
 {
-       _track = boost::optional<int> ();
+       _track = boost::optional<int>();
 }
 
+
 boost::optional<int>
 TimelineContentView::track () const
 {
        return _track;
 }
 
+
 void
-TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int> > overlaps)
+TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>> overlaps)
 {
        DCPOMATIC_ASSERT (_track);
 
-       shared_ptr<const Film> film = _timeline.film ();
-       shared_ptr<const Content> cont = content ();
+       auto film = _timeline.film ();
+       auto cont = content ();
        if (!film || !cont) {
                return;
        }
 
-       DCPTime const position = cont->position ();
-       DCPTime const len = cont->length_after_trim (film);
+       auto const position = cont->position ();
+       auto const len = cont->length_after_trim (film);
 
        wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
 
@@ -116,7 +132,7 @@ TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>
        }
 
        /* Outline */
-       wxGraphicsPath path = gc->CreatePath ();
+       auto path = gc->CreatePath ();
        path.MoveToPoint    (time_x (position) + 2,           y_pos (_track.get()) + 4);
        path.AddLineToPoint (time_x (position + len) - 1,     y_pos (_track.get()) + 4);
        path.AddLineToPoint (time_x (position + len) - 1,     y_pos (_track.get() + 1) - 4);
@@ -127,7 +143,7 @@ TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>
 
        /* Reel split points */
        gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 1, wxPENSTYLE_DOT));
-       BOOST_FOREACH (DCPTime i, cont->reel_split_points ()) {
+       for (auto i: cont->reel_split_points(film)) {
                path = gc->CreatePath ();
                path.MoveToPoint (time_x (i), y_pos (_track.get()) + 4);
                path.AddLineToPoint (time_x (i), y_pos (_track.get() + 1) - 4);
@@ -136,33 +152,29 @@ TimelineContentView::do_paint (wxGraphicsContext* gc, list<dcpomatic::Rect<int>
 
        /* Overlaps */
        gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (foreground_colour(), wxBRUSHSTYLE_CROSSDIAG_HATCH));
-       for (list<dcpomatic::Rect<int> >::const_iterator i = overlaps.begin(); i != overlaps.end(); ++i) {
-               gc->DrawRectangle (i->x, i->y + 4, i->width, i->height - 8);
+       for (auto const& i: overlaps) {
+               gc->DrawRectangle (i.x, i.y + 4, i.width, i.height - 8);
        }
 
        /* Label text */
-       wxString lab = label ();
+       auto lab = label ();
        wxDouble lab_width;
        wxDouble lab_height;
        wxDouble lab_descent;
        wxDouble lab_leading;
        gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
        gc->GetTextExtent (lab, &lab_width, &lab_height, &lab_descent, &lab_leading);
+       gc->PushState ();
        gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.pixels_per_track()));
        gc->DrawText (lab, time_x (position) + 12, y_pos (_track.get() + 1) - lab_height - 4);
-       gc->ResetClip ();
+       gc->PopState ();
 }
 
-int
-TimelineContentView::y_pos (int t) const
-{
-       return t * _timeline.pixels_per_track() + _timeline.tracks_y_offset();
-}
 
 void
 TimelineContentView::content_change (ChangeType type, int p)
 {
-       if (type != CHANGE_TYPE_DONE) {
+       if (type != ChangeType::DONE) {
                return;
        }
 
@@ -173,6 +185,7 @@ TimelineContentView::content_change (ChangeType type, int p)
        }
 }
 
+
 wxString
 TimelineContentView::label () const
 {