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 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"
49 /* === U S I N G =========================================================== */
53 using namespace synfig;
54 using namespace studio;
56 /* === M A C R O S ========================================================= */
58 /* === C L A S S E S ======================================================= */
60 class TimeTrackView : public Gtk::TreeView
62 CellRenderer_TimeTrack *cellrenderer_time_track;
64 Glib::RefPtr<LayerParamTreeStore> param_tree_store_;
66 Gtk::TreeView *mimic_tree_view;
69 sigc::signal<void,synfigapp::ValueDesc,synfig::Waypoint,int> signal_waypoint_clicked;
71 LayerParamTreeStore::Model model;
73 void set_canvas_view(handle<CanvasView> canvas_view)
75 cellrenderer_time_track->set_adjustment(canvas_view->time_adjustment());
80 int label_index(append_column_editable(_("Name"),model.label));
81 Gtk::TreeView::Column* label_column = get_column(label_index-1);
83 { // --- T I M E T R A C K --------------------------------------------
84 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
86 // Set up the value-node cell-renderer
87 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
88 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
89 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_clicked) );
90 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_changed) );
91 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
92 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
93 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
95 //column->pack_start(*cellrenderer_time_track);
97 // Finish setting up the column
98 column->set_reorderable();
99 column->set_resizable();
100 column->set_min_width(200);
103 append_column(*column);
107 set_expander_column(*label_column);
108 label_column->set_visible(false);
109 set_headers_visible(false);
110 set_size_request(-1,64);
114 on_event(GdkEvent *event)
121 if(event->scroll.direction==GDK_SCROLL_DOWN)
123 mimic_tree_view->get_vadjustment()->set_value(
125 mimic_tree_view->get_vadjustment()->get_value()+
126 mimic_tree_view->get_vadjustment()->get_step_increment(),
127 mimic_tree_view->get_vadjustment()->get_upper()-
128 mimic_tree_view->get_vadjustment()->get_page_size()
131 mimic_tree_view->get_vadjustment()->value_changed();
133 else if(event->scroll.direction==GDK_SCROLL_UP)
135 mimic_tree_view->get_vadjustment()->set_value(
137 mimic_tree_view->get_vadjustment()->get_value()-
138 mimic_tree_view->get_vadjustment()->get_step_increment(),
139 mimic_tree_view->get_vadjustment()->get_lower()
142 mimic_tree_view->get_vadjustment()->value_changed();
146 case GDK_BUTTON_PRESS:
148 Gtk::TreeModel::Path path;
149 Gtk::TreeViewColumn *column;
152 int(event->button.x),int(event->button.y), // x, y
153 path, // TreeModel::Path&
154 column, //TreeViewColumn*&
155 cell_x,cell_y //int&cell_x,int&cell_y
158 const Gtk::TreeRow row = *(get_model()->get_iter(path));
160 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
163 get_cell_area(path,*column,rect);
164 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
165 cellrenderer_time_track->property_canvas()=row[model.canvas];
166 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
167 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
169 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
173 if(event->button.button==3)
175 LayerList layer_list(get_selected_layers());
176 if(layer_list.size()<=1)
178 synfigapp::ValueDesc value_desc(row[model.value_desc]);
179 Gtk::Menu* menu(manage(new Gtk::Menu()));
180 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);
181 menu->popup(event->button.button,gtk_get_current_event_time());
184 Gtk::Menu* menu(manage(new Gtk::Menu()));
185 std::list<synfigapp::ValueDesc> value_desc_list;
186 ParamDesc param_desc(row[model.param_desc]);
187 for(;!layer_list.empty();layer_list.pop_back())
188 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
189 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
190 menu->popup(event->button.button,gtk_get_current_event_time());
195 if(column->get_first_cell_renderer()==cellrenderer_value)
196 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
198 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
205 case GDK_MOTION_NOTIFY:
207 Gtk::TreeModel::Path path;
208 Gtk::TreeViewColumn *column;
211 (int)event->motion.x,(int)event->motion.y, // x, y
212 path, // TreeModel::Path&
213 column, //TreeViewColumn*&
214 cell_x,cell_y //int&cell_x,int&cell_y
218 if(!get_model()->get_iter(path))
221 Gtk::TreeRow row = *(get_model()->get_iter(path));
223 if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
226 get_cell_area(path,*column,rect);
227 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
228 cellrenderer_time_track->property_canvas()=row[model.canvas];
229 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
231 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
235 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
237 tooltips_.unset_tip(*this);
238 Glib::ustring tooltips_string(row[layer_model.tooltip]);
239 last_tooltip_path=path;
240 if(!tooltips_string.empty())
242 tooltips_.set_tip(*this,tooltips_string);
243 tooltips_.force_window();
250 case GDK_BUTTON_RELEASE:
252 Gtk::TreeModel::Path path;
253 Gtk::TreeViewColumn *column;
256 (int)event->button.x,(int)event->button.y, // x, y
257 path, // TreeModel::Path&
258 column, //TreeViewColumn*&
259 cell_x,cell_y //int&cell_x,int&cell_y
263 if(!get_model()->get_iter(path))
266 Gtk::TreeRow row = *(get_model()->get_iter(path));
268 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
271 get_cell_area(path,*column,rect);
272 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
273 cellrenderer_time_track->property_canvas()=row[model.canvas];
274 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
276 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
285 return Gtk::TreeView::on_event(event);
291 synfig::info("*************QUEUE_DRAW***************** (time track view)");
292 Widget::queue_draw();
294 void set_model(Glib::RefPtr<LayerParamTreeStore> store)
296 Gtk::TreeView::set_model(store);
297 param_tree_store_=store;
298 cellrenderer_time_track->set_canvas_interface(param_tree_store_->canvas_interface());
299 store->signal_changed().connect(sigc::mem_fun(*this, &TimeTrackView::queue_draw));
303 on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
305 synfigapp::Action::ParamList param_list;
306 param_list.add("canvas",param_tree_store_->canvas_interface()->get_canvas());
307 param_list.add("canvas_interface",param_tree_store_->canvas_interface());
308 param_list.add("value_node",value_node);
309 param_list.add("waypoint",waypoint);
310 // param_list.add("time",canvas_interface()->get_time());
312 etl::handle<studio::Instance>::cast_static(param_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
315 void mimic(Gtk::TreeView *param_tree_view)
317 mimic_tree_view=param_tree_view;
318 param_tree_view->signal_row_expanded().connect(
324 &Gtk::TreeView::expand_row
330 param_tree_view->signal_row_collapsed().connect(
335 &Gtk::TreeView::collapse_row
347 Gtk::Adjustment &adjustment(*mimic_tree_view->get_vadjustment());
348 set_vadjustment(adjustment);
350 if(adjustment.get_page_size()>get_height())
351 adjustment.set_page_size(get_height());
354 if(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"))
355 row_height = atoi(getenv("SYNFIG_TIMETRACK_ROW_HEIGHT"));
359 cellrenderer_time_track->set_fixed_size(-1,row_height);
364 on_waypoint_clicked(const Glib::ustring &/*path_string*/, synfig::Waypoint waypoint,int button)
367 Gtk::TreePath path(path_string);
369 const Gtk::TreeRow row = *(get_model()->get_iter(path));
374 ValueNode::Handle value_node(waypoint.get_parent_value_node());
378 if(!param_tree_store_->find_first_value_node(value_node, row))
380 synfig::error(__FILE__":%d: Unable to find the valuenode",__LINE__);
387 synfigapp::ValueDesc value_desc(static_cast<synfigapp::ValueDesc>(row[model.value_desc]));
389 signal_waypoint_clicked(value_desc,waypoint,button);
393 /* === G L O B A L S ======================================================= */
395 /* === P R O C E D U R E S ================================================= */
397 /* === M E T H O D S ======================================================= */
399 Dock_Timetrack::Dock_Timetrack():
400 Dock_CanvasSpecific("timetrack",_("Timetrack"),Gtk::StockID("synfig-timetrack"))
403 widget_timeslider_= new Widget_Timeslider();
405 int header_height = 0;
406 if(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"))
407 header_height = atoi(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"));
408 if (header_height < 3)
411 widget_timeslider_->set_size_request(-1,header_height);
412 hscrollbar_=new Gtk::HScrollbar();
413 vscrollbar_=new Gtk::VScrollbar();
416 Dock_Timetrack::~Dock_Timetrack()
418 if(table_)delete table_;
421 delete widget_timeslider_;
425 Dock_Timetrack::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
427 LayerParamTreeStore::Model model;
429 Glib::RefPtr<LayerParamTreeStore> tree_store(
430 Glib::RefPtr<LayerParamTreeStore>::cast_dynamic(
431 canvas_view->get_tree_model("params")
435 TimeTrackView* tree_view(new TimeTrackView());
436 tree_view->set_canvas_view(canvas_view);
437 tree_view->set_model(tree_store);
438 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
439 tree_view->mimic(param_tree_view);
441 tree_view->signal_waypoint_clicked.connect(sigc::mem_fun(*canvas_view, &studio::CanvasView::on_waypoint_clicked));
444 canvas_view->time_adjustment().signal_value_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
445 canvas_view->time_adjustment().signal_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
447 canvas_view->set_ext_widget(get_name(),tree_view);
451 Dock_Timetrack::refresh_selected_param()
453 /* Gtk::TreeView* tree_view(
454 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
456 Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
460 LayerParamTreeStore::Model model;
461 get_canvas_view()->work_area->set_selected_value_node(
462 (synfig::ValueNode::Handle)(*iter)[model.value_node]
467 get_canvas_view()->work_area->set_selected_value_node(0);
473 Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
479 hscrollbar_->unset_adjustment();
480 vscrollbar_->unset_adjustment();
481 //widget_timeslider_->unset_adjustment();
488 TimeTrackView* tree_view(dynamic_cast<TimeTrackView*>(canvas_view->get_ext_widget(get_name())));
489 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
490 tree_view->set_vadjustment(*param_tree_view->get_vadjustment());
494 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
495 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
496 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
498 vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
499 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
500 table_=new Gtk::Table(2,2);
501 table_->attach(*widget_timeslider_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
502 table_->attach(*tree_view, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
503 table_->attach(*hscrollbar_, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
504 table_->attach(*vscrollbar_, 1, 2, 0, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
507 //add(*last_widget_curves_);