1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasview.cpp
3 ** \brief Template File
5 ** $Id: canvasview.cpp,v 1.7 2005/01/16 19:55:57 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 <sigc++/adaptors/hide.h>
37 #include <gtkmm/paned.h>
38 #include <gtkmm/scale.h>
39 #include <gtkmm/dialog.h>
40 #include <gtkmm/treemodelsort.h>
41 #include <gtkmm/buttonbox.h>
43 #include <gtk/gtktreestore.h>
44 #include <gtk/gtkversion.h>
46 #include <synfig/valuenode_reference.h>
47 #include <synfig/valuenode_subtract.h>
48 #include <synfig/valuenode_linear.h>
49 #include <synfig/valuenode_timedswap.h>
50 #include <synfig/valuenode_scale.h>
51 #include <synfig/valuenode_dynamiclist.h>
52 #include <synfig/valuenode_twotone.h>
53 #include <synfig/valuenode_stripes.h>
54 #include <synfig/layer.h>
56 #include <synfigapp/uimanager.h>
57 #include <synfigapp/canvasinterface.h>
58 #include <synfigapp/selectionmanager.h>
59 //#include <synfigapp/action_setwaypoint.h>
60 //#include <synfigapp/action_deletewaypoint.h>
62 #include <sigc++/retype_return.h>
63 #include <sigc++/retype.h>
64 //#include <sigc++/hide.h>
66 #include "canvasview.h"
69 #include "cellrenderer_value.h"
70 #include "cellrenderer_timetrack.h"
72 #include "dialog_color.h"
75 #include "state_polygon.h"
76 #include "state_bline.h"
77 #include "state_normal.h"
78 #include "state_eyedrop.h"
79 #include "state_draw.h"
81 #include "ducktransform_scale.h"
82 #include "ducktransform_translate.h"
83 #include "ducktransform_rotate.h"
85 #include "event_mouse.h"
86 #include "event_layerclick.h"
90 #include "dialog_preview.h"
91 #include "dialog_soundselect.h"
94 #include "audiocontainer.h"
95 #include "widget_timeslider.h"
97 #include <synfigapp/main.h>
98 #include <synfigapp/inputdevice.h>
102 /* === U S I N G =========================================================== */
106 using namespace synfig;
107 using namespace studio;
108 using namespace SigC;
110 /* === M A C R O S ========================================================= */
112 #define GRAB_HINT_DATA(y) { \
114 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
116 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
120 #define DEFAULT_TIME_WINDOW_SIZE (10.0)
130 #define SMALL_BUTTON(button,stockid,tooltip) \
131 button = manage(new class Gtk::Button()); \
132 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
133 button->add(*icon); \
134 tooltips.set_tip(*button,tooltip); \
135 icon->set_padding(0,0);\
137 button->set_relief(Gtk::RELIEF_NONE); \
141 #ifndef NORMAL_BUTTON
142 #define NORMAL_BUTTON(button,stockid,tooltip) \
143 button = manage(new class Gtk::Button()); \
144 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
145 button->add(*icon); \
146 tooltips.set_tip(*button,tooltip); \
147 icon->set_padding(0,0);\
149 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
153 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
155 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
157 #define SLOT_EVENT(x) sigc::hide_return(sigc::bind(sigc::mem_fun(*this,&studio::CanvasView::process_event_key),x))
159 /* === C L A S S E S ======================================================= */
162 class studio::UniversalScrubber
164 CanvasView *canvas_view;
167 etl::clock scrub_timer;
169 sigc::connection end_scrub_connection;
171 UniversalScrubber(CanvasView *canvas_view):
172 canvas_view(canvas_view),
175 canvas_view->canvas_interface()->signal_time_changed().connect(
176 sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
182 end_scrub_connection.disconnect();
185 void on_time_changed()
187 // Make sure we are changing the time quickly
188 // before we enable scrubbing
189 if(!scrubbing && scrub_timer()>1)
195 // If we aren't scrubbing already, enable it
199 audio_container()->start_scrubbing(canvas_view->get_time());
202 // Reset the scrubber ender
203 end_scrub_connection.disconnect();
204 end_scrub_connection=Glib::signal_timeout().connect(
206 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
213 audio_container()->scrub(canvas_view->get_time());
218 void end_of_scrubbing()
221 audio_container()->stop_scrubbing();
225 handle<AudioContainer> audio_container()
227 assert(canvas_view->audio);
228 return canvas_view->audio;
233 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
239 CanvasViewUIInterface(CanvasView *view):
243 view->statusbar->push("Idle");
246 ~CanvasViewUIInterface()
248 //view->statusbar->pop();
249 //view->progressbar->set_fraction(0);
252 virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
255 //while(studio::App::events_pending())studio::App::iteration(false);
260 true // use_separator
262 Gtk::Label label(message);
265 dialog.get_vbox()->pack_start(label);
266 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
267 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
269 dialog.set_default_response(dflt);
271 return (Response)dialog.run();
273 virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
276 //while(studio::App::events_pending())studio::App::iteration(false);
281 true // use_separator
283 Gtk::Label label(message);
286 dialog.get_vbox()->pack_start(label);
287 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
288 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
289 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
291 dialog.set_default_response(dflt);
293 return (Response)dialog.run();
295 virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
298 //while(studio::App::events_pending())studio::App::iteration(false);
303 true // use_separator
305 Gtk::Label label(message);
308 dialog.get_vbox()->pack_start(label);
309 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
310 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
312 dialog.set_default_response(dflt);
314 return (Response)dialog.run();
318 task(const std::string &task)
320 if(!view->is_playing_)
322 view->statusbar->pop();
323 view->statusbar->push(task);
325 //while(studio::App::events_pending())studio::App::iteration(false);
326 if(view->cancel){return false;}
331 error(const std::string &err)
333 view->statusbar->push("ERROR");
335 // If we are in the process of canceling,
336 // then just go ahead and return false --
337 // don't bother displaying a dialog
338 if(view->cancel)return false;
344 true // use_separator
346 Gtk::Label label(err);
349 dialog.get_vbox()->pack_start(label);
350 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
353 view->statusbar->pop();
358 warning(const std::string &err)
360 view->statusbar->pop();
361 view->statusbar->push(err);
363 //while(studio::App::events_pending())studio::App::iteration(false);
364 if(view->cancel)return false;
369 amount_complete(int current, int total)
371 if(!view->is_playing_)
373 if(!view->working_depth)
376 view->stopbutton->set_sensitive(true);
378 view->stopbutton->set_sensitive(false);
380 float x((float)current/(float)total);
383 view->progressbar->set_fraction(x);
385 //while(studio::App::events_pending())studio::App::iteration(false);
386 if(view->cancel){/*view->cancel=false;*/return false;}
393 error("Feature not yet implemented");
397 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
400 CanvasView::LayerTreeModel layer_tree_model;
401 CanvasView::ChildrenTreeModel children_tree_model;
404 CanvasViewSelectionManager(CanvasView *view): view(view)
411 void _set_selected_layer(const synfig::Layer::Handle &layer)
413 view->layer_tree->select_layer(layer);
415 // Don't change the selection while we are busy
416 // I cannot remember exactly why I put this here...
417 // It musta been for some reason, but I cannot recall.
418 //if(App::Busy::count)
421 if(view->layer_tree->get_selection()->get_selected())
423 const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
425 // Don't do anything if that layer is already selected
426 if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
429 Gtk::TreeModel::Children::iterator iter;
430 if(view->layer_tree_store()->find_layer_row(layer,iter))
432 Gtk::TreePath path(iter);
433 for(int i=path.get_depth();i;i--)
436 path=Gtk::TreePath(iter);
439 view->layer_tree->get_tree_view().expand_row(path,false);
441 view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
442 view->layer_tree->get_selection()->select(iter);
448 //! Returns the number of layers selected.
449 virtual int get_selected_layer_count()const
451 return get_selected_layers().size();
454 //! Returns a list of the currently selected layers.
455 virtual LayerList get_selected_layers()const
457 // assert(view->layer_tree);
459 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return LayerList(); }
460 return view->layer_tree->get_selected_layers();
463 //! Returns the first layer selected or an empty handle if none are selected.
464 virtual synfig::Layer::Handle get_selected_layer()const
466 // assert(view->layer_tree);
468 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return 0; }
469 return view->layer_tree->get_selected_layer();
472 //! Sets which layers should be selected
473 virtual void set_selected_layers(const LayerList &layer_list)
475 // assert(view->layer_tree);
477 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return; }
478 view->layer_tree->select_layers(layer_list);
479 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
481 //view->queue_rebuild_ducks();
484 //! Sets which layer should be selected.
485 virtual void set_selected_layer(const synfig::Layer::Handle &layer)
487 // assert(view->layer_tree);
489 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return; }
490 view->layer_tree->select_layer(layer);
491 //view->queue_rebuild_ducks();
494 //! Clears the layer selection list
495 virtual void clear_selected_layers()
497 if(!view->layer_tree) return;
498 view->layer_tree->clear_selected_layers();
503 //! Returns the number of value_nodes selected.
504 virtual int get_selected_children_count()const
506 return get_selected_children().size();
509 static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
511 const CanvasView::ChildrenTreeModel children_tree_model;
512 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
514 ret->push_back(value_desc);
517 //! Returns a list of the currently selected value_nodes.
518 virtual ChildrenList get_selected_children()const
520 if(!view->children_tree) return ChildrenList();
522 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
525 return ChildrenList();
529 selection->selected_foreach_iter(
532 &studio::CanvasViewSelectionManager::__child_grabber
539 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
541 Gtk::TreeModel::Children children = iter->children();
542 for(iter = children.begin(); iter != children.end(); ++iter)
544 Gtk::TreeModel::Row row = *iter;
545 if(selection->is_selected(row))
546 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
552 //! Returns the first value_node selected or an empty handle if none are selected.
553 virtual ChildrenList::value_type get_selected_child()const
555 if(!view->children_tree) return ChildrenList::value_type();
557 ChildrenList children(get_selected_children());
560 return ChildrenList::value_type();
562 return children.front();
565 //! Sets which value_nodes should be selected
566 virtual void set_selected_children(const ChildrenList &children_list)
571 //! Sets which value_node should be selected. Empty handle if none.
572 virtual void set_selected_child(const ChildrenList::value_type &child)
577 //! Clears the value_node selection list
578 virtual void clear_selected_children()
585 int get_selected_layer_parameter_count()const
587 return get_selected_layer_parameters().size();
590 LayerParamList get_selected_layer_parameters()const
592 if(!view->layer_tree) return LayerParamList();
594 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
597 return LayerParamList();
601 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
602 Gtk::TreeModel::Children::iterator iter;
603 for(iter = children.begin(); iter != children.end(); ++iter)
605 Gtk::TreeModel::Row row = *iter;
606 Gtk::TreeModel::Children::iterator iter;
607 for(iter=row.children().begin();iter!=row.children().end();iter++)
609 Gtk::TreeModel::Row row = *iter;
610 if(selection->is_selected(row))
611 ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
617 LayerParam get_selected_layer_parameter() const
619 if(!view->layer_tree) return LayerParam();
620 return get_selected_layer_parameters().front();
623 void set_selected_layer_parameters(const LayerParamList &layer_param_list)
628 void set_selected_layer_param(const LayerParam &layer_param)
633 void clear_selected_layer_parameters()
638 }; // END of class SelectionManager
641 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
642 canvas_view_(canvas_view_)
644 if(!canvas_view_.working_depth)
645 canvas_view_.stopbutton->set_sensitive(true);
646 canvas_view_.working_depth++;
647 canvas_view_.cancel=false;
650 CanvasView::IsWorking::~IsWorking()
652 canvas_view_.working_depth--;
653 if(!canvas_view_.working_depth)
654 canvas_view_.stopbutton->set_sensitive(false);
657 CanvasView::IsWorking::operator bool()const
659 if(canvas_view_.cancel)
664 /* === M E T H O D S ======================================================= */
666 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
668 instance_ (instance),
669 canvas_interface_ (canvas_interface_),
670 //layer_tree_store_ (LayerTreeStore::create(canvas_interface_)),
671 //children_tree_store_ (ChildrenTreeStore::create(canvas_interface_)),
672 //keyframe_tree_store_ (KeyframeTreeStore::create(canvas_interface_)),
673 time_adjustment_ (0,0,25,0,0,0),
674 time_window_adjustment_ (0,0,25,0,0,0),
675 statusbar (manage(new class Gtk::Statusbar())),
677 timeslider (new Widget_Timeslider),
679 ui_interface_ (new CanvasViewUIInterface(this)),
680 selection_manager_ (new CanvasViewSelectionManager(this)),
686 canvas_properties (*this,canvas_interface_),
687 canvas_options (this),
688 render_settings (*this,canvas_interface_),
689 waypoint_dialog (*this,canvas_interface_->get_canvas()),
690 keyframe_dialog (*this,canvas_interface_),
691 preview_dialog (new Dialog_Preview),
692 sound_dialog (new Dialog_SoundSelect(*this,canvas_interface_))
696 duck_refresh_flag=true;
698 smach_.set_default_state(&state_normal);
700 disp_audio = new Widget_Sound();
702 //synfig::info("Canvasview: Entered constructor");
704 get_canvas()->set_time(0);
705 //layer_tree_store_->rebuild();
707 // Set up the UI and Selection managers
708 canvas_interface()->set_ui_interface(get_ui_interface());
709 canvas_interface()->set_selection_manager(get_selection_manager());
710 rebuild_ducks_queued=false;
712 //notebook=manage(new class Gtk::Notebook());
713 //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
714 //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
715 //vpaned->pack2(*notebook, Gtk::SHRINK);
716 //vpaned->show_all();
721 //notebook->append_page(*create_layer_tree(),"Layers");
722 //notebook->append_page(*create_children_tree(),"Children");
723 //notebook->append_page(*create_keyframe_tree(),"Keyframes");
725 //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
726 //create all allocated stuff for this canvas
727 audio = new AudioContainer();
729 Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
730 //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
731 layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
733 //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
736 layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
737 layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
741 layout_table->show();
744 //set_transient_for(*App::toolbox);
746 //synfig::info("Canvasview: Before Signals");
748 -- ** -- Signals -------------------------------------------------------------
751 canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
752 canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
754 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
756 //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
757 canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
758 canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
759 waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
760 waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
762 //MODIFIED TIME ADJUSTMENT STUFF....
763 time_window_adjustment().set_child_adjustment(&time_adjustment());
764 time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
765 time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
768 work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
769 work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
771 canvas_interface()->signal_canvas_added().connect(
773 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
776 canvas_interface()->signal_canvas_removed().connect(
778 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
782 canvas_interface()->signal_layer_param_changed().connect(
785 SLOT_EVENT(EVENT_REFRESH_DUCKS)
791 //MUCH TIME STUFF TAKES PLACE IN HERE
793 refresh_time_window();
795 /*! \todo We shouldn't need to do this at construction --
796 ** This should be preformed at the first time the window
799 work_area->queue_render_preview();
801 // If the canvas is really big, zoom out so that we can fit it all in the window
802 /*! \todo In other words, this is a zoom-to-fit, and should be
803 ** in it's own function.
805 int w=get_canvas()->rend_desc().get_w()+70;
806 int h=get_canvas()->rend_desc().get_h()+70;
807 while(w>700 || h>600)
809 work_area->zoom_out();
810 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
811 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
815 set_default_size(w,h);
816 property_window_position().set_value(Gtk::WIN_POS_NONE);
821 std::list<Gtk::TargetEntry> listTargets;
822 listTargets.push_back( Gtk::TargetEntry("STRING") );
823 listTargets.push_back( Gtk::TargetEntry("text/plain") );
824 listTargets.push_back( Gtk::TargetEntry("image") );
826 drag_dest_set(listTargets);
827 signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
831 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
834 time_window_adjustment().set_page_increment(length);
835 time_window_adjustment().set_page_size(length);
839 time_window_adjustment().set_page_increment(10.0);
840 time_window_adjustment().set_page_size(10.0);
844 //synfig::info("Canvasview: Before Sound Hookup");
845 //load sound info from meta data
847 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
849 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
850 on_audio_offset_notify();
852 //signal connection - since they are all associated with the canvas view
854 //hook in signals for sound options box
855 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
856 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
858 //attach to the preview when it's visible
859 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
860 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
862 //hook to metadata signals
863 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
864 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
866 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
869 //synfig::info("Canvasview: Before Final time set up");
871 time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
872 time_window_adjustment().value_changed();
875 GRAB_HINT_DATA("canvas_view");
878 set_skip_taskbar_hint(true);
879 set_skip_pager_hint(true);
880 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
888 //synfig::info("Canvasview: Constructor Done");
891 CanvasView::~CanvasView()
895 App::ui_manager()->remove_action_group(action_group);
897 // Shut down the smach
899 smach_.set_default_state(0);
901 // We want to ensure that the UI_Manager and
902 // the selection manager get destructed right now.
903 ui_interface_.reset();
904 selection_manager_.reset();
906 // Delete any external widgets
907 for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
909 if(ext_widget_book_.begin()->second)
910 delete ext_widget_book_.begin()->second;
918 synfig::info("CanvasView:~CanvasView(): Destructor Finished");
924 CanvasView::create_time_bar()
928 Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
929 //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
930 //TIME BAR TEMPORARY POSITION
931 //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
933 timeslider->set_time_adjustment(&time_adjustment());
934 timeslider->set_bounds_adjustment(&time_window_adjustment());
935 //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
938 tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
939 tooltips.set_tip(*timeslider,_("Changes the current time"));
940 time_window_scroll->show();
942 time_window_scroll->set_flags(Gtk::CAN_FOCUS);
943 timeslider->set_flags(Gtk::CAN_FOCUS);
945 //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
946 //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
948 NORMAL_BUTTON(animatebutton,"gtk-yes","Animate");
949 animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
950 animatebutton->show();
952 NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all","All Keyframes Locked");
953 keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
954 keyframebutton->show();
956 Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
958 //setup the audio display
959 disp_audio->set_size_request(-1,32); //disp_audio.show();
960 disp_audio->set_time_adjustment(&time_adjustment());
961 disp_audio->signal_start_scrubbing().connect(
962 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
964 disp_audio->signal_scrub().connect(
965 sigc::mem_fun(*audio,&AudioContainer::scrub)
967 disp_audio->signal_stop_scrubbing().connect(
968 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
971 table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
972 table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
973 table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
975 table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
976 table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
983 CanvasView::create_work_area()
985 work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
986 work_area->set_instance(get_instance());
987 work_area->set_canvas(get_canvas());
988 work_area->set_canvas_view(this);
989 work_area->set_progress_callback(get_ui_interface().get());
990 work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
992 return work_area.get();
997 CanvasView::create_status_bar()
1000 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
1003 // Create the status bar at the bottom of the window
1004 Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
1005 // statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
1006 progressbar =manage(new class Gtk::ProgressBar());
1007 SMALL_BUTTON(stopbutton,"gtk-stop","Stop");
1008 SMALL_BUTTON(refreshbutton,"gtk-refresh","Refresh");
1009 //SMALL_BUTTON(treetogglebutton,"gtk-go-down","Toggle Layer Tree");
1010 // NEW_SMALL_BUTTON(raisebutton,"gtk-go-up","Raise Layer");
1011 // NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down","Lower Layer");
1012 //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1013 // statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1014 // statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1017 current_time_widget=manage(new Widget_Time);
1018 current_time_widget->set_value(get_time());
1019 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1020 current_time_widget->signal_value_changed().connect(
1021 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1024 statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1025 statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1026 statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1027 statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1028 statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1029 statusbar->set_has_resize_grip(false);
1032 refreshbutton->show();
1033 progressbar->show();
1034 stopbutton->set_sensitive(false);
1036 //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1037 //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1038 //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1040 refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1041 stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1044 statusbartable->show_all();
1045 return statusbartable;
1049 CanvasView::on_current_time_widget_changed()
1051 set_time(current_time_widget->get_value());
1055 CanvasView::create_children_tree()
1057 // Create the layer tree
1058 children_tree=manage(new class ChildrenTree());
1060 // Set up the layer tree
1061 //children_tree->set_model(children_tree_store());
1062 if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1063 if(children_tree)children_tree->show();
1066 if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1067 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1068 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1069 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1071 return children_tree;
1075 CanvasView::create_keyframe_tree()
1077 keyframe_tree=manage(new KeyframeTree());
1079 //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1080 //keyframe_tree->show();
1081 //keyframe_tree->set_model(keyframe_tree_store());
1082 keyframe_tree->set_editable(true);
1083 //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1085 keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1087 Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1088 scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1089 scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1090 scroll_layer_tree->add(*keyframe_tree);
1091 scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1092 //scroll_layer_tree->show();
1095 Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1096 layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1099 Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1101 NEW_SMALL_BUTTON(button_add,"gtk-add","New Keyframe");
1102 NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate Keyframe");
1103 NEW_SMALL_BUTTON(button_delete,"gtk-delete","Delete Keyframe");
1105 Gtk::HBox *hbox(manage(new Gtk::HBox()));
1106 layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1108 hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1109 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1110 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1113 button_raise->set_relief(Gtk::RELIEF_HALF);
1114 button_lower->set_relief(Gtk::RELIEF_HALF);
1115 button_duplicate->set_relief(Gtk::RELIEF_HALF);
1116 button_delete->set_relief(Gtk::RELIEF_HALF);
1119 button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1120 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1121 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1123 //layout_table->show_all();
1125 keyframe_tab_child=layout_table;
1128 layout_table->hide();
1130 return layout_table;
1134 CanvasView::create_layer_tree()
1136 // Create the layer tree
1137 layer_tree=manage(new class LayerTree());
1139 // Set up the layer tree
1140 //layer_tree->set_model(layer_tree_store());
1141 layer_tree->set_time_adjustment(time_adjustment());
1145 layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1146 layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1147 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1148 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1149 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1150 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1157 CanvasView::init_menus()
1160 mainmenu.set_accel_group(get_accel_group());
1161 mainmenu.set_accel_path("<Canvas-view>");
1163 filemenu.set_accel_group(get_accel_group());
1164 filemenu.set_accel_path("<Canvas-view>/File");
1166 editmenu.set_accel_group(get_accel_group());
1167 editmenu.set_accel_path("<Canvas-view>/Edit");
1169 layermenu.set_accel_group(get_accel_group());
1170 layermenu.set_accel_path("<Canvas-view>/Layer");
1172 //cache the position of desired widgets
1174 /*Menus to worry about:
1183 action_group = Gtk::ActionGroup::create();
1185 //action_group->add( Gtk::Action::create("MenuFile", "_File") );
1186 action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1187 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1189 action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1190 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1192 action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1193 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1195 action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1196 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1198 action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1199 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1201 action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1202 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1204 action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1205 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1207 action_group->add( Gtk::Action::create("import", _("Import")),
1208 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1210 action_group->add( Gtk::Action::create("render", _("Render")),
1211 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1213 action_group->add( Gtk::Action::create("preview", _("Preview")),
1214 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1216 action_group->add( Gtk::Action::create("sound", _("Sound File")),
1217 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1219 action_group->add( Gtk::Action::create("options", _("Options")),
1220 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1222 action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close")),
1223 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))
1226 //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1227 // SLOT_EVENT(EVENT_UNDO)
1230 //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1231 // SLOT_EVENT(EVENT_REDO)
1234 action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1235 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1238 action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1239 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1242 action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1243 SLOT_EVENT(EVENT_STOP)
1246 action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1247 SLOT_EVENT(EVENT_REFRESH)
1250 action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1251 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1254 // Preview Quality Menu
1257 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1259 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1265 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i), strprintf("Set Quality to %d",i)));
1267 action->property_value()=10;
1268 action_group->add( action,
1270 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1277 action_group->add( Gtk::Action::create("play", Gtk::StockID("synfig-play")),
1278 sigc::mem_fun(*this, &studio::CanvasView::play)
1281 action_group->add( Gtk::Action::create("dialog-flipbook", _("Flipbook Dialog")),
1282 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1285 action_group->add( Gtk::Action::create("toggle-grid-show", _("Toggle Grid Show")),
1286 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)
1288 action_group->add( Gtk::Action::create("toggle-grid-snap", _("Toggle Grid Snap")),
1289 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)
1291 action_group->add( Gtk::Action::create("toggle-guide-show", _("Toggle Guide Show")),
1292 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)
1294 action_group->add( Gtk::Action::create("toggle-low-res", _("Toggle Low-Res")),
1295 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)
1297 action_group->add( Gtk::Action::create("toggle-onion-skin", _("Toggle Onion Skin")),
1298 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_onion_skin)
1302 action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1303 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1305 action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1306 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1311 Glib::RefPtr<Gtk::Action> action;
1313 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1314 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1315 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1316 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1318 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Foward"),_("Seek Foward"));
1319 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1320 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1321 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1325 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1326 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1328 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1329 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1331 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1332 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1334 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1335 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1337 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1338 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1340 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1341 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1343 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1344 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1346 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1347 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1352 #define DUCK_MASK(lower,upper) \
1353 duck_mask_##lower=Gtk::ToggleAction::create("mask-" #lower "-ducks", _("Show "#lower" ducks")); \
1354 duck_mask_##lower->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper)); \
1355 action_group->add( duck_mask_##lower, \
1357 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask), \
1358 Duck::TYPE_##upper \
1361 DUCK_MASK(position,POSITION);
1362 DUCK_MASK(tangent,TANGENT);
1363 DUCK_MASK(vertex,VERTEX);
1364 DUCK_MASK(radius,RADIUS);
1365 DUCK_MASK(width,WIDTH);
1366 DUCK_MASK(angle,ANGLE);
1369 add_accel_group(App::ui_manager()->get_accel_group());
1371 /* // Here is where we add the actions that may have conflicting
1372 // keyboard accelerators.
1374 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1375 Glib::RefPtr<Gtk::Action> action;
1377 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1378 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1380 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1381 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1383 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1384 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1386 action=Gtk::Action::create("jump-prev-keyframe", Gtk::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1387 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1389 action=Gtk::Action::create("canvas-zoom-in", Gtk::StockID("gtk-zoom-in"));
1390 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1392 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1393 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1395 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1396 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1398 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1399 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1401 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1403 Glib::ustring ui_info =
1406 <accelerator action='seek-next-frame' />
1407 <accelerator action='seek-prev-frame' />
1408 <accelerator action='jump-next-keyframe' />
1409 <accelerator action='jump-prev-keyframe' />
1410 <accelerator action='canvas-zoom-in' />
1411 <accelerator action='canvas-zoom-out' />
1412 <accelerator action='time-zoom-in' />
1413 <accelerator action='time-zoom-out' />
1417 accel_ui_manager->add_ui_from_string(ui_info);
1418 add_accel_group(accel_ui_manager->get_accel_group());
1420 accel_ui_manager->insert_action_group(accel_action_group);
1421 set_ref_obj("accel_ui_manager",accel_ui_manager);
1422 set_ref_obj("accel_action_group",accel_action_group);
1430 //Test some key stuff
1432 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1433 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1434 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save-as"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_save_as))));
1435 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-revert-to-saved"),hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))));
1436 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1438 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_add"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))));
1439 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_update"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))));
1440 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-cvs_commit"),sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))));
1442 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1443 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Import..."),Gtk::AccelKey('I',Gdk::CONTROL_MASK),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))));
1444 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1445 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1446 sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1448 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1449 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1451 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1452 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1455 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1456 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1457 sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1459 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1460 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))));
1462 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1463 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1464 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1465 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1466 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1467 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1468 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1469 editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Ducks"),Gtk::AccelKey('E',Gdk::CONTROL_MASK),sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)));
1470 editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Unselect All Layers"),Gtk::AccelKey('D',Gdk::CONTROL_MASK),sigc::mem_fun(*this,&CanvasView::on_unselect_layers)));
1471 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1473 //editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-stop"),Gtk::AccelKey(GDK_Escape,static_cast<Gdk::ModifierType>(0)),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::stop))));
1474 //editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed))));
1475 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-stop"),Gtk::AccelKey(GDK_Escape,static_cast<Gdk::ModifierType>(0)),SLOT_EVENT(EVENT_STOP)));
1476 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1477 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1478 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rotoscope_bline"),
1479 sigc::mem_fun(*this, &studio::CanvasView::do_rotoscope_bline)));
1480 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rotoscope_polygon"),
1481 sigc::mem_fun(*this, &studio::CanvasView::do_rotoscope_poly)));
1482 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-eyedrop"),
1483 sigc::mem_fun(*this, &studio::CanvasView::do_eyedrop)));
1484 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1485 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1486 sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1489 build_new_layer_menu(newlayermenu);
1490 layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New",newlayermenu));
1494 synfigapp::Action::ParamList param_list;
1495 param_list.add("canvas",Canvas::Handle(get_canvas()));
1496 param_list.add("canvas_interface",canvas_interface());
1497 add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1501 //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Keyframe Dialog",sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1506 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1508 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1509 duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1510 duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1511 duck_mask_position->signal_toggled().connect(
1513 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1518 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1519 duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1520 duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1521 duck_mask_vertex->signal_toggled().connect(
1523 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1528 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1529 duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1530 duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1531 duck_mask_tangent->signal_toggled().connect(
1533 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1538 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1539 duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1540 duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1541 duck_mask_radius->signal_toggled().connect(
1543 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1548 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1549 duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1550 duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1551 duck_mask_width->signal_toggled().connect(
1553 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1558 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1559 duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1560 duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1561 duck_mask_angle->signal_toggled().connect(
1563 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1568 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1571 // Preview Quality Menu
1574 qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1576 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1578 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1584 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1586 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1591 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1594 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-play"),
1595 sigc::mem_fun(*this, &studio::CanvasView::play)));
1596 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1597 sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1599 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1601 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1602 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1603 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1604 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1605 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1606 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1607 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1608 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1610 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1612 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1613 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1614 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1615 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1616 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1617 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1618 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1619 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
1620 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1622 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('+',static_cast<Gdk::ModifierType>(0)),
1623 sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in)));
1624 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('_',static_cast<Gdk::ModifierType>(0)),
1625 sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out)));
1627 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1628 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1629 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1630 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1632 mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1633 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_File",filemenu));
1634 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Edit",editmenu));
1635 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_View",viewmenu));
1636 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Canvas",canvasmenu));
1637 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Layer",layermenu));
1639 mainmenu.accelerate(*this);
1643 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Waypoint",NOT_IMPLEMENTED_SLOT));
1644 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete Waypoint",NOT_IMPLEMENTED_SLOT));
1645 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Export",NOT_IMPLEMENTED_SLOT));
1646 trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1647 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Properties",NOT_IMPLEMENTED_SLOT));
1655 keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1656 sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1660 get_accel_group()->unlock();
1662 //Set the accelerator paths for all the menus
1663 filemenu.set_accel_path("<synfig>/File");
1664 editmenu.set_accel_path("<synfig>/Edit");
1665 layermenu.set_accel_path("<synfig>/Layer");
1666 //mainmenu.set_accel_path("<synfig-main>");
1667 canvasmenu.set_accel_path("<synfig>/Canvas");
1668 viewmenu.set_accel_path("<synfig>/View");
1669 duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1674 CanvasView::on_unselect_layers()
1676 layer_tree->clear_selected_layers();
1680 CanvasView::show_keyframe_dialog()
1682 Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
1683 if(selection->get_selected())
1685 Gtk::TreeRow row(*selection->get_selected());
1687 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
1689 keyframe_dialog.set_keyframe(keyframe);
1690 keyframe_dialog.present();
1695 CanvasView::add_layer(synfig::String x)
1697 Canvas::Handle canvas;
1699 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1701 int target_depth(0);
1703 if(layer_list.empty())
1705 canvas=get_canvas();
1709 canvas=(*layer_list.begin())->get_canvas();
1710 target_depth=canvas->get_depth(*layer_list.begin());
1714 Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
1717 get_selection_manager()->clear_selected_layers();
1718 get_selection_manager()->set_selected_layer(layer);
1723 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
1725 //Gtk::Menu* menu(manage(new Gtk::Menu));
1726 Gtk::Menu* menu(¶mmenu);
1727 menu->items().clear();
1729 synfigapp::Action::ParamList param_list;
1730 param_list.add("time",canvas_interface()->get_time());
1731 param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
1732 param_list.add("canvas_interface",canvas_interface());
1733 param_list.add("layer",layer);
1735 //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
1736 //build_new_layer_menu(*newlayers);
1738 //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
1740 if(layer->get_name()=="PasteCanvas")
1742 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
1746 &studio::LayerTree::select_all_children_layers
1753 add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
1755 menu->popup(3,gtk_get_current_event_time());
1759 CanvasView::register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>* category_map)
1761 /* if(lyr.second.category==_("Do Not Use"))
1764 if(category_map->count(lyr.second.category)==0)
1765 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
1767 (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
1770 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
1779 CanvasView::build_new_layer_menu(Gtk::Menu &menu)
1782 std::map<synfig::String,Gtk::Menu*> category_map;
1785 synfig::Layer::book().begin(),
1786 synfig::Layer::book().end(),
1790 &studio::CanvasView::register_layer_type
1796 menu.items().clear();
1797 menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1799 std::map<synfig::String,Gtk::Menu*>::iterator iter;
1800 for(iter=category_map.begin();iter!=category_map.end();++iter)
1801 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
1808 CanvasView::popup_main_menu()
1810 //mainmenu.popup(0,gtk_get_current_event_time());
1811 Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
1814 //menu->set_accel_group(App::ui_manager()->get_accel_group());
1815 //menu->accelerate(*this);
1816 menu->popup(0,gtk_get_current_event_time());
1821 CanvasView::on_refresh_pressed()
1825 work_area->queue_render_preview();
1829 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
1831 get_selection_manager()->clear_selected_layers();
1833 get_selection_manager()->set_selected_layer(layer);
1838 CanvasView::refresh_rend_desc()
1840 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1844 //synfig::info("Canvasview: Refreshing render desc info");
1845 if(!get_time().is_equal(time_adjustment().get_value()))
1847 time_adjustment().set_value(get_time());
1848 time_adjustment().value_changed();
1851 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1852 if(length<DEFAULT_TIME_WINDOW_SIZE)
1854 time_window_adjustment().set_page_increment(length);
1855 time_window_adjustment().set_page_size(length);
1859 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
1860 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
1863 //set the FPS of the timeslider
1864 timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
1866 //set the beginning and ending time of the time slider
1867 Time begin_time=get_canvas()->rend_desc().get_time_start();
1868 Time end_time=get_canvas()->rend_desc().get_time_end();
1870 // Setup the time_window adjustment
1871 time_window_adjustment().set_lower(begin_time);
1872 time_window_adjustment().set_upper(end_time);
1873 time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1875 //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1876 if(length < time_window_adjustment().get_page_size())
1878 time_window_adjustment().set_page_increment(length);
1879 time_window_adjustment().set_page_size(length);
1882 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1883 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1884 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1885 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1888 time_window_adjustment().changed(); //only non-value stuff was changed
1890 // Setup the time adjustment
1892 //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
1893 //time_adjustment().set_lower(time_window_adjustment().get_value());
1894 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
1896 // time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
1897 // time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
1898 time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1899 time_adjustment().set_page_increment(synfig::Time(1.0));
1900 time_adjustment().set_page_size(0);
1902 time_adjustment().changed();
1904 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1905 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1906 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1907 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1910 if(begin_time==end_time)
1919 //clamp time to big bounds...
1920 if(time_adjustment().get_value() < begin_time)
1922 time_adjustment().set_value(begin_time);
1923 time_adjustment().value_changed();
1926 if(time_adjustment().get_value() > end_time)
1928 time_adjustment().set_value(end_time);
1929 time_adjustment().value_changed();
1932 /*synfig::info("Time stats: \n"
1933 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
1934 "t: %p - [%.3f,%.3f] %.3f",
1935 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1936 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1937 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
1938 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
1939 time_adjustment_.get_value()
1942 work_area->queue_render_preview();
1949 get_instance()->safe_close();
1954 CanvasView::create(loose_handle<Instance> instance,handle<Canvas> canvas)
1956 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
1957 instance->canvas_view_list().push_front(view);
1958 instance->signal_canvas_view_created()(view.get());
1963 CanvasView::update_title()
1967 title+=etl::basename(get_instance()->get_file_name())
1969 if(get_canvas()->get_name().empty())
1970 title+='"'+get_canvas()->get_id()+'"';
1972 title+='"'+get_canvas()->get_name()+'"';
1974 if(get_instance()->synfigapp::Instance::get_action_count())
1975 title+=_(" (Unsaved)");
1977 if(get_instance()->synfigapp::Instance::in_repository())
1980 if(get_instance()->synfigapp::Instance::is_modified())
1981 title+=_("-MODIFIED");
1982 if(get_instance()->synfigapp::Instance::is_updated())
1983 title+=_("-UPDATED");
1987 if(get_canvas()->is_root())
1988 title+=_(" (Root)");
1995 CanvasView::on_hide()
1998 Gtk::Window::on_hide();
2002 CanvasView::present()
2004 grab_focus();//on_focus_in_event(0);
2005 Gtk::Window::present();
2009 CanvasView::on_focus_in_event(GdkEventFocus*x)
2011 if(studio::App::get_selected_canvas_view()!=this)
2013 if(studio::App::get_selected_canvas_view())
2015 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2016 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2019 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2021 studio::App::set_selected_canvas_view(this);
2023 App::ui_manager()->insert_action_group(action_group);
2026 // HACK ... Questionable...?
2028 return Gtk::Window::on_focus_in_event(x);
2034 CanvasView::on_focus_out_event(GdkEventFocus*x)
2036 //App::ui_manager()->remove_action_group(action_group);
2037 //App::ui_manager()->ensure_update();
2038 return Gtk::Window::on_focus_out_event(x);
2042 CanvasView::refresh_tables()
2044 // if(layer_tree_store_)layer_tree_store_->refresh();
2045 // if(children_tree_store_)children_tree_store_->refresh();
2049 CanvasView::rebuild_tables()
2051 // layer_tree_store_->rebuild();
2052 // children_tree_store_->rebuild();
2056 CanvasView::build_tables()
2058 // layer_tree_store_->rebuild();
2059 // children_tree_store_->rebuild();
2063 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2065 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2071 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2072 if(!action->set_param("canvas_interface",canvas_interface()))
2073 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2074 synfig::error("LayerActivate didn't like CanvasInterface...?");
2075 action->set_param("time",get_time());
2076 action->set_param("layer",layer);
2077 action->set_param("new_status",!layer->active());
2079 assert(action->is_ready());
2081 canvas_interface()->get_instance()->perform_action(action);
2086 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location)
2088 parammenu.items().clear();
2089 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location);
2091 parammenu.popup(3,gtk_get_current_event_time());
2095 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2097 get_instance()->add_actions_to_menu(menu, param_list, category);
2101 CanvasView::on_layer_user_click(int button, Gtk::TreeRow row, LayerTree::ColumnID column_id)
2108 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2109 if(menu && menu->get_submenu())
2111 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2112 //menu->accelerate(*this);
2113 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2118 bool multiple_selected=true;
2120 if(layer_tree->get_selection()->count_selected_rows()<=1)
2121 multiple_selected=false;
2123 // If the clicked row is not selected, then unselect
2124 // everything that isn't selected and select this row
2125 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2127 layer_tree->get_selection()->unselect_all();
2128 layer_tree->get_selection()->select(row);
2129 multiple_selected=false;
2132 if(column_id==COLUMNID_TIME_TRACK)
2135 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2136 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2137 //ValueNode::Handle parent_value_node;
2138 //ValueBase value=row[layer_param_tree_model.value];
2142 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2146 Layer::Handle layer(row[layer_tree_model.layer]);
2147 synfigapp::Action::ParamList param_list;
2148 param_list.add("time",canvas_interface()->get_time());
2149 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2150 param_list.add("canvas_interface",canvas_interface());
2151 if(!multiple_selected)
2152 param_list.add("layer",layer);
2155 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2156 synfigapp::SelectionManager::LayerList::iterator iter;
2158 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2159 param_list.add("layer",Layer::Handle(*iter));
2162 parammenu.items().clear();
2164 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2165 build_new_layer_menu(*newlayers);
2167 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Layer",*newlayers));
2168 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2170 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2174 &studio::LayerTree::select_all_children_layers
2181 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2182 parammenu.popup(button,gtk_get_current_event_time());
2186 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2188 // Right-click on time track with animated
2189 // trackmenu.popup(0,0);
2194 if(!multiple_selected)
2196 popup_param_menu(value_desc);
2203 parammenu.items().clear();
2204 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Connect",
2205 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2207 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Disconnect",
2208 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2210 parammenu.popup(0,0);
2230 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2236 if(column_id==COLUMNID_TIME_TRACK)
2238 if(!(bool)row[children_tree_model.is_canvas])
2240 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2242 popup_param_menu(value_desc);
2256 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2260 case GDK_BUTTON_PRESS:
2261 switch(event->button.button)
2265 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2271 case GDK_MOTION_NOTIFY:
2273 case GDK_BUTTON_RELEASE:
2283 CanvasView::refresh_time_window()
2285 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2286 //time_adjustment().set_lower(time_window_adjustment().get_value());
2287 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2289 time_adjustment().set_page_increment(1.0); // One second
2290 time_adjustment().set_page_size(0);
2293 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2294 time_adjustment().changed();
2296 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2298 children_tree->queue_draw();
2302 CanvasView::on_time_changed()
2304 Time time(get_time());
2306 current_time_widget->set_value(time);
2308 get_canvas()->keyframe_list().find(time);
2309 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2311 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2314 if(get_time() != time_adjustment().get_value())
2317 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2318 if(time < time_window_adjustment().get_value() ||
2319 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2321 time_window_adjustment().set_value(
2322 time-time_window_adjustment().get_page_size()/2
2325 time_adjustment().set_value(time);
2326 time_adjustment().value_changed();
2328 // Shouldn't these trees just hook into
2329 // the time changed signal...?
2330 //YES THEY SHOULD...
2331 if(layer_tree)layer_tree->queue_draw();
2332 if(children_tree)children_tree->queue_draw();
2337 CanvasView::time_zoom_in()
2339 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2340 time_window_adjustment().changed();
2342 refresh_time_window();
2346 CanvasView::time_zoom_out()
2348 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2349 time_window_adjustment().changed();
2351 refresh_time_window();
2355 CanvasView::time_was_changed()
2357 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2362 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2364 canvas_interface()->change_value(value_desc,new_value);
2369 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2371 Gtk::TreePath path(path_string);
2373 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2375 assert((bool)row[children_tree_model.is_value_node]);
2377 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2380 on_edited_value(value_desc,value);
2385 CanvasView::on_id_changed()
2392 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2394 // If the aninimate flag was set in mode...
2395 if(mode&synfigapp::MODE_ANIMATE)
2398 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2399 animatebutton->remove();
2400 animatebutton->add(*icon);
2401 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2402 icon->set_padding(0,0);
2408 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2409 animatebutton->remove();
2410 animatebutton->add(*icon);
2411 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2412 icon->set_padding(0,0);
2416 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2419 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2420 keyframebutton->remove();
2421 keyframebutton->add(*icon);
2422 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2423 icon->set_padding(0,0);
2426 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2429 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2430 keyframebutton->remove();
2431 keyframebutton->add(*icon);
2432 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2433 icon->set_padding(0,0);
2436 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2439 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2440 keyframebutton->remove();
2441 keyframebutton->add(*icon);
2442 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2443 icon->set_padding(0,0);
2446 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2449 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2450 keyframebutton->remove();
2451 keyframebutton->add(*icon);
2452 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2453 icon->set_padding(0,0);
2457 work_area->queue_draw();
2461 CanvasView::on_animate_button_pressed()
2463 if(get_mode()&synfigapp::MODE_ANIMATE)
2464 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2466 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2470 CanvasView::on_keyframe_button_pressed()
2472 synfigapp::CanvasInterface::Mode mode(get_mode());
2474 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2476 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2478 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2480 set_mode(get_mode()-synfigapp::MODE_ANIMATE_PAST|synfigapp::MODE_ANIMATE_FUTURE);
2482 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2484 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2486 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2488 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2493 CanvasView::duck_change_param(const Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2495 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2499 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2501 switch(value_desc.get_value_type())
2503 case ValueBase::TYPE_REAL:
2504 return canvas_interface()->change_value(value_desc,value.mag());
2506 case ValueBase::TYPE_ANGLE:
2507 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2510 return canvas_interface()->change_value(value_desc,value);
2518 CanvasView::selected_layer_color_set(Color color)
2520 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2521 synfigapp::SelectionManager::LayerList::iterator iter;
2523 // Create the action group
2524 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2526 Layer::Handle layer;
2527 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2532 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2537 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2542 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2546 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2549 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2551 Layer::Handle layer(*iter);
2553 if(selected_list.count(layer))
2555 if(!curr_transform_stack_set)
2557 curr_transform_stack_set=true;
2558 curr_transform_stack=transform_stack;
2561 // This layer is currently selected.
2562 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2564 // do the bounding box thing
2565 bbox|=transform_stack.perform(layer->get_bounding_rect());
2567 // Grab the layer's list pf parameters
2568 Layer::ParamList paramlist(layer->get_param_list());
2570 // Grab the layer vocabulary
2571 Layer::Vocab vocab=layer->get_param_vocab();
2572 Layer::Vocab::iterator iter;
2574 for(iter=vocab.begin();iter!=vocab.end();iter++)
2576 if(!iter->get_hidden() && !iter->get_invisible_duck())
2578 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2579 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2580 if(value_desc.is_value_node())
2581 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2583 if(iter->get_name()=="color")
2586 if(!App::dialog_color->busy())
2588 App::dialog_color->reset();
2589 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2590 App::dialog_color->signal_edited().connect(
2593 &studio::CanvasView::selected_layer_color_set
2602 layer_name=layer->get_name();
2606 Transform::Handle trans(layer->get_transform());
2609 transform_stack.push(trans);
2613 /* // Add transforms onto the stack
2614 if(layer_name=="Translate")
2616 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2619 if(layer_name=="Zoom")
2622 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2623 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2626 if(layer_name=="stretch")
2628 Vector scale(layer->get_param("amount").get(Vector()));
2629 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2632 if(layer_name=="Rotate")
2634 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2640 // If this is a paste canvas layer, then we need to
2642 if(layer_name=="PasteCanvas")
2645 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2646 Vector origin(layer->get_param("origin").get(Vector()));
2648 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2650 if(!scale.is_equal_to(Vector(1,1)))
2651 transform_stack.push(new Transform_Scale(scale,origin));
2652 if(!scale.is_equal_to(Vector(0,0)))
2653 transform_stack.push(new Transform_Translate(origin));
2655 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2657 if(!scale.is_equal_to(Vector(0,0)))
2658 transform_stack.pop();
2659 if(!scale.is_equal_to(Vector(1,1)))
2660 transform_stack.pop();
2663 // Remove all of the transforms we have added
2664 while(transforms--) { transform_stack.pop(); }
2666 #undef QUEUE_REBUILD_DUCKS
2670 CanvasView::queue_rebuild_ducks()
2673 if(rebuild_ducks_queued)
2676 if(rebuild_ducks_queued)
2677 queue_rebuild_ducks_connection.disconnect();
2680 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2682 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2688 rebuild_ducks_queued=true;
2692 CanvasView::rebuild_ducks()
2697 synfig::info("%d",i/(i-i));
2700 rebuild_ducks_queued=false;
2701 //queue_rebuild_ducks_connection.disconnect();
2703 if(work_area->is_dragging())
2705 queue_rebuild_ducks();
2709 if(!duck_refresh_flag)
2711 duck_refresh_needed=true;
2717 work_area->clear_ducks();
2718 work_area->set_time(get_time());
2719 get_canvas()->set_time(get_time());
2720 curr_transform_stack.clear();
2721 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2722 curr_transform_stack_set=false;
2724 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2726 //get_canvas()->set_time(get_time());
2727 bool not_empty(false);
2729 // First do the layers...
2731 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2732 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2734 if(!layer_set.empty())
2737 synfig::TransformStack transform_stack;
2739 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2743 // Now do the children
2745 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2746 synfigapp::SelectionManager::ChildrenList::iterator iter;
2747 synfig::TransformStack transform_stack;
2749 if(selected_list.empty())
2756 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2758 work_area->add_to_ducks(*iter,this,transform_stack);
2762 work_area->refresh_selected_ducks();
2763 work_area->queue_draw_preview();
2767 CanvasView::on_dirty_preview()
2771 IsWorking is_working(*this);
2773 work_area->queue_render_preview();
2780 assert(get_canvas());
2782 // If we are already busy, don't play!
2783 if(working_depth)return;
2785 // Set us up as working
2786 IsWorking is_working(*this);
2790 time=work_area->get_time(),
2791 endtime=get_canvas()->rend_desc().get_time_end();
2793 // If we are already at the end of time, start over
2795 time=get_canvas()->rend_desc().get_time_start();
2799 work_area->clear_ducks();
2801 for(timer.reset(); time + timer() < endtime;)
2803 //Clamp the time window so we can see the time value as it races across the horizon
2804 bool timewindreset = false;
2806 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
2808 time_window_adjustment().set_value(
2810 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
2811 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
2813 timewindreset = true;
2816 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
2818 time_window_adjustment().set_value(
2820 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
2821 time_window_adjustment().get_lower())
2824 timewindreset = true;
2827 //we need to tell people that the value changed
2828 if(timewindreset) time_window_adjustment().value_changed();
2830 //update actual time to next step
2831 time_adjustment().set_value(time+timer());
2832 time_adjustment().value_changed();
2834 if(!work_area->sync_render_preview())
2837 studio::App::iteration(false);
2839 if(get_cancel_status())
2844 time_adjustment().set_value(endtime);
2845 time_adjustment().value_changed();
2849 CanvasView::show_tables()
2852 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
2853 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2855 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2856 treetogglebutton->remove();
2857 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
2858 treetogglebutton->show_all();
2865 CanvasView::hide_tables()
2868 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
2869 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2871 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2872 treetogglebutton->remove();
2873 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
2874 treetogglebutton->show_all();
2881 CanvasView::tables_are_visible()
2883 // return notebook->is_visible();
2888 CanvasView::toggle_tables()
2890 // if(tables_are_visible())
2897 CanvasView::do_rotoscope_bline()
2899 smach_.enter(&state_bline);
2903 CanvasView::do_rotoscope()
2905 smach_.enter(&state_draw);
2909 CanvasView::do_rotoscope_poly()
2911 smach_.enter(&state_polygon);
2915 CanvasView::do_eyedrop()
2917 smach_.enter(&state_eyedrop);
2921 CanvasView::show_timebar()
2924 current_time_widget->show();
2926 //keyframe_tab_child->show();
2928 layer_tree->set_show_timetrack(true);
2930 children_tree->set_show_timetrack(true);
2934 CanvasView::hide_timebar()
2937 current_time_widget->hide();
2938 //keyframe_tab_child->hide();
2940 layer_tree->set_show_timetrack(false);
2942 children_tree->set_show_timetrack(false);
2948 CanvasView::on_waypoint_clicked(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint,int button)
2950 waypoint_dialog.set_value_desc(value_desc);
2951 waypoint_dialog.set_waypoint(waypoint);
2956 waypoint_dialog.show();
2960 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
2962 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-jump-to"),
2965 *canvas_interface(),
2966 &synfigapp::CanvasInterface::set_time
2972 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Edit Waypoint"),
2979 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-duplicate"),
2983 *canvas_interface(),
2984 &synfigapp::CanvasInterface::waypoint_duplicate
2991 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
2995 *canvas_interface(),
2996 &synfigapp::CanvasInterface::waypoint_remove
3003 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3012 CanvasView::on_waypoint_changed()
3014 synfigapp::Action::ParamList param_list;
3015 param_list.add("canvas",get_canvas());
3016 param_list.add("canvas_interface",canvas_interface());
3017 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3018 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3019 // param_list.add("time",canvas_interface()->get_time());
3021 get_instance()->process_action("waypoint_set_smart", param_list);
3025 CanvasView::on_waypoint_delete()
3027 synfigapp::Action::ParamList param_list;
3028 param_list.add("canvas",get_canvas());
3029 param_list.add("canvas_interface",canvas_interface());
3030 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3031 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3032 // param_list.add("time",canvas_interface()->get_time());
3034 get_instance()->process_action("waypoint_remove", param_list);
3038 CanvasView::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data_, guint info, guint time)
3040 // We will make this true once we have a solid drop
3041 bool success(false);
3042 //synfig::info("Droped data of type \"%s\"",selection_data.get_data_type());
3043 //synfig::info("Droped data of target \"%s\"",gdk_atom_name(selection_data->target));
3044 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3046 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3048 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3050 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3052 Layer::Handle layer(synfig::Layer::create("Text"));
3055 if(!layer->set_param("text",ValueBase(selection_data)))
3058 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3064 action->set_param("canvas",get_canvas());
3065 action->set_param("canvas_interface",canvas_interface());
3066 action->set_param("new",layer);
3068 if(!get_instance()->perform_action(action))
3071 // Ok, we have successfuly imported at least one item.
3073 } while(0); // END of "STRING"
3075 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3077 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3079 // For some reason, GTK hands us a list of URL's seperated
3080 // by not only Carrage-Returns, but also Line-Feeds.
3081 // Line-Feeds will mess us up. Remove all the line-feeds.
3082 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3083 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3085 std::stringstream stream(selection_data);
3087 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3090 synfig::String filename,URI;
3091 getline(stream,filename);
3093 // If we don't have a filename, move on.
3094 if(filename.empty())
3097 // Make sure this URL is of the "file://" type.
3098 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3101 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3105 // Strip the "file://" part from the filename
3106 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3109 try{ext=(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));}catch(...){continue;}
3111 // If this is a SIF file, then we need to do things slightly differently
3114 if(work_area->load_sketch(filename))
3117 work_area->queue_draw();
3122 if(canvas_interface()->import(filename))
3128 } // END of "text/plain"
3131 ui_interface_->error("Drop failed: bad selection data");
3134 context->drag_finish(success, false, time);
3138 CanvasView::on_keyframe_add_pressed()
3140 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3144 ui_interface_->error("I am unable to find the appropriate action");
3148 action->set_param("canvas",get_canvas());
3149 action->set_param("canvas_interface",canvas_interface());
3150 action->set_param("keyframe",Keyframe(get_time()));
3152 canvas_interface()->get_instance()->perform_action(action);
3156 CanvasView::on_keyframe_duplicate_pressed()
3158 const KeyframeTreeStore::Model model;
3159 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3163 ui_interface_->error("I am unable to duplicate the keyframe");
3166 keyframe=row[model.keyframe];
3168 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3172 ui_interface_->error("I am unable to find the appropriate action");
3176 action->set_param("canvas",get_canvas());
3177 action->set_param("canvas_interface",canvas_interface());
3178 action->set_param("keyframe",keyframe);
3179 action->set_param("time",get_time());
3181 canvas_interface()->get_instance()->perform_action(action);
3185 CanvasView::on_keyframe_remove_pressed()
3187 const KeyframeTreeStore::Model model;
3188 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3192 ui_interface_->error("I am unable to remove the keyframe");
3195 keyframe=row[model.keyframe];
3197 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3201 ui_interface_->error("I am unable to find the appropriate action");
3205 action->set_param("canvas",get_canvas());
3206 action->set_param("canvas_interface",canvas_interface());
3207 action->set_param("keyframe",keyframe);
3209 canvas_interface()->get_instance()->perform_action(action);
3214 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3216 bool is_currently_on(work_area->get_type_mask()&type);
3220 case Duck::TYPE_POSITION:
3221 if(duck_mask_position)
3222 duck_mask_position->set_active(!is_currently_on);
3225 case Duck::TYPE_VERTEX:
3226 if(duck_mask_vertex)
3227 duck_mask_vertex->set_active(!is_currently_on);
3230 case Duck::TYPE_TANGENT:
3231 if(duck_mask_tangent)
3232 duck_mask_tangent->set_active(!is_currently_on);
3235 case Duck::TYPE_RADIUS:
3236 if(duck_mask_radius)
3237 duck_mask_radius->set_active(!is_currently_on);
3240 case Duck::TYPE_WIDTH:
3242 duck_mask_width->set_active(!is_currently_on);
3245 case Duck::TYPE_ANGLE:
3247 duck_mask_angle->set_active(!is_currently_on);
3251 synfig::warning("CanvasView::toggle_duck_mask():Unknown duck type!");
3256 work_area->set_type_mask(work_area->get_type_mask()-type);
3258 work_area->set_type_mask(work_area->get_type_mask()|type);
3260 work_area->queue_draw();
3265 CanvasView::image_import()
3267 String filename(dirname(get_canvas()->get_file_name()));
3268 if(App::dialog_open_file(_("Import Image"), filename))
3269 canvas_interface()->import(filename);
3273 CanvasView::process_event_key(EventKey x)
3275 return smach_.process_event(x);
3279 CanvasView::on_input_device_changed(GdkDevice* device)
3283 get_smach().egress();
3287 synfigapp::InputDevice::Handle input_device;
3288 input_device=synfigapp::Main::select_input_device(device->name);
3289 App::toolbox->change_state(input_device->get_state());
3290 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3294 CanvasView::on_preview_option()
3296 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3298 Canvas::Handle canv = get_canvas();
3302 RendDesc &r = canv->rend_desc();
3303 if(r.get_frame_rate())
3305 float rate = 1/r.get_frame_rate();
3306 float beg = r.get_time_start() + r.get_frame_start()*rate;
3307 float end = r.get_time_start() + r.get_frame_end()*rate;
3311 po = new Dialog_PreviewOptions;
3312 po->set_zoom(work_area->get_zoom()/2);
3313 po->set_fps(r.get_frame_rate()/2);
3314 po->set_begintime(beg);
3315 po->set_begin_override(false);
3316 po->set_endtime(end);
3317 po->set_end_override(false);
3319 set_ext_widget("prevoptions",po);
3321 /*po->set_zoom(work_area->get_zoom()/2);
3322 po->set_fps(r.get_frame_rate()/2);
3323 po->set_begintime(beg);
3324 po->set_begin_override(false);
3325 po->set_endtime(end);
3326 po->set_end_override(false);*/
3328 po->set_global_fps(r.get_frame_rate());
3329 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3336 CanvasView::on_preview_create(const PreviewInfo &info)
3338 //set all the options
3339 etl::handle<Preview> prev = new Preview;
3341 prev->set_canvasview(this);
3342 prev->set_zoom(info.zoom);
3343 prev->set_fps(info.fps);
3344 prev->set_overbegin(info.overbegin);
3345 prev->set_begintime(info.begintime);
3346 prev->set_overend(info.overend);
3347 prev->set_endtime(info.endtime);
3348 prev->set_quality(work_area->get_quality());
3353 Dialog_Preview *pd = preview_dialog.get();
3356 pd->set_preview(prev.get());
3361 CanvasView::on_audio_option()
3363 synfig::warning("Launching Audio Options");
3364 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3365 sound_dialog->present();
3369 CanvasView::on_audio_file_change(const std::string &f)
3371 //save in meta data - always even when not valid...
3372 canvas_interface()->set_meta_data("audiofile",f);
3376 CanvasView::on_audio_offset_change(const Time &t)
3378 canvas_interface()->set_meta_data("audiooffset",t.get_string());
3382 CanvasView::on_audio_file_notify()
3384 std::string file(get_canvas()->get_meta_data("audiofile"));
3385 if(!file.c_str()) return;
3387 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3389 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3390 get_canvas()->erase_meta_data("audiofile");
3392 disp_audio->set_profile(etl::handle<AudioProfile>());
3395 //save in canvasview
3396 synfig::warning("Getting the profile of the music stuff");
3398 //profile specific stuff for the preview widget
3399 //similar for other attachments
3400 Dialog_Preview *pd = preview_dialog.get();
3401 pd->get_widget().set_audio(audio);
3403 handle<AudioProfile> prof = audio->get_profile();
3407 synfig::warning("Agh, I couldn't build the profile captain!");
3409 pd->get_widget().set_audioprofile(prof);
3411 disp_audio->set_profile(audio->get_profile());
3414 synfig::warning("successfully set the profiles and stuff");
3416 disp_audio->queue_draw();
3420 CanvasView::on_audio_offset_notify()
3422 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3423 audio->set_offset(t);
3424 sound_dialog->set_offset(t);
3425 disp_audio->queue_draw();
3427 synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3431 CanvasView::play_audio(float t)
3435 synfig::info("Playing audio at %f s",t);
3441 CanvasView::stop_audio()
3450 CanvasView::on_audio_scrub()
3458 Glib::RefPtr<Glib::ObjectBase>
3459 CanvasView::get_ref_obj(const synfig::String& x)
3461 return ref_obj_book_[x];
3464 Glib::RefPtr<const Glib::ObjectBase>
3465 CanvasView::get_ref_obj(const synfig::String& x)const
3467 return ref_obj_book_.find(x)->second;
3471 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3476 Glib::RefPtr<Gtk::TreeModel>
3477 CanvasView::get_tree_model(const synfig::String& x)
3479 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3482 Glib::RefPtr<const Gtk::TreeModel>
3483 CanvasView::get_tree_model(const synfig::String& x)const
3485 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3489 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3491 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3495 CanvasView::get_ext_widget(const synfig::String& x)
3497 return ext_widget_book_[x];
3501 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3503 ext_widget_book_[x]=y;
3506 layer_tree=dynamic_cast<LayerTree*>(y);
3508 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3509 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3510 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3511 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3512 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3516 children_tree=dynamic_cast<ChildrenTree*>(y);
3517 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3518 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3519 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3522 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3525 static bool _close_instance(etl::handle<Instance> instance)
3527 etl::handle<Instance> argh(instance);
3528 instance->safe_close();
3529 synfig::info("closed");
3534 CanvasView::on_delete_event(GdkEventAny* event)
3536 if(get_instance()->get_visible_canvases()==1)
3538 // Schedule a close to occur in a few moments
3539 Glib::signal_timeout().connect(
3541 sigc::ptr_fun(_close_instance),
3542 (etl::handle<Instance>)get_instance()
3548 return Gtk::Window::on_delete_event(event);