Removed a bunch more DEBUGPOINT()s.
[synfig.git] / synfig-studio / trunk / src / gtkmm / cellrenderer_timetrack.cpp
index 81529e7..c1759d9 100644 (file)
@@ -48,6 +48,8 @@
 
 #include <synfig/timepointcollect.h>
 
+#include "general.h"
+
 #endif
 
 using namespace synfig;
@@ -84,7 +86,7 @@ CellRenderer_TimeTrack::CellRenderer_TimeTrack():
        property_adjustment_(*this,"adjustment",&adjustment_),
        property_enable_timing_info_(*this,"enable-timing-info", false)
 {
-               dragging=false;
+       dragging=false;
        selection=false;
 }
 
@@ -124,6 +126,30 @@ CellRenderer_TimeTrack::is_selected(const Waypoint& waypoint)const
        return selected==waypoint;
 }
 
+const synfig::Time get_time_offset_from_vdesc(const synfigapp::ValueDesc &v)
+{
+#ifdef ADJUST_WAYPOINTS_FOR_TIME_OFFSET
+       if(v.get_value_type() != synfig::ValueBase::TYPE_CANVAS)
+               return synfig::Time::zero();
+
+       synfig::Canvas::Handle canvasparam = v.get_value().get(Canvas::Handle());
+       if(!canvasparam)
+               return synfig::Time::zero();
+
+       if (!v.parent_is_layer_param())
+               return synfig::Time::zero();
+
+       synfig::Layer::Handle layer = v.get_layer();
+
+       if (layer->get_name()!="PasteCanvas")
+               return synfig::Time::zero();
+
+       return layer->get_param("time_offset").get(Time());
+#else // ADJUST_WAYPOINTS_FOR_TIME_OFFSET
+       return synfig::Time::zero();
+#endif
+}
+
 //kind of a hack... pointer is ugly
 const synfig::Node::time_set *get_times_from_vdesc(const synfigapp::ValueDesc &v)
 {
@@ -132,9 +158,7 @@ const synfig::Node::time_set *get_times_from_vdesc(const synfigapp::ValueDesc &v
                synfig::Canvas::Handle canvasparam = v.get_value().get(Canvas::Handle());
 
                if(canvasparam)
-               {
                        return &canvasparam->get_times();
-               }
        }
 
        ValueNode *base_value = v.get_value_node().get();
@@ -263,6 +287,7 @@ CellRenderer_TimeTrack::render_vfunc(
 
                if(tset)
                {
+                       const synfig::Time time_offset = get_time_offset_from_vdesc(value_desc);
                        synfig::Node::time_set::const_iterator  i = tset->begin(), end = tset->end();
 
                        float   lower = adjustment->get_lower(),
@@ -284,10 +309,9 @@ CellRenderer_TimeTrack::render_vfunc(
                        for(; i != end; ++i)
                        {
                                //find the coordinate in the drawable space...
-                               Time t = i->get_time();
-
-                               if(!t.is_valid())
-                                       continue;
+                               Time t_orig = i->get_time();
+                               if(!t_orig.is_valid()) continue;
+                               Time t = t_orig - time_offset;
 
                                //if it found it... (might want to change comparison, and optimize
                                //                                       sel_times.find to not produce an overall nlogn solution)
@@ -297,13 +321,13 @@ CellRenderer_TimeTrack::render_vfunc(
                                //if move dragging draw offset
                                //if copy dragging draw both...
 
-                               if(valselected && sel_times.find(t) != sel_times.end())
+                               if(valselected && sel_times.find(t_orig) != sel_times.end())
                                {
                                        if(dragging) //skip if we're dragging because we'll render it later
                                        {
                                                if(mode & COPY_MASK) // draw both blue and red moved
                                                {
-                                                       drawredafter.push_back((t + diff).round(cfps));
+                                                       drawredafter.push_back(t + diff.round(cfps));
                                                        gc->set_rgb_fg_color(Gdk::Color("#00EEEE"));
                                                }else if(mode & DELETE_MASK) //it's just red...
                                                {
@@ -311,7 +335,7 @@ CellRenderer_TimeTrack::render_vfunc(
                                                        selected=true;
                                                }else //move - draw the red on top of the others...
                                                {
-                                                       drawredafter.push_back((t + diff).round(cfps));
+                                                       drawredafter.push_back(t + diff.round(cfps));
                                                        continue;
                                                }
                                        }else
@@ -334,7 +358,7 @@ CellRenderer_TimeTrack::render_vfunc(
                                        area.get_height()-2,
                                        area.get_height()-2
                                );
-                               render_time_point_to_window(window,area2,*i,selected);
+                               render_time_point_to_window(window,area2,*i - time_offset,selected);
 
                                /*window->draw_arc(gc,true,
                                area.get_x() + x - area.get_height()/4, area.get_y() + area.get_height()/8,
@@ -628,8 +652,8 @@ CellRenderer_TimeTrack::activate_vfunc(
 
                        /*!     UI specification:
 
-                               When nothing is selected, clicking on a point in either normal mode order
-                                       addative mode will select the time point closest to the click.
+                               When nothing is selected, clicking on a point in either normal mode or
+                                       additive mode will select the time point closest to the click.
                                        Subtractive click will do nothing
 
                                When things are already selected, clicking on a selected point does
@@ -641,8 +665,9 @@ CellRenderer_TimeTrack::activate_vfunc(
 
                        synfigapp::ValueDesc valdesc = property_value_desc().get_value();
                        const Node::time_set *tset = get_times_from_vdesc(valdesc);
+                       const synfig::Time time_offset = get_time_offset_from_vdesc(valdesc);
 
-                       bool clickfound = tset && get_closest_time(*tset,actual_time,pixel_width*cell_area.get_height(),stime);
+                       bool clickfound = tset && get_closest_time(*tset,actual_time+time_offset,pixel_width*cell_area.get_height(),stime);
                        bool selectmode = mode & SELECT_MASK;
 
                        //NOTE LATER ON WE SHOULD MAKE IT SO MULTIPLE VALUENODES CAN BE SELECTED AT ONCE
@@ -715,7 +740,7 @@ CellRenderer_TimeTrack::activate_vfunc(
                                        selection=true;
                                }
                        }
-                       // Perhaps I sould signal if we selected this activepoint?
+                       // Perhaps I should signal if we selected this activepoint?
                }*/
 
                        if(event->button.button==3)
@@ -723,8 +748,9 @@ CellRenderer_TimeTrack::activate_vfunc(
                                Time stime;
                                synfigapp::ValueDesc valdesc = property_value_desc().get_value();
                                const Node::time_set *tset = get_times_from_vdesc(valdesc);
+                               synfig::Time time_offset = get_time_offset_from_vdesc(valdesc);
 
-                               bool clickfound = tset && get_closest_time(*tset,actual_time,pixel_width*cell_area.get_height(),stime);
+                               bool clickfound = tset && get_closest_time(*tset,actual_time+time_offset,pixel_width*cell_area.get_height(),stime);
 
                                etl::handle<synfig::Node> node;
                                if(valdesc.get_value(stime).get_type()==ValueBase::TYPE_CANVAS)
@@ -738,13 +764,12 @@ CellRenderer_TimeTrack::activate_vfunc(
 
                                if(clickfound && node)
                                {
-                                       show_timepoint_menu(node, stime, actual_time<stime?SIDE_LEFT:SIDE_RIGHT);
+                                       show_timepoint_menu(node, stime, time_offset, actual_time+time_offset<stime?SIDE_LEFT:SIDE_RIGHT);
                                }
                        }
 
                break;
        case GDK_MOTION_NOTIFY:
-               //DEBUGPOINT();
                //if(selection && dragging)
                //      selected_time=((float)event->motion.x-(float)cell_area.get_x())/(float)cell_area.get_width()*(adjustment->get_upper()-adjustment->get_lower())+adjustment->get_lower();
                return true;
@@ -752,8 +777,6 @@ CellRenderer_TimeTrack::activate_vfunc(
                break;
        case GDK_BUTTON_RELEASE:
                {
-                       DEBUGPOINT();
-
                        //selected_time=((float)event->button.x-(float)cell_area.get_x())/(float)cell_area.get_width()*(adjustment->get_upper()-adjustment->get_lower())+adjustment->get_lower();
                        dragging=false;
 
@@ -852,6 +875,10 @@ CellRenderer_TimeTrack::activate_vfunc(
 
 
 
+// The following three functions don't get documented correctly by
+// doxygen 1.5.[23] because of a bug with any function whose name
+// begins with 'property'.  Fixed in doxygen 1.5.4 apparently.  See
+// http://bugzilla.gnome.org/show_bug.cgi?id=471185 .
 Glib::PropertyProxy<synfigapp::ValueDesc>
 CellRenderer_TimeTrack::property_value_desc()
 {
@@ -907,18 +934,20 @@ set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints, W
 }
 
 void
-CellRenderer_TimeTrack::show_timepoint_menu(const etl::handle<synfig::Node>& node, const synfig::Time& time, Side side)
+CellRenderer_TimeTrack::show_timepoint_menu(const etl::handle<synfig::Node>& node, const synfig::Time& time, const synfig::Time& time_offset, Side side)
 {
        std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
        int n;
        n=synfig::waypoint_collect(waypoint_set,time,node);
 
        Gtk::Menu* menu(manage(new Gtk::Menu()));
+       menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
 
        // Create the interpolation method menu
        if(!waypoint_set.empty())
        {
                Gtk::Menu* interp_menu(manage(new Gtk::Menu()));
+               // no need to connect to signal_hide for this one - it will be deleted when its parent is deleted
                Waypoint::Model model;
 
                // note: each of the following 4 'if' blocks provokes these warnings:
@@ -989,13 +1018,15 @@ CellRenderer_TimeTrack::show_timepoint_menu(const etl::handle<synfig::Node>& nod
                                *canvas_interface(),
                                &synfigapp::CanvasInterface::set_time
                        ),
-                       time
+                       time - time_offset
                )
        ));
 
        if(!waypoint_set.empty())
        {
-               if(waypoint_set.size()==1)
+               // attempting to locate the valuenode for the clicked waypoint doesn't work if this is a Canvas parameter,
+               // so act as if there were multiple waypoints in that case as a workaround
+               if(waypoint_set.size()==1 && !Canvas::Handle::cast_dynamic(node))
                {
                        delete menu;
                        menu=0;