1 /* === S Y N F I G ========================================================= */
2 /*! \file layertree.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 "layertree.h"
34 #include "layerparamtreestore.h"
35 #include "cellrenderer_value.h"
36 #include "cellrenderer_timetrack.h"
37 #include <synfigapp/action.h>
38 #include <synfigapp/instance.h>
39 #include <gtkmm/scrolledwindow.h>
40 #include <gtkmm/paned.h>
43 #include <gtkmm/treemodelsort.h>
45 #ifdef TIMETRACK_IN_PARAMS_PANEL
46 # include <synfig/timepointcollect.h>
47 #endif // TIMETRACK_IN_PARAMS_PANEL
53 /* === U S I N G =========================================================== */
57 using namespace synfig;
58 using namespace studio;
60 /* === M A C R O S ========================================================= */
63 #define SMALL_BUTTON(button,stockid,tooltip) \
64 button = manage(new class Gtk::Button()); \
65 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
67 tooltips_.set_tip(*button,tooltip); \
68 icon->set_padding(0,0);\
70 button->set_relief(Gtk::RELIEF_NONE); \
75 #define NORMAL_BUTTON(button,stockid,tooltip) \
76 button = manage(new class Gtk::Button()); \
77 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
79 tooltips_.set_tip(*button,tooltip); \
80 icon->set_padding(0,0);\
82 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
86 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
88 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
90 /* === G L O B A L S ======================================================= */
92 /* === P R O C E D U R E S ================================================= */
94 /* === M E T H O D S ======================================================= */
96 LayerTree::LayerTree():
97 layer_amount_adjustment_(1,0,1,0.01,0.01,0)
99 param_tree_view_=new Gtk::TreeView;
100 layer_tree_view_=new Gtk::TreeView;
102 //Gtk::HPaned* hpaned(manage(new Gtk::HPaned()));
104 //attach(*hpaned, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
105 //attach(*create_layer_tree(), 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
110 //hpaned->pack1(*create_layer_tree(),false,false);
111 //hpaned->pack2(*create_param_tree(),true,false);
112 //hpaned->set_position(200);
113 hbox=manage(new Gtk::HBox());
115 attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
116 attach(blend_method_widget, 2, 3, 1, 2,Gtk::SHRINK, Gtk::SHRINK, 0, 0);
118 layer_amount_hscale=manage(new Gtk::HScale(layer_amount_adjustment_));
119 layer_amount_hscale->set_digits(2);
120 layer_amount_hscale->set_value_pos(Gtk::POS_LEFT);
121 layer_amount_hscale->set_sensitive(false);
122 layer_amount_hscale->set_update_policy( Gtk::UPDATE_DISCONTINUOUS);
123 attach(*layer_amount_hscale, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 1, 1);
124 layer_amount_adjustment_.signal_value_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_amount_value_changed));
127 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
128 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
130 SMALL_BUTTON(button_raise,"gtk-go-up","Raise");
131 SMALL_BUTTON(button_lower,"gtk-go-down","Lower");
132 SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate");
133 SMALL_BUTTON(button_encapsulate,"synfig-encapsulate","Encapsulate");
134 SMALL_BUTTON(button_delete,"gtk-delete","Delete");
136 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
137 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
138 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
139 hbox->pack_start(*button_encapsulate,Gtk::PACK_SHRINK);
140 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
142 // button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_raise_pressed));
143 // button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_lower_pressed));
144 // button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_duplicate_pressed));
145 // button_encapsulate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_encapsulate_pressed));
146 // button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_delete_pressed));
148 button_raise->set_sensitive(false);
149 button_lower->set_sensitive(false);
150 button_duplicate->set_sensitive(false);
151 button_encapsulate->set_sensitive(false);
152 button_delete->set_sensitive(false);
154 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_selection_changed));
156 get_layer_tree_view().set_reorderable(true);
157 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
158 //get_param_tree_view().get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
159 get_layer_tree_view().show();
160 get_param_tree_view().show();
163 layer_amount_hscale->show();
164 blend_method_widget.show();
167 disable_amount_changed_signal=false;
169 blend_method_widget.set_param_desc(ParamDesc(Color::BlendMethod(),"blend_method"));
171 blend_method_widget.set_value((int)Color::BLEND_COMPOSITE);
172 blend_method_widget.set_size_request(150,-1);
173 blend_method_widget.set_sensitive(false);
174 blend_method_widget.signal_activate().connect(sigc::mem_fun(*this, &studio::LayerTree::on_blend_method_changed));
177 LayerTree::~LayerTree()
179 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
180 synfig::info("LayerTree::~LayerTree(): Deleted");
184 LayerTree::create_layer_tree()
186 const LayerTreeStore::Model model;
188 { // --- O N / O F F ----------------------------------------------------
190 //index=get_layer_tree_view().append_column_editable(_(" "),layer_model.active);
191 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
193 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
195 // Set up the icon cell-renderer
196 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
197 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
199 column->pack_start(*cellrenderer,false);
200 column->add_attribute(cellrenderer->property_active(), layer_model.active);
201 get_layer_tree_view().append_column(*column);
204 { // --- I C O N --------------------------------------------------------
206 index=get_layer_tree_view().append_column(_("Z"),layer_model.icon);
207 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
208 get_layer_tree_view().set_expander_column(*column);
210 column->set_sort_column(layer_model.z_depth);
211 //column->set_reorderable();
212 //column->set_resizable();
213 //column->set_clickable();
215 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
216 //column->pack_start(*icon_cellrenderer,false);
217 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
219 //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
220 { // --- N A M E --------------------------------------------------------
221 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
223 // Set up the icon cell-renderer
224 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
225 column->pack_start(*cellrenderer,false);
226 column->add_attribute(cellrenderer->property_text(), layer_model.label);
227 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
228 cellrenderer->property_editable()=true;
230 column->set_reorderable();
231 // column->set_resizable();
232 column->set_clickable(true);
233 column->set_sort_column(layer_model.label);
235 get_layer_tree_view().append_column(*column);
238 // index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
239 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
241 //get_layer_tree_view().set_expander_column(*column);
243 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
244 //column->pack_start(*icon_cellrenderer,false);
245 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
247 { // --- Z D E P T H ----------------------------------------------------
249 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
250 column_z_depth=get_layer_tree_view().get_column(index-1);
252 column_z_depth->set_reorderable();
253 column_z_depth->set_resizable();
254 column_z_depth->set_clickable();
256 column_z_depth->set_sort_column(layer_model.z_depth);
259 get_layer_tree_view().set_enable_search(true);
260 get_layer_tree_view().set_search_column(layer_model.label);
261 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
263 std::list<Gtk::TargetEntry> listTargets;
264 listTargets.push_back( Gtk::TargetEntry("LAYER") );
265 get_layer_tree_view().drag_dest_set(listTargets);
267 // This makes things easier to read.
268 get_layer_tree_view().set_rules_hint();
270 // Make us more sensitive to several events
271 //get_layer_tree_view().add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
273 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
274 get_layer_tree_view().show();
276 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
277 scroll->set_flags(Gtk::CAN_FOCUS);
278 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
279 //scroll->add(get_layer_tree_view());
280 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
287 LayerTree::create_param_tree()
289 Pango::AttrList attr_list;
291 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
292 pango_size.set_start_index(0);
293 pango_size.set_end_index(64);
294 attr_list.change(pango_size);
297 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
299 { // --- N A M E --------------------------------------------------------
300 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
302 // Set up the icon cell-renderer
303 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
304 column->pack_start(*icon_cellrenderer,false);
305 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
307 // Pack the label into the column
308 //column->pack_start(layer_model.label,true);
309 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
310 column->pack_start(*text_cellrenderer,false);
311 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
312 text_cellrenderer->property_attributes()=attr_list;
314 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
315 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
317 // Pack the label into the column
318 //column->pack_start(param_model.label,true);
320 // Set up the value-node icon cell-renderer to be on the far right
321 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
322 column->pack_end(*valuenode_icon_cellrenderer,false);
323 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
324 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
326 // Finish setting up the column
327 column->set_reorderable();
328 column->set_resizable();
329 column->set_clickable();
331 get_param_tree_view().append_column(*column);
333 { // --- V A L U E -----------------------------------------------------
334 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
336 // Set up the value cell-renderer
337 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
338 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
339 cellrenderer_value->property_value()=synfig::ValueBase();
340 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
341 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
342 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
343 cellrenderer_value->property_attributes()=attr_list;
345 // Finish setting up the column
346 get_param_tree_view().append_column(*column);
347 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
348 column->set_clickable();
349 column->set_min_width(120);
350 column->set_reorderable();
351 column->set_resizable();
353 { // --- T Y P E --------------------------------------------------------
354 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
355 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
356 column->pack_start(*text_cellrenderer,false);
357 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
358 text_cellrenderer->property_attributes()=attr_list;
359 get_param_tree_view().append_column(*column);
360 column->set_reorderable();
361 column->set_resizable();
362 column->set_clickable();
363 column->set_sort_column(param_model.type);
365 #ifdef TIMETRACK_IN_PARAMS_PANEL
366 { // --- T I M E T R A C K --------------------------------------------
367 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
368 column_time_track=column;
370 // Set up the value-node cell-renderer
371 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
372 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
373 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked_layertree) );
374 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
375 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
376 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
377 column->add_attribute(cellrenderer_time_track->property_visible(), param_model.is_value_node);
379 // Finish setting up the column
380 column->set_reorderable();
381 column->set_resizable();
382 column->set_min_width(200);
384 if (!getenv("SYNFIG_DISABLE_PARAMS_PANEL_TIMETRACK"))
385 get_param_tree_view().append_column(*column);
387 #endif // TIMETRACK_IN_PARAMS_PANEL
389 // This makes things easier to read.
390 get_param_tree_view().set_rules_hint();
392 // Make us more sensitive to several events
393 get_param_tree_view().add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
395 get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
396 get_param_tree_view().show();
398 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
399 scroll->set_flags(Gtk::CAN_FOCUS);
400 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
401 //scroll->add(get_param_tree_view());
402 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
405 //column_time_track->set_visible(false);
411 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
413 synfigapp::Action::ParamList param_list;
414 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
415 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
416 param_list.add("value_node",value_node);
417 param_list.add("waypoint",waypoint);
418 // param_list.add("time",canvas_interface()->get_time());
420 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
424 LayerTree::select_layer(synfig::Layer::Handle layer)
426 Gtk::TreeModel::Children::iterator iter;
427 if(layer_tree_store_->find_layer_row(layer,iter))
429 if(sorted_layer_tree_store_)
430 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
432 Gtk::TreePath path(iter);
433 for(int i=path.get_depth();i;i--)
436 path=Gtk::TreePath(iter);
439 get_layer_tree_view().expand_row(path,false);
441 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
442 get_layer_tree_view().get_selection()->select(iter);
447 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
449 get_layer_tree_view().get_selection()->select(iter);
450 if((bool)(*iter)[layer_model.children_lock])
452 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
453 Gtk::TreeModel::Children children(iter->children());
454 for(iter=children.begin();iter!=children.end();++iter)
455 select_all_children(iter);
459 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
461 Gtk::TreeModel::Children::iterator iter;
462 if(layer_tree_store_->find_layer_row(layer,iter))
463 select_all_children(iter);
467 LayerTree::select_layers(const LayerList &layer_list)
469 LayerList::const_iterator iter;
470 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
474 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
476 const LayerTreeStore::Model layer_tree_model;
477 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
481 LayerTree::get_selected_layers()const
483 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
490 selection->selected_foreach_iter(
502 synfig::Layer::Handle
503 LayerTree::get_selected_layer()const
505 LayerList layers(get_selected_layers());
510 return *layers.begin();
514 LayerTree::clear_selected_layers()
516 get_layer_tree_view().get_selection()->unselect_all();
520 LayerTree::set_show_timetrack(bool x)
522 //column_time_track->set_visible(x);
523 // column_time_track->set_visible(false);
524 column_z_depth->set_visible(x);
528 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
530 layer_tree_store_=layer_tree_store;
534 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
536 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
538 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
539 //sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
541 get_layer_tree_view().set_model(sorted_layer_tree_store_);
544 get_layer_tree_view().set_model(layer_tree_store_);
546 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
548 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
550 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
552 &get_param_tree_view(),
553 &Gtk::Widget::queue_draw
556 if(!param_tree_store_)
558 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
559 get_param_tree_view().set_model(param_tree_store_);
562 #ifdef TIMETRACK_IN_PARAMS_PANEL
563 if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
564 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
565 #endif // TIMETRACK_IN_PARAMS_PANEL
569 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
571 #ifdef TIMETRACK_IN_PARAMS_PANEL
572 cellrenderer_time_track->set_adjustment(adjustment);
573 #endif // TIMETRACK_IN_PARAMS_PANEL
574 adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
575 adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
579 LayerTree::on_dirty_preview()
582 if(quick_layer && !disable_amount_changed_signal)
584 layer_amount_hscale->set_sensitive(true);
585 disable_amount_changed_signal=true;
586 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
587 disable_amount_changed_signal=false;
588 if(quick_layer->get_param("blend_method").is_valid())
590 blend_method_widget.set_sensitive(true);
591 disable_amount_changed_signal=true;
592 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
593 disable_amount_changed_signal=false;
600 LayerTree::on_selection_changed()
602 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
605 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
607 if(layer_list.empty())
609 last_top_selected_layer=0;
610 layer_tree_view_->get_selection()->select(last_top_selected_path);
616 if(!layer_list.empty())
618 last_top_selected_layer=layer_list.front();
619 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
623 last_top_selected_layer=0;
627 if(layer_list.empty())
629 button_raise->set_sensitive(false);
630 button_lower->set_sensitive(false);
631 button_duplicate->set_sensitive(false);
632 button_encapsulate->set_sensitive(false);
633 button_delete->set_sensitive(false);
634 layer_amount_hscale->set_sensitive(false);
635 blend_method_widget.set_sensitive(false);
639 button_raise->set_sensitive(true);
640 button_lower->set_sensitive(true);
641 button_duplicate->set_sensitive(true);
642 button_encapsulate->set_sensitive(true);
643 button_delete->set_sensitive(true);
645 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
647 quick_layer=*layer_list.begin();
654 layer_amount_hscale->set_sensitive(true);
655 disable_amount_changed_signal=true;
656 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
657 disable_amount_changed_signal=false;
658 if(quick_layer->get_param("blend_method").is_valid())
660 blend_method_widget.set_sensitive(true);
661 disable_amount_changed_signal=true;
662 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
663 disable_amount_changed_signal=false;
666 blend_method_widget.set_sensitive(false);
670 layer_amount_hscale->set_sensitive(false);
671 blend_method_widget.set_sensitive(false);
676 LayerTree::on_blend_method_changed()
678 if(disable_amount_changed_signal)
683 if(quick_layer->get_param("blend_method").is_valid())
685 disable_amount_changed_signal=true;
686 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
687 disable_amount_changed_signal=false;
692 LayerTree::on_amount_value_changed()
694 if(disable_amount_changed_signal)
699 disable_amount_changed_signal=true;
700 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
701 disable_amount_changed_signal=false;
705 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
707 Gtk::TreePath path(path_string);
709 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
712 row[param_model.value]=value;
713 //signal_edited_value()(row[param_model.value_desc],value);
717 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
719 Gtk::TreePath path(path_string);
721 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
724 row[layer_model.label]=value;
725 get_layer_tree_view().columns_autosize();
729 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
731 Gtk::TreePath path(path_string);
733 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
734 bool active=static_cast<bool>(row[layer_model.active]);
735 row[layer_model.active]=!active;
738 #ifdef TIMETRACK_IN_PARAMS_PANEL
740 LayerTree::on_waypoint_clicked_layertree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
741 const synfig::Time& time __attribute__ ((unused)),
742 const synfig::Time& time_offset __attribute__ ((unused)),
743 int button __attribute__ ((unused)))
745 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
746 synfig::waypoint_collect(waypoint_set,time,node);
748 synfigapp::ValueDesc value_desc;
750 if (waypoint_set.size() == 1)
752 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
756 if (param_tree_store_->find_first_value_node(value_node, row) && row)
757 value_desc = static_cast<synfigapp::ValueDesc>(row[param_tree_store_->model.value_desc]);
760 if (!waypoint_set.empty())
761 signal_waypoint_clicked_layertree()(value_desc,waypoint_set,button);
763 #endif // TIMETRACK_IN_PARAMS_PANEL
766 LayerTree::on_layer_tree_event(GdkEvent *event)
770 case GDK_BUTTON_PRESS:
772 Gtk::TreeModel::Path path;
773 Gtk::TreeViewColumn *column;
775 if(!get_layer_tree_view().get_path_at_pos(
776 int(event->button.x),int(event->button.y), // x, y
777 path, // TreeModel::Path&
778 column, //TreeViewColumn*&
779 cell_x,cell_y //int&cell_x,int&cell_y
782 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
784 #ifdef TIMETRACK_IN_PARAMS_PANEL
785 if(column->get_first_cell_renderer()==cellrenderer_time_track)
786 return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
788 #endif // TIMETRACK_IN_PARAMS_PANEL
789 if(column->get_first_cell_renderer()==cellrenderer_value)
790 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
792 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
797 case GDK_MOTION_NOTIFY:
799 Gtk::TreeModel::Path path;
800 Gtk::TreeViewColumn *column;
802 if(!get_layer_tree_view().get_path_at_pos(
803 (int)event->button.x,(int)event->button.y, // x, y
804 path, // TreeModel::Path&
805 column, //TreeViewColumn*&
806 cell_x,cell_y //int&cell_x,int&cell_y
810 if(!get_layer_tree_view().get_model()->get_iter(path))
813 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
815 #ifdef TIMETRACK_IN_PARAMS_PANEL
816 if(cellrenderer_time_track==column->get_first_cell_renderer())
817 // Movement on TimeLine
820 #endif // TIMETRACK_IN_PARAMS_PANEL
821 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
823 tooltips_.unset_tip(*this);
824 Glib::ustring tooltips_string(row[layer_model.tooltip]);
825 last_tooltip_path=path;
826 if(!tooltips_string.empty())
828 tooltips_.set_tip(*this,tooltips_string);
829 tooltips_.force_window();
834 case GDK_BUTTON_RELEASE:
843 LayerTree::on_param_tree_event(GdkEvent *event)
847 case GDK_BUTTON_PRESS:
849 Gtk::TreeModel::Path path;
850 Gtk::TreeViewColumn *column;
852 if(!get_param_tree_view().get_path_at_pos(
853 int(event->button.x),int(event->button.y), // x, y
854 path, // TreeModel::Path&
855 column, //TreeViewColumn*&
856 cell_x,cell_y //int&cell_x,int&cell_y
859 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
861 #ifdef TIMETRACK_IN_PARAMS_PANEL
862 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
865 get_param_tree_view().get_cell_area(path,*column,rect);
866 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
867 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
868 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
869 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
871 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
874 #endif // TIMETRACK_IN_PARAMS_PANEL
876 if(event->button.button==3)
878 LayerList layer_list(get_selected_layers());
879 if(layer_list.size()<=1)
881 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
882 Gtk::Menu* menu(manage(new Gtk::Menu()));
883 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
884 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);
885 menu->popup(event->button.button,gtk_get_current_event_time());
888 Gtk::Menu* menu(manage(new Gtk::Menu()));
889 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
890 std::list<synfigapp::ValueDesc> value_desc_list;
891 ParamDesc param_desc(row[param_model.param_desc]);
892 for(;!layer_list.empty();layer_list.pop_back())
893 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
894 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
895 menu->popup(event->button.button,gtk_get_current_event_time());
900 if(column->get_first_cell_renderer()==cellrenderer_value)
901 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
903 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
909 case GDK_MOTION_NOTIFY:
911 Gtk::TreeModel::Path path;
912 Gtk::TreeViewColumn *column;
914 if(!get_param_tree_view().get_path_at_pos(
915 (int)event->motion.x,(int)event->motion.y, // x, y
916 path, // TreeModel::Path&
917 column, //TreeViewColumn*&
918 cell_x,cell_y //int&cell_x,int&cell_y
922 if(!get_param_tree_view().get_model()->get_iter(path))
925 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
927 #ifdef TIMETRACK_IN_PARAMS_PANEL
928 if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
931 get_param_tree_view().get_cell_area(path,*column,rect);
932 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
933 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
934 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
935 get_param_tree_view().queue_draw();
936 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
940 #endif // TIMETRACK_IN_PARAMS_PANEL
941 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
943 tooltips_.unset_tip(*this);
944 Glib::ustring tooltips_string(row[layer_model.tooltip]);
945 last_tooltip_path=path;
946 if(!tooltips_string.empty())
948 tooltips_.set_tip(*this,tooltips_string);
949 tooltips_.force_window();
954 case GDK_BUTTON_RELEASE:
956 Gtk::TreeModel::Path path;
957 Gtk::TreeViewColumn *column;
959 if(!get_param_tree_view().get_path_at_pos(
960 (int)event->button.x,(int)event->button.y, // x, y
961 path, // TreeModel::Path&
962 column, //TreeViewColumn*&
963 cell_x,cell_y //int&cell_x,int&cell_y
967 if(!get_param_tree_view().get_model()->get_iter(path))
970 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
972 #ifdef TIMETRACK_IN_PARAMS_PANEL
973 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
976 get_param_tree_view().get_cell_area(path,*column,rect);
977 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
978 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
979 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
980 get_param_tree_view().queue_draw();
981 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
985 #endif // TIMETRACK_IN_PARAMS_PANEL
995 // LayerTree::on_raise_pressed()
997 // synfigapp::Action::ParamList param_list;
998 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
999 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1000 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1003 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1004 // synfigapp::SelectionManager::LayerList::iterator iter;
1006 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1007 // param_list.add("layer",Layer::Handle(*iter));
1009 // synfigapp::Action::Handle action(synfigapp::Action::create("layer_raise"));
1010 // action->set_param_list(param_list);
1011 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1015 // LayerTree::on_lower_pressed()
1017 // synfigapp::Action::ParamList param_list;
1018 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1019 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1020 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1023 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1024 // synfigapp::SelectionManager::LayerList::iterator iter;
1026 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1027 // param_list.add("layer",Layer::Handle(*iter));
1030 // synfigapp::Action::Handle action(synfigapp::Action::create("layer_lower"));
1031 // action->set_param_list(param_list);
1032 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1036 // LayerTree::on_duplicate_pressed()
1038 // synfigapp::Action::ParamList param_list;
1039 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1040 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1041 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1044 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1045 // synfigapp::SelectionManager::LayerList::iterator iter;
1047 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1048 // param_list.add("layer",Layer::Handle(*iter));
1051 // synfigapp::Action::Handle action(synfigapp::Action::create("layer_duplicate"));
1052 // action->set_param_list(param_list);
1053 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1057 // LayerTree::on_encapsulate_pressed()
1059 // synfigapp::Action::ParamList param_list;
1060 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1061 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1062 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1065 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1066 // synfigapp::SelectionManager::LayerList::iterator iter;
1068 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1069 // param_list.add("layer",Layer::Handle(*iter));
1072 // synfigapp::Action::Handle action(synfigapp::Action::create("layer_encapsulate"));
1073 // action->set_param_list(param_list);
1074 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1078 // LayerTree::on_delete_pressed()
1080 // synfigapp::Action::ParamList param_list;
1081 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1082 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1083 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1086 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1087 // synfigapp::SelectionManager::LayerList::iterator iter;
1089 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1090 // param_list.add("layer",Layer::Handle(*iter));
1093 // synfigapp::Action::Handle action(synfigapp::Action::create("layer_remove"));
1094 // action->set_param_list(param_list);
1095 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1100 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1102 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1103 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1104 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1106 Gtk::TreeModel::Path path;
1107 Gtk::TreeViewColumn *column;
1110 Gtk::TreeRow row = *(get_selection()->get_selected());
1112 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1114 Layer* layer(((Layer::Handle)row[model.layer]).get());
1116 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1122 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1124 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1125 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1126 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1127 synfig::info("Dropped x=%d, y=%d",x,y);
1129 bool dropped_on_specific_row=false;
1131 Gtk::TreeModel::Path path;
1132 Gtk::TreeViewColumn *column;
1134 if(!get_path_at_pos(
1136 path, // TreeModel::Path&
1137 column, //TreeViewColumn*&
1138 cell_x,cell_y //int&cell_x,int&cell_y
1142 dropped_on_specific_row=false;
1145 dropped_on_specific_row=true;
1147 Gtk::TreeRow row = *(get_model()->get_iter(path));
1149 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1151 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1153 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1156 Canvas::Handle dest_canvas;
1157 Layer::Handle dest_layer;
1159 if(dropped_on_specific_row)
1161 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1162 dest_layer=(Layer::Handle)(row[model.layer]);
1163 assert(dest_canvas);
1166 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1168 // In this case, we are just moving.
1169 if(dest_canvas==src->get_canvas())
1171 if(!dest_layer || dest_layer==src)
1174 synfigapp::Action::Handle action(synfigapp::Action::create("layer_move"));
1175 action->set_param("canvas",dest_canvas);
1176 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1177 action->set_param("layer",src);
1178 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1179 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1189 context->drag_finish(success, false, time);
1194 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1196 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1200 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1202 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1205 if(context->gobj()->source_window==context->gobj()->dest_window)
1207 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1211 Gtk::TreeModel::Path path;
1212 Gtk::TreeViewColumn *column;
1214 if(!get_path_at_pos(
1216 path, // TreeModel::Path&
1217 column, //TreeViewColumn*&
1218 cell_x,cell_y //int&cell_x,int&cell_y
1222 context->drag_finish(false, false, time);
1225 if(layer_tree_store_->row_drop_possible(path,selection_data))
1227 if(layer_tree_store_->drag_data_received(path,selection_data))
1228 context->drag_finish(true, false, time);
1230 context->drag_finish(false, false, time);