Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / src / gtkmm / cellrenderer_timetrack.cpp
index 95a9d97..bb6d7b1 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -45,7 +46,7 @@
 #include <synfigapp/canvasinterface.h>
 #include "instance.h"
 
-#include <synfig/timepointcollect.h>
+#include "general.h"
 
 #endif
 
@@ -83,13 +84,14 @@ CellRenderer_TimeTrack::CellRenderer_TimeTrack():
        property_adjustment_(*this,"adjustment",&adjustment_),
        property_enable_timing_info_(*this,"enable-timing-info", false)
 {
-               dragging=false;
+       dragging=false;
        selection=false;
 }
 
 CellRenderer_TimeTrack::~CellRenderer_TimeTrack()
 {
-       synfig::info("CellRenderer_TimeTrack::~CellRenderer_TimeTrack(): deleted");
+       if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
+               synfig::info("CellRenderer_TimeTrack::~CellRenderer_TimeTrack(): Deleted");
 }
 
 void
@@ -123,17 +125,41 @@ 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(getenv("SYNFIG_SHOW_CANVAS_PARAM_WAYPOINTS") ||
+          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)
 {
-       if(v.get_value_type() == synfig::ValueBase::TYPE_CANVAS)
+       if(!getenv("SYNFIG_SHOW_CANVAS_PARAM_WAYPOINTS") &&
+          v.get_value_type() == synfig::ValueBase::TYPE_CANVAS)
        {
                synfig::Canvas::Handle canvasparam = v.get_value().get(Canvas::Handle());
 
                if(canvasparam)
-               {
                        return &canvasparam->get_times();
-               }
        }
 
        ValueNode *base_value = v.get_value_node().get();
@@ -199,10 +225,10 @@ void
 CellRenderer_TimeTrack::render_vfunc(
                const Glib::RefPtr<Gdk::Drawable>& window,
                Gtk::Widget& widget,
-               const Gdk::Rectangle& background_area,
+               const Gdk::Rectangle& /*background_area*/,
                const Gdk::Rectangle& area_,
-               const Gdk::Rectangle& expose_area,
-               Gtk::CellRendererState flags)
+               const Gdk::Rectangle& /*expose_area*/,
+               Gtk::CellRendererState /*flags*/)
 {
        if(!window)
                return;
@@ -262,6 +288,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(),
@@ -283,10 +310,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)
@@ -296,13 +322,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...
                                                {
@@ -310,7 +336,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
@@ -333,7 +359,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,
@@ -529,7 +555,7 @@ CellRenderer_TimeTrack::render_vfunc(
 }
 
 synfig::ValueNode_Animated::WaypointList::iterator
-CellRenderer_TimeTrack::find_waypoint(const synfig::Time& t,const synfig::Time& scope)
+CellRenderer_TimeTrack::find_waypoint(const synfig::Time& /*t*/,const synfig::Time& scope)
 {
        synfig::ValueNode_Animated *value_node=dynamic_cast<synfig::ValueNode_Animated*>(property_value_desc().get_value().get_value_node().get());
 
@@ -564,11 +590,11 @@ CellRenderer_TimeTrack::find_waypoint(const synfig::Time& t,const synfig::Time&
 bool
 CellRenderer_TimeTrack::activate_vfunc(
        GdkEvent* event,
-       Gtk::Widget& widget,
+       Gtk::Widget& /*widget*/,
        const Glib::ustring& treepath,
-       const Gdk::Rectangle& background_area,
+       const Gdk::Rectangle& /*background_area*/,
        const Gdk::Rectangle& cell_area,
-       Gtk::CellRendererState flags)
+       Gtk::CellRendererState /*flags*/)
 {
        path=treepath;
        synfig::ValueNode_Animated::WaypointList::iterator iter;
@@ -627,8 +653,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
@@ -640,8 +666,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
@@ -714,7 +741,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)
@@ -722,11 +749,13 @@ 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)
+                               if(!getenv("SYNFIG_SHOW_CANVAS_PARAM_WAYPOINTS") &&
+                                  valdesc.get_value(stime).get_type()==ValueBase::TYPE_CANVAS)
                                {
                                        node=Canvas::Handle(valdesc.get_value(stime).get(Canvas::Handle()));
                                }
@@ -737,13 +766,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?Waypoint::SIDE_LEFT:Waypoint::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;
@@ -751,14 +779,12 @@ 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;
 
                        /*if(event->button.button==3 && selection)
                        {
-                               signal_waypoint_clicked_(path,*selected_waypoint,event->button.button-1);
+                               signal_waypoint_clicked_cellrenderer_(path,*selected_waypoint,event->button.button-1);
                                return true;
                        }
                        */
@@ -774,7 +800,8 @@ CellRenderer_TimeTrack::activate_vfunc(
                                        param_list.add("canvas",canvas_interface()->get_canvas());
                                        param_list.add("canvas_interface",canvas_interface());
 
-                                       if(sel_value.get_value_type() == synfig::ValueBase::TYPE_CANVAS)
+                                       if(!getenv("SYNFIG_SHOW_CANVAS_PARAM_WAYPOINTS") &&
+                                          sel_value.get_value_type() == synfig::ValueBase::TYPE_CANVAS)
                                        {
                                                param_list.add("addcanvas",sel_value.get_value().get(Canvas::Handle()));
                                        }else
@@ -819,7 +846,7 @@ CellRenderer_TimeTrack::activate_vfunc(
                        /*if(value_node && selection)
                        {
                                if(selected_time==drag_time && event->button.button!=3)
-                                       signal_waypoint_clicked_(path,*selected_waypoint,event->button.button-1);
+                                       signal_waypoint_clicked_cellrenderer_(path,*selected_waypoint,event->button.button-1);
                                else
                                if(event->button.button==1)
                                {
@@ -851,6 +878,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()
 {
@@ -875,128 +906,8 @@ CellRenderer_TimeTrack::set_canvas_interface(etl::loose_handle<synfigapp::Canvas
        canvas_interface_ = h;
 }
 
-static void
-set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints, Waypoint::Model model, etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
-{
-       // Create the action group
-       synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Change Waypoint Group"));
-
-       std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
-       for(iter=waypoints.begin();iter!=waypoints.end();++iter)
-       {
-               Waypoint waypoint(*iter);
-               waypoint.apply_model(model);
-
-               synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set"));
-
-               assert(action);
-
-               action->set_param("canvas",canvas_interface->get_canvas());
-               action->set_param("canvas_interface",canvas_interface);
-
-               action->set_param("waypoint",waypoint);
-               action->set_param("value_node",waypoint.get_parent_value_node());
-
-               if(!canvas_interface->get_instance()->perform_action(action))
-               {
-                       group.cancel();
-                       return;
-               }
-       }
-}
-
 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, Waypoint::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()));
-
-       // Create the interpolation method menu
-       if(!waypoint_set.empty())
-       {
-               Gtk::Menu* interp_menu(manage(new Gtk::Menu()));
-               Waypoint::Model model;
-
-               if(side==SIDE_LEFT)model.set_before(INTERPOLATION_TCB);
-               else model.set_after(INTERPOLATION_TCB);
-               interp_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("TCB"),
-                       sigc::bind(
-                               sigc::ptr_fun(set_waypoint_model),
-                               waypoint_set,
-                               model,
-                               canvas_interface()
-                       )
-               ));
-
-               if(side==SIDE_LEFT)model.set_before(INTERPOLATION_LINEAR);
-               else model.set_after(INTERPOLATION_LINEAR);
-               interp_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Linear"),
-                       sigc::bind(
-                               sigc::ptr_fun(set_waypoint_model),
-                               waypoint_set,
-                               model,
-                               canvas_interface()
-                       )
-               ));
-
-               if(side==SIDE_LEFT)model.set_before(INTERPOLATION_HALT);
-               else model.set_after(INTERPOLATION_HALT);
-               interp_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Ease"),
-                       sigc::bind(
-                               sigc::ptr_fun(set_waypoint_model),
-                               waypoint_set,
-                               model,
-                               canvas_interface()
-                       )
-               ));
-
-               if(side==SIDE_LEFT)model.set_before(INTERPOLATION_CONSTANT);
-               else model.set_after(INTERPOLATION_CONSTANT);
-               interp_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Constant"),
-                       sigc::bind(
-                               sigc::ptr_fun(set_waypoint_model),
-                               waypoint_set,
-                               model,
-                               canvas_interface()
-                       )
-               ));
-
-
-               menu->items().push_back(
-                       Gtk::Menu_Helpers::MenuElem(
-                               side==SIDE_LEFT?_("Change \"In\" Interp."):_("Change \"Out\" Interp."),
-                               *interp_menu
-                       )
-               );
-       }
-
-       menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-jump-to"),
-               sigc::bind(
-                       sigc::mem_fun(
-                               *canvas_interface(),
-                               &synfigapp::CanvasInterface::set_time
-                       ),
-                       time
-               )
-       ));
-
-       if(!waypoint_set.empty())
-       {
-               if(waypoint_set.size()==1)
-               {
-                       delete menu;
-                       menu=0;
-                       signal_waypoint_clicked_(" ",*waypoint_set.begin(),2);
-                       return;
-               }
-               else
-                       synfig::info("Too many waypoints under me");
-       }
-       else
-               synfig::info("ZERO waypoints under me");
-
-       if(menu)menu->popup(3,gtk_get_current_event_time());
+       signal_waypoint_clicked_cellrenderer_(node,time,time_offset,2,side);
 }