/* === 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),
+ kf_list_(&default_kf_list_)
{
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);
}
}
bool
-Widget_Gradient::redraw(GdkEventExpose */*bleh*/)
+Widget_Keyframe_List::redraw(GdkEventExpose */*bleh*/)
{
+ if (kf_list_->empty()) return false;
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<Gdk::GC> gc(Gdk::GC::create(get_window()));
+ //! A rectangle that defines the drawing area.
Gdk::Rectangle area(0,0,w,h);
+
if(!editable_)
{
return true;
}
- gc->set_rgb_fg_color(Gdk::Color("#7f7f7f"));
- get_window()->draw_rectangle(gc, false, 0, 0, w, h);
+ //! draw a background
+ gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
+ get_window()->draw_rectangle(gc, true, 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++)
+ 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()<bottom)
+ continue;
+ //! If the keyframe is not the selected one
if(*iter!=selected_kf)
- get_style()->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;
}
// 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;
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(synfig::KeyframeList* x)
{
kf_list_=x;
- if(kf_list_.size())
- set_selected_keyframe(*kf_list_.find_next(synfig::Time::zero()));
- queue_draw();
+ if(kf_list_->size())
+ set_selected_keyframe(*kf_list_->find_next(synfig::Time::zero()));
}
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<int>(event->button.x));
+ const int y(static_cast<int>(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)));
+
+ //Do not respond mouse events if the list is empty
+ if(!kf_list_->size())
{
- const int x(static_cast<int>(event->button.x));
- const int y(static_cast<int>(event->button.y));
+ synfig::info("Keyframe list empty");
+ return true;
+ }
- float pos((float)x/(float)get_width());
- if(pos<0.0f)pos=0.0f;////////
- if(pos>1.0f)pos=1.0f;////////
+ //! here the guts of the event
+ switch(event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ if(editable_)
+ {
- switch(event->type)
+ // 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)
{
- case GDK_MOTION_NOTIFY:
- if(editable_ && y>get_height()-h)
+ synfig::info("Looking keyframe at %s", t.get_string().c_str());
+ synfig::info("Total amount of keyframes %i", kf_list_->size());
+ 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)
- {
- 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)
+ else
{
- 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().c_str());
+ 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));
+ }
+}
+
+void
+Widget_Keyframe_List::set_fps(float d)
+{
+ if(fps != d)
+ {
+ fps = d;
+ //update everything since we need to redraw already
+ queue_draw();
+ }
+}