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", _("Mask "#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();
1950 // I think this is bad..., removing
1951 // get_instance()->canvas_view_list().erase(std::find(get_instance()->canvas_view_list().begin(),get_instance()->canvas_view_list().end(),this));
1956 CanvasView::create(loose_handle<Instance> instance,handle<Canvas> canvas)
1958 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
1959 instance->canvas_view_list().push_front(view);
1960 instance->signal_canvas_view_created()(view.get());
1965 CanvasView::update_title()
1969 title+=etl::basename(get_instance()->get_file_name())
1971 if(get_canvas()->get_name().empty())
1972 title+='"'+get_canvas()->get_id()+'"';
1974 title+='"'+get_canvas()->get_name()+'"';
1976 if(get_instance()->synfigapp::Instance::get_action_count())
1977 title+=_(" (Unsaved)");
1979 if(get_instance()->synfigapp::Instance::in_repository())
1982 if(get_instance()->synfigapp::Instance::is_modified())
1983 title+=_("-MODIFIED");
1984 if(get_instance()->synfigapp::Instance::is_updated())
1985 title+=_("-UPDATED");
1989 if(get_canvas()->is_root())
1990 title+=_(" (Root)");
1997 CanvasView::on_hide()
2000 Gtk::Window::on_hide();
2004 CanvasView::present()
2006 grab_focus();//on_focus_in_event(0);
2007 Gtk::Window::present();
2011 CanvasView::on_focus_in_event(GdkEventFocus*x)
2013 if(studio::App::get_selected_canvas_view()!=this)
2015 if(studio::App::get_selected_canvas_view())
2017 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2018 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2021 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2023 studio::App::set_selected_canvas_view(this);
2025 App::ui_manager()->insert_action_group(action_group);
2028 // HACK ... Questionable...?
2030 return Gtk::Window::on_focus_in_event(x);
2036 CanvasView::on_focus_out_event(GdkEventFocus*x)
2038 //App::ui_manager()->remove_action_group(action_group);
2039 //App::ui_manager()->ensure_update();
2040 return Gtk::Window::on_focus_out_event(x);
2044 CanvasView::refresh_tables()
2046 // if(layer_tree_store_)layer_tree_store_->refresh();
2047 // if(children_tree_store_)children_tree_store_->refresh();
2051 CanvasView::rebuild_tables()
2053 // layer_tree_store_->rebuild();
2054 // children_tree_store_->rebuild();
2058 CanvasView::build_tables()
2060 // layer_tree_store_->rebuild();
2061 // children_tree_store_->rebuild();
2065 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2067 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2073 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2074 if(!action->set_param("canvas_interface",canvas_interface()))
2075 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2076 synfig::error("LayerActivate didn't like CanvasInterface...?");
2077 action->set_param("time",get_time());
2078 action->set_param("layer",layer);
2079 action->set_param("new_status",!layer->active());
2081 assert(action->is_ready());
2083 canvas_interface()->get_instance()->perform_action(action);
2088 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location)
2090 parammenu.items().clear();
2091 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location);
2093 parammenu.popup(3,gtk_get_current_event_time());
2097 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2099 get_instance()->add_actions_to_menu(menu, param_list, category);
2103 CanvasView::on_layer_user_click(int button, Gtk::TreeRow row, LayerTree::ColumnID column_id)
2110 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2111 if(menu && menu->get_submenu())
2113 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2114 //menu->accelerate(*this);
2115 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2120 bool multiple_selected=true;
2122 if(layer_tree->get_selection()->count_selected_rows()<=1)
2123 multiple_selected=false;
2125 // If the clicked row is not selected, then unselect
2126 // everything that isn't selected and select this row
2127 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2129 layer_tree->get_selection()->unselect_all();
2130 layer_tree->get_selection()->select(row);
2131 multiple_selected=false;
2134 if(column_id==COLUMNID_TIME_TRACK)
2137 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2138 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2139 //ValueNode::Handle parent_value_node;
2140 //ValueBase value=row[layer_param_tree_model.value];
2144 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2148 Layer::Handle layer(row[layer_tree_model.layer]);
2149 synfigapp::Action::ParamList param_list;
2150 param_list.add("time",canvas_interface()->get_time());
2151 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2152 param_list.add("canvas_interface",canvas_interface());
2153 if(!multiple_selected)
2154 param_list.add("layer",layer);
2157 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2158 synfigapp::SelectionManager::LayerList::iterator iter;
2160 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2161 param_list.add("layer",Layer::Handle(*iter));
2164 parammenu.items().clear();
2166 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2167 build_new_layer_menu(*newlayers);
2169 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Layer",*newlayers));
2170 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2172 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2176 &studio::LayerTree::select_all_children_layers
2183 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2184 parammenu.popup(button,gtk_get_current_event_time());
2188 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2190 // Right-click on time track with animated
2191 // trackmenu.popup(0,0);
2196 if(!multiple_selected)
2198 popup_param_menu(value_desc);
2205 parammenu.items().clear();
2206 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Connect",
2207 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2209 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Disconnect",
2210 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2212 parammenu.popup(0,0);
2232 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2238 if(column_id==COLUMNID_TIME_TRACK)
2240 if(!(bool)row[children_tree_model.is_canvas])
2242 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2244 popup_param_menu(value_desc);
2258 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2262 case GDK_BUTTON_PRESS:
2263 switch(event->button.button)
2267 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2273 case GDK_MOTION_NOTIFY:
2275 case GDK_BUTTON_RELEASE:
2285 CanvasView::refresh_time_window()
2287 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2288 //time_adjustment().set_lower(time_window_adjustment().get_value());
2289 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2291 time_adjustment().set_page_increment(1.0); // One second
2292 time_adjustment().set_page_size(0);
2295 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2296 time_adjustment().changed();
2298 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2300 children_tree->queue_draw();
2304 CanvasView::on_time_changed()
2306 Time time(get_time());
2308 current_time_widget->set_value(time);
2310 get_canvas()->keyframe_list().find(time);
2311 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2313 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2316 if(get_time() != time_adjustment().get_value())
2319 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2320 if(time < time_window_adjustment().get_value() ||
2321 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2323 time_window_adjustment().set_value(
2324 time-time_window_adjustment().get_page_size()/2
2327 time_adjustment().set_value(time);
2328 time_adjustment().value_changed();
2330 // Shouldn't these trees just hook into
2331 // the time changed signal...?
2332 //YES THEY SHOULD...
2333 if(layer_tree)layer_tree->queue_draw();
2334 if(children_tree)children_tree->queue_draw();
2339 CanvasView::time_zoom_in()
2341 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2342 time_window_adjustment().changed();
2344 refresh_time_window();
2348 CanvasView::time_zoom_out()
2350 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2351 time_window_adjustment().changed();
2353 refresh_time_window();
2357 CanvasView::time_was_changed()
2359 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2364 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2366 canvas_interface()->change_value(value_desc,new_value);
2371 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2373 Gtk::TreePath path(path_string);
2375 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2377 assert((bool)row[children_tree_model.is_value_node]);
2379 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2382 on_edited_value(value_desc,value);
2387 CanvasView::on_id_changed()
2394 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2396 // If the aninimate flag was set in mode...
2397 if(mode&synfigapp::MODE_ANIMATE)
2400 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2401 animatebutton->remove();
2402 animatebutton->add(*icon);
2403 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2404 icon->set_padding(0,0);
2410 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2411 animatebutton->remove();
2412 animatebutton->add(*icon);
2413 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2414 icon->set_padding(0,0);
2418 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2421 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2422 keyframebutton->remove();
2423 keyframebutton->add(*icon);
2424 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2425 icon->set_padding(0,0);
2428 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2431 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2432 keyframebutton->remove();
2433 keyframebutton->add(*icon);
2434 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2435 icon->set_padding(0,0);
2438 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2441 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2442 keyframebutton->remove();
2443 keyframebutton->add(*icon);
2444 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2445 icon->set_padding(0,0);
2448 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2451 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2452 keyframebutton->remove();
2453 keyframebutton->add(*icon);
2454 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2455 icon->set_padding(0,0);
2459 work_area->queue_draw();
2463 CanvasView::on_animate_button_pressed()
2465 if(get_mode()&synfigapp::MODE_ANIMATE)
2466 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2468 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2472 CanvasView::on_keyframe_button_pressed()
2474 synfigapp::CanvasInterface::Mode mode(get_mode());
2476 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2478 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2480 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2482 set_mode(get_mode()-synfigapp::MODE_ANIMATE_PAST|synfigapp::MODE_ANIMATE_FUTURE);
2484 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2486 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2488 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2490 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2495 CanvasView::duck_change_param(const Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2497 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2501 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2503 switch(value_desc.get_value_type())
2505 case ValueBase::TYPE_REAL:
2506 return canvas_interface()->change_value(value_desc,value.mag());
2508 case ValueBase::TYPE_ANGLE:
2509 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2512 return canvas_interface()->change_value(value_desc,value);
2520 CanvasView::selected_layer_color_set(Color color)
2522 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2523 synfigapp::SelectionManager::LayerList::iterator iter;
2525 // Create the action group
2526 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2528 Layer::Handle layer;
2529 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2534 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2539 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2544 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2548 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2551 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2553 Layer::Handle layer(*iter);
2555 if(selected_list.count(layer))
2557 if(!curr_transform_stack_set)
2559 curr_transform_stack_set=true;
2560 curr_transform_stack=transform_stack;
2563 // This layer is currently selected.
2564 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2566 // do the bounding box thing
2567 bbox|=transform_stack.perform(layer->get_bounding_rect());
2569 // Grab the layer's list pf parameters
2570 Layer::ParamList paramlist(layer->get_param_list());
2572 // Grab the layer vocabulary
2573 Layer::Vocab vocab=layer->get_param_vocab();
2574 Layer::Vocab::iterator iter;
2576 for(iter=vocab.begin();iter!=vocab.end();iter++)
2578 if(!iter->get_hidden() && !iter->get_invisible_duck())
2580 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2581 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2582 if(value_desc.is_value_node())
2583 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2585 if(iter->get_name()=="color")
2588 if(!App::dialog_color->busy())
2590 App::dialog_color->reset();
2591 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2592 App::dialog_color->signal_edited().connect(
2595 &studio::CanvasView::selected_layer_color_set
2604 layer_name=layer->get_name();
2608 Transform::Handle trans(layer->get_transform());
2611 transform_stack.push(trans);
2615 /* // Add transforms onto the stack
2616 if(layer_name=="Translate")
2618 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2621 if(layer_name=="Zoom")
2624 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2625 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2628 if(layer_name=="stretch")
2630 Vector scale(layer->get_param("amount").get(Vector()));
2631 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2634 if(layer_name=="Rotate")
2636 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2642 // If this is a paste canvas layer, then we need to
2644 if(layer_name=="PasteCanvas")
2647 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2648 Vector origin(layer->get_param("origin").get(Vector()));
2650 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2652 if(!scale.is_equal_to(Vector(1,1)))
2653 transform_stack.push(new Transform_Scale(scale,origin));
2654 if(!scale.is_equal_to(Vector(0,0)))
2655 transform_stack.push(new Transform_Translate(origin));
2657 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2659 if(!scale.is_equal_to(Vector(0,0)))
2660 transform_stack.pop();
2661 if(!scale.is_equal_to(Vector(1,1)))
2662 transform_stack.pop();
2665 // Remove all of the transforms we have added
2666 while(transforms--) { transform_stack.pop(); }
2668 #undef QUEUE_REBUILD_DUCKS
2672 CanvasView::queue_rebuild_ducks()
2675 if(rebuild_ducks_queued)
2678 if(rebuild_ducks_queued)
2679 queue_rebuild_ducks_connection.disconnect();
2682 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2684 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2690 rebuild_ducks_queued=true;
2694 CanvasView::rebuild_ducks()
2699 synfig::info("%d",i/(i-i));
2702 rebuild_ducks_queued=false;
2703 //queue_rebuild_ducks_connection.disconnect();
2705 if(work_area->is_dragging())
2707 queue_rebuild_ducks();
2711 if(!duck_refresh_flag)
2713 duck_refresh_needed=true;
2719 work_area->clear_ducks();
2720 work_area->set_time(get_time());
2721 get_canvas()->set_time(get_time());
2722 curr_transform_stack.clear();
2723 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2724 curr_transform_stack_set=false;
2726 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2728 //get_canvas()->set_time(get_time());
2729 bool not_empty(false);
2731 // First do the layers...
2733 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2734 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2736 if(!layer_set.empty())
2739 synfig::TransformStack transform_stack;
2741 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2745 // Now do the children
2747 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2748 synfigapp::SelectionManager::ChildrenList::iterator iter;
2749 synfig::TransformStack transform_stack;
2751 if(selected_list.empty())
2758 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2760 work_area->add_to_ducks(*iter,this,transform_stack);
2764 work_area->refresh_selected_ducks();
2765 work_area->queue_draw_preview();
2769 CanvasView::on_dirty_preview()
2773 IsWorking is_working(*this);
2775 work_area->queue_render_preview();
2782 assert(get_canvas());
2784 // If we are already busy, don't play!
2785 if(working_depth)return;
2787 // Set us up as working
2788 IsWorking is_working(*this);
2792 time=work_area->get_time(),
2793 endtime=get_canvas()->rend_desc().get_time_end();
2795 // If we are already at the end of time, start over
2797 time=get_canvas()->rend_desc().get_time_start();
2801 work_area->clear_ducks();
2803 for(timer.reset(); time + timer() < endtime;)
2805 //Clamp the time window so we can see the time value as it races across the horizon
2806 bool timewindreset = false;
2808 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
2810 time_window_adjustment().set_value(
2812 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
2813 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
2815 timewindreset = true;
2818 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
2820 time_window_adjustment().set_value(
2822 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
2823 time_window_adjustment().get_lower())
2826 timewindreset = true;
2829 //we need to tell people that the value changed
2830 if(timewindreset) time_window_adjustment().value_changed();
2832 //update actual time to next step
2833 time_adjustment().set_value(time+timer());
2834 time_adjustment().value_changed();
2836 if(!work_area->sync_render_preview())
2839 studio::App::iteration(false);
2841 if(get_cancel_status())
2846 time_adjustment().set_value(endtime);
2847 time_adjustment().value_changed();
2851 CanvasView::show_tables()
2854 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
2855 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2857 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2858 treetogglebutton->remove();
2859 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
2860 treetogglebutton->show_all();
2867 CanvasView::hide_tables()
2870 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
2871 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2873 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2874 treetogglebutton->remove();
2875 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
2876 treetogglebutton->show_all();
2883 CanvasView::tables_are_visible()
2885 // return notebook->is_visible();
2890 CanvasView::toggle_tables()
2892 // if(tables_are_visible())
2899 CanvasView::do_rotoscope_bline()
2901 smach_.enter(&state_bline);
2905 CanvasView::do_rotoscope()
2907 smach_.enter(&state_draw);
2911 CanvasView::do_rotoscope_poly()
2913 smach_.enter(&state_polygon);
2917 CanvasView::do_eyedrop()
2919 smach_.enter(&state_eyedrop);
2923 CanvasView::show_timebar()
2926 current_time_widget->show();
2928 //keyframe_tab_child->show();
2930 layer_tree->set_show_timetrack(true);
2932 children_tree->set_show_timetrack(true);
2936 CanvasView::hide_timebar()
2939 current_time_widget->hide();
2940 //keyframe_tab_child->hide();
2942 layer_tree->set_show_timetrack(false);
2944 children_tree->set_show_timetrack(false);
2950 CanvasView::on_waypoint_clicked(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint,int button)
2952 waypoint_dialog.set_value_desc(value_desc);
2953 waypoint_dialog.set_waypoint(waypoint);
2958 waypoint_dialog.show();
2962 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
2964 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-jump-to"),
2967 *canvas_interface(),
2968 &synfigapp::CanvasInterface::set_time
2974 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Edit Waypoint"),
2981 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-duplicate"),
2985 *canvas_interface(),
2986 &synfigapp::CanvasInterface::waypoint_duplicate
2993 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
2997 *canvas_interface(),
2998 &synfigapp::CanvasInterface::waypoint_remove
3005 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3014 CanvasView::on_waypoint_changed()
3016 synfigapp::Action::ParamList param_list;
3017 param_list.add("canvas",get_canvas());
3018 param_list.add("canvas_interface",canvas_interface());
3019 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3020 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3021 // param_list.add("time",canvas_interface()->get_time());
3023 get_instance()->process_action("waypoint_set_smart", param_list);
3027 CanvasView::on_waypoint_delete()
3029 synfigapp::Action::ParamList param_list;
3030 param_list.add("canvas",get_canvas());
3031 param_list.add("canvas_interface",canvas_interface());
3032 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3033 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3034 // param_list.add("time",canvas_interface()->get_time());
3036 get_instance()->process_action("waypoint_remove", param_list);
3040 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)
3042 // We will make this true once we have a solid drop
3043 bool success(false);
3044 //synfig::info("Droped data of type \"%s\"",selection_data.get_data_type());
3045 //synfig::info("Droped data of target \"%s\"",gdk_atom_name(selection_data->target));
3046 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3048 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3050 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3052 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3054 Layer::Handle layer(synfig::Layer::create("Text"));
3057 if(!layer->set_param("text",ValueBase(selection_data)))
3060 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3066 action->set_param("canvas",get_canvas());
3067 action->set_param("canvas_interface",canvas_interface());
3068 action->set_param("new",layer);
3070 if(!get_instance()->perform_action(action))
3073 // Ok, we have successfuly imported at least one item.
3075 } while(0); // END of "STRING"
3077 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3079 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3081 // For some reason, GTK hands us a list of URL's seperated
3082 // by not only Carrage-Returns, but also Line-Feeds.
3083 // Line-Feeds will mess us up. Remove all the line-feeds.
3084 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3085 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3087 std::stringstream stream(selection_data);
3089 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3092 synfig::String filename,URI;
3093 getline(stream,filename);
3095 // If we don't have a filename, move on.
3096 if(filename.empty())
3099 // Make sure this URL is of the "file://" type.
3100 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3103 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3107 // Strip the "file://" part from the filename
3108 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3111 try{ext=(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));}catch(...){continue;}
3113 // If this is a SIF file, then we need to do things slightly differently
3116 if(work_area->load_sketch(filename))
3119 work_area->queue_draw();
3124 if(canvas_interface()->import(filename))
3130 } // END of "text/plain"
3133 ui_interface_->error("Drop failed: bad selection data");
3136 context->drag_finish(success, false, time);
3140 CanvasView::on_keyframe_add_pressed()
3142 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3146 ui_interface_->error("I am unable to find the appropriate action");
3150 action->set_param("canvas",get_canvas());
3151 action->set_param("canvas_interface",canvas_interface());
3152 action->set_param("keyframe",Keyframe(get_time()));
3154 canvas_interface()->get_instance()->perform_action(action);
3158 CanvasView::on_keyframe_duplicate_pressed()
3160 const KeyframeTreeStore::Model model;
3161 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3165 ui_interface_->error("I am unable to duplicate the keyframe");
3168 keyframe=row[model.keyframe];
3170 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3174 ui_interface_->error("I am unable to find the appropriate action");
3178 action->set_param("canvas",get_canvas());
3179 action->set_param("canvas_interface",canvas_interface());
3180 action->set_param("keyframe",keyframe);
3181 action->set_param("time",get_time());
3183 canvas_interface()->get_instance()->perform_action(action);
3187 CanvasView::on_keyframe_remove_pressed()
3189 const KeyframeTreeStore::Model model;
3190 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3194 ui_interface_->error("I am unable to remove the keyframe");
3197 keyframe=row[model.keyframe];
3199 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3203 ui_interface_->error("I am unable to find the appropriate action");
3207 action->set_param("canvas",get_canvas());
3208 action->set_param("canvas_interface",canvas_interface());
3209 action->set_param("keyframe",keyframe);
3211 canvas_interface()->get_instance()->perform_action(action);
3216 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3218 bool is_currently_on(work_area->get_type_mask()&type);
3222 case Duck::TYPE_POSITION:
3223 if(duck_mask_position)
3224 duck_mask_position->set_active(!is_currently_on);
3227 case Duck::TYPE_VERTEX:
3228 if(duck_mask_vertex)
3229 duck_mask_vertex->set_active(!is_currently_on);
3232 case Duck::TYPE_TANGENT:
3233 if(duck_mask_tangent)
3234 duck_mask_tangent->set_active(!is_currently_on);
3237 case Duck::TYPE_RADIUS:
3238 if(duck_mask_radius)
3239 duck_mask_radius->set_active(!is_currently_on);
3242 case Duck::TYPE_WIDTH:
3244 duck_mask_width->set_active(!is_currently_on);
3247 case Duck::TYPE_ANGLE:
3249 duck_mask_angle->set_active(!is_currently_on);
3253 synfig::warning("CanvasView::toggle_duck_mask():Unknown duck type!");
3258 work_area->set_type_mask(work_area->get_type_mask()-type);
3260 work_area->set_type_mask(work_area->get_type_mask()|type);
3262 work_area->queue_draw();
3267 CanvasView::image_import()
3269 String filename(dirname(get_canvas()->get_file_name()));
3270 if(App::dialog_open_file(_("Import Image"), filename))
3271 canvas_interface()->import(filename);
3275 CanvasView::process_event_key(EventKey x)
3277 return smach_.process_event(x);
3281 CanvasView::on_input_device_changed(GdkDevice* device)
3285 get_smach().egress();
3289 synfigapp::InputDevice::Handle input_device;
3290 input_device=synfigapp::Main::select_input_device(device->name);
3291 App::toolbox->change_state(input_device->get_state());
3292 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3296 CanvasView::on_preview_option()
3298 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3300 Canvas::Handle canv = get_canvas();
3304 RendDesc &r = canv->rend_desc();
3305 if(r.get_frame_rate())
3307 float rate = 1/r.get_frame_rate();
3308 float beg = r.get_time_start() + r.get_frame_start()*rate;
3309 float end = r.get_time_start() + r.get_frame_end()*rate;
3313 po = new Dialog_PreviewOptions;
3314 po->set_zoom(work_area->get_zoom()/2);
3315 po->set_fps(r.get_frame_rate()/2);
3316 po->set_begintime(beg);
3317 po->set_begin_override(false);
3318 po->set_endtime(end);
3319 po->set_end_override(false);
3321 set_ext_widget("prevoptions",po);
3323 /*po->set_zoom(work_area->get_zoom()/2);
3324 po->set_fps(r.get_frame_rate()/2);
3325 po->set_begintime(beg);
3326 po->set_begin_override(false);
3327 po->set_endtime(end);
3328 po->set_end_override(false);*/
3330 po->set_global_fps(r.get_frame_rate());
3331 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3338 CanvasView::on_preview_create(const PreviewInfo &info)
3340 //set all the options
3341 etl::handle<Preview> prev = new Preview;
3343 prev->set_canvasview(this);
3344 prev->set_zoom(info.zoom);
3345 prev->set_fps(info.fps);
3346 prev->set_overbegin(info.overbegin);
3347 prev->set_begintime(info.begintime);
3348 prev->set_overend(info.overend);
3349 prev->set_endtime(info.endtime);
3350 prev->set_quality(work_area->get_quality());
3355 Dialog_Preview *pd = preview_dialog.get();
3358 pd->set_preview(prev.get());
3363 CanvasView::on_audio_option()
3365 synfig::warning("Launching Audio Options");
3366 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3367 sound_dialog->present();
3371 CanvasView::on_audio_file_change(const std::string &f)
3373 //save in meta data - always even when not valid...
3374 canvas_interface()->set_meta_data("audiofile",f);
3378 CanvasView::on_audio_offset_change(const Time &t)
3380 canvas_interface()->set_meta_data("audiooffset",t.get_string());
3384 CanvasView::on_audio_file_notify()
3386 std::string file(get_canvas()->get_meta_data("audiofile"));
3387 if(!file.c_str()) return;
3389 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3391 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3392 get_canvas()->erase_meta_data("audiofile");
3394 disp_audio->set_profile(etl::handle<AudioProfile>());
3397 //save in canvasview
3398 synfig::warning("Getting the profile of the music stuff");
3400 //profile specific stuff for the preview widget
3401 //similar for other attachments
3402 Dialog_Preview *pd = preview_dialog.get();
3403 pd->get_widget().set_audio(audio);
3405 handle<AudioProfile> prof = audio->get_profile();
3409 synfig::warning("Agh, I couldn't build the profile captain!");
3411 pd->get_widget().set_audioprofile(prof);
3413 disp_audio->set_profile(audio->get_profile());
3416 synfig::warning("successfully set the profiles and stuff");
3418 disp_audio->queue_draw();
3422 CanvasView::on_audio_offset_notify()
3424 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3425 audio->set_offset(t);
3426 sound_dialog->set_offset(t);
3427 disp_audio->queue_draw();
3429 synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3433 CanvasView::play_audio(float t)
3437 synfig::info("Playing audio at %f s",t);
3443 CanvasView::stop_audio()
3452 CanvasView::on_audio_scrub()
3460 Glib::RefPtr<Glib::ObjectBase>
3461 CanvasView::get_ref_obj(const synfig::String& x)
3463 return ref_obj_book_[x];
3466 Glib::RefPtr<const Glib::ObjectBase>
3467 CanvasView::get_ref_obj(const synfig::String& x)const
3469 return ref_obj_book_.find(x)->second;
3473 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3478 Glib::RefPtr<Gtk::TreeModel>
3479 CanvasView::get_tree_model(const synfig::String& x)
3481 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3484 Glib::RefPtr<const Gtk::TreeModel>
3485 CanvasView::get_tree_model(const synfig::String& x)const
3487 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3491 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3493 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3497 CanvasView::get_ext_widget(const synfig::String& x)
3499 return ext_widget_book_[x];
3503 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3505 ext_widget_book_[x]=y;
3508 layer_tree=dynamic_cast<LayerTree*>(y);
3510 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3511 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3512 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3513 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3514 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3518 children_tree=dynamic_cast<ChildrenTree*>(y);
3519 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3520 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3521 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3524 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3527 static bool _close_instance(etl::handle<Instance> instance)
3529 etl::handle<Instance> argh(instance);
3530 instance->safe_close();
3531 synfig::info("closed");
3536 CanvasView::on_delete_event(GdkEventAny* event)
3538 if(get_instance()->get_visible_canvases()==1)
3540 // Schedule a close to occur in a few moments
3541 Glib::signal_timeout().connect(
3543 sigc::ptr_fun(_close_instance),
3544 (etl::handle<Instance>)get_instance()
3550 return Gtk::Window::on_delete_event(event);