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 synfig::info("LayerTree::~LayerTree(): Deleted");
174 LayerTree::create_layer_tree()
176 const LayerTreeStore::Model model;
178 { // --- O N / O F F ----------------------------------------------------
180 //index=get_layer_tree_view().append_column_editable(_(" "),layer_model.active);
181 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
183 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
185 // Set up the icon cell-renderer
186 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
187 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
189 column->pack_start(*cellrenderer,false);
190 column->add_attribute(cellrenderer->property_active(), layer_model.active);
191 get_layer_tree_view().append_column(*column);
194 { // --- I C O N --------------------------------------------------------
196 index=get_layer_tree_view().append_column(_("Z"),layer_model.icon);
197 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
198 get_layer_tree_view().set_expander_column(*column);
200 column->set_sort_column_id(layer_model.z_depth);
201 //column->set_reorderable();
202 //column->set_resizable();
203 //column->set_clickable();
205 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
206 //column->pack_start(*icon_cellrenderer,false);
207 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
209 //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
210 { // --- N A M E --------------------------------------------------------
211 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Layer")) );
213 // Set up the icon cell-renderer
214 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
215 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
216 cellrenderer->property_editable()=true;
218 column->pack_start(*cellrenderer,false);
219 column->add_attribute(cellrenderer->property_text(), layer_model.label);
220 get_layer_tree_view().append_column(*column);
223 // index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
224 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
226 //column->set_sort_column_id(layer_model.index);
228 //get_layer_tree_view().set_expander_column(*column);
229 //column->set_reorderable();
230 //column->set_resizable();
231 //column->set_clickable(false);
233 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
234 //column->pack_start(*icon_cellrenderer,false);
235 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
237 { // --- Z D E P T H ----------------------------------------------------
239 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
240 column_z_depth=get_layer_tree_view().get_column(index-1);
242 column_z_depth->set_reorderable();
243 column_z_depth->set_resizable();
244 column_z_depth->set_clickable();
246 column_z_depth->set_sort_column_id(layer_model.z_depth);
249 get_layer_tree_view().set_enable_search(true);
250 get_layer_tree_view().set_search_column(layer_model.label);
251 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
253 std::list<Gtk::TargetEntry> listTargets;
254 listTargets.push_back( Gtk::TargetEntry("LAYER") );
255 get_layer_tree_view().drag_dest_set(listTargets);
257 // This makes things easier to read.
258 get_layer_tree_view().set_rules_hint();
260 // Make us more sensitive to several events
261 //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);
263 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
264 get_layer_tree_view().show();
266 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
267 scroll->set_flags(Gtk::CAN_FOCUS);
268 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
269 //scroll->add(get_layer_tree_view());
270 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
277 LayerTree::create_param_tree()
279 Pango::AttrList attr_list;
281 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
282 pango_size.set_start_index(0);
283 pango_size.set_end_index(64);
284 attr_list.change(pango_size);
287 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
289 { // --- N A M E --------------------------------------------------------
290 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
292 // Set up the icon cell-renderer
293 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
294 column->pack_start(*icon_cellrenderer,false);
295 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
297 // Pack the label into the column
298 //column->pack_start(layer_model.label,true);
299 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
300 column->pack_start(*text_cellrenderer,false);
301 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
302 text_cellrenderer->property_attributes()=attr_list;
304 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
305 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
307 // Pack the label into the column
308 //column->pack_start(param_model.label,true);
310 // Set up the value-node icon cell-renderer to be on the far right
311 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
312 column->pack_end(*valuenode_icon_cellrenderer,false);
313 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
314 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
316 // Finish setting up the column
317 column->set_reorderable();
318 column->set_resizable();
319 column->set_clickable();
321 get_param_tree_view().append_column(*column);
323 { // --- V A L U E -----------------------------------------------------
324 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
326 // Set up the value cell-renderer
327 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
328 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
329 cellrenderer_value->property_value()=synfig::ValueBase();
330 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
331 column->add_attribute(cellrenderer_value->property_inconsistent(),param_model.is_inconsistent);
332 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
333 cellrenderer_value->property_attributes()=attr_list;
335 // Finish setting up the column
336 get_param_tree_view().append_column(*column);
337 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
338 column->set_clickable();
339 column->set_min_width(120);
340 column->set_reorderable();
341 column->set_resizable();
343 { // --- T Y P E --------------------------------------------------------
344 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Type")) );
345 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
346 column->pack_start(*text_cellrenderer,false);
347 column->add_attribute(text_cellrenderer->property_text(), param_model.type);
348 text_cellrenderer->property_attributes()=attr_list;
349 get_param_tree_view().append_column(*column);
350 column->set_reorderable();
351 column->set_resizable();
352 column->set_clickable();
353 column->set_sort_column_id(param_model.type);
355 /*{ // --- T I M E T R A C K --------------------------------------------
356 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
357 column_time_track=column;
359 // Set up the value-node cell-renderer
360 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
361 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
362 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked) );
363 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
364 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
365 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
366 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
368 //column->pack_start(*cellrenderer_time_track);
370 // Finish setting up the column
371 column->set_reorderable();
372 column->set_resizable();
373 column->set_min_width(200);
374 //get_param_tree_view().append_column(*column);
377 // This makes things easier to read.
378 get_param_tree_view().set_rules_hint();
380 // Make us more sensitive to several events
381 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);
383 get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
384 get_param_tree_view().show();
386 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
387 scroll->set_flags(Gtk::CAN_FOCUS);
388 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
389 //scroll->add(get_param_tree_view());
390 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
393 //column_time_track->set_visible(false);
399 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
401 synfigapp::Action::ParamList param_list;
402 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
403 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
404 param_list.add("value_node",value_node);
405 param_list.add("waypoint",waypoint);
406 // param_list.add("time",canvas_interface()->get_time());
408 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
412 LayerTree::select_layer(synfig::Layer::Handle layer)
414 Gtk::TreeModel::Children::iterator iter;
415 if(layer_tree_store_->find_layer_row(layer,iter))
417 if(sorted_layer_tree_store_)
418 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
420 Gtk::TreePath path(iter);
421 for(int i=path.get_depth();i;i--)
424 path=Gtk::TreePath(iter);
427 get_layer_tree_view().expand_row(path,false);
429 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
430 get_layer_tree_view().get_selection()->select(iter);
435 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
437 get_layer_tree_view().get_selection()->select(iter);
438 if((bool)(*iter)[layer_model.children_lock])
440 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
441 Gtk::TreeModel::Children children(iter->children());
442 for(iter=children.begin();iter!=children.end();++iter)
443 select_all_children(iter);
447 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
449 Gtk::TreeModel::Children::iterator iter;
450 if(layer_tree_store_->find_layer_row(layer,iter))
451 select_all_children(iter);
455 LayerTree::select_layers(const LayerList &layer_list)
457 LayerList::const_iterator iter;
458 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
462 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
464 const LayerTreeStore::Model layer_tree_model;
465 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
469 LayerTree::get_selected_layers()const
471 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
478 selection->selected_foreach_iter(
490 synfig::Layer::Handle
491 LayerTree::get_selected_layer()const
493 LayerList layers(get_selected_layers());
498 return *layers.begin();
502 LayerTree::clear_selected_layers()
504 get_layer_tree_view().get_selection()->unselect_all();
508 LayerTree::set_show_timetrack(bool x)
510 //column_time_track->set_visible(x);
511 // column_time_track->set_visible(false);
512 column_z_depth->set_visible(x);
516 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
518 layer_tree_store_=layer_tree_store;
522 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
524 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
526 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
527 //sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
529 get_layer_tree_view().set_model(sorted_layer_tree_store_);
532 get_layer_tree_view().set_model(layer_tree_store_);
534 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
536 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
538 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
540 &get_param_tree_view(),
541 &Gtk::Widget::queue_draw
544 if(!param_tree_store_)
546 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
547 get_param_tree_view().set_model(param_tree_store_);
550 /* if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
552 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
558 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
560 //cellrenderer_time_track->set_adjustment(adjustment);
561 adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
562 adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
566 LayerTree::on_dirty_preview()
569 if(quick_layer && !disable_amount_changed_signal)
571 layer_amount_hscale->set_sensitive(true);
572 disable_amount_changed_signal=true;
573 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
574 disable_amount_changed_signal=false;
575 if(quick_layer->get_param("blend_method").is_valid())
577 blend_method_widget.set_sensitive(true);
578 disable_amount_changed_signal=true;
579 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
580 disable_amount_changed_signal=false;
587 LayerTree::on_selection_changed()
589 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
592 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
594 if(layer_list.empty())
596 last_top_selected_layer=0;
597 layer_tree_view_->get_selection()->select(last_top_selected_path);
603 if(!layer_list.empty())
605 last_top_selected_layer=layer_list.front();
606 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
610 last_top_selected_layer=0;
614 if(layer_list.empty())
616 button_raise->set_sensitive(false);
617 button_lower->set_sensitive(false);
618 button_duplicate->set_sensitive(false);
619 button_delete->set_sensitive(false);
620 layer_amount_hscale->set_sensitive(false);
621 blend_method_widget.set_sensitive(false);
625 button_raise->set_sensitive(true);
626 button_lower->set_sensitive(true);
627 button_duplicate->set_sensitive(true);
628 button_delete->set_sensitive(true);
630 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
632 quick_layer=*layer_list.begin();
639 layer_amount_hscale->set_sensitive(true);
640 disable_amount_changed_signal=true;
641 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
642 disable_amount_changed_signal=false;
643 if(quick_layer->get_param("blend_method").is_valid())
645 blend_method_widget.set_sensitive(true);
646 disable_amount_changed_signal=true;
647 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
648 disable_amount_changed_signal=false;
651 blend_method_widget.set_sensitive(false);
655 layer_amount_hscale->set_sensitive(false);
656 blend_method_widget.set_sensitive(false);
661 LayerTree::on_blend_method_changed()
663 if(disable_amount_changed_signal)
668 if(quick_layer->get_param("blend_method").is_valid())
670 disable_amount_changed_signal=true;
671 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
672 disable_amount_changed_signal=false;
677 LayerTree::on_amount_value_changed()
679 if(disable_amount_changed_signal)
684 disable_amount_changed_signal=true;
685 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
686 disable_amount_changed_signal=false;
690 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
692 Gtk::TreePath path(path_string);
694 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
697 row[param_model.value]=value;
698 //signal_edited_value()(row[param_model.value_desc],value);
702 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
704 Gtk::TreePath path(path_string);
706 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
709 row[layer_model.label]=value;
713 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
715 Gtk::TreePath path(path_string);
717 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
718 bool active=static_cast<bool>(row[layer_model.active]);
719 row[layer_model.active]=!active;
723 LayerTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
725 Gtk::TreePath path(path_string);
727 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
731 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[param_model.value_desc]),waypoint,button);
735 LayerTree::on_layer_tree_event(GdkEvent *event)
739 case GDK_BUTTON_PRESS:
741 Gtk::TreeModel::Path path;
742 Gtk::TreeViewColumn *column;
744 if(!get_layer_tree_view().get_path_at_pos(
745 int(event->button.x),int(event->button.y), // x, y
746 path, // TreeModel::Path&
747 column, //TreeViewColumn*&
748 cell_x,cell_y //int&cell_x,int&cell_y
751 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
753 //if(column->get_first_cell_renderer()==cellrenderer_time_track)
754 // return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
756 if(column->get_first_cell_renderer()==cellrenderer_value)
757 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
759 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
764 case GDK_MOTION_NOTIFY:
766 Gtk::TreeModel::Path path;
767 Gtk::TreeViewColumn *column;
769 if(!get_layer_tree_view().get_path_at_pos(
770 (int)event->button.x,(int)event->button.y, // x, y
771 path, // TreeModel::Path&
772 column, //TreeViewColumn*&
773 cell_x,cell_y //int&cell_x,int&cell_y
777 if(!get_layer_tree_view().get_model()->get_iter(path))
780 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
783 if(cellrenderer_time_track==column->get_first_cell_renderer())
785 // Movement on TimeLine
790 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
792 tooltips_.unset_tip(*this);
793 Glib::ustring tooltips_string(row[layer_model.tooltip]);
794 last_tooltip_path=path;
795 if(!tooltips_string.empty())
797 tooltips_.set_tip(*this,tooltips_string);
798 tooltips_.force_window();
803 case GDK_BUTTON_RELEASE:
812 LayerTree::on_param_tree_event(GdkEvent *event)
816 case GDK_BUTTON_PRESS:
818 Gtk::TreeModel::Path path;
819 Gtk::TreeViewColumn *column;
821 if(!get_param_tree_view().get_path_at_pos(
822 int(event->button.x),int(event->button.y), // x, y
823 path, // TreeModel::Path&
824 column, //TreeViewColumn*&
825 cell_x,cell_y //int&cell_x,int&cell_y
828 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
830 /* if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
833 get_param_tree_view().get_cell_area(path,*column,rect);
834 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
835 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
836 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
837 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
839 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
843 if(event->button.button==3)
845 LayerList layer_list(get_selected_layers());
846 if(layer_list.size()<=1)
848 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
849 Gtk::Menu* menu(manage(new Gtk::Menu()));
850 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
851 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);
852 menu->popup(event->button.button,gtk_get_current_event_time());
855 Gtk::Menu* menu(manage(new Gtk::Menu()));
856 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
857 std::list<synfigapp::ValueDesc> value_desc_list;
858 ParamDesc param_desc(row[param_model.param_desc]);
859 for(;!layer_list.empty();layer_list.pop_back())
860 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
861 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
862 menu->popup(event->button.button,gtk_get_current_event_time());
867 if(column->get_first_cell_renderer()==cellrenderer_value)
868 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
870 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
876 case GDK_MOTION_NOTIFY:
878 Gtk::TreeModel::Path path;
879 Gtk::TreeViewColumn *column;
881 if(!get_param_tree_view().get_path_at_pos(
882 (int)event->motion.x,(int)event->motion.y, // x, y
883 path, // TreeModel::Path&
884 column, //TreeViewColumn*&
885 cell_x,cell_y //int&cell_x,int&cell_y
889 if(!get_param_tree_view().get_model()->get_iter(path))
892 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
894 /* if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
897 get_param_tree_view().get_cell_area(path,*column,rect);
898 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
899 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
900 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
901 get_param_tree_view().queue_draw();
902 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
906 */ if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
908 tooltips_.unset_tip(*this);
909 Glib::ustring tooltips_string(row[layer_model.tooltip]);
910 last_tooltip_path=path;
911 if(!tooltips_string.empty())
913 tooltips_.set_tip(*this,tooltips_string);
914 tooltips_.force_window();
919 case GDK_BUTTON_RELEASE:
921 Gtk::TreeModel::Path path;
922 Gtk::TreeViewColumn *column;
924 if(!get_param_tree_view().get_path_at_pos(
925 (int)event->button.x,(int)event->button.y, // x, y
926 path, // TreeModel::Path&
927 column, //TreeViewColumn*&
928 cell_x,cell_y //int&cell_x,int&cell_y
932 if(!get_param_tree_view().get_model()->get_iter(path))
935 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
937 /* if(column && cellrenderer_time_track==column->get_first_cell_renderer())
940 get_param_tree_view().get_cell_area(path,*column,rect);
941 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
942 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
943 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
944 get_param_tree_view().queue_draw();
945 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
959 LayerTree::on_raise_pressed()
961 synfigapp::Action::ParamList param_list;
962 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
963 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
964 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
967 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
968 synfigapp::SelectionManager::LayerList::iterator iter;
970 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
971 param_list.add("layer",Layer::Handle(*iter));
973 synfigapp::Action::Handle action(synfigapp::Action::create("layer_raise"));
974 action->set_param_list(param_list);
975 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
979 LayerTree::on_lower_pressed()
981 synfigapp::Action::ParamList param_list;
982 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
983 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
984 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
987 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
988 synfigapp::SelectionManager::LayerList::iterator iter;
990 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
991 param_list.add("layer",Layer::Handle(*iter));
994 synfigapp::Action::Handle action(synfigapp::Action::create("layer_lower"));
995 action->set_param_list(param_list);
996 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1000 LayerTree::on_duplicate_pressed()
1002 synfigapp::Action::ParamList param_list;
1003 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1004 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1005 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1008 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1009 synfigapp::SelectionManager::LayerList::iterator iter;
1011 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1012 param_list.add("layer",Layer::Handle(*iter));
1015 synfigapp::Action::Handle action(synfigapp::Action::create("layer_duplicate"));
1016 action->set_param_list(param_list);
1017 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1021 LayerTree::on_delete_pressed()
1023 synfigapp::Action::ParamList param_list;
1024 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1025 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1026 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1029 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1030 synfigapp::SelectionManager::LayerList::iterator iter;
1032 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1033 param_list.add("layer",Layer::Handle(*iter));
1036 synfigapp::Action::Handle action(synfigapp::Action::create("layer_remove"));
1037 action->set_param_list(param_list);
1038 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1043 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1045 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1046 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1047 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1049 Gtk::TreeModel::Path path;
1050 Gtk::TreeViewColumn *column;
1053 Gtk::TreeRow row = *(get_selection()->get_selected());
1055 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1057 Layer* layer(((Layer::Handle)row[model.layer]).get());
1059 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1065 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1067 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1068 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1069 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1070 synfig::info("Dropped x=%d, y=%d",x,y);
1072 bool dropped_on_specific_row=false;
1074 Gtk::TreeModel::Path path;
1075 Gtk::TreeViewColumn *column;
1077 if(!get_path_at_pos(
1079 path, // TreeModel::Path&
1080 column, //TreeViewColumn*&
1081 cell_x,cell_y //int&cell_x,int&cell_y
1085 dropped_on_specific_row=false;
1088 dropped_on_specific_row=true;
1090 Gtk::TreeRow row = *(get_model()->get_iter(path));
1092 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1094 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1096 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1099 Canvas::Handle dest_canvas;
1100 Layer::Handle dest_layer;
1102 if(dropped_on_specific_row)
1104 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1105 dest_layer=(Layer::Handle)(row[model.layer]);
1106 assert(dest_canvas);
1109 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1111 // In this case, we are just moving.
1112 if(dest_canvas==src->get_canvas())
1114 if(!dest_layer || dest_layer==src)
1117 synfigapp::Action::Handle action(synfigapp::Action::create("layer_move"));
1118 action->set_param("canvas",dest_canvas);
1119 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1120 action->set_param("layer",src);
1121 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1122 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1132 context->drag_finish(success, false, time);
1137 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1139 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1143 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1145 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1148 if(context->gobj()->source_window==context->gobj()->dest_window)
1150 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1154 Gtk::TreeModel::Path path;
1155 Gtk::TreeViewColumn *column;
1157 if(!get_path_at_pos(
1159 path, // TreeModel::Path&
1160 column, //TreeViewColumn*&
1161 cell_x,cell_y //int&cell_x,int&cell_y
1165 context->drag_finish(false, false, time);
1168 if(layer_tree_store_->row_drop_possible(path,selection_data))
1170 if(layer_tree_store_->drag_data_received(path,selection_data))
1171 context->drag_finish(true, false, time);
1173 context->drag_finish(false, false, time);