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>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
56 #define SMALL_BUTTON(button,stockid,tooltip) \
57 button = manage(new class Gtk::Button()); \
58 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
60 tooltips_.set_tip(*button,tooltip); \
61 icon->set_padding(0,0);\
63 button->set_relief(Gtk::RELIEF_NONE); \
68 #define NORMAL_BUTTON(button,stockid,tooltip) \
69 button = manage(new class Gtk::Button()); \
70 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
72 tooltips_.set_tip(*button,tooltip); \
73 icon->set_padding(0,0);\
75 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
79 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
81 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
83 /* === G L O B A L S ======================================================= */
85 /* === P R O C E D U R E S ================================================= */
87 /* === M E T H O D S ======================================================= */
89 LayerTree::LayerTree():
90 layer_amount_adjustment_(1,0,1,0.01,0.01,0)
92 param_tree_view_=new Gtk::TreeView;
93 layer_tree_view_=new Gtk::TreeView;
95 //Gtk::HPaned* hpaned(manage(new Gtk::HPaned()));
97 //attach(*hpaned, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
98 //attach(*create_layer_tree(), 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
103 //hpaned->pack1(*create_layer_tree(),false,false);
104 //hpaned->pack2(*create_param_tree(),true,false);
105 //hpaned->set_position(200);
106 hbox=manage(new Gtk::HBox());
108 attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
109 attach(blend_method_widget, 2, 3, 1, 2,Gtk::SHRINK, Gtk::SHRINK, 0, 0);
111 layer_amount_hscale=manage(new Gtk::HScale(layer_amount_adjustment_));
112 layer_amount_hscale->set_digits(2);
113 layer_amount_hscale->set_value_pos(Gtk::POS_LEFT);
114 layer_amount_hscale->set_sensitive(false);
115 layer_amount_hscale->set_update_policy( Gtk::UPDATE_DISCONTINUOUS);
116 attach(*layer_amount_hscale, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 1, 1);
117 layer_amount_adjustment_.signal_value_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_amount_value_changed));
123 //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
124 Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
126 SMALL_BUTTON(button_raise,"gtk-go-up","Raise");
127 SMALL_BUTTON(button_lower,"gtk-go-down","Lower");
128 SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate");
129 SMALL_BUTTON(button_delete,"gtk-delete","Delete");
131 hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
132 hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
133 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
134 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
136 button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_raise_pressed));
137 button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_lower_pressed));
138 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_duplicate_pressed));
139 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_delete_pressed));
141 button_raise->set_sensitive(false);
142 button_lower->set_sensitive(false);
143 button_duplicate->set_sensitive(false);
144 button_delete->set_sensitive(false);
149 get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_selection_changed));
152 get_layer_tree_view().set_reorderable(true);
153 get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
154 //get_param_tree_view().get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
155 get_layer_tree_view().show();
156 get_param_tree_view().show();
160 layer_amount_hscale->show();
161 blend_method_widget.show();
164 disable_amount_changed_signal=false;
170 blend_method_widget.set_param_desc(ParamDesc(Color::BlendMethod(),"blend_method"));
172 blend_method_widget.set_value((int)Color::BLEND_COMPOSITE);
173 blend_method_widget.set_size_request(150,-1);
174 blend_method_widget.set_sensitive(false);
175 blend_method_widget.signal_activate().connect(sigc::mem_fun(*this, &studio::LayerTree::on_blend_method_changed));
179 LayerTree::~LayerTree()
181 synfig::info("LayerTree::~LayerTree(): Deleted");
185 LayerTree::create_layer_tree()
187 const LayerTreeStore::Model model;
190 { // --- O N / O F F ----------------------------------------------------
192 //index=get_layer_tree_view().append_column_editable(_(" "),layer_model.active);
193 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
195 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_(" ")) );
197 // Set up the icon cell-renderer
198 Gtk::CellRendererToggle* cellrenderer = Gtk::manage( new Gtk::CellRendererToggle() );
199 cellrenderer->signal_toggled().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_toggle));
201 column->pack_start(*cellrenderer,false);
202 column->add_attribute(cellrenderer->property_active(), layer_model.active);
203 get_layer_tree_view().append_column(*column);
206 { // --- I C O N --------------------------------------------------------
208 index=get_layer_tree_view().append_column(_("Z"),layer_model.icon);
209 Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
210 get_layer_tree_view().set_expander_column(*column);
213 column->set_sort_column_id(layer_model.z_depth);
214 //column->set_reorderable();
215 //column->set_resizable();
216 //column->set_clickable();
218 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
219 //column->pack_start(*icon_cellrenderer,false);
220 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
222 //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
223 { // --- N A M E --------------------------------------------------------
224 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Layer")) );
226 // Set up the icon cell-renderer
227 Gtk::CellRendererText* cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
228 cellrenderer->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_renamed));
229 cellrenderer->property_editable()=true;
231 column->pack_start(*cellrenderer,false);
232 column->add_attribute(cellrenderer->property_text(), layer_model.label);
233 get_layer_tree_view().append_column(*column);
236 // index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
237 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
239 //column->set_sort_column_id(layer_model.index);
241 //get_layer_tree_view().set_expander_column(*column);
242 //column->set_reorderable();
243 //column->set_resizable();
244 //column->set_clickable(false);
246 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
247 //column->pack_start(*icon_cellrenderer,false);
248 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
250 { // --- Z D E P T H ----------------------------------------------------
252 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
253 column_z_depth=get_layer_tree_view().get_column(index-1);
255 column_z_depth->set_reorderable();
256 column_z_depth->set_resizable();
257 column_z_depth->set_clickable();
259 column_z_depth->set_sort_column_id(layer_model.z_depth);
262 get_layer_tree_view().set_enable_search(true);
263 get_layer_tree_view().set_search_column(layer_model.label);
264 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
266 std::list<Gtk::TargetEntry> listTargets;
267 listTargets.push_back( Gtk::TargetEntry("LAYER") );
268 get_layer_tree_view().drag_dest_set(listTargets);
271 // This makes things easier to read.
272 get_layer_tree_view().set_rules_hint();
274 // Make us more sensitive to several events
275 //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);
277 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
278 get_layer_tree_view().show();
282 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
283 scroll->set_flags(Gtk::CAN_FOCUS);
284 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
285 //scroll->add(get_layer_tree_view());
286 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
293 LayerTree::create_param_tree()
295 Pango::AttrList attr_list;
297 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
298 pango_size.set_start_index(0);
299 pango_size.set_end_index(64);
300 attr_list.change(pango_size);
303 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
305 { // --- N A M E --------------------------------------------------------
306 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
308 // Set up the icon cell-renderer
309 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
310 column->pack_start(*icon_cellrenderer,false);
311 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
313 // Pack the label into the column
314 //column->pack_start(layer_model.label,true);
315 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
316 column->pack_start(*text_cellrenderer,false);
317 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
318 text_cellrenderer->property_attributes()=attr_list;
320 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
321 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
323 // Pack the label into the column
324 //column->pack_start(param_model.label,true);
326 // Set up the value-node icon cell-renderer to be on the far right
327 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
328 column->pack_end(*valuenode_icon_cellrenderer,false);
329 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
330 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
332 // Finish setting up the column
333 column->set_reorderable();
334 column->set_resizable();
335 column->set_clickable();
337 get_param_tree_view().append_column(*column);
339 { // --- V A L U E -----------------------------------------------------
340 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Value")) );
342 // Set up the value cell-renderer
343 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
344 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
345 cellrenderer_value->property_value()=synfig::ValueBase();
346 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
347 column->add_attribute(cellrenderer_value->property_inconsistant(),param_model.is_inconsistent);
348 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
349 cellrenderer_value->property_attributes()=attr_list;
351 // Finish setting up the column
352 get_param_tree_view().append_column(*column);
353 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
354 column->set_clickable();
355 column->set_min_width(120);
356 column->set_reorderable();
357 column->set_resizable();
359 /*{ // --- T I M E T R A C K --------------------------------------------
360 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
361 column_time_track=column;
363 // Set up the value-node cell-renderer
364 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
365 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
366 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked) );
367 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
368 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
369 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
370 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
372 //column->pack_start(*cellrenderer_time_track);
374 // Finish setting up the column
375 column->set_reorderable();
376 column->set_resizable();
377 column->set_min_width(200);
378 //get_param_tree_view().append_column(*column);
383 // This makes things easier to read.
384 get_param_tree_view().set_rules_hint();
386 // Make us more sensitive to several events
387 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);
389 get_param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
390 get_param_tree_view().show();
392 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
393 scroll->set_flags(Gtk::CAN_FOCUS);
394 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
395 //scroll->add(get_param_tree_view());
396 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
399 //column_time_track->set_visible(false);
405 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
407 synfigapp::Action::ParamList param_list;
408 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
409 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
410 param_list.add("value_node",value_node);
411 param_list.add("waypoint",waypoint);
412 // param_list.add("time",canvas_interface()->get_time());
414 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
418 LayerTree::select_layer(Layer::Handle layer)
420 Gtk::TreeModel::Children::iterator iter;
421 if(layer_tree_store_->find_layer_row(layer,iter))
423 if(sorted_layer_tree_store_)
424 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
426 Gtk::TreePath path(iter);
427 for(int i=path.get_depth();i;i--)
430 path=Gtk::TreePath(iter);
433 get_layer_tree_view().expand_row(path,false);
435 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
436 get_layer_tree_view().get_selection()->select(iter);
441 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
443 get_layer_tree_view().get_selection()->select(iter);
444 if((bool)(*iter)[layer_model.children_lock])
446 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
447 Gtk::TreeModel::Children children(iter->children());
448 for(iter=children.begin();iter!=children.end();++iter)
449 select_all_children(iter);
453 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
455 Gtk::TreeModel::Children::iterator iter;
456 if(layer_tree_store_->find_layer_row(layer,iter))
457 select_all_children(iter);
461 LayerTree::select_layers(const LayerList &layer_list)
463 LayerList::const_iterator iter;
464 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
468 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
470 const LayerTreeStore::Model layer_tree_model;
471 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
475 LayerTree::get_selected_layers()const
477 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
484 selection->selected_foreach_iter(
496 synfig::Layer::Handle
497 LayerTree::get_selected_layer()const
499 LayerList layers(get_selected_layers());
504 return *layers.begin();
508 LayerTree::clear_selected_layers()
510 get_layer_tree_view().get_selection()->unselect_all();
526 LayerTree::set_show_timetrack(bool x)
528 //column_time_track->set_visible(x);
529 // column_time_track->set_visible(false);
530 column_z_depth->set_visible(x);
534 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
536 layer_tree_store_=layer_tree_store;
541 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
543 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
545 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
546 //sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
548 get_layer_tree_view().set_model(sorted_layer_tree_store_);
551 get_layer_tree_view().set_model(layer_tree_store_);
553 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
555 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
557 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
559 &get_param_tree_view(),
560 &Gtk::Widget::queue_draw
563 if(!param_tree_store_)
565 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
566 get_param_tree_view().set_model(param_tree_store_);
569 /* if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
571 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
577 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
579 //cellrenderer_time_track->set_adjustment(adjustment);
580 adjustment.signal_value_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
581 adjustment.signal_changed().connect(sigc::mem_fun(get_param_tree_view(),&Gtk::TreeView::queue_draw));
585 LayerTree::on_dirty_preview()
588 if(quick_layer && !disable_amount_changed_signal)
590 layer_amount_hscale->set_sensitive(true);
591 disable_amount_changed_signal=true;
592 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
593 disable_amount_changed_signal=false;
594 if(quick_layer->get_param("blend_method").is_valid())
596 blend_method_widget.set_sensitive(true);
597 disable_amount_changed_signal=true;
598 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
599 disable_amount_changed_signal=false;
606 LayerTree::on_selection_changed()
608 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
611 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
613 if(layer_list.empty())
615 last_top_selected_layer=0;
616 layer_tree_view_->get_selection()->select(last_top_selected_path);
623 if(!layer_list.empty())
625 last_top_selected_layer=layer_list.front();
626 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
630 last_top_selected_layer=0;
635 if(layer_list.empty())
637 button_raise->set_sensitive(false);
638 button_lower->set_sensitive(false);
639 button_duplicate->set_sensitive(false);
640 button_delete->set_sensitive(false);
641 layer_amount_hscale->set_sensitive(false);
642 blend_method_widget.set_sensitive(false);
646 button_raise->set_sensitive(true);
647 button_lower->set_sensitive(true);
648 button_duplicate->set_sensitive(true);
649 button_delete->set_sensitive(true);
651 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_type_as(Real()))
653 quick_layer=*layer_list.begin();
660 layer_amount_hscale->set_sensitive(true);
661 disable_amount_changed_signal=true;
662 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
663 disable_amount_changed_signal=false;
664 if(quick_layer->get_param("blend_method").is_valid())
666 blend_method_widget.set_sensitive(true);
667 disable_amount_changed_signal=true;
668 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
669 disable_amount_changed_signal=false;
672 blend_method_widget.set_sensitive(false);
676 layer_amount_hscale->set_sensitive(false);
677 blend_method_widget.set_sensitive(false);
683 LayerTree::on_blend_method_changed()
685 if(disable_amount_changed_signal)
690 if(quick_layer->get_param("blend_method").is_valid())
692 disable_amount_changed_signal=true;
693 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
694 disable_amount_changed_signal=false;
699 LayerTree::on_amount_value_changed()
701 if(disable_amount_changed_signal)
706 disable_amount_changed_signal=true;
707 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
708 disable_amount_changed_signal=false;
713 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
715 Gtk::TreePath path(path_string);
717 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
720 row[param_model.value]=value;
721 //signal_edited_value()(row[param_model.value_desc],value);
725 LayerTree::on_layer_renamed(const Glib::ustring&path_string,const Glib::ustring& value)
727 Gtk::TreePath path(path_string);
729 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
732 row[layer_model.label]=value;
736 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
738 Gtk::TreePath path(path_string);
740 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
741 bool active=static_cast<bool>(row[layer_model.active]);
742 row[layer_model.active]=!active;
746 LayerTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
748 Gtk::TreePath path(path_string);
750 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
754 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[param_model.value_desc]),waypoint,button);
758 LayerTree::on_layer_tree_event(GdkEvent *event)
762 case GDK_BUTTON_PRESS:
764 Gtk::TreeModel::Path path;
765 Gtk::TreeViewColumn *column;
767 if(!get_layer_tree_view().get_path_at_pos(
768 int(event->button.x),int(event->button.y), // x, y
769 path, // TreeModel::Path&
770 column, //TreeViewColumn*&
771 cell_x,cell_y //int&cell_x,int&cell_y
774 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
776 //if(column->get_first_cell_renderer()==cellrenderer_time_track)
777 // return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
779 if(column->get_first_cell_renderer()==cellrenderer_value)
780 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
782 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
787 case GDK_MOTION_NOTIFY:
789 Gtk::TreeModel::Path path;
790 Gtk::TreeViewColumn *column;
792 if(!get_layer_tree_view().get_path_at_pos(
793 (int)event->button.x,(int)event->button.y, // x, y
794 path, // TreeModel::Path&
795 column, //TreeViewColumn*&
796 cell_x,cell_y //int&cell_x,int&cell_y
800 if(!get_layer_tree_view().get_model()->get_iter(path))
803 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
806 if(cellrenderer_time_track==column->get_first_cell_renderer())
808 // Movement on TimeLine
813 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
815 tooltips_.unset_tip(*this);
816 Glib::ustring tooltips_string(row[layer_model.tooltip]);
817 last_tooltip_path=path;
818 if(!tooltips_string.empty())
820 tooltips_.set_tip(*this,tooltips_string);
821 tooltips_.force_window();
826 case GDK_BUTTON_RELEASE:
836 LayerTree::on_param_tree_event(GdkEvent *event)
840 case GDK_BUTTON_PRESS:
842 Gtk::TreeModel::Path path;
843 Gtk::TreeViewColumn *column;
845 if(!get_param_tree_view().get_path_at_pos(
846 int(event->button.x),int(event->button.y), // x, y
847 path, // TreeModel::Path&
848 column, //TreeViewColumn*&
849 cell_x,cell_y //int&cell_x,int&cell_y
852 const Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
854 /* if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
857 get_param_tree_view().get_cell_area(path,*column,rect);
858 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
859 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
860 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
861 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
863 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
867 if(event->button.button==3)
869 LayerList layer_list(get_selected_layers());
870 if(layer_list.size()<=1)
872 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
873 Gtk::Menu* menu(manage(new Gtk::Menu()));
874 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);
875 menu->popup(event->button.button,gtk_get_current_event_time());
878 Gtk::Menu* menu(manage(new Gtk::Menu()));
879 std::list<synfigapp::ValueDesc> value_desc_list;
880 ParamDesc param_desc(row[param_model.param_desc]);
881 for(;!layer_list.empty();layer_list.pop_back())
882 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
883 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
884 menu->popup(event->button.button,gtk_get_current_event_time());
889 if(column->get_first_cell_renderer()==cellrenderer_value)
890 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
892 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
898 case GDK_MOTION_NOTIFY:
900 Gtk::TreeModel::Path path;
901 Gtk::TreeViewColumn *column;
903 if(!get_param_tree_view().get_path_at_pos(
904 (int)event->motion.x,(int)event->motion.y, // x, y
905 path, // TreeModel::Path&
906 column, //TreeViewColumn*&
907 cell_x,cell_y //int&cell_x,int&cell_y
911 if(!get_param_tree_view().get_model()->get_iter(path))
914 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
916 /* if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
919 get_param_tree_view().get_cell_area(path,*column,rect);
920 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
921 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
922 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
923 get_param_tree_view().queue_draw();
924 //get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
928 */ if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
930 tooltips_.unset_tip(*this);
931 Glib::ustring tooltips_string(row[layer_model.tooltip]);
932 last_tooltip_path=path;
933 if(!tooltips_string.empty())
935 tooltips_.set_tip(*this,tooltips_string);
936 tooltips_.force_window();
941 case GDK_BUTTON_RELEASE:
943 Gtk::TreeModel::Path path;
944 Gtk::TreeViewColumn *column;
946 if(!get_param_tree_view().get_path_at_pos(
947 (int)event->button.x,(int)event->button.y, // x, y
948 path, // TreeModel::Path&
949 column, //TreeViewColumn*&
950 cell_x,cell_y //int&cell_x,int&cell_y
954 if(!get_param_tree_view().get_model()->get_iter(path))
957 Gtk::TreeRow row = *(get_param_tree_view().get_model()->get_iter(path));
959 /* if(column && cellrenderer_time_track==column->get_first_cell_renderer())
962 get_param_tree_view().get_cell_area(path,*column,rect);
963 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
964 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
965 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
966 get_param_tree_view().queue_draw();
967 get_param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
981 LayerTree::on_raise_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));
995 synfigapp::Action::Handle action(synfigapp::Action::create("layer_raise"));
996 action->set_param_list(param_list);
997 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1001 LayerTree::on_lower_pressed()
1003 synfigapp::Action::ParamList param_list;
1004 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1005 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1006 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1009 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1010 synfigapp::SelectionManager::LayerList::iterator iter;
1012 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1013 param_list.add("layer",Layer::Handle(*iter));
1016 synfigapp::Action::Handle action(synfigapp::Action::create("layer_lower"));
1017 action->set_param_list(param_list);
1018 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1022 LayerTree::on_duplicate_pressed()
1024 synfigapp::Action::ParamList param_list;
1025 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1026 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1027 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1030 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1031 synfigapp::SelectionManager::LayerList::iterator iter;
1033 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1034 param_list.add("layer",Layer::Handle(*iter));
1037 synfigapp::Action::Handle action(synfigapp::Action::create("layer_duplicate"));
1038 action->set_param_list(param_list);
1039 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1043 LayerTree::on_delete_pressed()
1045 synfigapp::Action::ParamList param_list;
1046 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1047 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1048 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1051 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1052 synfigapp::SelectionManager::LayerList::iterator iter;
1054 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1055 param_list.add("layer",Layer::Handle(*iter));
1058 synfigapp::Action::Handle action(synfigapp::Action::create("layer_remove"));
1059 action->set_param_list(param_list);
1060 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1084 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1086 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1087 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1088 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1092 Gtk::TreeModel::Path path;
1093 Gtk::TreeViewColumn *column;
1096 Gtk::TreeRow row = *(get_selection()->get_selected());
1099 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1102 Layer* layer(((Layer::Handle)row[model.layer]).get());
1104 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1111 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1113 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1114 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1115 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1116 synfig::info("Dropped x=%d, y=%d",x,y);
1118 bool dropped_on_specific_row=false;
1120 Gtk::TreeModel::Path path;
1121 Gtk::TreeViewColumn *column;
1123 if(!get_path_at_pos(
1125 path, // TreeModel::Path&
1126 column, //TreeViewColumn*&
1127 cell_x,cell_y //int&cell_x,int&cell_y
1131 dropped_on_specific_row=false;
1134 dropped_on_specific_row=true;
1136 Gtk::TreeRow row = *(get_model()->get_iter(path));
1139 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1141 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1143 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1146 Canvas::Handle dest_canvas;
1147 Layer::Handle dest_layer;
1149 if(dropped_on_specific_row)
1151 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1152 dest_layer=(Layer::Handle)(row[model.layer]);
1153 assert(dest_canvas);
1156 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1158 // In this case, we are just moving.
1159 if(dest_canvas==src->get_canvas())
1161 if(!dest_layer || dest_layer==src)
1164 synfigapp::Action::Handle action(synfigapp::Action::create("layer_move"));
1165 action->set_param("canvas",dest_canvas);
1166 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1167 action->set_param("layer",src);
1168 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1169 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1179 context->drag_finish(success, false, time);
1184 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1186 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1190 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1192 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1195 if(context->gobj()->source_window==context->gobj()->dest_window)
1197 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1201 Gtk::TreeModel::Path path;
1202 Gtk::TreeViewColumn *column;
1204 if(!get_path_at_pos(
1206 path, // TreeModel::Path&
1207 column, //TreeViewColumn*&
1208 cell_x,cell_y //int&cell_x,int&cell_y
1212 context->drag_finish(false, false, time);
1215 if(layer_tree_store_->row_drop_possible(path,selection_data))
1217 if(layer_tree_store_->drag_data_received(path,selection_data))
1218 context->drag_finish(true, false, time);
1220 context->drag_finish(false, false, time);