1 /* === S Y N F I G ========================================================= */
2 /*! \file layertree.cpp
3 ** \brief Template File
5 ** $Id: layertree.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 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 { // --- 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);
202 column->set_sort_column_id(layer_model.z_depth);
203 //column->set_reorderable();
204 //column->set_resizable();
205 //column->set_clickable();
207 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
208 //column->pack_start(*icon_cellrenderer,false);
209 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
211 //get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
212 { // --- N A M E --------------------------------------------------------
214 index=get_layer_tree_view().append_column_editable(_("Layer"),layer_model.label);
215 //Gtk::TreeView::Column* column = get_layer_tree_view().get_column(index-1);
217 //column->set_sort_column_id(layer_model.index);
219 //get_layer_tree_view().set_expander_column(*column);
220 //column->set_reorderable();
221 //column->set_resizable();
222 //column->set_clickable(false);
224 //Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
225 //column->pack_start(*icon_cellrenderer,false);
226 //column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
228 { // --- Z D E P T H ----------------------------------------------------
230 index=get_layer_tree_view().append_column(_("Z"),layer_model.z_depth);
231 column_z_depth=get_layer_tree_view().get_column(index-1);
233 column_z_depth->set_reorderable();
234 column_z_depth->set_resizable();
235 column_z_depth->set_clickable();
237 column_z_depth->set_sort_column_id(layer_model.z_depth);
240 { // --- N A M E --------------------------------------------------------
241 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Layer")) );
243 // Set up the icon cell-renderer
244 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
245 column->pack_start(*icon_cellrenderer,false);
246 column->add_attribute(icon_cellrenderer->property_pixbuf(), layer_model.icon);
248 // Set up the text attributes
249 Pango::AttrList attr_list;
251 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
252 pango_size.set_start_index(0);
253 pango_size.set_end_index(64);
254 attr_list.change(pango_size);
257 // Pack the label into the column
258 //column->pack_start(layer_model.label,true);
259 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
260 column->pack_start(*text_cellrenderer,false);
261 column->add_attribute(text_cellrenderer->property_text(), layer_model.label);
262 text_cellrenderer->property_attributes()=attr_list;
264 // Finish setting up the column
265 column->set_reorderable();
266 column->set_resizable();
267 column->set_clickable();
268 get_layer_tree_view().append_column(*column);
269 get_layer_tree_view().set_expander_column(*column);
274 Gtk::Widget& widget(get_layer_tree_view());
275 Pango::FontDescription font(widget.get_modifier_style()->get_font());
276 font.set_size(font.get_size()*3/4);
277 widget.get_modifier_style()->set_font(font);
278 widget.modify_style(widget.get_modifier_style());
281 get_layer_tree_view().set_enable_search(true);
282 get_layer_tree_view().set_search_column(layer_model.label);
283 get_layer_tree_view().set_search_equal_func(sigc::ptr_fun(&studio::LayerTreeStore::search_func));
285 std::list<Gtk::TargetEntry> listTargets;
286 listTargets.push_back( Gtk::TargetEntry("LAYER") );
287 get_layer_tree_view().drag_dest_set(listTargets);
290 // This makes things easier to read.
291 get_layer_tree_view().set_rules_hint();
293 // Make us more sensitive to several events
294 //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);
296 get_layer_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_layer_tree_event));
297 get_layer_tree_view().show();
301 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
302 scroll->set_flags(Gtk::CAN_FOCUS);
303 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
304 //scroll->add(get_layer_tree_view());
305 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
312 LayerTree::create_param_tree()
314 Pango::AttrList attr_list;
316 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*8));
317 pango_size.set_start_index(0);
318 pango_size.set_end_index(64);
319 attr_list.change(pango_size);
322 Gtk::IconSize icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
324 { // --- N A M E --------------------------------------------------------
325 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Param")) );
327 // Set up the icon cell-renderer
328 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
329 column->pack_start(*icon_cellrenderer,false);
330 column->add_attribute(icon_cellrenderer->property_pixbuf(), param_model.icon);
332 // Pack the label into the column
333 //column->pack_start(layer_model.label,true);
334 Gtk::CellRendererText* text_cellrenderer = Gtk::manage( new Gtk::CellRendererText() );
335 column->pack_start(*text_cellrenderer,false);
336 column->add_attribute(text_cellrenderer->property_text(), param_model.label);
337 text_cellrenderer->property_attributes()=attr_list;
339 text_cellrenderer->property_foreground()=Glib::ustring("#7f7f7f");
340 column->add_attribute(text_cellrenderer->property_foreground_set(),param_model.is_inconsistent);
342 // Pack the label into the column
343 //column->pack_start(param_model.label,true);
345 // Set up the value-node icon cell-renderer to be on the far right
346 Gtk::CellRendererPixbuf* valuenode_icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
347 column->pack_end(*valuenode_icon_cellrenderer,false);
348 valuenode_icon_cellrenderer->property_pixbuf()=Gtk::Button().render_icon(Gtk::StockID("synfig-value_node"),icon_size);
349 column->add_attribute(valuenode_icon_cellrenderer->property_visible(), param_model.is_shared);
351 // Finish setting up the column
352 column->set_reorderable();
353 column->set_resizable();
354 column->set_clickable();
356 param_tree_view().append_column(*column);
358 { // --- V A L U E -----------------------------------------------------
359 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
361 // Set up the value cell-renderer
362 cellrenderer_value=LayerParamTreeStore::add_cell_renderer_value(column);
363 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::LayerTree::on_edited_value));
364 cellrenderer_value->property_value()=synfig::ValueBase();
365 column->add_attribute(cellrenderer_value->property_param_desc(), param_model.param_desc);
366 column->add_attribute(cellrenderer_value->property_inconsistant(),param_model.is_inconsistent);
367 //cellrenderer_value->property_canvas()=canvas_interface->get_canvas(); // Is this line necessary?
368 cellrenderer_value->property_attributes()=attr_list;
370 // Finish setting up the column
371 param_tree_view().append_column(*column);
372 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
373 column->set_clickable();
374 column->set_min_width(120);
375 column->set_reorderable();
376 column->set_resizable();
378 /*{ // --- T I M E T R A C K --------------------------------------------
379 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
380 column_time_track=column;
382 // Set up the value-node cell-renderer
383 cellrenderer_time_track=LayerParamTreeStore::add_cell_renderer_value_node(column);
384 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
385 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_clicked) );
386 cellrenderer_time_track->signal_waypoint_changed().connect(sigc::mem_fun(*this, &studio::LayerTree::on_waypoint_changed) );
387 column->add_attribute(cellrenderer_time_track->property_value_desc(), param_model.value_desc);
388 column->add_attribute(cellrenderer_time_track->property_canvas(), param_model.canvas);
389 //column->add_attribute(cellrenderer_time_track->property_visible(), model.is_value_node);
391 //column->pack_start(*cellrenderer_time_track);
393 // Finish setting up the column
394 column->set_reorderable();
395 column->set_resizable();
396 column->set_min_width(200);
397 //param_tree_view().append_column(*column);
402 // This makes things easier to read.
403 param_tree_view().set_rules_hint();
405 // Make us more sensitive to several events
406 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);
408 param_tree_view().signal_event().connect(sigc::mem_fun(*this, &studio::LayerTree::on_param_tree_event));
409 param_tree_view().show();
411 Gtk::ScrolledWindow *scroll = manage(new class Gtk::ScrolledWindow());
412 scroll->set_flags(Gtk::CAN_FOCUS);
413 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
414 //scroll->add(param_tree_view());
415 scroll->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
418 //column_time_track->set_visible(false);
424 LayerTree::on_waypoint_changed( synfig::Waypoint waypoint , synfig::ValueNode::Handle value_node)
426 synfigapp::Action::ParamList param_list;
427 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
428 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
429 param_list.add("value_node",value_node);
430 param_list.add("waypoint",waypoint);
431 // param_list.add("time",canvas_interface()->get_time());
433 etl::handle<studio::Instance>::cast_static(layer_tree_store_->canvas_interface()->get_instance())->process_action("waypoint_set_smart", param_list);
437 LayerTree::select_layer(Layer::Handle layer)
439 Gtk::TreeModel::Children::iterator iter;
440 if(layer_tree_store_->find_layer_row(layer,iter))
442 if(sorted_layer_tree_store_)
443 iter=sorted_layer_tree_store_->convert_child_iter_to_iter(iter);
445 Gtk::TreePath path(iter);
446 for(int i=path.get_depth();i;i--)
449 path=Gtk::TreePath(iter);
452 get_layer_tree_view().expand_row(path,false);
454 get_layer_tree_view().scroll_to_row(Gtk::TreePath(iter));
455 get_layer_tree_view().get_selection()->select(iter);
460 LayerTree::select_all_children(Gtk::TreeModel::Children::iterator iter)
462 get_layer_tree_view().get_selection()->select(iter);
463 if((bool)(*iter)[layer_model.children_lock])
465 get_layer_tree_view().expand_row(layer_tree_store_->get_path(iter),false);
466 Gtk::TreeModel::Children children(iter->children());
467 for(iter=children.begin();iter!=children.end();++iter)
468 select_all_children(iter);
472 LayerTree::select_all_children_layers(synfig::Layer::Handle layer)
474 Gtk::TreeModel::Children::iterator iter;
475 if(layer_tree_store_->find_layer_row(layer,iter))
476 select_all_children(iter);
480 LayerTree::select_layers(const LayerList &layer_list)
482 LayerList::const_iterator iter;
483 for(iter = layer_list.begin(); iter != layer_list.end(); ++iter)
487 static inline void __layer_grabber(const Gtk::TreeModel::iterator& iter, LayerTree::LayerList* ret)
489 const LayerTreeStore::Model layer_tree_model;
490 ret->push_back((Layer::Handle)(*iter)[layer_tree_model.layer]);
494 LayerTree::get_selected_layers()const
496 Glib::RefPtr<Gtk::TreeSelection> selection=const_cast<Gtk::TreeView&>(get_layer_tree_view()).get_selection();
503 selection->selected_foreach_iter(
515 synfig::Layer::Handle
516 LayerTree::get_selected_layer()const
518 LayerList layers(get_selected_layers());
523 return *layers.begin();
527 LayerTree::clear_selected_layers()
529 get_layer_tree_view().get_selection()->unselect_all();
545 LayerTree::set_show_timetrack(bool x)
547 //column_time_track->set_visible(x);
548 // column_time_track->set_visible(false);
549 column_z_depth->set_visible(x);
553 LayerTree::set_model(Glib::RefPtr<LayerTreeStore> layer_tree_store)
555 layer_tree_store_=layer_tree_store;
560 sorted_layer_tree_store_=Gtk::TreeModelSort::create(layer_tree_store);
562 sorted_layer_tree_store_->set_default_sort_func(sigc::ptr_fun(&studio::LayerTreeStore::z_sorter));
564 //sorted_store->set_sort_func(model.time.index(),sigc::mem_fun(&studio::KeyframeTreeStore::time_sorter));
565 //sorted_store->set_sort_column_id(model.time.index(), Gtk::SORT_ASCENDING);
567 get_layer_tree_view().set_model(sorted_layer_tree_store_);
570 get_layer_tree_view().set_model(layer_tree_store_);
572 layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
574 //layer_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::LayerTree::on_dirty_preview));
576 layer_tree_store_->canvas_interface()->signal_time_changed().connect(
579 &Gtk::Widget::queue_draw
582 if(!param_tree_store_)
584 param_tree_store_=LayerParamTreeStore::create(layer_tree_store_->canvas_interface(), this);
585 param_tree_view().set_model(param_tree_store_);
588 /* if(cellrenderer_time_track && layer_tree_store_ && layer_tree_store_->canvas_interface())
590 cellrenderer_time_track->set_canvas_interface(layer_tree_store_->canvas_interface());
596 LayerTree::set_time_adjustment(Gtk::Adjustment &adjustment)
598 //cellrenderer_time_track->set_adjustment(adjustment);
599 adjustment.signal_value_changed().connect(sigc::mem_fun(param_tree_view(),&Gtk::TreeView::queue_draw));
600 adjustment.signal_changed().connect(sigc::mem_fun(param_tree_view(),&Gtk::TreeView::queue_draw));
604 LayerTree::on_dirty_preview()
607 if(quick_layer && !disable_amount_changed_signal)
609 layer_amount_hscale->set_sensitive(true);
610 disable_amount_changed_signal=true;
611 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
612 disable_amount_changed_signal=false;
613 if(quick_layer->get_param("blend_method").is_valid())
615 blend_method_widget.set_sensitive(true);
616 disable_amount_changed_signal=true;
617 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
618 disable_amount_changed_signal=false;
625 LayerTree::on_selection_changed()
627 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
630 if(last_top_selected_layer && !layer_tree_store_->find_layer_row(last_top_selected_layer,iter))
632 if(layer_list.empty())
634 last_top_selected_layer=0;
635 layer_tree_view_->get_selection()->select(last_top_selected_path);
642 if(!layer_list.empty())
644 last_top_selected_layer=layer_list.front();
645 last_top_selected_path=*layer_tree_view_->get_selection()->get_selected_rows().begin();
649 last_top_selected_layer=0;
654 if(layer_list.empty())
656 button_raise->set_sensitive(false);
657 button_lower->set_sensitive(false);
658 button_duplicate->set_sensitive(false);
659 button_delete->set_sensitive(false);
660 layer_amount_hscale->set_sensitive(false);
661 blend_method_widget.set_sensitive(false);
665 button_raise->set_sensitive(true);
666 button_lower->set_sensitive(true);
667 button_duplicate->set_sensitive(true);
668 button_delete->set_sensitive(true);
670 if(layer_list.size()==1 && (*layer_list.begin())->get_param("amount").is_valid()&& (*layer_list.begin())->get_param("amount").same_as(Real()))
672 quick_layer=*layer_list.begin();
679 layer_amount_hscale->set_sensitive(true);
680 disable_amount_changed_signal=true;
681 layer_amount_adjustment_.set_value(quick_layer->get_param("amount").get(Real()));
682 disable_amount_changed_signal=false;
683 if(quick_layer->get_param("blend_method").is_valid())
685 blend_method_widget.set_sensitive(true);
686 disable_amount_changed_signal=true;
687 blend_method_widget.set_value(quick_layer->get_param("blend_method"));
688 disable_amount_changed_signal=false;
691 blend_method_widget.set_sensitive(false);
695 layer_amount_hscale->set_sensitive(false);
696 blend_method_widget.set_sensitive(false);
702 LayerTree::on_blend_method_changed()
704 if(disable_amount_changed_signal)
709 if(quick_layer->get_param("blend_method").is_valid())
711 disable_amount_changed_signal=true;
712 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"blend_method"),blend_method_widget.get_value());
713 disable_amount_changed_signal=false;
718 LayerTree::on_amount_value_changed()
720 if(disable_amount_changed_signal)
725 disable_amount_changed_signal=true;
726 signal_edited_value()(synfigapp::ValueDesc(quick_layer,"amount"),synfig::ValueBase(layer_amount_adjustment_.get_value()));
727 disable_amount_changed_signal=false;
732 LayerTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
734 Gtk::TreePath path(path_string);
736 const Gtk::TreeRow row = *(param_tree_view().get_model()->get_iter(path));
739 row[param_model.value]=value;
740 //signal_edited_value()(row[param_model.value_desc],value);
745 LayerTree::on_layer_toggle(const Glib::ustring& path_string)
747 Gtk::TreePath path(path_string);
749 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
751 signal_layer_toggle()(row[layer_model.layer]);
756 LayerTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
758 Gtk::TreePath path(path_string);
760 const Gtk::TreeRow row = *(param_tree_view().get_model()->get_iter(path));
764 signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[param_model.value_desc]),waypoint,button);
768 LayerTree::on_layer_tree_event(GdkEvent *event)
772 case GDK_BUTTON_PRESS:
774 Gtk::TreeModel::Path path;
775 Gtk::TreeViewColumn *column;
777 if(!get_layer_tree_view().get_path_at_pos(
778 int(event->button.x),int(event->button.y), // x, y
779 path, // TreeModel::Path&
780 column, //TreeViewColumn*&
781 cell_x,cell_y //int&cell_x,int&cell_y
784 const Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
786 //if(column->get_first_cell_renderer()==cellrenderer_time_track)
787 // return signal_layer_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
789 if(column->get_first_cell_renderer()==cellrenderer_value)
790 return signal_layer_user_click()(event->button.button,row,COLUMNID_VALUE);
792 return signal_layer_user_click()(event->button.button,row,COLUMNID_NAME);
797 case GDK_MOTION_NOTIFY:
799 Gtk::TreeModel::Path path;
800 Gtk::TreeViewColumn *column;
802 if(!get_layer_tree_view().get_path_at_pos(
803 (int)event->button.x,(int)event->button.y, // x, y
804 path, // TreeModel::Path&
805 column, //TreeViewColumn*&
806 cell_x,cell_y //int&cell_x,int&cell_y
810 if(!get_layer_tree_view().get_model()->get_iter(path))
813 Gtk::TreeRow row = *(get_layer_tree_view().get_model()->get_iter(path));
816 if(cellrenderer_time_track==column->get_first_cell_renderer())
818 // Movement on TimeLine
823 if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
825 tooltips_.unset_tip(*this);
826 Glib::ustring tooltips_string(row[layer_model.tooltip]);
827 last_tooltip_path=path;
828 if(!tooltips_string.empty())
830 tooltips_.set_tip(*this,tooltips_string);
831 tooltips_.force_window();
836 case GDK_BUTTON_RELEASE:
846 LayerTree::on_param_tree_event(GdkEvent *event)
850 case GDK_BUTTON_PRESS:
852 Gtk::TreeModel::Path path;
853 Gtk::TreeViewColumn *column;
855 if(!param_tree_view().get_path_at_pos(
856 int(event->button.x),int(event->button.y), // x, y
857 path, // TreeModel::Path&
858 column, //TreeViewColumn*&
859 cell_x,cell_y //int&cell_x,int&cell_y
862 const Gtk::TreeRow row = *(param_tree_view().get_model()->get_iter(path));
864 /* if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
867 param_tree_view().get_cell_area(path,*column,rect);
868 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
869 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
870 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
871 param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
873 //return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
877 if(event->button.button==3)
879 LayerList layer_list(get_selected_layers());
880 if(layer_list.size()<=1)
882 synfigapp::ValueDesc value_desc(row[param_model.value_desc]);
883 Gtk::Menu* menu(manage(new Gtk::Menu()));
884 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc,0.5f);
885 menu->popup(event->button.button,gtk_get_current_event_time());
888 Gtk::Menu* menu(manage(new Gtk::Menu()));
889 std::list<synfigapp::ValueDesc> value_desc_list;
890 ParamDesc param_desc(row[param_model.param_desc]);
891 for(;!layer_list.empty();layer_list.pop_back())
892 value_desc_list.push_back(synfigapp::ValueDesc(layer_list.back(),param_desc.get_name()));
893 App::get_instance(param_tree_store_->canvas_interface()->get_canvas())->make_param_menu(menu,param_tree_store_->canvas_interface()->get_canvas(),value_desc_list);
894 menu->popup(event->button.button,gtk_get_current_event_time());
899 if(column->get_first_cell_renderer()==cellrenderer_value)
900 return signal_param_user_click()(event->button.button,row,COLUMNID_VALUE);
902 return signal_param_user_click()(event->button.button,row,COLUMNID_NAME);
908 case GDK_MOTION_NOTIFY:
910 Gtk::TreeModel::Path path;
911 Gtk::TreeViewColumn *column;
913 if(!param_tree_view().get_path_at_pos(
914 (int)event->motion.x,(int)event->motion.y, // x, y
915 path, // TreeModel::Path&
916 column, //TreeViewColumn*&
917 cell_x,cell_y //int&cell_x,int&cell_y
921 if(!param_tree_view().get_model()->get_iter(path))
924 Gtk::TreeRow row = *(param_tree_view().get_model()->get_iter(path));
926 /* if((event->motion.state&GDK_BUTTON1_MASK ||event->motion.state&GDK_BUTTON3_MASK) && column && cellrenderer_time_track==column->get_first_cell_renderer())
929 param_tree_view().get_cell_area(path,*column,rect);
930 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
931 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
932 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
933 param_tree_view().queue_draw();
934 //param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
938 */ if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
940 tooltips_.unset_tip(*this);
941 Glib::ustring tooltips_string(row[layer_model.tooltip]);
942 last_tooltip_path=path;
943 if(!tooltips_string.empty())
945 tooltips_.set_tip(*this,tooltips_string);
946 tooltips_.force_window();
951 case GDK_BUTTON_RELEASE:
953 Gtk::TreeModel::Path path;
954 Gtk::TreeViewColumn *column;
956 if(!param_tree_view().get_path_at_pos(
957 (int)event->button.x,(int)event->button.y, // x, y
958 path, // TreeModel::Path&
959 column, //TreeViewColumn*&
960 cell_x,cell_y //int&cell_x,int&cell_y
964 if(!param_tree_view().get_model()->get_iter(path))
967 Gtk::TreeRow row = *(param_tree_view().get_model()->get_iter(path));
969 /* if(column && cellrenderer_time_track==column->get_first_cell_renderer())
972 param_tree_view().get_cell_area(path,*column,rect);
973 cellrenderer_time_track->property_value_desc()=row[param_model.value_desc];
974 cellrenderer_time_track->property_canvas()=row[param_model.canvas];
975 cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
976 param_tree_view().queue_draw();
977 param_tree_view().queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
991 LayerTree::on_raise_pressed()
993 synfigapp::Action::ParamList param_list;
994 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
995 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
996 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
999 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1000 synfigapp::SelectionManager::LayerList::iterator iter;
1002 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1003 param_list.add("layer",Layer::Handle(*iter));
1005 synfigapp::Action::Handle action(synfigapp::Action::create("layer_raise"));
1006 action->set_param_list(param_list);
1007 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1011 LayerTree::on_lower_pressed()
1013 synfigapp::Action::ParamList param_list;
1014 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1015 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1016 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1019 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1020 synfigapp::SelectionManager::LayerList::iterator iter;
1022 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1023 param_list.add("layer",Layer::Handle(*iter));
1026 synfigapp::Action::Handle action(synfigapp::Action::create("layer_lower"));
1027 action->set_param_list(param_list);
1028 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1032 LayerTree::on_duplicate_pressed()
1034 synfigapp::Action::ParamList param_list;
1035 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1036 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1037 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1040 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1041 synfigapp::SelectionManager::LayerList::iterator iter;
1043 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1044 param_list.add("layer",Layer::Handle(*iter));
1047 synfigapp::Action::Handle action(synfigapp::Action::create("layer_duplicate"));
1048 action->set_param_list(param_list);
1049 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1053 LayerTree::on_delete_pressed()
1055 synfigapp::Action::ParamList param_list;
1056 param_list.add("time",layer_tree_store_->canvas_interface()->get_time());
1057 param_list.add("canvas",layer_tree_store_->canvas_interface()->get_canvas());
1058 param_list.add("canvas_interface",layer_tree_store_->canvas_interface());
1061 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1062 synfigapp::SelectionManager::LayerList::iterator iter;
1064 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
1065 param_list.add("layer",Layer::Handle(*iter));
1068 synfigapp::Action::Handle action(synfigapp::Action::create("layer_remove"));
1069 action->set_param_list(param_list);
1070 layer_tree_store_->canvas_interface()->get_instance()->perform_action(action);
1094 LayerTree::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&context, Gtk::SelectionData& selection_data, guint info, guint time)
1096 synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
1097 synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
1098 synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
1102 Gtk::TreeModel::Path path;
1103 Gtk::TreeViewColumn *column;
1106 Gtk::TreeRow row = *(get_selection()->get_selected());
1109 if(synfig::String(gdk_atom_name(selection_data->target))=="LAYER" && (bool)row[model.is_layer])
1112 Layer* layer(((Layer::Handle)row[model.layer]).get());
1114 selection_data.set(8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
1121 LayerTree::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1123 synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
1124 synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
1125 synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
1126 synfig::info("Dropped x=%d, y=%d",x,y);
1128 bool dropped_on_specific_row=false;
1130 Gtk::TreeModel::Path path;
1131 Gtk::TreeViewColumn *column;
1133 if(!get_path_at_pos(
1135 path, // TreeModel::Path&
1136 column, //TreeViewColumn*&
1137 cell_x,cell_y //int&cell_x,int&cell_y
1141 dropped_on_specific_row=false;
1144 dropped_on_specific_row=true;
1146 Gtk::TreeRow row = *(get_model()->get_iter(path));
1149 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
1151 if(synfig::String(selection_data.get_data_type())=="LAYER")do
1153 Layer::Handle src(*reinterpret_cast<Layer**>(selection_data.get_data()));
1156 Canvas::Handle dest_canvas;
1157 Layer::Handle dest_layer;
1159 if(dropped_on_specific_row)
1161 dest_canvas=(Canvas::Handle)(row[model.canvas]);
1162 dest_layer=(Layer::Handle)(row[model.layer]);
1163 assert(dest_canvas);
1166 dest_canvas=layer_tree_store_->canvas_interface()->get_canvas();
1168 // In this case, we are just moving.
1169 if(dest_canvas==src->get_canvas())
1171 if(!dest_layer || dest_layer==src)
1174 synfigapp::Action::Handle action(synfigapp::Action::create("layer_move"));
1175 action->set_param("canvas",dest_canvas);
1176 action->set_param("canvas_interface",layer_tree_store_->canvas_interface());
1177 action->set_param("layer",src);
1178 action->set_param("new_index",dest_canvas->get_depth(dest_layer));
1179 if(layer_tree_store_->canvas_interface()->get_instance()->perform_action(action))
1189 context->drag_finish(success, false, time);
1194 LayerTree::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context,int x, int y, guint time)
1196 return get_layer_tree_view().on_drag_motion(context,x,y,time);
1200 LayerTree::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData& selection_data, guint info, guint time)
1202 get_layer_tree_view().on_drag_data_received(context,x,y,selection_data,info,time);
1205 if(context->gobj()->source_window==context->gobj()->dest_window)
1207 Gtk::TreeView::on_drag_data_received(context,x,y,selection_data,info,time);
1211 Gtk::TreeModel::Path path;
1212 Gtk::TreeViewColumn *column;
1214 if(!get_path_at_pos(
1216 path, // TreeModel::Path&
1217 column, //TreeViewColumn*&
1218 cell_x,cell_y //int&cell_x,int&cell_y
1222 context->drag_finish(false, false, time);
1225 if(layer_tree_store_->row_drop_possible(path,selection_data))
1227 if(layer_tree_store_->drag_data_received(path,selection_data))
1228 context->drag_finish(true, false, time);
1230 context->drag_finish(false, false, time);