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
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 "layertree.h"
33 #include "layerparamtreestore.h"
34 #include "cellrenderer_value.h"
35 #include "cellrenderer_timetrack.h"
36 #include <synfigapp/action.h>
37 #include <synfigapp/instance.h>
38 #include <gtkmm/scrolledwindow.h>
39 #include <gtkmm/paned.h>
42 #include <gtkmm/treemodelsort.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
58 #define SMALL_BUTTON(button,stockid,tooltip) \
59 button = manage(new class Gtk::Button()); \
60 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
62 tooltips_.set_tip(*button,tooltip); \
63 icon->set_padding(0,0);\
65 button->set_relief(Gtk::RELIEF_NONE); \
70 #define NORMAL_BUTTON(button,stockid,tooltip) \
71 button = manage(new class Gtk::Button()); \
72 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
74 tooltips_.set_tip(*button,tooltip); \
75 icon->set_padding(0,0);\
77 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
81 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
83 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
85 /* === G L O B A L S ======================================================= */
87 /* === P R O C E D U R E S ================================================= */
89 /* === M E T H O D S ======================================================= */
91 LayerTree::LayerTree():
92 layer_amount_adjustment_(1,0,1,0.01,0.01,0)
94 param_tree_view_=new Gtk::TreeView;
95 layer_tree_view_=new Gtk::TreeView;
97 //Gtk::HPaned* hpaned(manage(new Gtk::HPaned()));
99 //attach(*hpaned, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
100 //attach(*create_layer_tree(), 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
105 //hpaned->pack1(*create_layer_tree(),false,false);
106 //hpaned->pack2(*create_param_tree(),true,false);
107 //hpaned->set_position(200);
108 hbox=manage(new Gtk::HBox());
110 attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
111 attach(blend_method_widget, 2, 3, 1, 2,Gtk::SHRINK, Gtk::SHRINK, 0, 0);
113 layer_amount_hscale=manage(new Gtk::HScale(layer_amount_adjustment_));
114 layer_amount_hscale->set_digits(2);
115 layer_amount_hscale->set_value_pos(Gtk::POS_LEFT);
116 layer_amount_hscale->set_sensitive(false);
117 layer_amount_hscale->set_update_policy( Gtk::UPDATE_DISCONTINUOUS);
118 attach(*layer_amount_hscale, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 1, 1);
119 layer_amount_adjustment_.signal_value_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_amount_value_changed));
122 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
123 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
125 SMALL_BUTTON(button_raise,"gtk-go-up","Raise");
126 SMALL_BUTTON(button_lower,"gtk-go-down","Lower");
127 SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate");
128 SMALL_BUTTON(button_delete,"gtk-delete","Delete");
130 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
131 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
132 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
133 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
135 button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_raise_pressed));
136 button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_lower_pressed));
137 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_duplicate_pressed));
138 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_delete_pressed));
140 button_raise->set_sensitive(false);
141 button_lower->set_sensitive(false);
142 button_duplicate->set_sensitive(false);
143 button_delete->set_sensitive(false);
145 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_selection_changed));
147 get_layer_tree_view().set_reorderable(true);
148 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
149 //get_param_tree_view().get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
150 get_layer_tree_view().show();
151 get_param_tree_view().show();
154 layer_amount_hscale->show();
155 blend_method_widget.show();
158 disable_amount_changed_signal=false;
160 blend_method_widget.set_param_desc(ParamDesc(Color::BlendMethod(),"blend_method"));
162 blend_method_widget.set_value((int)Color::BLEND_COMPOSITE);
163 blend_method_widget.set_size_request(150,-1);
164 blend_method_widget.set_sensitive(false);
165 blend_method_widget.signal_activate().connect(sigc::mem_fun(*this, &studio::LayerTree::on_blend_method_changed));
168 LayerTree::~LayerTree()
170 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
171 synfig::info("LayerTree::~LayerTree(): Deleted");
175 LayerTree::create_layer_tree()
177 const LayerTreeStore::Model model;
179 { // --- O N / O F F ----------------------------------------------------
181 //index=get_layer_tree_view().append_column_editable(_(" "),layer_model.active);
182 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
184 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
186 // Set up the icon cell-renderer
187 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
188 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
190 column->pack_start(*cellrenderer,false);
191 column->add_attribute(cellrenderer->property_active(), layer_model.active);
192 get_layer_tree_view().append_column(*column);
195 { // --- I C O N --------------------------------------------------------
197 index=get_layer_tree_view().append_column(_("Z"),layer_model.icon);
198 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
199 get_layer_tree_view().set_expander_column(*column);
201 column->set_sort_column(layer_model.z_depth);
202 //column->set_reorderable();
203 //column->set_resizable();
204 //column->set_clickable();
206 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
207 //column->pack_start(*icon_cellrenderer,false);
208 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
210 //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
211 { // --- N A M E --------------------------------------------------------
212 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
214 // Set up the icon cell-renderer
215 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
216 column->pack_start(*cellrenderer,false);
217 column->add_attribute(cellrenderer->property_text(), layer_model.label);
218 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
219 cellrenderer->property_editable()=true;
221 column->set_reorderable();
222 // column->set_resizable();
223 column->set_clickable(true);
224 column->set_sort_column(layer_model.label);
226 get_layer_tree_view().append_column(*column);
229 // index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
230 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
232 //get_layer_tree_view().set_expander_column(*column);
234 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
235 //column->pack_start(*icon_cellrenderer,false);
236 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
238 { // --- Z D E P T H ----------------------------------------------------
240 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
241 column_z_depth=get_layer_tree_view().get_column(index-1);
243 column_z_depth->set_reorderable();
244 column_z_depth->set_resizable();
245 column_z_depth->set_clickable();
247 column_z_depth->set_sort_column(layer_model.z_depth);
250 get_layer_tree_view().set_enable_search(true);
251 get_layer_tree_view().set_search_column(layer_model.label);
252 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
254 std::list<Gtk::TargetEntry> listTargets;
255 listTargets.push_back( Gtk::TargetEntry("LAYER") );
256 get_layer_tree_view().drag_dest_set(listTargets);
258 // This makes things easier to read.
259 get_layer_tree_view().set_rules_hint();
261 // Make us more sensitive to several events
262 //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);
264 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
265 get_layer_tree_view().show();
267 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
268 scroll->set_flags(Gtk::CAN_FOCUS);
269 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
270 //scroll->add(get_layer_tree_view());
271 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
278 LayerTree::create_param_tree()
280 Pango::AttrList attr_list;
282 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
283 pango_size.set_start_index(0);
284 pango_size.set_end_index(64);
285 attr_list.change(pango_size);
288 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
290 { // --- N A M E --------------------------------------------------------
291 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
293 // Set up the icon cell-renderer
294 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
295 column->pack_start(*icon_cellrenderer,false);
296 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
298 // Pack the label into the column
299 //column->pack_start(layer_model.label,true);
300 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
301 column->pack_start(*text_cellrenderer,false);
302 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
303 text_cellrenderer->property_attributes()=attr_list;
305 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
306 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
308 // Pack the label into the column
309 //column->pack_start(param_model.label,true);
311 // Set up the value-node icon cell-renderer to be on the far right
312 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
313 column->pack_end(*valuenode_icon_cellrenderer,false);
314 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
315 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
317 // Finish setting up the column
318 column->set_reorderable();
319 column->set_resizable();
320 column->set_clickable();
322 get_param_tree_view().append_column(*column);
324 { // --- V A L U E -----------------------------------------------------
325 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
327 // Set up the value cell-renderer
328 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
329 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
330 cellrenderer_value->property_value()=synfig::ValueBase();
331 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
332 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
333 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
334 cellrenderer_value->property_attributes()=attr_list;
336 // Finish setting up the column
337 get_param_tree_view().append_column(*column);
338 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
339 column->set_clickable();
340 column->set_min_width(120);
341 column->set_reorderable();
342 column->set_resizable();
344 { // --- T Y P E --------------------------------------------------------
345 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
346 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
347 column->pack_start(*text_cellrenderer,false);
348 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
349 text_cellrenderer->property_attributes()=attr_list;
350 get_param_tree_view().append_column(*column);
351 column->set_reorderable();
352 column->set_resizable();
353 column->set_clickable();
354 column->set_sort_column(param_model.type);
356 /*{ // --- T I M E T R A C K --------------------------------------------
357 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
358 column_time_track=column;
360 // Set up the value-node cell-renderer
361 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
362 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
363 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked) );
364 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
365 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
366 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
367 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
369 //column->pack_start(*cellrenderer_time_track);
371 // Finish setting up the column
372 column->set_reorderable();
373 column->set_resizable();
374 column->set_min_width(200);
375 //get_param_tree_view().append_column(*column);
378 // This makes things easier to read.
379 get_param_tree_view().set_rules_hint();
381 // Make us more sensitive to several events
382 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);
384 get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
385 get_param_tree_view().show();
387 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
388 scroll->set_flags(Gtk::CAN_FOCUS);
389 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
390 //scroll->add(get_param_tree_view());
391 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
394 //column_time_track->set_visible(false);
400 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
402 synfigapp::Action::ParamList param_list;
403 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
404 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
405 param_list.add("value_node",value_node);
406 param_list.add("waypoint",waypoint);
407 // param_list.add("time",canvas_interface()->get_time());
409 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
413 LayerTree::select_layer(synfig::Layer::Handle layer)
415 Gtk::TreeModel::Children::iterator iter;
416 if(layer_tree_store_->find_layer_row(layer,iter))
418 if(sorted_layer_tree_store_)
419 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
421 Gtk::TreePath path(iter);
422 for(int i=path.get_depth();i;i--)
425 path=Gtk::TreePath(iter);
428 get_layer_tree_view().expand_row(path,false);
430 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
431 get_layer_tree_view().get_selection()->select(iter);
436 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
438 get_layer_tree_view().get_selection()->select(iter);
439 if((bool)(*iter)[layer_model.children_lock])
441 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
442 Gtk::TreeModel::Children children(iter->children());
443 for(iter=children.begin();iter!=children.end();++iter)
444 select_all_children(iter);
448 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
450 Gtk::TreeModel::Children::iterator iter;
451 if(layer_tree_store_->find_layer_row(layer,iter))
452 select_all_children(iter);
456 LayerTree::select_layers(const LayerList &layer_list)
458 LayerList::const_iterator iter;
459 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
463 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
465 const LayerTreeStore::Model layer_tree_model;
466 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
470 LayerTree::get_selected_layers()const
472 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
479 selection->selected_foreach_iter(
491 synfig::Layer::Handle
492 LayerTree::get_selected_layer()const
494 LayerList layers(get_selected_layers());
499 return *layers.begin();
503 LayerTree::clear_selected_layers()
505 get_layer_tree_view().get_selection()->unselect_all();
509 LayerTree::set_show_timetrack(bool x)
511 //column_time_track->set_visible(x);
512 // column_time_track->set_visible(false);
513 column_z_depth->set_visible(x);
517 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
519 layer_tree_store_=layer_tree_store;
523 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
525 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
527 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
528 //sorted_store->set_sort_column(model.time.index(), Gtk::SORT_ASCENDING);
530 get_layer_tree_view().set_model(sorted_layer_tree_store_);
533 get_layer_tree_view().set_model(layer_tree_store_);
535 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
537 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
539 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
541 &get_param_tree_view(),
542 &Gtk::Widget::queue_draw
545 if(!param_tree_store_)
547 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
548 get_param_tree_view().set_model(param_tree_store_);
551 /* if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
553 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
559 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
561 //cellrenderer_time_track->set_adjustment(adjustment);
562 adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
563 adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
567 LayerTree::on_dirty_preview()
570 if(quick_layer && !disable_amount_changed_signal)
572 layer_amount_hscale->set_sensitive(true);
573 disable_amount_changed_signal=true;
574 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
575 disable_amount_changed_signal=false;
576 if(quick_layer->get_param("blend_method").is_valid())
578 blend_method_widget.set_sensitive(true);
579 disable_amount_changed_signal=true;
580 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
581 disable_amount_changed_signal=false;
588 LayerTree::on_selection_changed()
590 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
593 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
595 if(layer_list.empty())
597 last_top_selected_layer=0;
598 layer_tree_view_->get_selection()->select(last_top_selected_path);
604 if(!layer_list.empty())
606 last_top_selected_layer=layer_list.front();
607 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
611 last_top_selected_layer=0;
615 if(layer_list.empty())
617 button_raise->set_sensitive(false);
618 button_lower->set_sensitive(false);
619 button_duplicate->set_sensitive(false);
620 button_delete->set_sensitive(false);
621 layer_amount_hscale->set_sensitive(false);
622 blend_method_widget.set_sensitive(false);
626 button_raise->set_sensitive(true);
627 button_lower->set_sensitive(true);
628 button_duplicate->set_sensitive(true);
629 button_delete->set_sensitive(true);
631 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
633 quick_layer=*layer_list.begin();
640 layer_amount_hscale->set_sensitive(true);
641 disable_amount_changed_signal=true;
642 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
643 disable_amount_changed_signal=false;
644 if(quick_layer->get_param("blend_method").is_valid())
646 blend_method_widget.set_sensitive(true);
647 disable_amount_changed_signal=true;
648 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
649 disable_amount_changed_signal=false;
652 blend_method_widget.set_sensitive(false);
656 layer_amount_hscale->set_sensitive(false);
657 blend_method_widget.set_sensitive(false);
662 LayerTree::on_blend_method_changed()
664 if(disable_amount_changed_signal)
669 if(quick_layer->get_param("blend_method").is_valid())
671 disable_amount_changed_signal=true;
672 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
673 disable_amount_changed_signal=false;
678 LayerTree::on_amount_value_changed()
680 if(disable_amount_changed_signal)
685 disable_amount_changed_signal=true;
686 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
687 disable_amount_changed_signal=false;
691 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
693 Gtk::TreePath path(path_string);
695 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
698 row[param_model.value]=value;
699 //signal_edited_value()(row[param_model.value_desc],value);
703 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
705 Gtk::TreePath path(path_string);
707 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
710 row[layer_model.label]=value;
711 get_layer_tree_view().columns_autosize();
715 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
717 Gtk::TreePath path(path_string);
719 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
720 bool active=static_cast<bool>(row[layer_model.active]);
721 row[layer_model.active]=!active;
725 LayerTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
727 Gtk::TreePath path(path_string);
729 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
733 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[param_model.value_desc]),waypoint,button);
737 LayerTree::on_layer_tree_event(GdkEvent *event)
741 case GDK_BUTTON_PRESS:
743 Gtk::TreeModel::Path path;
744 Gtk::TreeViewColumn *column;
746 if(!get_layer_tree_view().get_path_at_pos(
747 int(event->button.x),int(event->button.y), // x, y
748 path, // TreeModel::Path&
749 column, //TreeViewColumn*&
750 cell_x,cell_y //int&cell_x,int&cell_y
753 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
755 //if(column->get_first_cell_renderer()==cellrenderer_time_track)
756 // return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
758 if(column->get_first_cell_renderer()==cellrenderer_value)
759 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
761 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
766 case GDK_MOTION_NOTIFY:
768 Gtk::TreeModel::Path path;
769 Gtk::TreeViewColumn *column;
771 if(!get_layer_tree_view().get_path_at_pos(
772 (int)event->button.x,(int)event->button.y, // x, y
773 path, // TreeModel::Path&
774 column, //TreeViewColumn*&
775 cell_x,cell_y //int&cell_x,int&cell_y
779 if(!get_layer_tree_view().get_model()->get_iter(path))
782 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
785 if(cellrenderer_time_track==column->get_first_cell_renderer())
787 // Movement on TimeLine
792 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
794 tooltips_.unset_tip(*this);
795 Glib::ustring tooltips_string(row[layer_model.tooltip]);
796 last_tooltip_path=path;
797 if(!tooltips_string.empty())
799 tooltips_.set_tip(*this,tooltips_string);
800 tooltips_.force_window();
805 case GDK_BUTTON_RELEASE:
814 LayerTree::on_param_tree_event(GdkEvent *event)
818 case GDK_BUTTON_PRESS:
820 Gtk::TreeModel::Path path;
821 Gtk::TreeViewColumn *column;
823 if(!get_param_tree_view().get_path_at_pos(
824 int(event->button.x),int(event->button.y), // x, y
825 path, // TreeModel::Path&
826 column, //TreeViewColumn*&
827 cell_x,cell_y //int&cell_x,int&cell_y
830 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
832 /* if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
835 get_param_tree_view().get_cell_area(path,*column,rect);
836 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
837 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
838 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
839 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
841 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
845 if(event->button.button==3)
847 LayerList layer_list(get_selected_layers());
848 if(layer_list.size()<=1)
850 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
851 Gtk::Menu* menu(manage(new Gtk::Menu()));
852 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
853 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);
854 menu->popup(event->button.button,gtk_get_current_event_time());
857 Gtk::Menu* menu(manage(new Gtk::Menu()));
858 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
859 std::list<synfigapp::ValueDesc> value_desc_list;
860 ParamDesc param_desc(row[param_model.param_desc]);
861 for(;!layer_list.empty();layer_list.pop_back())
862 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
863 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
864 menu->popup(event->button.button,gtk_get_current_event_time());
869 if(column->get_first_cell_renderer()==cellrenderer_value)
870 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
872 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
878 case GDK_MOTION_NOTIFY:
880 Gtk::TreeModel::Path path;
881 Gtk::TreeViewColumn *column;
883 if(!get_param_tree_view().get_path_at_pos(
884 (int)event->motion.x,(int)event->motion.y, // x, y
885 path, // TreeModel::Path&
886 column, //TreeViewColumn*&
887 cell_x,cell_y //int&cell_x,int&cell_y
891 if(!get_param_tree_view().get_model()->get_iter(path))
894 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
896 /* if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
899 get_param_tree_view().get_cell_area(path,*column,rect);
900 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
901 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
902 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
903 get_param_tree_view().queue_draw();
904 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
908 */ if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
910 tooltips_.unset_tip(*this);
911 Glib::ustring tooltips_string(row[layer_model.tooltip]);
912 last_tooltip_path=path;
913 if(!tooltips_string.empty())
915 tooltips_.set_tip(*this,tooltips_string);
916 tooltips_.force_window();
921 case GDK_BUTTON_RELEASE:
923 Gtk::TreeModel::Path path;
924 Gtk::TreeViewColumn *column;
926 if(!get_param_tree_view().get_path_at_pos(
927 (int)event->button.x,(int)event->button.y, // x, y
928 path, // TreeModel::Path&
929 column, //TreeViewColumn*&
930 cell_x,cell_y //int&cell_x,int&cell_y
934 if(!get_param_tree_view().get_model()->get_iter(path))
937 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
939 /* if(column && cellrenderer_time_track==column->get_first_cell_renderer())
942 get_param_tree_view().get_cell_area(path,*column,rect);
943 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
944 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
945 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
946 get_param_tree_view().queue_draw();
947 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
961 LayerTree::on_raise_pressed()
963 synfigapp::Action::ParamList param_list;
964 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
965 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
966 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
969 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
970 synfigapp::SelectionManager::LayerList::iterator iter;
972 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
973 param_list.add("layer",Layer::Handle(*iter));
975 synfigapp::Action::Handle action(synfigapp::Action::create("layer_raise"));
976 action->set_param_list(param_list);
977 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
981 LayerTree::on_lower_pressed()
983 synfigapp::Action::ParamList param_list;
984 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
985 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
986 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
989 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
990 synfigapp::SelectionManager::LayerList::iterator iter;
992 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
993 param_list.add("layer",Layer::Handle(*iter));
996 synfigapp::Action::Handle action(synfigapp::Action::create("layer_lower"));
997 action->set_param_list(param_list);
998 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1002 LayerTree::on_duplicate_pressed()
1004 synfigapp::Action::ParamList param_list;
1005 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1006 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1007 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1010 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1011 synfigapp::SelectionManager::LayerList::iterator iter;
1013 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1014 param_list.add("layer",Layer::Handle(*iter));
1017 synfigapp::Action::Handle action(synfigapp::Action::create("layer_duplicate"));
1018 action->set_param_list(param_list);
1019 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1023 LayerTree::on_delete_pressed()
1025 synfigapp::Action::ParamList param_list;
1026 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1027 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1028 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1031 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1032 synfigapp::SelectionManager::LayerList::iterator iter;
1034 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1035 param_list.add("layer",Layer::Handle(*iter));
1038 synfigapp::Action::Handle action(synfigapp::Action::create("layer_remove"));
1039 action->set_param_list(param_list);
1040 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1045 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1047 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1048 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1049 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1051 Gtk::TreeModel::Path path;
1052 Gtk::TreeViewColumn *column;
1055 Gtk::TreeRow row = *(get_selection()->get_selected());
1057 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1059 Layer* layer(((Layer::Handle)row[model.layer]).get());
1061 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1067 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1069 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1070 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1071 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1072 synfig::info("Dropped x=%d, y=%d",x,y);
1074 bool dropped_on_specific_row=false;
1076 Gtk::TreeModel::Path path;
1077 Gtk::TreeViewColumn *column;
1079 if(!get_path_at_pos(
1081 path, // TreeModel::Path&
1082 column, //TreeViewColumn*&
1083 cell_x,cell_y //int&cell_x,int&cell_y
1087 dropped_on_specific_row=false;
1090 dropped_on_specific_row=true;
1092 Gtk::TreeRow row = *(get_model()->get_iter(path));
1094 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1096 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1098 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1101 Canvas::Handle dest_canvas;
1102 Layer::Handle dest_layer;
1104 if(dropped_on_specific_row)
1106 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1107 dest_layer=(Layer::Handle)(row[model.layer]);
1108 assert(dest_canvas);
1111 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1113 // In this case, we are just moving.
1114 if(dest_canvas==src->get_canvas())
1116 if(!dest_layer || dest_layer==src)
1119 synfigapp::Action::Handle action(synfigapp::Action::create("layer_move"));
1120 action->set_param("canvas",dest_canvas);
1121 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1122 action->set_param("layer",src);
1123 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1124 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1134 context->drag_finish(success, false, time);
1139 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1141 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1145 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1147 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1150 if(context->gobj()->source_window==context->gobj()->dest_window)
1152 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1156 Gtk::TreeModel::Path path;
1157 Gtk::TreeViewColumn *column;
1159 if(!get_path_at_pos(
1161 path, // TreeModel::Path&
1162 column, //TreeViewColumn*&
1163 cell_x,cell_y //int&cell_x,int&cell_y
1167 context->drag_finish(false, false, time);
1170 if(layer_tree_store_->row_drop_possible(path,selection_data))
1172 if(layer_tree_store_->drag_data_received(path,selection_data))
1173 context->drag_finish(true, false, time);
1175 context->drag_finish(false, false, time);