Now the widget is fully working. Need a place to be stored and better size.
authorCarlos Lopez <carlos@pcnuevo.(none)>
Sat, 18 Jul 2009 10:44:52 +0000 (12:44 +0200)
committerCarlos Lopez <carlos@pcnuevo.(none)>
Sat, 18 Jul 2009 10:44:52 +0000 (12:44 +0200)
synfig-studio/trunk/src/gtkmm/dock_timetrack.cpp
synfig-studio/trunk/src/gtkmm/widget_keyframe_list.cpp
synfig-studio/trunk/src/gtkmm/widget_keyframe_list.h

index 7f0c253..c13bb71 100644 (file)
@@ -504,8 +504,7 @@ Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_v
                widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
 
                widget_kf_list_->set_time_adjustment(&canvas_view->time_adjustment());
-               widget_kf_list_->set_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
-               widget_kf_list_->set_kf_list(&canvas_view->get_canvas()->keyframe_list());
+               widget_kf_list_->set_canvas_interface(canvas_view->canvas_interface());
 
                vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
                hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
index dba098d..9ab98ba 100644 (file)
@@ -48,6 +48,7 @@ using namespace etl;
 using namespace synfig;
 using namespace studio;
 
+
 /* === M A C R O S ========================================================= */
 
 /* === G L O B A L S ======================================================= */
@@ -165,23 +166,47 @@ void
 Widget_Keyframe_List::set_kf_list(synfig::KeyframeList* x)
 {
        kf_list_=x;
-       if(kf_list_->size())
-               set_selected_keyframe(selected_none);
+       set_selected_keyframe(selected_none);
+       selected_=false;
+       dragging_=false;
 }
 
 void
 Widget_Keyframe_List::set_selected_keyframe(const synfig::Keyframe &x)
 {
        selected_kf=x;
+       selected_=true;
        dragging_kf_time=selected_kf.get_time();
        //signal_keyframe_selected_(selected_kf);
+       dragging_=false;
        queue_draw();
 }
 
 bool
 Widget_Keyframe_List::perform_move_kf()
 {
-       return false;
+       if(!selected_)
+               return false;
+       if(dragging_kf_time == selected_kf.get_time())
+               return false;
+       synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeSet"));
+       if(!action)
+               return false;
+       selected_kf.set_time(dragging_kf_time);
+       action->set_param("canvas",canvas_interface_->get_canvas());
+       action->set_param("canvas_interface",canvas_interface_);
+       action->set_param("keyframe",selected_kf);
+       //synfig::info("DELTA: %s", (dragging_kf_time-selected_kf.get_time()).get_string().c_str());
+       try
+       {
+               canvas_interface_->get_instance()->perform_action(action);
+       }
+       catch(...)
+       {
+                       return false;
+       }
+       queue_draw();
+       return true;
 }
 
 bool
@@ -243,6 +268,7 @@ Widget_Keyframe_List::on_event(GdkEvent *event)
                                        )
                                {
                                        set_selected_keyframe(selected_none);
+                                       selected_=false;
                                        synfig::info("Selected keyframe set to none");
                                        synfig::info("Distance to prev %s", (t-prev_t).get_string().c_str());
                                        synfig::info("Distance to next %s", (next_t-t).get_string().c_str());
@@ -254,6 +280,7 @@ Widget_Keyframe_List::on_event(GdkEvent *event)
                                        set_selected_keyframe(*(kf_list_->find_prev(t)));
                                        synfig::info("Selected keyframe set to previous");
                                        queue_draw();
+                                       selected_=true;
                                        return true;
                                }
                                else
@@ -261,6 +288,7 @@ Widget_Keyframe_List::on_event(GdkEvent *event)
                                        set_selected_keyframe(*(kf_list_->find_next(t)));
                                        synfig::info("Selected keyframe set to next");
                                        queue_draw();
+                                       selected_=true;
                                        return true;
                                }
 
@@ -280,9 +308,12 @@ Widget_Keyframe_List::on_event(GdkEvent *event)
                        {
                                t = floor(t*fps + 0.5)/fps;
                        }
-               bool stat=perform_move_kf();
+               bool stat=false;
+               if(dragging_)
+                       stat=perform_move_kf();
                dragging_=false;
                synfig::info("Dropping keyframe time at: %s", t.get_string().c_str());
+               synfig::info("perform move result: %i", stat);
                return stat;
                }
        default:
@@ -320,3 +351,16 @@ Widget_Keyframe_List::set_fps(float d)
                queue_draw();
        }
 }
+
+void
+Widget_Keyframe_List::set_canvas_interface(etl::loose_handle<synfigapp::CanvasInterface> h)
+{
+       canvas_interface_=h;
+       if (canvas_interface_)
+       {
+               set_fps(canvas_interface_->get_canvas()->rend_desc().get_frame_rate());
+               set_kf_list(&canvas_interface_->get_canvas()->keyframe_list());
+       }
+}
+
+
index b42127d..4280a69 100644 (file)
@@ -32,6 +32,7 @@
 #include <gtkmm/adjustment.h>
 #include <synfig/keyframe.h>
 #include <sigc++/connection.h>
+#include <synfigapp/canvasinterface.h>
 
 
 /* === M A C R O S ========================================================= */
@@ -44,6 +45,9 @@ namespace studio {
 
 class Widget_Keyframe_List : public Gtk::DrawingArea
 {
+       //! The canvas interface being watched
+       etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_;
+
        //! Time adjustment window
        Gtk::Adjustment adj_default;
        Gtk::Adjustment *adj_timescale;
@@ -70,6 +74,7 @@ class Widget_Keyframe_List : public Gtk::DrawingArea
        //!Holds the selected keyframe of the keyframe list
        synfig::Keyframe selected_kf;
        synfig::Keyframe selected_none;
+       bool selected_;
 
        //!The time of the selected keyframe
        synfig::Time selected_kf_time;
@@ -114,6 +119,9 @@ public:
        //! Set the fps
        void set_fps(float x);
 
+       //! Set the canvas interface
+       void set_canvas_interface(etl::loose_handle<synfigapp::CanvasInterface> h);
+
        //! Performs the keyframe movement. Returns true if it was sucessful
        bool perform_move_kf();
 
@@ -129,6 +137,7 @@ public:
 
 }; // END of namespace studio
 
+
 /* === E N D =============================================================== */
 
 #endif