1 /* === S Y N F I G ========================================================= */
2 /*! \file dock_timetrack.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "dock_timetrack.h"
36 #include <gtkmm/scrolledwindow.h>
39 #include <sigc++/signal.h>
40 #include <sigc++/hide.h>
41 #include <sigc++/slot.h>
42 #include "canvasview.h"
43 #include "layerparamtreestore.h"
45 #include "widget_timeslider.h"
46 #include "layerparamtreestore.h"
48 #include <synfig/timepointcollect.h>
52 /* === U S I N G =========================================================== */
56 using namespace synfig;
57 using namespace studio;
59 /* === M A C R O S ========================================================= */
61 /* === C L A S S E S ======================================================= */
63 class TimeTrackView : public Gtk::TreeView
65 CellRenderer_TimeTrack *cellrenderer_time_track;
67 Glib::RefPtr<LayerParamTreeStore> param_tree_store_;
69 Gtk::TreeView *mimic_tree_view;
72 sigc::signal<void,synfigapp::ValueDesc,std::set<synfig::Waypoint, std::less<UniqueID> >,int> signal_waypoint_clicked_timetrackview;
74 LayerParamTreeStore::Model model;
76 void set_canvas_view(handle<CanvasView> canvas_view)
78 cellrenderer_time_track->set_adjustment(canvas_view->time_adjustment());
83 int label_index(append_column_editable(_("Name"),model.label));
84 Gtk::TreeView::Column* label_column = get_column(label_index-1);
86 { // --- T I M E T R A C K --------------------------------------------
87 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
89 // Set up the value-node cell-renderer
90 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
91 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
92 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_clicked_timetrackview));
93 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_changed) );
94 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
95 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
96 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
98 //column->pack_start(*cellrenderer_time_track);
100 // Finish setting up the column
101 column->set_reorderable();
102 column->set_resizable();
103 column->set_min_width(200);
105 append_column(*column);
109 set_expander_column(*label_column);
110 label_column->set_visible(false);
111 set_headers_visible(false);
112 set_size_request(-1,64);
116 on_event(GdkEvent *event)
123 if(event->scroll.direction==GDK_SCROLL_DOWN)
125 mimic_tree_view->get_vadjustment()->set_value(
127 mimic_tree_view->get_vadjustment()->get_value()+
128 mimic_tree_view->get_vadjustment()->get_step_increment(),
129 mimic_tree_view->get_vadjustment()->get_upper()-
130 mimic_tree_view->get_vadjustment()->get_page_size()
133 mimic_tree_view->get_vadjustment()->value_changed();
135 else if(event->scroll.direction==GDK_SCROLL_UP)
137 mimic_tree_view->get_vadjustment()->set_value(
139 mimic_tree_view->get_vadjustment()->get_value()-
140 mimic_tree_view->get_vadjustment()->get_step_increment(),
141 mimic_tree_view->get_vadjustment()->get_lower()
144 mimic_tree_view->get_vadjustment()->value_changed();
148 case GDK_BUTTON_PRESS:
150 Gtk::TreeModel::Path path;
151 Gtk::TreeViewColumn *column;
154 int(event->button.x),int(event->button.y), // x, y
155 path, // TreeModel::Path&
156 column, //TreeViewColumn*&
157 cell_x,cell_y //int&cell_x,int&cell_y
160 const Gtk::TreeRow row = *(get_model()->get_iter(path));
162 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
165 get_cell_area(path,*column,rect);
166 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
167 cellrenderer_time_track->property_canvas()=row[model.canvas];
168 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
169 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
171 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
175 if(event->button.button==3)
177 LayerList layer_list(get_selected_layers());
178 if(layer_list.size()<=1)
180 synfigapp::ValueDesc value_desc(row[model.value_desc]);
181 Gtk::Menu* menu(manage(new Gtk::Menu()));
182 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
183 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc,0.5f);
184 menu->popup(event->button.button,gtk_get_current_event_time());
187 Gtk::Menu* menu(manage(new Gtk::Menu()));
188 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
189 std::list<synfigapp::ValueDesc> value_desc_list;
190 ParamDesc param_desc(row[model.param_desc]);
191 for(;!layer_list.empty();layer_list.pop_back())
192 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
193 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
194 menu->popup(event->button.button,gtk_get_current_event_time());
199 if(column->get_first_cell_renderer()==cellrenderer_value)
200 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
202 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
209 case GDK_MOTION_NOTIFY:
211 Gtk::TreeModel::Path path;
212 Gtk::TreeViewColumn *column;
215 (int)event->motion.x,(int)event->motion.y, // x, y
216 path, // TreeModel::Path&
217 column, //TreeViewColumn*&
218 cell_x,cell_y //int&cell_x,int&cell_y
222 if(!get_model()->get_iter(path))
225 Gtk::TreeRow row = *(get_model()->get_iter(path));
227 if ((event->motion.state&GDK_BUTTON1_MASK || event->motion.state&GDK_BUTTON3_MASK) &&
229 cellrenderer_time_track == column->get_first_cell_renderer())
232 get_cell_area(path,*column,rect);
233 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
234 cellrenderer_time_track->property_canvas()=row[model.canvas];
235 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
237 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
241 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
243 tooltips_.unset_tip(*this);
244 Glib::ustring tooltips_string(row[layer_model.tooltip]);
245 last_tooltip_path=path;
246 if(!tooltips_string.empty())
248 tooltips_.set_tip(*this,tooltips_string);
249 tooltips_.force_window();
256 case GDK_BUTTON_RELEASE:
258 Gtk::TreeModel::Path path;
259 Gtk::TreeViewColumn *column;
262 (int)event->button.x,(int)event->button.y, // x, y
263 path, // TreeModel::Path&
264 column, //TreeViewColumn*&
265 cell_x,cell_y //int&cell_x,int&cell_y
269 if(!get_model()->get_iter(path))
272 Gtk::TreeRow row = *(get_model()->get_iter(path));
274 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
277 get_cell_area(path,*column,rect);
278 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
279 cellrenderer_time_track->property_canvas()=row[model.canvas];
280 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
282 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
291 return Gtk::TreeView::on_event(event);
297 synfig::info("*************QUEUE_DRAW***************** (time track view)");
298 Widget::queue_draw();
300 void set_model(Glib::RefPtr<LayerParamTreeStore> store)
302 Gtk::TreeView::set_model(store);
303 param_tree_store_=store;
304 cellrenderer_time_track->set_canvas_interface(param_tree_store_->canvas_interface());
305 store->signal_changed().connect(sigc::mem_fun(*this, &TimeTrackView::queue_draw));
309 on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
311 // is this code used?
314 synfigapp::Action::ParamList param_list;
315 param_list.add("canvas",param_tree_store_->canvas_interface()->get_canvas());
316 param_list.add("canvas_interface",param_tree_store_->canvas_interface());
317 param_list.add("value_node",value_node);
318 param_list.add("waypoint",waypoint);
319 // param_list.add("time",canvas_interface()->get_time());
321 etl::handle<studio::Instance>::cast_static(param_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
324 void mimic(Gtk::TreeView *param_tree_view)
326 mimic_tree_view=param_tree_view;
327 param_tree_view->signal_row_expanded().connect(
333 &Gtk::TreeView::expand_row
339 param_tree_view->signal_row_collapsed().connect(
344 &Gtk::TreeView::collapse_row
355 Gtk::Adjustment &adjustment(*mimic_tree_view->get_vadjustment());
356 set_vadjustment(adjustment);
358 if(adjustment.get_page_size()>get_height())
359 adjustment.set_page_size(get_height());
362 if(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"))
363 row_height = atoi(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"));
367 cellrenderer_time_track->set_fixed_size(-1,row_height);
372 on_waypoint_clicked_timetrackview(const etl::handle<synfig::Node>& node,
373 const synfig::Time& time,
374 const synfig::Time& time_offset __attribute__ ((unused)),
377 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
378 synfig::waypoint_collect(waypoint_set,time,node);
380 synfigapp::ValueDesc value_desc;
382 if (waypoint_set.size() == 1)
384 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
388 if (param_tree_store_->find_first_value_node(value_node, row) && row)
389 value_desc = static_cast<synfigapp::ValueDesc>(row[model.value_desc]);
392 if (!waypoint_set.empty())
393 signal_waypoint_clicked_timetrackview(value_desc,waypoint_set,button);
397 /* === G L O B A L S ======================================================= */
399 /* === P R O C E D U R E S ================================================= */
401 /* === M E T H O D S ======================================================= */
403 Dock_Timetrack::Dock_Timetrack():
404 Dock_CanvasSpecific("timetrack",_("Timetrack"),Gtk::StockID("synfig-timetrack"))
407 widget_timeslider_= new Widget_Timeslider();
409 int header_height = 0;
410 if(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"))
411 header_height = atoi(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"));
412 if (header_height < 3)
415 widget_timeslider_->set_size_request(-1,header_height);
416 hscrollbar_=new Gtk::HScrollbar();
417 vscrollbar_=new Gtk::VScrollbar();
420 Dock_Timetrack::~Dock_Timetrack()
422 if(table_)delete table_;
425 delete widget_timeslider_;
429 Dock_Timetrack::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
431 LayerParamTreeStore::Model model;
433 Glib::RefPtr<LayerParamTreeStore> tree_store(
434 Glib::RefPtr<LayerParamTreeStore>::cast_dynamic(
435 canvas_view->get_tree_model("params")
439 TimeTrackView* tree_view(new TimeTrackView());
440 tree_view->set_canvas_view(canvas_view);
441 tree_view->set_model(tree_store);
442 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
443 tree_view->mimic(param_tree_view);
445 tree_view->signal_waypoint_clicked_timetrackview.connect(sigc::mem_fun(*canvas_view, &studio::CanvasView::on_waypoint_clicked_canvasview));
447 canvas_view->time_adjustment().signal_value_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
448 canvas_view->time_adjustment().signal_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
450 canvas_view->set_ext_widget(get_name(),tree_view);
454 Dock_Timetrack::refresh_selected_param()
456 /* Gtk::TreeView* tree_view(
457 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
459 Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
463 LayerParamTreeStore::Model model;
464 get_canvas_view()->work_area->set_selected_value_node(
465 (synfig::ValueNode::Handle)(*iter)[model.value_node]
470 get_canvas_view()->work_area->set_selected_value_node(0);
476 Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
482 hscrollbar_->unset_adjustment();
483 vscrollbar_->unset_adjustment();
484 //widget_timeslider_->unset_adjustment();
490 TimeTrackView* tree_view(dynamic_cast<TimeTrackView*>(canvas_view->get_ext_widget(get_name())));
491 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
492 tree_view->set_vadjustment(*param_tree_view->get_vadjustment());
496 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
497 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
498 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
500 vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
501 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
502 table_=new Gtk::Table(2,2);
503 table_->attach(*widget_timeslider_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
504 table_->attach(*tree_view, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
505 table_->attach(*hscrollbar_, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
506 table_->attach(*vscrollbar_, 1, 2, 0, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
509 //add(*last_widget_curves_);