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/cellrenderer_value.h"
36 #include "cellrenderer/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 ----------------------------------------------------
189 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
191 // Set up the on/off cell-renderer
192 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
193 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
194 column->pack_start(*cellrenderer,false);
195 column->add_attribute(cellrenderer->property_active(), layer_model.active);
196 get_layer_tree_view().append_column(*column);
199 { // --- I C O N --------------------------------------------------------
201 // Set up the icon cell-renderer
202 index=get_layer_tree_view().append_column(_("Icon"),layer_model.icon);
203 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
204 get_layer_tree_view().set_expander_column(*column);
206 { // --- N A M E --------------------------------------------------------
207 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
209 // Set up the Layer label cell-renderer
210 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
211 column->pack_start(*cellrenderer,false);
212 column->add_attribute(cellrenderer->property_text(), layer_model.label);
213 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
214 cellrenderer->property_editable()=true;
216 column->set_reorderable();
217 column->set_resizable();
218 column->set_clickable(true);
219 column->set_sort_column(layer_model.label);
221 get_layer_tree_view().append_column(*column);
223 { // --- Z D E P T H ----------------------------------------------------
225 index=get_layer_tree_view().append_column(_("Z Depth"),layer_model.z_depth);
226 // Set up the Z-Depth label cell-renderer
228 column_z_depth=get_layer_tree_view().get_column(index-1);
229 column_z_depth->set_reorderable();
230 column_z_depth->set_resizable();
231 column_z_depth->set_clickable();
233 column_z_depth->set_sort_column(layer_model.z_depth);
236 get_layer_tree_view().set_enable_search(true);
237 get_layer_tree_view().set_search_column(layer_model.label);
238 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
240 std::list<Gtk::TargetEntry> listTargets;
241 listTargets.push_back( Gtk::TargetEntry("LAYER") );
242 get_layer_tree_view().drag_dest_set(listTargets);
244 // This makes things easier to read.
245 get_layer_tree_view().set_rules_hint();
247 // Make us more sensitive to several events
248 //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);
250 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
251 get_layer_tree_view().show();
253 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
254 scroll->set_flags(Gtk::CAN_FOCUS);
255 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
256 //scroll->add(get_layer_tree_view());
257 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
264 LayerTree::create_param_tree()
266 Pango::AttrList attr_list;
268 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
269 pango_size.set_start_index(0);
270 pango_size.set_end_index(64);
271 attr_list.change(pango_size);
274 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
276 { // --- N A M E --------------------------------------------------------
277 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
279 // Set up the icon cell-renderer
280 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
281 column->pack_start(*icon_cellrenderer,false);
282 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
284 // Pack the label into the column
285 //column->pack_start(layer_model.label,true);
286 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
287 column->pack_start(*text_cellrenderer,false);
288 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
289 text_cellrenderer->property_attributes()=attr_list;
291 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
292 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
294 // Pack the label into the column
295 //column->pack_start(param_model.label,true);
297 // Set up the value-node icon cell-renderer to be on the far right
298 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
299 column->pack_end(*valuenode_icon_cellrenderer,false);
300 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
301 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
303 // Finish setting up the column
304 column->set_reorderable();
305 column->set_resizable();
306 column->set_clickable();
308 get_param_tree_view().append_column(*column);
310 { // --- V A L U E -----------------------------------------------------
311 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
313 // Set up the value cell-renderer
314 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
315 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
316 cellrenderer_value->property_value()=synfig::ValueBase();
317 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
318 column->add_attribute(cellrenderer_value->property_child_param_desc(), param_model.child_param_desc);
319 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
320 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
321 cellrenderer_value->property_attributes()=attr_list;
323 // Finish setting up the column
324 get_param_tree_view().append_column(*column);
325 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
326 column->set_clickable();
327 column->set_min_width(120);
328 column->set_reorderable();
329 column->set_resizable();
331 { // --- T Y P E --------------------------------------------------------
332 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
333 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
334 column->pack_start(*text_cellrenderer,false);
335 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
336 text_cellrenderer->property_attributes()=attr_list;
337 get_param_tree_view().append_column(*column);
338 column->set_reorderable();
339 column->set_resizable();
340 column->set_clickable();
341 column->set_sort_column(param_model.type);
343 #ifdef TIMETRACK_IN_PARAMS_PANEL
344 { // --- T I M E T R A C K --------------------------------------------
345 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
346 column_time_track=column;
348 // Set up the value-node cell-renderer
349 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
350 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
351 cellrenderer_time_track->signal_waypoint_clicked_cellrenderer().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked_layertree) );
352 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
353 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
354 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
355 column->add_attribute(cellrenderer_time_track->property_visible(), param_model.is_value_node);
357 // Finish setting up the column
358 column->set_reorderable();
359 column->set_resizable();
360 column->set_min_width(200);
362 if (!getenv("SYNFIG_DISABLE_PARAMS_PANEL_TIMETRACK"))
363 get_param_tree_view().append_column(*column);
365 #endif // TIMETRACK_IN_PARAMS_PANEL
367 // This makes things easier to read.
368 get_param_tree_view().set_rules_hint();
370 // Make us more sensitive to several events
371 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);
373 get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
374 get_param_tree_view().show();
376 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
377 scroll->set_flags(Gtk::CAN_FOCUS);
378 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
379 //scroll->add(get_param_tree_view());
380 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
383 //column_time_track->set_visible(false);
389 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
391 synfigapp::Action::ParamList param_list;
392 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
393 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
394 param_list.add("value_node",value_node);
395 param_list.add("waypoint",waypoint);
396 // param_list.add("time",canvas_interface()->get_time());
398 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("WaypointSetSmart", param_list);
402 LayerTree::select_layer(synfig::Layer::Handle layer)
404 Gtk::TreeModel::Children::iterator iter;
405 if(layer_tree_store_->find_layer_row(layer,iter))
407 if(sorted_layer_tree_store_)
408 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
410 Gtk::TreePath path(iter);
411 for(int i=path.get_depth();i;i--)
414 path=Gtk::TreePath(iter);
417 get_layer_tree_view().expand_row(path,false);
419 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
420 get_layer_tree_view().get_selection()->select(iter);
425 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
427 get_layer_tree_view().get_selection()->select(iter);
428 if((bool)(*iter)[layer_model.children_lock])
430 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
431 Gtk::TreeModel::Children children(iter->children());
432 for(iter=children.begin();iter!=children.end();++iter)
433 select_all_children(iter);
437 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
439 Gtk::TreeModel::Children::iterator iter;
440 if(layer_tree_store_->find_layer_row(layer,iter))
441 select_all_children(iter);
445 LayerTree::select_layers(const LayerList &layer_list)
447 LayerList::const_iterator iter;
448 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
452 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
454 const LayerTreeStore::Model layer_tree_model;
455 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
459 LayerTree::get_selected_layers()const
461 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
468 selection->selected_foreach_iter(
480 synfig::Layer::Handle
481 LayerTree::get_selected_layer()const
483 LayerList layers(get_selected_layers());
488 return *layers.begin();
492 LayerTree::clear_selected_layers()
494 get_layer_tree_view().get_selection()->unselect_all();
498 LayerTree::set_show_timetrack(bool x)
500 //column_time_track->set_visible(x);
501 // column_time_track->set_visible(false);
502 column_z_depth->set_visible(x);
506 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
508 layer_tree_store_=layer_tree_store;
512 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
514 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
516 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
517 //sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
519 get_layer_tree_view().set_model(sorted_layer_tree_store_);
522 get_layer_tree_view().set_model(layer_tree_store_);
524 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
526 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
528 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
530 &get_param_tree_view(),
531 &Gtk::Widget::queue_draw
534 if(!param_tree_store_)
536 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
537 get_param_tree_view().set_model(param_tree_store_);
540 #ifdef TIMETRACK_IN_PARAMS_PANEL
541 if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
542 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
543 #endif // TIMETRACK_IN_PARAMS_PANEL
547 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
549 #ifdef TIMETRACK_IN_PARAMS_PANEL
550 cellrenderer_time_track->set_adjustment(adjustment);
551 #endif // TIMETRACK_IN_PARAMS_PANEL
552 adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
553 adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
557 LayerTree::on_dirty_preview()
560 if(quick_layer && !disable_amount_changed_signal)
562 layer_amount_hscale->set_sensitive(true);
563 disable_amount_changed_signal=true;
564 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
565 disable_amount_changed_signal=false;
566 if(quick_layer->get_param("blend_method").is_valid())
568 blend_method_widget.set_sensitive(true);
569 disable_amount_changed_signal=true;
570 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
571 disable_amount_changed_signal=false;
578 LayerTree::on_selection_changed()
580 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
583 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
585 if(layer_list.empty())
587 last_top_selected_layer=0;
588 layer_tree_view_->get_selection()->select(last_top_selected_path);
594 if(!layer_list.empty())
596 last_top_selected_layer=layer_list.front();
597 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
601 last_top_selected_layer=0;
605 if(layer_list.empty())
607 button_raise->set_sensitive(false);
608 button_lower->set_sensitive(false);
609 button_duplicate->set_sensitive(false);
610 button_encapsulate->set_sensitive(false);
611 button_delete->set_sensitive(false);
612 layer_amount_hscale->set_sensitive(false);
613 blend_method_widget.set_sensitive(false);
617 button_raise->set_sensitive(true);
618 button_lower->set_sensitive(true);
619 button_duplicate->set_sensitive(true);
620 button_encapsulate->set_sensitive(true);
621 button_delete->set_sensitive(true);
623 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
625 quick_layer=*layer_list.begin();
632 layer_amount_hscale->set_sensitive(true);
633 disable_amount_changed_signal=true;
634 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
635 disable_amount_changed_signal=false;
636 if(quick_layer->get_param("blend_method").is_valid())
638 blend_method_widget.set_sensitive(true);
639 disable_amount_changed_signal=true;
640 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
641 disable_amount_changed_signal=false;
644 blend_method_widget.set_sensitive(false);
648 layer_amount_hscale->set_sensitive(false);
649 blend_method_widget.set_sensitive(false);
654 LayerTree::on_blend_method_changed()
656 if(disable_amount_changed_signal)
661 if(quick_layer->get_param("blend_method").is_valid())
663 disable_amount_changed_signal=true;
664 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
665 disable_amount_changed_signal=false;
670 LayerTree::on_amount_value_changed()
672 if(disable_amount_changed_signal)
677 disable_amount_changed_signal=true;
678 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
679 disable_amount_changed_signal=false;
683 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
685 Gtk::TreePath path(path_string);
687 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
690 row[param_model.value]=value;
691 //signal_edited_value()(row[param_model.value_desc],value);
695 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
697 Gtk::TreePath path(path_string);
699 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
702 row[layer_model.label]=value;
703 get_layer_tree_view().columns_autosize();
707 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
709 Gtk::TreePath path(path_string);
711 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
712 bool active=static_cast<bool>(row[layer_model.active]);
713 row[layer_model.active]=!active;
716 #ifdef TIMETRACK_IN_PARAMS_PANEL
718 LayerTree::on_waypoint_clicked_layertree(const etl::handle<synfig::Node>& node __attribute__ ((unused)),
719 const synfig::Time& time __attribute__ ((unused)),
720 const synfig::Time& time_offset __attribute__ ((unused)),
721 int button __attribute__ ((unused)))
723 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
724 synfig::waypoint_collect(waypoint_set,time,node);
726 synfigapp::ValueDesc value_desc;
728 if (waypoint_set.size() == 1)
730 ValueNode::Handle value_node(waypoint_set.begin()->get_parent_value_node());
734 if (param_tree_store_->find_first_value_node(value_node, row) && row)
735 value_desc = static_cast<synfigapp::ValueDesc>(row[param_tree_store_->model.value_desc]);
738 if (!waypoint_set.empty())
739 signal_waypoint_clicked_layertree()(value_desc,waypoint_set,button);
741 #endif // TIMETRACK_IN_PARAMS_PANEL
744 LayerTree::on_layer_tree_event(GdkEvent *event)
748 case GDK_BUTTON_PRESS:
750 Gtk::TreeModel::Path path;
751 Gtk::TreeViewColumn *column;
753 if(!get_layer_tree_view().get_path_at_pos(
754 int(event->button.x),int(event->button.y), // x, y
755 path, // TreeModel::Path&
756 column, //TreeViewColumn*&
757 cell_x,cell_y //int&cell_x,int&cell_y
760 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
762 #ifdef TIMETRACK_IN_PARAMS_PANEL
763 if(column->get_first_cell_renderer()==cellrenderer_time_track)
764 return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
766 #endif // TIMETRACK_IN_PARAMS_PANEL
767 if(column->get_first_cell_renderer()==cellrenderer_value)
768 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
770 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
775 case GDK_MOTION_NOTIFY:
777 Gtk::TreeModel::Path path;
778 Gtk::TreeViewColumn *column;
780 if(!get_layer_tree_view().get_path_at_pos(
781 (int)event->button.x,(int)event->button.y, // x, y
782 path, // TreeModel::Path&
783 column, //TreeViewColumn*&
784 cell_x,cell_y //int&cell_x,int&cell_y
788 if(!get_layer_tree_view().get_model()->get_iter(path))
791 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
793 #ifdef TIMETRACK_IN_PARAMS_PANEL
794 if(cellrenderer_time_track==column->get_first_cell_renderer())
795 // Movement on TimeLine
798 #endif // TIMETRACK_IN_PARAMS_PANEL
799 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
801 tooltips_.unset_tip(*this);
802 Glib::ustring tooltips_string(row[layer_model.tooltip]);
803 last_tooltip_path=path;
804 if(!tooltips_string.empty())
806 tooltips_.set_tip(*this,tooltips_string);
807 tooltips_.force_window();
812 case GDK_BUTTON_RELEASE:
821 LayerTree::on_param_tree_event(GdkEvent *event)
825 case GDK_BUTTON_PRESS:
827 Gtk::TreeModel::Path path;
828 Gtk::TreeViewColumn *column;
830 if(!get_param_tree_view().get_path_at_pos(
831 int(event->button.x),int(event->button.y), // x, y
832 path, // TreeModel::Path&
833 column, //TreeViewColumn*&
834 cell_x,cell_y //int&cell_x,int&cell_y
837 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
839 #ifdef TIMETRACK_IN_PARAMS_PANEL
840 if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
843 get_param_tree_view().get_cell_area(path,*column,rect);
844 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
845 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
846 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
847 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
849 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
852 #endif // TIMETRACK_IN_PARAMS_PANEL
854 if(event->button.button==3)
856 LayerList layer_list(get_selected_layers());
857 if(layer_list.size()<=1)
859 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
860 Gtk::Menu* menu(manage(new Gtk::Menu()));
861 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
862 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);
863 menu->popup(event->button.button,gtk_get_current_event_time());
866 Gtk::Menu* menu(manage(new Gtk::Menu()));
867 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
868 std::list<synfigapp::ValueDesc> value_desc_list;
869 ParamDesc param_desc(row[param_model.param_desc]);
870 for(;!layer_list.empty();layer_list.pop_back())
871 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
872 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
873 menu->popup(event->button.button,gtk_get_current_event_time());
878 if(column->get_first_cell_renderer()==cellrenderer_value)
879 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
881 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
887 case GDK_MOTION_NOTIFY:
889 Gtk::TreeModel::Path path;
890 Gtk::TreeViewColumn *column;
892 if(!get_param_tree_view().get_path_at_pos(
893 (int)event->motion.x,(int)event->motion.y, // x, y
894 path, // TreeModel::Path&
895 column, //TreeViewColumn*&
896 cell_x,cell_y //int&cell_x,int&cell_y
900 if(!get_param_tree_view().get_model()->get_iter(path))
903 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
905 #ifdef TIMETRACK_IN_PARAMS_PANEL
906 if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
909 get_param_tree_view().get_cell_area(path,*column,rect);
910 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
911 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
912 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
913 get_param_tree_view().queue_draw();
914 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
918 #endif // TIMETRACK_IN_PARAMS_PANEL
919 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
921 tooltips_.unset_tip(get_param_tree_view());
922 Glib::ustring tooltips_string(row[param_model.tooltip]);
923 last_tooltip_path=path;
924 if(!tooltips_string.empty())
926 tooltips_.set_tip(get_param_tree_view(),tooltips_string);
927 tooltips_.force_window();
932 case GDK_BUTTON_RELEASE:
934 Gtk::TreeModel::Path path;
935 Gtk::TreeViewColumn *column;
937 if(!get_param_tree_view().get_path_at_pos(
938 (int)event->button.x,(int)event->button.y, // x, y
939 path, // TreeModel::Path&
940 column, //TreeViewColumn*&
941 cell_x,cell_y //int&cell_x,int&cell_y
945 if(!get_param_tree_view().get_model()->get_iter(path))
948 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
950 #ifdef TIMETRACK_IN_PARAMS_PANEL
951 if(column && cellrenderer_time_track==column->get_first_cell_renderer())
954 get_param_tree_view().get_cell_area(path,*column,rect);
955 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
956 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
957 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
958 get_param_tree_view().queue_draw();
959 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
963 #endif // TIMETRACK_IN_PARAMS_PANEL
973 // LayerTree::on_raise_pressed()
975 // synfigapp::Action::ParamList param_list;
976 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
977 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
978 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
981 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
982 // synfigapp::SelectionManager::LayerList::iterator iter;
984 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
985 // param_list.add("layer",Layer::Handle(*iter));
987 // synfigapp::Action::Handle action(synfigapp::Action::create("LayerRaise"));
988 // action->set_param_list(param_list);
989 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
993 // LayerTree::on_lower_pressed()
995 // synfigapp::Action::ParamList param_list;
996 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
997 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
998 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1001 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1002 // synfigapp::SelectionManager::LayerList::iterator iter;
1004 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1005 // param_list.add("layer",Layer::Handle(*iter));
1008 // synfigapp::Action::Handle action(synfigapp::Action::create("LayerLower"));
1009 // action->set_param_list(param_list);
1010 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1014 // LayerTree::on_duplicate_pressed()
1016 // synfigapp::Action::ParamList param_list;
1017 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1018 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1019 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1022 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1023 // synfigapp::SelectionManager::LayerList::iterator iter;
1025 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1026 // param_list.add("layer",Layer::Handle(*iter));
1029 // synfigapp::Action::Handle action(synfigapp::Action::create("LayerDuplicate"));
1030 // action->set_param_list(param_list);
1031 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1035 // LayerTree::on_encapsulate_pressed()
1037 // synfigapp::Action::ParamList param_list;
1038 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1039 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1040 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1043 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1044 // synfigapp::SelectionManager::LayerList::iterator iter;
1046 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1047 // param_list.add("layer",Layer::Handle(*iter));
1050 // synfigapp::Action::Handle action(synfigapp::Action::create("LayerEncapsulate"));
1051 // action->set_param_list(param_list);
1052 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1056 // LayerTree::on_delete_pressed()
1058 // synfigapp::Action::ParamList param_list;
1059 // param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1060 // param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1061 // param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1064 // synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1065 // synfigapp::SelectionManager::LayerList::iterator iter;
1067 // for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1068 // param_list.add("layer",Layer::Handle(*iter));
1071 // synfigapp::Action::Handle action(synfigapp::Action::create("LayerRemove"));
1072 // action->set_param_list(param_list);
1073 // layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1078 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1080 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1081 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1082 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1084 Gtk::TreeModel::Path path;
1085 Gtk::TreeViewColumn *column;
1088 Gtk::TreeRow row = *(get_selection()->get_selected());
1090 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1092 Layer* layer(((Layer::Handle)row[model.layer]).get());
1094 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1100 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1102 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1103 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1104 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1105 synfig::info("Dropped x=%d, y=%d",x,y);
1107 bool dropped_on_specific_row=false;
1109 Gtk::TreeModel::Path path;
1110 Gtk::TreeViewColumn *column;
1112 if(!get_path_at_pos(
1114 path, // TreeModel::Path&
1115 column, //TreeViewColumn*&
1116 cell_x,cell_y //int&cell_x,int&cell_y
1120 dropped_on_specific_row=false;
1123 dropped_on_specific_row=true;
1125 Gtk::TreeRow row = *(get_model()->get_iter(path));
1127 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1129 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1131 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1134 Canvas::Handle dest_canvas;
1135 Layer::Handle dest_layer;
1137 if(dropped_on_specific_row)
1139 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1140 dest_layer=(Layer::Handle)(row[model.layer]);
1141 assert(dest_canvas);
1144 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1146 // In this case, we are just moving.
1147 if(dest_canvas==src->get_canvas())
1149 if(!dest_layer || dest_layer==src)
1152 synfigapp::Action::Handle action(synfigapp::Action::create("LayerMove"));
1153 action->set_param("canvas",dest_canvas);
1154 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1155 action->set_param("layer",src);
1156 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1157 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1167 context->drag_finish(success, false, time);
1172 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1174 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1178 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1180 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1183 if(context->gobj()->source_window==context->gobj()->dest_window)
1185 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1189 Gtk::TreeModel::Path path;
1190 Gtk::TreeViewColumn *column;
1192 if(!get_path_at_pos(
1194 path, // TreeModel::Path&
1195 column, //TreeViewColumn*&
1196 cell_x,cell_y //int&cell_x,int&cell_y
1200 context->drag_finish(false, false, time);
1203 if(layer_tree_store_->row_drop_possible(path,selection_data))
1205 if(layer_tree_store_->drag_data_received(path,selection_data))
1206 context->drag_finish(true, false, time);
1208 context->drag_finish(false, false, time);