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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "dock_timetrack.h"
35 #include <gtkmm/scrolledwindow.h>
38 #include <sigc++/signal.h>
39 #include <sigc++/hide.h>
40 #include <sigc++/slot.h>
41 #include "canvasview.h"
42 #include "layerparamtreestore.h"
44 #include "widget_timeslider.h"
45 #include "layerparamtreestore.h"
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === C L A S S E S ======================================================= */
59 class TimeTrackView : public Gtk::TreeView
61 CellRenderer_TimeTrack *cellrenderer_time_track;
63 Glib::RefPtr<LayerParamTreeStore> param_tree_store_;
65 Gtk::TreeView *mimic_tree_view;
68 sigc::signal<void,synfigapp::ValueDesc,synfig::Waypoint,int> signal_waypoint_clicked;
70 LayerParamTreeStore::Model model;
72 void set_canvas_view(handle<CanvasView> canvas_view)
74 cellrenderer_time_track->set_adjustment(canvas_view->time_adjustment());
79 int label_index(append_column_editable(_("Name"),model.label));
80 Gtk::TreeView::Column* label_column = get_column(label_index-1);
82 { // --- T I M E T R A C K --------------------------------------------
83 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
85 // Set up the value-node cell-renderer
86 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
87 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
88 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_clicked) );
89 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &TimeTrackView::on_waypoint_changed) );
90 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
91 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
92 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
94 //column->pack_start(*cellrenderer_time_track);
96 // Finish setting up the column
97 column->set_reorderable();
98 column->set_resizable();
99 column->set_min_width(200);
102 append_column(*column);
106 set_expander_column(*label_column);
107 label_column->set_visible(false);
108 set_headers_visible(false);
109 set_size_request(-1,64);
113 on_event(GdkEvent *event)
120 if(event->scroll.direction==GDK_SCROLL_DOWN)
122 mimic_tree_view->get_vadjustment()->set_value(
124 mimic_tree_view->get_vadjustment()->get_value()+
125 mimic_tree_view->get_vadjustment()->get_step_increment(),
126 mimic_tree_view->get_vadjustment()->get_upper()-
127 mimic_tree_view->get_vadjustment()->get_page_size()
130 mimic_tree_view->get_vadjustment()->value_changed();
132 else if(event->scroll.direction==GDK_SCROLL_UP)
134 mimic_tree_view->get_vadjustment()->set_value(
136 mimic_tree_view->get_vadjustment()->get_value()-
137 mimic_tree_view->get_vadjustment()->get_step_increment(),
138 mimic_tree_view->get_vadjustment()->get_lower()
141 mimic_tree_view->get_vadjustment()->value_changed();
145 case GDK_BUTTON_PRESS:
147 Gtk::TreeModel::Path path;
148 Gtk::TreeViewColumn *column;
151 int(event->button.x),int(event->button.y), // x, y
152 path, // TreeModel::Path&
153 column, //TreeViewColumn*&
154 cell_x,cell_y //int&cell_x,int&cell_y
157 const Gtk::TreeRow row = *(get_model()->get_iter(path));
159 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
162 get_cell_area(path,*column,rect);
163 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
164 cellrenderer_time_track->property_canvas()=row[model.canvas];
165 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
166 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
168 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
172 if(event->button.button==3)
174 LayerList layer_list(get_selected_layers());
175 if(layer_list.size()<=1)
177 synfigapp::ValueDesc value_desc(row[model.value_desc]);
178 Gtk::Menu* menu(manage(new Gtk::Menu()));
179 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);
180 menu->popup(event->button.button,gtk_get_current_event_time());
183 Gtk::Menu* menu(manage(new Gtk::Menu()));
184 std::list<synfigapp::ValueDesc> value_desc_list;
185 ParamDesc param_desc(row[model.param_desc]);
186 for(;!layer_list.empty();layer_list.pop_back())
187 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
188 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
189 menu->popup(event->button.button,gtk_get_current_event_time());
194 if(column->get_first_cell_renderer()==cellrenderer_value)
195 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
197 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
204 case GDK_MOTION_NOTIFY:
206 Gtk::TreeModel::Path path;
207 Gtk::TreeViewColumn *column;
210 (int)event->motion.x,(int)event->motion.y, // x, y
211 path, // TreeModel::Path&
212 column, //TreeViewColumn*&
213 cell_x,cell_y //int&cell_x,int&cell_y
217 if(!get_model()->get_iter(path))
220 Gtk::TreeRow row = *(get_model()->get_iter(path));
222 if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
225 get_cell_area(path,*column,rect);
226 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
227 cellrenderer_time_track->property_canvas()=row[model.canvas];
228 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
230 //queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
234 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
236 tooltips_.unset_tip(*this);
237 Glib::ustring tooltips_string(row[layer_model.tooltip]);
238 last_tooltip_path=path;
239 if(!tooltips_string.empty())
241 tooltips_.set_tip(*this,tooltips_string);
242 tooltips_.force_window();
249 case GDK_BUTTON_RELEASE:
251 Gtk::TreeModel::Path path;
252 Gtk::TreeViewColumn *column;
255 (int)event->button.x,(int)event->button.y, // x, y
256 path, // TreeModel::Path&
257 column, //TreeViewColumn*&
258 cell_x,cell_y //int&cell_x,int&cell_y
262 if(!get_model()->get_iter(path))
265 Gtk::TreeRow row = *(get_model()->get_iter(path));
267 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
270 get_cell_area(path,*column,rect);
271 cellrenderer_time_track->property_value_desc()=row[model.value_desc];
272 cellrenderer_time_track->property_canvas()=row[model.canvas];
273 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
275 queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
284 return Gtk::TreeView::on_event(event);
290 synfig::info("*************QUEUE_DRAW***************** (time track view)");
291 Widget::queue_draw();
293 void set_model(Glib::RefPtr<LayerParamTreeStore> store)
295 Gtk::TreeView::set_model(store);
296 param_tree_store_=store;
297 cellrenderer_time_track->set_canvas_interface(param_tree_store_->canvas_interface());
298 store->signal_changed().connect(sigc::mem_fun(*this, &TimeTrackView::queue_draw));
302 on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
304 synfigapp::Action::ParamList param_list;
305 param_list.add("canvas",param_tree_store_->canvas_interface()->get_canvas());
306 param_list.add("canvas_interface",param_tree_store_->canvas_interface());
307 param_list.add("value_node",value_node);
308 param_list.add("waypoint",waypoint);
309 // param_list.add("time",canvas_interface()->get_time());
311 etl::handle<studio::Instance>::cast_static(param_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
314 void mimic(Gtk::TreeView *param_tree_view)
316 mimic_tree_view=param_tree_view;
317 param_tree_view->signal_row_expanded().connect(
323 &Gtk::TreeView::expand_row
329 param_tree_view->signal_row_collapsed().connect(
334 &Gtk::TreeView::collapse_row
346 Gtk::Adjustment &adjustment(*mimic_tree_view->get_vadjustment());
347 set_vadjustment(adjustment);
349 if(adjustment.get_page_size()>get_height())
350 adjustment.set_page_size(get_height());
352 cellrenderer_time_track->set_fixed_size(-1,18);
357 on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
360 Gtk::TreePath path(path_string);
362 const Gtk::TreeRow row = *(get_model()->get_iter(path));
367 ValueNode::Handle value_node(waypoint.get_parent_value_node());
371 if(!param_tree_store_->find_first_value_node(value_node, row))
373 synfig::error(__FILE__":%d: Unable to find the valuenode",__LINE__);
380 synfigapp::ValueDesc value_desc(static_cast<synfigapp::ValueDesc>(row[model.value_desc]));
382 signal_waypoint_clicked(value_desc,waypoint,button);
386 /* === G L O B A L S ======================================================= */
388 /* === P R O C E D U R E S ================================================= */
390 /* === M E T H O D S ======================================================= */
392 Dock_Timetrack::Dock_Timetrack():
393 Dock_CanvasSpecific("timetrack",_("Timetrack"),Gtk::StockID("synfig-timetrack"))
396 widget_timeslider_= new Widget_Timeslider();
397 widget_timeslider_->set_size_request(-1,22);
398 hscrollbar_=new Gtk::HScrollbar();
399 vscrollbar_=new Gtk::VScrollbar();
402 Dock_Timetrack::~Dock_Timetrack()
404 if(table_)delete table_;
407 delete widget_timeslider_;
411 Dock_Timetrack::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
413 LayerParamTreeStore::Model model;
415 Glib::RefPtr<LayerParamTreeStore> tree_store(
416 Glib::RefPtr<LayerParamTreeStore>::cast_dynamic(
417 canvas_view->get_tree_model("params")
421 TimeTrackView* tree_view(new TimeTrackView());
422 tree_view->set_canvas_view(canvas_view);
423 tree_view->set_model(tree_store);
424 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
425 tree_view->mimic(param_tree_view);
427 tree_view->signal_waypoint_clicked.connect(sigc::mem_fun(*canvas_view, &studio::CanvasView::on_waypoint_clicked));
430 canvas_view->time_adjustment().signal_value_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
431 canvas_view->time_adjustment().signal_changed().connect(sigc::mem_fun(*tree_view,&Gtk::TreeView::queue_draw));
433 canvas_view->set_ext_widget(get_name(),tree_view);
437 Dock_Timetrack::refresh_selected_param()
439 /* Gtk::TreeView* tree_view(
440 static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name()))
442 Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
446 LayerParamTreeStore::Model model;
447 get_canvas_view()->work_area->set_selected_value_node(
448 (synfig::ValueNode::Handle)(*iter)[model.value_node]
453 get_canvas_view()->work_area->set_selected_value_node(0);
459 Dock_Timetrack::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
465 hscrollbar_->unset_adjustment();
466 vscrollbar_->unset_adjustment();
467 //widget_timeslider_->unset_adjustment();
474 TimeTrackView* tree_view(dynamic_cast<TimeTrackView*>(canvas_view->get_ext_widget(get_name())));
475 Gtk::TreeView* param_tree_view(dynamic_cast<Gtk::TreeView*>(canvas_view->get_ext_widget("params")));
476 tree_view->set_vadjustment(*param_tree_view->get_vadjustment());
480 widget_timeslider_->set_time_adjustment(&canvas_view->time_adjustment());
481 widget_timeslider_->set_bounds_adjustment(&canvas_view->time_window_adjustment());
482 widget_timeslider_->set_global_fps(canvas_view->get_canvas()->rend_desc().get_frame_rate());
484 vscrollbar_->set_adjustment(*tree_view->get_vadjustment());
485 hscrollbar_->set_adjustment(canvas_view->time_window_adjustment());
486 table_=new Gtk::Table(2,2);
487 table_->attach(*widget_timeslider_, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
488 table_->attach(*tree_view, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
489 table_->attach(*hscrollbar_, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
490 table_->attach(*vscrollbar_, 1, 2, 0, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::EXPAND);
493 //add(*last_widget_curves_);