From: Carlos Lopez Date: Fri, 17 Jul 2009 17:32:51 +0000 (+0200) Subject: Now builds. Does not nothing yet. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=eb5f135abc7ac06543500f32362ab56d75370be5;p=synfig.git Now builds. Does not nothing yet. --- diff --git a/synfig-studio/trunk/src/gtkmm/Makefile.am b/synfig-studio/trunk/src/gtkmm/Makefile.am index 1be3e71..c5cc73d 100644 --- a/synfig-studio/trunk/src/gtkmm/Makefile.am +++ b/synfig-studio/trunk/src/gtkmm/Makefile.am @@ -138,7 +138,8 @@ WIDGET_HH = \ widget_value.h \ widget_vector.h \ widget_waypoint.h \ - widget_waypointmodel.h + widget_waypointmodel.h \ + widget_keyframe_list.h WIDGET_CC = \ widget_canvaschooser.cpp \ @@ -157,7 +158,8 @@ WIDGET_CC = \ widget_value.cpp \ widget_vector.cpp \ widget_waypoint.cpp \ - widget_waypointmodel.cpp + widget_waypointmodel.cpp \ + widget_keyframe_list.cpp STATE_HH = \ diff --git a/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.cpp b/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.cpp index e0f372f..d3269de 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.cpp +++ b/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.cpp @@ -57,12 +57,19 @@ using namespace studio; /* === M E T H O D S ======================================================= */ Widget_Keyframe_List::Widget_Keyframe_List(): - editable_(false) + editable_(true), + adj_default(0,0,2,1/24,10/24), + adj_timescale(0), + fps(24) { set_size_request(-1,64); + //!This signal is called when the widget need to be redrawn signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Keyframe_List::redraw)); + //! The widget respond to mouse button press and release and to + //! left button motion add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); add_events(Gdk::BUTTON1_MOTION_MASK); + set_time_adjustment(&adj_default); } @@ -71,40 +78,45 @@ Widget_Keyframe_List::~Widget_Keyframe_List() } bool -Widget_Gradient::redraw(GdkEventExpose */*bleh*/) +Widget_Keyframe_List::redraw(GdkEventExpose */*bleh*/) { const int h(get_height()); const int w(get_width()); + //!Boundaries of the drawing area in time units. + synfig::Time top(adj_timescale->get_upper()); + synfig::Time bottom(adj_timescale->get_lower()); + + //! The graphic context Glib::RefPtr gc(Gdk::GC::create(get_window())); + //! A rectangle that defines the drawing area. Gdk::Rectangle area(0,0,w,h); + if(!editable_) { return true; } + //! draw a background gc->set_rgb_fg_color(Gdk::Color("#7f7f7f")); get_window()->draw_rectangle(gc, false, 0, 0, w, h); - KeyframeList::iterator iter,selected_iter; + //!Loop all the keyframes + synfig::KeyframeList::iterator iter,selected_iter; bool show_selected(false); for(iter=kf_list_.begin();iter!=kf_list_.end();iter++) { + //!do not draw keyframes out of the widget boundaries + if (iter->get_time()>top || iter->get_time()paint_arrow( - get_window(), - (*iter==selected_kf)?Gtk::STATE_SELECTED:Gtk::STATE_ACTIVE, - Gtk::SHADOW_OUT, - area, - *this, - " ", - Gtk::ARROW_DOWN, - 1, - int(iter->get_time()*w)-h/2+1, /// to be fixed - 0, - h, - h - ); + { + const int x((int)((float)(iter->get_time()-bottom) * (w/(top-bottom)) ) ); + get_style()->paint_arrow(get_window(), Gtk::STATE_NORMAL, + Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, + x-h/2, 0, h, h ); + } else { selected_iter=iter; @@ -113,23 +125,13 @@ Widget_Gradient::redraw(GdkEventExpose */*bleh*/) } // we do this so that we can be sure that - // the selected marker is shown on top + // the selected keyframe is shown on top if(show_selected) { - get_style()->paint_arrow( - get_window(), - Gtk::STATE_SELECTED, - Gtk::SHADOW_OUT, - area, - *this, - " ", - Gtk::ARROW_DOWN, - 1, - round_to_int(selected_iter->get_time()*w)-h/2+1, - 0, - h, - h - ); + const int x((int)((float)(selected_iter->get_time()-bottom) * (w/(top-bottom)) ) ); + get_style()->paint_arrow(get_window(), Gtk::STATE_SELECTED, + Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, + x-h/2, 0, h, h ); } return true; @@ -137,134 +139,109 @@ Widget_Gradient::redraw(GdkEventExpose */*bleh*/) void -Widget_Keyframe_List::popup_menu(Time /*t*/) -{ -/* Gtk::Menu* menu(manage(new Gtk::Menu())); - menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu)); - - menu->items().clear(); - - menu->items().push_back( - Gtk::Menu_Helpers::MenuElem( - _("Insert CPoint"), - sigc::bind( - sigc::mem_fun(*this,&studio::Widget_Gradient::insert_cpoint), - x - ) - ) - ); - - if(!gradient_.empty()) - { - menu->items().push_back( - Gtk::Menu_Helpers::MenuElem( - _("Remove CPoint"), - sigc::bind( - sigc::mem_fun(*this,&studio::Widget_Gradient::remove_cpoint), - x - ) - ) - ); - } - - menu->popup(0,0); -*/} - -void -Widget_Keyframe_List::set_value(const synfig::KeyframeList& x) +Widget_Keyframe_List::set_kf_list(const synfig::KeyframeList& x) { kf_list_=x; if(kf_list_.size()) set_selected_keyframe(*kf_list_.find_next(synfig::Time::zero())); - queue_draw(); } void Widget_Keyframe_List::set_selected_keyframe(const synfig::Keyframe &x) { selected_kf=x; - signal_keyframe_selected_(selected_kf); + //signal_keyframe_selected_(selected_kf); queue_draw(); } -void -Widget_Keyframe_List::update_keyframe(const synfig::Keyframe &x) +bool +Widget_Keyframe_List::perform_move_kf() { - try - { - KeyframeList::iterator iter(keyframe_list_.find(x)); - iter->pos=x.pos;///////7 - iter->color=x.color;///////// - gradient_.sort();///////// - queue_draw(); - } - catch(synfig::Exception::NotFound) - { - // Yotta... - } + return false; } bool Widget_Keyframe_List::on_event(GdkEvent *event) { - //if(editable_) + const int x(static_cast(event->button.x)); + const int y(static_cast(event->button.y)); + //!Boundaries of the drawing area in time units. + synfig::Time top(adj_timescale->get_upper()); + synfig::Time bottom(adj_timescale->get_lower()); + //!pos is the [0,1] relative horizontal place on the widget + float pos((float)x/(float)get_width()); + if(pos<0.0f)pos=0.0f; + if(pos>1.0f)pos=1.0f; + //! The time where the event x is + synfig::Time t((float)(pos*(top-bottom))); + //! here the guts of the event + switch(event->type) { - const int x(static_cast(event->button.x)); - const int y(static_cast(event->button.y)); - - float pos((float)x/(float)get_width()); - if(pos<0.0f)pos=0.0f;//////// - if(pos>1.0f)pos=1.0f;//////// - - switch(event->type) + case GDK_MOTION_NOTIFY: + if(editable_) { - case GDK_MOTION_NOTIFY: - if(editable_ && y>get_height()-h) + if(!kf_list_.size()) return true; + // stick to integer frames. + if(fps) + { + t = floor(t*fps + 0.5)/fps; + } + dragging_kf_time=t; + queue_draw(); + return true; + } + break; + case GDK_BUTTON_PRESS: + changed_=false; + if(event->button.button==1) + { + if(editable_) { - if(!keyframe_list_.size()) return true; - synfig::KeyframeList::iterator iter(keyframe_list_.find(selected_kf.get_guid())); - iter->pos=pos;///// - gradient_.sort(); - -// signal_value_changed_(); - changed_=true; + synfig::KeyframeList::iterator selected; + selected = kf_list_.find_next(t); + set_selected_keyframe(*selected); queue_draw(); return true; } - break; - case GDK_BUTTON_PRESS: - changed_=false; - if(event->button.button==1) + else { - if(editable_ && y>get_height()-CONTROL_HEIGHT) - { - set_selected_cpoint(*gradient_.proximity(pos)); - queue_draw(); - return true; - } - else - { - signal_clicked_(); - return true; - } - } - else if(editable_ && event->button.button==3) - { - popup_menu(pos); return true; } - break; - case GDK_BUTTON_RELEASE: - if(editable_ && event->button.button==1 && y>get_height()-CONTROL_HEIGHT) + } + break; + case GDK_BUTTON_RELEASE: + if(editable_ && event->button.button==1) + { + // stick to integer frames. + if(fps) { - set_selected_cpoint(*gradient_.proximity(pos)); - if(changed_)signal_value_changed_(); - return true; + t = floor(t*fps + 0.5)/fps; } - default: - break; + bool stat=perform_move_kf(); + synfig::info("Dropping keyframe at: %s", t.get_string()); + return stat; } + default: + break; } + return false; } + + +void Widget_Keyframe_List::set_time_adjustment(Gtk::Adjustment *x) +{ + //disconnect old connections + time_value_change.disconnect(); + time_other_change.disconnect(); + + //connect update function to new adjustment + adj_timescale = x; + + if(x) + { + time_value_change = x->signal_value_changed().connect(sigc::mem_fun(*this,&Widget_Keyframe_List::queue_draw)); + time_other_change = x->signal_changed().connect(sigc::mem_fun(*this,&Widget_Keyframe_List::queue_draw)); + } +} diff --git a/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.h b/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.h index 6a7ef73..3b83722 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.h +++ b/synfig-studio/trunk/src/gtkmm/widget_keyframe_list.h @@ -29,7 +29,10 @@ /* === H E A D E R S ======================================================= */ #include +#include #include +#include + /* === M A C R O S ========================================================= */ @@ -41,56 +44,77 @@ namespace studio { class Widget_Keyframe_List : public Gtk::DrawingArea { - sigc::signal signal_value_changed_; - sigc::signal signal_clicked_; - - sigc::signal signal_keyframe_selected_; + //! Time adjustment window + Gtk::Adjustment adj_default; + Gtk::Adjustment *adj_timescale; + //!The list of keyframes to be drawn on the widget and moved with mouse synfig::KeyframeList kf_list_; + //! The frames per second of the canvas + synfig::Time fps; + //!True if it is editable. Keyframes can be moved. bool editable_; + //!True if a keyframe is being dragged. + bool dragging_; + + //!True if a keyframe has been moved bool changed_; + //!Holds the selected keyframe of the keyframe list synfig::Keyframe selected_kf; - void popup_menu(float x); + //!The time of the selected keyframe + synfig::Time selected_kf_time; - //void insert_cpoint(float x); + //!The time of the selected keyframe during draging + synfig::Time dragging_kf_time; - //void remove_cpoint(float x); + //!Connectors for handling the signals of the time adjustment + sigc::connection time_value_change; + sigc::connection time_other_change; public: + //!Default constructor Widget_Keyframe_List(); + //!Destructror ~Widget_Keyframe_List(); - sigc::signal& signal_value_changed() { return signal_value_changed_; } - sigc::signal& signal_clicked() { return signal_clicked_; } - - sigc::signal& signal_keyframe_selected() { return signal_keyframe_selected_; } + //!Loads a new keyframe list on the widget. + void set_kf_list(const synfig::KeyframeList& x); - void set_value(const synfig::KeyframeList& x); - - const synfig::KayframeList& get_value()const { return kf_list_; } + //!Member for private data. + const synfig::KeyframeList& get_kf_list()const { return kf_list_; } + //!Member for private data void set_editable(bool x=true) { editable_=x; } + //!Member for private data bool get_editable()const { return editable_; } - + //!Store the selected keyframe value void set_selected_keyframe(const synfig::Keyframe &x); - const synfig::Kayframe& get_selected_keyframe() { return selected_kf; } + //!Returns the selected keyframe + const synfig::Keyframe& get_selected_keyframe() { return selected_kf; } + + //! Set the time adjustment and proper connects its change signals + void set_time_adjustment(Gtk::Adjustment *x); - void update_keyframe(const synfig::Keyframe &x); + //! Performs the keyframe movement. Returns true if it was sucessful + bool perform_move_kf(); +/* ======================= EVENTS HANDLERS ===========================*/ + //!Redraw event. Should draw all the keyframes + the selected + the dragged bool redraw(GdkEventExpose*bleh=NULL); + //!Mouse event handler. bool on_event(GdkEvent *event); }; // END of class Keyframe_List