X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fwidget_keyframe_list.cpp;fp=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fwidget_keyframe_list.cpp;h=d3269de7ab6e3e4c37b4f90915b649288484fe02;hb=eb5f135abc7ac06543500f32362ab56d75370be5;hp=e0f372f208f996cf5d86ad2e881384069cb103af;hpb=d984a091f5a0cb0c903d4abfcf7a7afb57ec82e3;p=synfig.git 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)); + } +}