1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_keyframe_list.cpp
3 ** \brief A custom widget to manage keyframes in the timeline.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
10 ** Copyright (c) 2009 Carlos López
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "widget_keyframe_list.h"
36 #include <gtkmm/menu.h>
37 #include <synfig/exception.h>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace studio;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 Widget_Keyframe_List::Widget_Keyframe_List():
62 set_size_request(-1,64);
63 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Keyframe_List::redraw));
64 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
65 add_events(Gdk::BUTTON1_MOTION_MASK);
69 Widget_Keyframe_List::~Widget_Keyframe_List()
74 Widget_Gradient::redraw(GdkEventExpose */*bleh*/)
76 const int h(get_height());
77 const int w(get_width());
79 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
80 Gdk::Rectangle area(0,0,w,h);
86 gc->set_rgb_fg_color(Gdk::Color("#7f7f7f"));
87 get_window()->draw_rectangle(gc, false, 0, 0, w, h);
89 KeyframeList::iterator iter,selected_iter;
90 bool show_selected(false);
91 for(iter=kf_list_.begin();iter!=kf_list_.end();iter++)
93 if(*iter!=selected_kf)
94 get_style()->paint_arrow(
96 (*iter==selected_kf)?Gtk::STATE_SELECTED:Gtk::STATE_ACTIVE,
103 int(iter->get_time()*w)-h/2+1, /// to be fixed
115 // we do this so that we can be sure that
116 // the selected marker is shown on top
119 get_style()->paint_arrow(
128 round_to_int(selected_iter->get_time()*w)-h/2+1,
140 Widget_Keyframe_List::popup_menu(Time /*t*/)
142 /* Gtk::Menu* menu(manage(new Gtk::Menu()));
143 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
145 menu->items().clear();
147 menu->items().push_back(
148 Gtk::Menu_Helpers::MenuElem(
151 sigc::mem_fun(*this,&studio::Widget_Gradient::insert_cpoint),
157 if(!gradient_.empty())
159 menu->items().push_back(
160 Gtk::Menu_Helpers::MenuElem(
163 sigc::mem_fun(*this,&studio::Widget_Gradient::remove_cpoint),
174 Widget_Keyframe_List::set_value(const synfig::KeyframeList& x)
178 set_selected_keyframe(*kf_list_.find_next(synfig::Time::zero()));
183 Widget_Keyframe_List::set_selected_keyframe(const synfig::Keyframe &x)
186 signal_keyframe_selected_(selected_kf);
191 Widget_Keyframe_List::update_keyframe(const synfig::Keyframe &x)
195 KeyframeList::iterator iter(keyframe_list_.find(x));
196 iter->pos=x.pos;///////7
197 iter->color=x.color;/////////
198 gradient_.sort();/////////
201 catch(synfig::Exception::NotFound)
208 Widget_Keyframe_List::on_event(GdkEvent *event)
212 const int x(static_cast<int>(event->button.x));
213 const int y(static_cast<int>(event->button.y));
215 float pos((float)x/(float)get_width());
216 if(pos<0.0f)pos=0.0f;////////
217 if(pos>1.0f)pos=1.0f;////////
221 case GDK_MOTION_NOTIFY:
222 if(editable_ && y>get_height()-h)
224 if(!keyframe_list_.size()) return true;
225 synfig::KeyframeList::iterator iter(keyframe_list_.find(selected_kf.get_guid()));
229 // signal_value_changed_();
235 case GDK_BUTTON_PRESS:
237 if(event->button.button==1)
239 if(editable_ && y>get_height()-CONTROL_HEIGHT)
241 set_selected_cpoint(*gradient_.proximity(pos));
251 else if(editable_ && event->button.button==3)
257 case GDK_BUTTON_RELEASE:
258 if(editable_ && event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
260 set_selected_cpoint(*gradient_.proximity(pos));
261 if(changed_)signal_value_changed_();