tabs -> spaces.
[dcpomatic.git] / src / wx / timeline.cc
index 902788bc9efab0fe8867a54ca3633a2d246c529f..8def5550ab920b670258045df958c45e383aad21 100644 (file)
@@ -38,7 +38,7 @@ class View
 {
 public:
        View (Timeline& t)
-               : _timeline (t)
+               : _timeline (t)
        {
 
        }
@@ -55,7 +55,7 @@ public:
                _timeline.force_redraw (bbox ());
        }
 
-       virtual Rect bbox () const = 0;
+       virtual dcpomatic::Rect<int> bbox () const = 0;
 
 protected:
        virtual void do_paint (wxGraphicsContext *) = 0;
@@ -68,7 +68,7 @@ protected:
        Timeline& _timeline;
 
 private:
-       Rect _last_paint_bbox;
+       dcpomatic::Rect<int> _last_paint_bbox;
 };
 
 class ContentView : public View
@@ -83,15 +83,15 @@ public:
                _content_connection = c->Changed.connect (bind (&ContentView::content_changed, this, _2));
        }
 
-       Rect bbox () const
+       dcpomatic::Rect<int> bbox () const
        {
                shared_ptr<const Film> film = _timeline.film ();
                shared_ptr<const Content> content = _content.lock ();
                if (!film || !content) {
-                       return Rect ();
+                       return dcpomatic::Rect<int> ();
                }
                
-               return Rect (
+               return dcpomatic::Rect<int> (
                        time_x (content->start ()) - 8,
                        y_pos (_track) - 8,
                        content->length () * _timeline.pixels_per_time_unit() + 16,
@@ -140,28 +140,19 @@ private:
 
                gc->SetPen (*wxBLACK_PEN);
                
-#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
                gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 4, wxPENSTYLE_SOLID));
                if (_selected) {
                        gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
                } else {
                        gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (colour(), wxBRUSHSTYLE_SOLID));
                }
-#else                  
-               gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 4, wxSOLID));
-               if (_selected) {
-                       gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxSOLID));
-               } else {
-                       gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (colour(), wxSOLID));
-               }
-#endif
                
                wxGraphicsPath path = gc->CreatePath ();
-               path.MoveToPoint    (time_x (start),       y_pos (_track) + 4);
+               path.MoveToPoint    (time_x (start),       y_pos (_track) + 4);
                path.AddLineToPoint (time_x (start + len), y_pos (_track) + 4);
                path.AddLineToPoint (time_x (start + len), y_pos (_track + 1) - 4);
-               path.AddLineToPoint (time_x (start),       y_pos (_track + 1) - 4);
-               path.AddLineToPoint (time_x (start),       y_pos (_track) + 4);
+               path.AddLineToPoint (time_x (start),       y_pos (_track + 1) - 4);
+               path.AddLineToPoint (time_x (start),       y_pos (_track) + 4);
                gc->StrokePath (path);
                gc->FillPath (path);
 
@@ -239,13 +230,13 @@ class TimeAxisView : public View
 {
 public:
        TimeAxisView (Timeline& tl, int y)
-               : View (tl)
+               : View (tl)
                , _y (y)
        {}
        
-       Rect bbox () const
+       dcpomatic::Rect<int> bbox () const
        {
-               return Rect (0, _y - 4, _timeline.width(), 24);
+               return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
        }
 
        void set_y (int y)
@@ -258,11 +249,7 @@ private:
 
        void do_paint (wxGraphicsContext* gc)
        {
-#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
                gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
-#else              
-               gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxSOLID));
-#endif             
                
                int mark_interval = rint (128 / (TIME_HZ * _timeline.pixels_per_time_unit ()));
                if (mark_interval > 5) {
@@ -332,7 +319,9 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        , _down_view_start (0)
        , _first_move (false)
 {
+#ifndef __WXOSX__
        SetDoubleBuffered (true);
+#endif 
 
        setup_pixels_per_time_unit ();
        
@@ -474,7 +463,7 @@ void
 Timeline::left_down (wxMouseEvent& ev)
 {
        list<shared_ptr<View> >::iterator i = _views.begin();
-       Position const p (ev.GetX(), ev.GetY());
+       Position<int> const p (ev.GetX(), ev.GetY());
        while (i != _views.end() && !(*i)->bbox().contains (p)) {
                ++i;
        }
@@ -504,12 +493,28 @@ Timeline::left_down (wxMouseEvent& ev)
        _left_down = true;
        _down_point = ev.GetPosition ();
        _first_move = false;
+
+       if (_down_view) {
+               shared_ptr<Content> c = _down_view->content().lock ();
+               if (c) {
+                       c->set_change_signals_frequent (true);
+               }
+       }
 }
 
 void
-Timeline::left_up (wxMouseEvent &)
+Timeline::left_up (wxMouseEvent& ev)
 {
        _left_down = false;
+
+       if (_down_view) {
+               shared_ptr<Content> c = _down_view->content().lock ();
+               if (c) {
+                       c->set_change_signals_frequent (false);
+               }
+       }
+
+       set_start_from_event (ev);
 }
 
 void
@@ -519,6 +524,12 @@ Timeline::mouse_moved (wxMouseEvent& ev)
                return;
        }
 
+       set_start_from_event (ev);
+}
+
+void
+Timeline::set_start_from_event (wxMouseEvent& ev)
+{
        wxPoint const p = ev.GetPosition();
 
        if (!_first_move) {
@@ -543,7 +554,7 @@ Timeline::mouse_moved (wxMouseEvent& ev)
 }
 
 void
-Timeline::force_redraw (Rect const & r)
+Timeline::force_redraw (dcpomatic::Rect<int> const & r)
 {
        RefreshRect (wxRect (r.x, r.y, r.width, r.height), false);
 }