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 "widget_keyframe_list.h"
47 #include "layerparamtreestore.h"
49 #include <synfig/timepointcollect.h>
53 /* === U S I N G =========================================================== */
57 using namespace synfig;
58 using namespace studio;
60 /* === M A C R O S ========================================================= */
62 /* === C L A S S E S ======================================================= */
64 class TimeTrackView : public Gtk::TreeView
66 CellRenderer_TimeTrack *cellrenderer_time_track;
68 Glib::RefPtr<LayerParamTreeStore> param_tree_store_;
70 Gtk::TreeView *mimic_tree_view;
73 sigc::signal<void,synfigapp::ValueDesc,std::set<synfig::Waypoint, std::less<UniqueID> >,int> signal_waypoint_clicked_timetrackview;
75 LayerParamTreeStore::Model model;
77 void set_canvas_view(handle<CanvasView> canvas_view)
79 cellrenderer_time_track->set_adjustment(canvas_view->time_adjustment());
84 int label_index(append_column_editable(_("Name"),model.label));
85 Gtk::TreeView::Column* label_column = get_column(label_index-1);
87 { // --- T I M E T R A C K --------------------------------------------
88 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
90 // Set up the value-node cell-renderer
91 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
92 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
93 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_clicked_timetrackview));
94 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_changed) );
95 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
96 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
97 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
99 //column->pack_start(*cellrenderer_time_track);
101 // Finish setting up the column
102 column->set_reorderable();
103 column->set_resizable();
104 column->set_min_width(200);
106 append_column(*column);
110 set_expander_column(*label_column);
111 label_column->set_visible(false);
112 set_headers_visible(false);
113 set_size_request(-1,64);
117 on_event(GdkEvent *event)
124 if(event->scroll.direction==GDK_SCROLL_DOWN)
126 mimic_tree_view->get_vadjustment()->set_value(
128 mimic_tree_view->get_vadjustment()->get_value()+
129 mimic_tree_view->get_vadjustment()->get_step_increment(),
130 mimic_tree_view->get_vadjustment()->get_upper()-
131 mimic_tree_view->get_vadjustment()->get_page_size()
134 mimic_tree_view->get_vadjustment()->value_changed();
136 else if(event->scroll.direction==GDK_SCROLL_UP)
138 mimic_tree_view->get_vadjustment()->set_value(
140 mimic_tree_view->get_vadjustment()->get_value()-
141 mimic_tree_view->get_vadjustment()->get_step_increment(),
142 mimic_tree_view->get_vadjustment()->get_lower()
145 mimic_tree_view->get_vadjustment()->value_changed();
149 case GDK_BUTTON_PRESS:
151 Gtk::TreeModel::Path path;
152 Gtk::TreeViewColumn *column;
155 int(event->button.x),int(event->button.y), // x, y
156 path, // TreeModel::Path&
157 column, //TreeViewColumn*&
158 cell_x,cell_y //int&cell_x,int&cell_y
161 const Gtk::TreeRow row = *(get_model()->get_iter(path));
163 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
166 get_cell_area(path,*column,rect);
167 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
168 cellrenderer_time_track->property_canvas()=row[model.canvas];
169 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
170 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
172 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
176 if(event->button.button==3)
178 LayerList layer_list(get_selected_layers());
179 if(layer_list.size()<=1)
181 synfigapp::ValueDesc value_desc(row[model.value_desc]);
182 Gtk::Menu* menu(manage(new Gtk::Menu()));
183 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
184 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);
185 menu->popup(event->button.button,gtk_get_current_event_time());
188 Gtk::Menu* menu(manage(new Gtk::Menu()));
189 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
190 std::list<synfigapp::ValueDesc> value_desc_list;
191 ParamDesc param_desc(row[model.param_desc]);
192 for(;!layer_list.empty();layer_list.pop_back())
193 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
194 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
195 menu->popup(event->button.button,gtk_get_current_event_time());
200 if(column->get_first_cell_renderer()==cellrenderer_value)
201 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
203 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
210 case GDK_MOTION_NOTIFY:
212 Gtk::TreeModel::Path path;
213 Gtk::TreeViewColumn *column;
216 (int)event->motion.x,(int)event->motion.y, // x, y
217 path, // TreeModel::Path&
218 column, //TreeViewColumn*&
219 cell_x,cell_y //int&cell_x,int&cell_y
223 if(!get_model()->get_iter(path))
226 Gtk::TreeRow row = *(get_model()->get_iter(path));
228 if ((event->motion.state&GDK_BUTTON1_MASK || event->motion.state&GDK_BUTTON3_MASK) &&
230 cellrenderer_time_track == column->get_first_cell_renderer())
233 get_cell_area(path,*column,rect);
234 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
235 cellrenderer_time_track->property_canvas()=row[model.canvas];
236 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
238 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
242 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
244 tooltips_.unset_tip(*this);
245 Glib::ustring tooltips_string(row[layer_model.tooltip]);
246 last_tooltip_path=path;
247 if(!tooltips_string.empty())
249 tooltips_.set_tip(*this,tooltips_string);
250 tooltips_.force_window();
257 case GDK_BUTTON_RELEASE:
259 Gtk::TreeModel::Path path;
260 Gtk::TreeViewColumn *column;
263 (int)event->button.x,(int)event->button.y, // x, y
264 path, // TreeModel::Path&
265 column, //TreeViewColumn*&
266 cell_x,cell_y //int&cell_x,int&cell_y
270 if(!get_model()->get_iter(path))
273 Gtk::TreeRow row = *(get_model()->get_iter(path));
275 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
278 get_cell_area(path,*column,rect);
279 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
280 cellrenderer_time_track->property_canvas()=row[model.canvas];
281 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
283 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
292 return Gtk::TreeView::on_event(event);
298 synfig::info("*************QUEUE_DRAW***************** (time track view)");
299 Widget::queue_draw();
301 void set_model(Glib::RefPtr<LayerParamTreeStore> store)
303 Gtk::TreeView::set_model(store);
304 param_tree_store_=store;
305 cellrenderer_time_track->set_canvas_interface(param_tree_store_->canvas_interface());
306 store->signal_changed().connect(sigc::mem_fun(*this, &TimeTrackView::queue_draw));
310 on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
312 // is this code used?
315 synfigapp::Action::ParamList param_list;
316 param_list.add("canvas",param_tree_store_->canvas_interface()->get_canvas());
317 param_list.add("canvas_interface",param_tree_store_->canvas_interface());
318 param_list.add("value_node",value_node);
319 param_list.add("waypoint",waypoint);
320 // param_list.add("time",canvas_interface()->get_time());
322 etl::handle<studio::Instance>::cast_static(param_tree_store_->canvas_interface()->get_instance())->process_action("WaypointSetSmart", param_list);
325 void mimic(Gtk::TreeView *param_tree_view)
327 mimic_tree_view=param_tree_view;
328 param_tree_view->signal_row_expanded().connect(
334 &Gtk::TreeView::expand_row
340 param_tree_view->signal_row_collapsed().connect(
345 &Gtk::TreeView::collapse_row
356 Gtk::Adjustment &adjustment(*mimic_tree_view->get_vadjustment());
357 set_vadjustment(adjustment);
359 if(adjustment.get_page_size()>get_height())
360 adjustment.set_page_size(get_height());
363 if(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"))
364 row_height = atoi(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"));
368 cellrenderer_time_track->set_fixed_size(-1,row_height);
373 on_waypoint_clicked_timetrackview(const etl::handle<synfig::Node>& node,
374 const synfig::Time& time,
375 const synfig::Time& time_offset __attribute__ ((unused)),
378 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
379 synfig::waypoint_collect(waypoint_set,time,node);
381 synfigapp::ValueDesc value_desc;
383 if (waypoint_set.size() == 1)
385 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
389 if (param_tree_store_->find_first_value_node(value_node, row) && row)
390 value_desc = static_cast<synfigapp::ValueDesc>(row[model.value_desc]);
393 if (!waypoint_set.empty())
394 signal_waypoint_clicked_timetrackview(value_desc,waypoint_set,button);
398 /* === G L O B A L S ======================================================= */
400 /* === P R O C E D U R E S ================================================= */
402 /* === M E T H O D S ======================================================= */
404 Dock_Timetrack::Dock_Timetrack():
405 Dock_CanvasSpecific("timetrack",_("Timetrack"),Gtk::StockID("synfig-timetrack"))
408 widget_timeslider_= new Widget_Timeslider();
409 widget_kf_list_= new Widget_Keyframe_List();
411 int header_height = 0;
412 if(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"))
413 header_height = atoi(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"));
414 if (header_height < 3)
417 widget_timeslider_->set_size_request(-1,header_height-header_height/3+1);
418 widget_kf_list_->set_size_request(-1,header_height/3+1);
420 hscrollbar_=new Gtk::HScrollbar();
421 vscrollbar_=new Gtk::VScrollbar();
424 Dock_Timetrack::~Dock_Timetrack()
426 if(table_)delete table_;
429 delete widget_timeslider_;
430 delete widget_kf_list_;
434 Dock_Timetrack::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
436 LayerParamTreeStore::Model model;
438 Glib::RefPtr<LayerParamTreeStore> tree_store(
439 Glib::RefPtr<LayerParamTreeStore>::cast_dynamic(
440 canvas_view->get_tree_model("params")
444 TimeTrackView* tree_view(new TimeTrackView());
445 tree_view->set_canvas_view(canvas_view);
446 tree_view->set_model(tree_store);
447 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
448 tree_view->mimic(param_tree_view);
450 tree_view->signal_waypoint_clicked_timetrackview.connect(sigc::mem_fun(*canvas_view, &studio::CanvasView::on_waypoint_clicked_canvasview));
452 canvas_view->time_adjustment().signal_value_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
453 canvas_view->time_adjustment().signal_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
455 canvas_view->set_ext_widget(get_name(),tree_view);
459 Dock_Timetrack::refresh_selected_param()
461 /* Gtk::TreeView* tree_view(
462 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
464 Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
468 LayerParamTreeStore::Model model;
469 get_canvas_view()->work_area->set_selected_value_node(
470 (synfig::ValueNode::Handle)(*iter)[model.value_node]
475 get_canvas_view()->work_area->set_selected_value_node(0);
481 Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
487 hscrollbar_->unset_adjustment();
488 vscrollbar_->unset_adjustment();
489 //widget_timeslider_->unset_adjustment();
495 TimeTrackView* tree_view(dynamic_cast<TimeTrackView*>(canvas_view->get_ext_widget(get_name())));
496 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
497 tree_view->set_vadjustment(*param_tree_view->get_vadjustment());
502 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
503 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
504 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
506 widget_kf_list_->set_time_adjustment(&canvas_view->time_adjustment());
507 widget_kf_list_->set_canvas_interface(canvas_view->canvas_interface());
509 vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
510 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
511 table_=new Gtk::Table(2,3);
512 table_->attach(*widget_timeslider_, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::SHRINK);
513 table_->attach(*widget_kf_list_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
514 table_->attach(*tree_view, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
515 table_->attach(*hscrollbar_, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
516 table_->attach(*vscrollbar_, 1, 2, 0, 3, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
519 //add(*last_widget_curves_);