1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasview.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include <sigc++/adaptors/hide.h>
37 #include <gtkmm/paned.h>
38 #include <gtkmm/scale.h>
39 #include <gtkmm/dialog.h>
40 #include <gtkmm/messagedialog.h>
41 #include <gtkmm/treemodelsort.h>
42 #include <gtkmm/buttonbox.h>
44 #include <gtk/gtktreestore.h>
45 #include <gtk/gtkversion.h>
47 #include <synfig/valuenode_reference.h>
48 #include <synfig/valuenode_subtract.h>
49 #include <synfig/valuenode_linear.h>
50 #include <synfig/valuenode_timedswap.h>
51 #include <synfig/valuenode_scale.h>
52 #include <synfig/valuenode_dynamiclist.h>
53 #include <synfig/valuenode_twotone.h>
54 #include <synfig/valuenode_stripes.h>
55 #include <synfig/layer.h>
57 #include <synfigapp/uimanager.h>
58 #include <synfigapp/canvasinterface.h>
59 #include <synfigapp/selectionmanager.h>
60 //#include <synfigapp/action_setwaypoint.h>
61 //#include <synfigapp/action_deletewaypoint.h>
63 #include <sigc++/retype_return.h>
64 #include <sigc++/retype.h>
65 //#include <sigc++/hide.h>
67 #include "canvasview.h"
70 #include "cellrenderer_value.h"
71 #include "cellrenderer_timetrack.h"
73 #include "dialog_color.h"
76 #include "state_polygon.h"
77 #include "state_bline.h"
78 #include "state_normal.h"
79 #include "state_eyedrop.h"
80 #include "state_draw.h"
82 #include "ducktransform_scale.h"
83 #include "ducktransform_translate.h"
84 #include "ducktransform_rotate.h"
86 #include "event_mouse.h"
87 #include "event_layerclick.h"
91 #include "dialog_preview.h"
92 #include "dialog_soundselect.h"
95 #include "audiocontainer.h"
96 #include "widget_timeslider.h"
98 #include <synfigapp/main.h>
99 #include <synfigapp/inputdevice.h>
103 /* === U S I N G =========================================================== */
107 using namespace synfig;
108 using namespace studio;
109 using namespace SigC;
111 /* === M A C R O S ========================================================= */
113 #define GRAB_HINT_DATA(y) { \
115 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
117 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
121 #define DEFAULT_TIME_WINDOW_SIZE (10.0)
131 #define SMALL_BUTTON(button,stockid,tooltip) \
132 button = manage(new class Gtk::Button()); \
133 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
134 button->add(*icon); \
135 tooltips.set_tip(*button,tooltip); \
136 icon->set_padding(0,0);\
138 button->set_relief(Gtk::RELIEF_NONE); \
142 #ifndef NORMAL_BUTTON
143 #define NORMAL_BUTTON(button,stockid,tooltip) \
144 button = manage(new class Gtk::Button()); \
145 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
146 button->add(*icon); \
147 tooltips.set_tip(*button,tooltip); \
148 icon->set_padding(0,0);\
150 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
154 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
156 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
158 #define SLOT_EVENT(x) sigc::hide_return(sigc::bind(sigc::mem_fun(*this,&studio::CanvasView::process_event_key),x))
160 /* === C L A S S E S ======================================================= */
163 class studio::UniversalScrubber
165 CanvasView *canvas_view;
168 etl::clock scrub_timer;
170 sigc::connection end_scrub_connection;
172 UniversalScrubber(CanvasView *canvas_view):
173 canvas_view(canvas_view),
176 canvas_view->canvas_interface()->signal_time_changed().connect(
177 sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
183 end_scrub_connection.disconnect();
186 void on_time_changed()
188 // Make sure we are changing the time quickly
189 // before we enable scrubbing
190 if(!scrubbing && scrub_timer()>1)
196 // If we aren't scrubbing already, enable it
200 audio_container()->start_scrubbing(canvas_view->get_time());
203 // Reset the scrubber ender
204 end_scrub_connection.disconnect();
205 end_scrub_connection=Glib::signal_timeout().connect(
207 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
214 audio_container()->scrub(canvas_view->get_time());
219 void end_of_scrubbing()
222 audio_container()->stop_scrubbing();
226 handle<AudioContainer> audio_container()
228 assert(canvas_view->audio);
229 return canvas_view->audio;
234 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
240 CanvasViewUIInterface(CanvasView *view):
244 view->statusbar->push("Idle");
247 ~CanvasViewUIInterface()
249 //view->statusbar->pop();
250 //view->progressbar->set_fraction(0);
253 virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
256 //while(studio::App::events_pending())studio::App::iteration(false);
261 true // use_separator
263 Gtk::Label label(message);
266 dialog.get_vbox()->pack_start(label);
267 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
268 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
270 dialog.set_default_response(dflt);
272 return (Response)dialog.run();
274 virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
277 //while(studio::App::events_pending())studio::App::iteration(false);
282 true // use_separator
284 Gtk::Label label(message);
287 dialog.get_vbox()->pack_start(label);
288 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
289 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
290 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
292 dialog.set_default_response(dflt);
294 return (Response)dialog.run();
296 virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
299 //while(studio::App::events_pending())studio::App::iteration(false);
304 true // use_separator
306 Gtk::Label label(message);
309 dialog.get_vbox()->pack_start(label);
310 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
311 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
313 dialog.set_default_response(dflt);
315 return (Response)dialog.run();
319 task(const std::string &task)
321 if(!view->is_playing_)
323 view->statusbar->pop();
324 view->statusbar->push(task);
326 //while(studio::App::events_pending())studio::App::iteration(false);
327 if(view->cancel){return false;}
332 error(const std::string &err)
334 view->statusbar->push("ERROR");
336 // If we are in the process of canceling,
337 // then just go ahead and return false --
338 // don't bother displaying a dialog
339 if(view->cancel)return false;
340 Gtk::MessageDialog dialog(*view, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
343 view->statusbar->pop();
348 warning(const std::string &err)
350 view->statusbar->pop();
351 view->statusbar->push(err);
353 //while(studio::App::events_pending())studio::App::iteration(false);
354 if(view->cancel)return false;
359 amount_complete(int current, int total)
361 if(!view->is_playing_)
363 if(!view->working_depth)
366 view->stopbutton->set_sensitive(true);
368 view->stopbutton->set_sensitive(false);
370 float x((float)current/(float)total);
373 view->progressbar->set_fraction(x);
375 //while(studio::App::events_pending())studio::App::iteration(false);
376 if(view->cancel){/*view->cancel=false;*/return false;}
383 error("Feature not yet implemented");
387 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
390 CanvasView::LayerTreeModel layer_tree_model;
391 CanvasView::ChildrenTreeModel children_tree_model;
394 CanvasViewSelectionManager(CanvasView *view): view(view)
401 void _set_selected_layer(const synfig::Layer::Handle &layer)
403 view->layer_tree->select_layer(layer);
405 // Don't change the selection while we are busy
406 // I cannot remember exactly why I put this here...
407 // It musta been for some reason, but I cannot recall.
408 //if(App::Busy::count)
411 if(view->layer_tree->get_selection()->get_selected())
413 const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
415 // Don't do anything if that layer is already selected
416 if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
419 Gtk::TreeModel::Children::iterator iter;
420 if(view->layer_tree_store()->find_layer_row(layer,iter))
422 Gtk::TreePath path(iter);
423 for(int i=path.get_depth();i;i--)
426 path=Gtk::TreePath(iter);
429 view->layer_tree->get_tree_view().expand_row(path,false);
431 view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
432 view->layer_tree->get_selection()->select(iter);
438 //! Returns the number of layers selected.
439 virtual int get_selected_layer_count()const
441 return get_selected_layers().size();
444 //! Returns a list of the currently selected layers.
445 virtual LayerList get_selected_layers()const
447 // assert(view->layer_tree);
449 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return LayerList(); }
450 return view->layer_tree->get_selected_layers();
453 //! Returns the first layer selected or an empty handle if none are selected.
454 virtual synfig::Layer::Handle get_selected_layer()const
456 // assert(view->layer_tree);
458 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return 0; }
459 return view->layer_tree->get_selected_layer();
462 //! Sets which layers should be selected
463 virtual void set_selected_layers(const LayerList &layer_list)
465 // assert(view->layer_tree);
467 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return; }
468 view->layer_tree->select_layers(layer_list);
469 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
471 //view->queue_rebuild_ducks();
474 //! Sets which layer should be selected.
475 virtual void set_selected_layer(const synfig::Layer::Handle &layer)
477 // assert(view->layer_tree);
479 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return; }
480 view->layer_tree->select_layer(layer);
481 //view->queue_rebuild_ducks();
484 //! Clears the layer selection list
485 virtual void clear_selected_layers()
487 if(!view->layer_tree) return;
488 view->layer_tree->clear_selected_layers();
493 //! Returns the number of value_nodes selected.
494 virtual int get_selected_children_count()const
496 return get_selected_children().size();
499 static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
501 const CanvasView::ChildrenTreeModel children_tree_model;
502 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
504 ret->push_back(value_desc);
507 //! Returns a list of the currently selected value_nodes.
508 virtual ChildrenList get_selected_children()const
510 if(!view->children_tree) return ChildrenList();
512 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
515 return ChildrenList();
519 selection->selected_foreach_iter(
522 &studio::CanvasViewSelectionManager::__child_grabber
529 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
531 Gtk::TreeModel::Children children = iter->children();
532 for(iter = children.begin(); iter != children.end(); ++iter)
534 Gtk::TreeModel::Row row = *iter;
535 if(selection->is_selected(row))
536 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
542 //! Returns the first value_node selected or an empty handle if none are selected.
543 virtual ChildrenList::value_type get_selected_child()const
545 if(!view->children_tree) return ChildrenList::value_type();
547 ChildrenList children(get_selected_children());
550 return ChildrenList::value_type();
552 return children.front();
555 //! Sets which value_nodes should be selected
556 virtual void set_selected_children(const ChildrenList &children_list)
561 //! Sets which value_node should be selected. Empty handle if none.
562 virtual void set_selected_child(const ChildrenList::value_type &child)
567 //! Clears the value_node selection list
568 virtual void clear_selected_children()
575 int get_selected_layer_parameter_count()const
577 return get_selected_layer_parameters().size();
580 LayerParamList get_selected_layer_parameters()const
582 if(!view->layer_tree) return LayerParamList();
584 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
587 return LayerParamList();
591 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
592 Gtk::TreeModel::Children::iterator iter;
593 for(iter = children.begin(); iter != children.end(); ++iter)
595 Gtk::TreeModel::Row row = *iter;
596 Gtk::TreeModel::Children::iterator iter;
597 for(iter=row.children().begin();iter!=row.children().end();iter++)
599 Gtk::TreeModel::Row row = *iter;
600 if(selection->is_selected(row))
601 ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
607 LayerParam get_selected_layer_parameter() const
609 if(!view->layer_tree) return LayerParam();
610 return get_selected_layer_parameters().front();
613 void set_selected_layer_parameters(const LayerParamList &layer_param_list)
618 void set_selected_layer_param(const LayerParam &layer_param)
623 void clear_selected_layer_parameters()
628 }; // END of class SelectionManager
631 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
632 canvas_view_(canvas_view_)
634 if(!canvas_view_.working_depth)
635 canvas_view_.stopbutton->set_sensitive(true);
636 canvas_view_.working_depth++;
637 canvas_view_.cancel=false;
640 CanvasView::IsWorking::~IsWorking()
642 canvas_view_.working_depth--;
643 if(!canvas_view_.working_depth)
644 canvas_view_.stopbutton->set_sensitive(false);
647 CanvasView::IsWorking::operator bool()const
649 if(canvas_view_.cancel)
654 /* === M E T H O D S ======================================================= */
656 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
658 instance_ (instance),
659 canvas_interface_ (canvas_interface_),
660 //layer_tree_store_ (LayerTreeStore::create(canvas_interface_)),
661 //children_tree_store_ (ChildrenTreeStore::create(canvas_interface_)),
662 //keyframe_tree_store_ (KeyframeTreeStore::create(canvas_interface_)),
663 time_adjustment_ (0,0,25,0,0,0),
664 time_window_adjustment_ (0,0,25,0,0,0),
665 statusbar (manage(new class Gtk::Statusbar())),
667 timeslider (new Widget_Timeslider),
669 ui_interface_ (new CanvasViewUIInterface(this)),
670 selection_manager_ (new CanvasViewSelectionManager(this)),
676 canvas_properties (*this,canvas_interface_),
677 canvas_options (this),
678 render_settings (*this,canvas_interface_),
679 waypoint_dialog (*this,canvas_interface_->get_canvas()),
680 keyframe_dialog (*this,canvas_interface_),
681 preview_dialog (new Dialog_Preview),
682 sound_dialog (new Dialog_SoundSelect(*this,canvas_interface_))
686 duck_refresh_flag=true;
688 smach_.set_default_state(&state_normal);
690 disp_audio = new Widget_Sound();
692 //synfig::info("Canvasview: Entered constructor");
694 get_canvas()->set_time(0);
695 //layer_tree_store_->rebuild();
697 // Set up the UI and Selection managers
698 canvas_interface()->set_ui_interface(get_ui_interface());
699 canvas_interface()->set_selection_manager(get_selection_manager());
700 rebuild_ducks_queued=false;
702 //notebook=manage(new class Gtk::Notebook());
703 //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
704 //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
705 //vpaned->pack2(*notebook, Gtk::SHRINK);
706 //vpaned->show_all();
711 //notebook->append_page(*create_layer_tree(),"Layers");
712 //notebook->append_page(*create_children_tree(),"Children");
713 //notebook->append_page(*create_keyframe_tree(),"Keyframes");
715 //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
716 //create all allocated stuff for this canvas
717 audio = new AudioContainer();
719 Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
720 //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
721 layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
723 //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
726 layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
727 layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
731 layout_table->show();
734 //set_transient_for(*App::toolbox);
736 //synfig::info("Canvasview: Before Signals");
738 -- ** -- Signals -------------------------------------------------------------
741 canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
742 canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
744 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
746 //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
747 canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
748 canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
749 waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
750 waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
752 //MODIFIED TIME ADJUSTMENT STUFF....
753 time_window_adjustment().set_child_adjustment(&time_adjustment());
754 time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
755 time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
758 work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
759 work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
761 canvas_interface()->signal_canvas_added().connect(
763 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
766 canvas_interface()->signal_canvas_removed().connect(
768 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
772 canvas_interface()->signal_layer_param_changed().connect(
775 SLOT_EVENT(EVENT_REFRESH_DUCKS)
781 //MUCH TIME STUFF TAKES PLACE IN HERE
783 refresh_time_window();
785 /*! \todo We shouldn't need to do this at construction --
786 ** This should be preformed at the first time the window
789 work_area->queue_render_preview();
791 // If the canvas is really big, zoom out so that we can fit it all in the window
792 /*! \todo In other words, this is a zoom-to-fit, and should be
793 ** in it's own function.
795 int w=get_canvas()->rend_desc().get_w()+70;
796 int h=get_canvas()->rend_desc().get_h()+70;
797 while(w>700 || h>600)
799 work_area->zoom_out();
800 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
801 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
805 set_default_size(w,h);
806 property_window_position().set_value(Gtk::WIN_POS_NONE);
811 std::list<Gtk::TargetEntry> listTargets;
812 listTargets.push_back( Gtk::TargetEntry("STRING") );
813 listTargets.push_back( Gtk::TargetEntry("text/plain") );
814 listTargets.push_back( Gtk::TargetEntry("image") );
816 drag_dest_set(listTargets);
817 signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
821 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
824 time_window_adjustment().set_page_increment(length);
825 time_window_adjustment().set_page_size(length);
829 time_window_adjustment().set_page_increment(10.0);
830 time_window_adjustment().set_page_size(10.0);
834 //synfig::info("Canvasview: Before Sound Hookup");
835 //load sound info from meta data
837 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
839 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
840 on_audio_offset_notify();
842 //signal connection - since they are all associated with the canvas view
844 //hook in signals for sound options box
845 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
846 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
848 //attach to the preview when it's visible
849 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
850 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
852 //hook to metadata signals
853 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
854 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
856 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
859 //synfig::info("Canvasview: Before Final time set up");
861 time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
862 time_window_adjustment().value_changed();
865 GRAB_HINT_DATA("canvas_view");
868 set_skip_taskbar_hint(true);
869 set_skip_pager_hint(true);
870 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
878 //synfig::info("Canvasview: Constructor Done");
881 CanvasView::~CanvasView()
885 App::ui_manager()->remove_action_group(action_group);
887 // Shut down the smach
889 smach_.set_default_state(0);
891 // We want to ensure that the UI_Manager and
892 // the selection manager get destructed right now.
893 ui_interface_.reset();
894 selection_manager_.reset();
896 // Delete any external widgets
897 for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
899 if(ext_widget_book_.begin()->second)
900 delete ext_widget_book_.begin()->second;
908 synfig::info("CanvasView:~CanvasView(): Destructor Finished");
914 CanvasView::create_time_bar()
918 Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
919 //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
920 //TIME BAR TEMPORARY POSITION
921 //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
923 timeslider->set_time_adjustment(&time_adjustment());
924 timeslider->set_bounds_adjustment(&time_window_adjustment());
925 //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
928 tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
929 tooltips.set_tip(*timeslider,_("Changes the current time"));
930 time_window_scroll->show();
932 time_window_scroll->set_flags(Gtk::CAN_FOCUS);
933 timeslider->set_flags(Gtk::CAN_FOCUS);
935 //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
936 //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
938 NORMAL_BUTTON(animatebutton,"gtk-yes","Animate");
939 animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
940 animatebutton->show();
942 NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all","All Keyframes Locked");
943 keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
944 keyframebutton->show();
946 Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
948 //setup the audio display
949 disp_audio->set_size_request(-1,32); //disp_audio.show();
950 disp_audio->set_time_adjustment(&time_adjustment());
951 disp_audio->signal_start_scrubbing().connect(
952 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
954 disp_audio->signal_scrub().connect(
955 sigc::mem_fun(*audio,&AudioContainer::scrub)
957 disp_audio->signal_stop_scrubbing().connect(
958 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
961 table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
962 table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
963 table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
965 table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
966 table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
973 CanvasView::create_work_area()
975 work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
976 work_area->set_instance(get_instance());
977 work_area->set_canvas(get_canvas());
978 work_area->set_canvas_view(this);
979 work_area->set_progress_callback(get_ui_interface().get());
980 work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
982 return work_area.get();
987 CanvasView::create_status_bar()
990 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
993 // Create the status bar at the bottom of the window
994 Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
995 // statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
996 progressbar =manage(new class Gtk::ProgressBar());
997 SMALL_BUTTON(stopbutton,"gtk-stop","Stop");
998 SMALL_BUTTON(refreshbutton,"gtk-refresh","Refresh");
999 //SMALL_BUTTON(treetogglebutton,"gtk-go-down","Toggle Layer Tree");
1000 // NEW_SMALL_BUTTON(raisebutton,"gtk-go-up","Raise Layer");
1001 // NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down","Lower Layer");
1002 //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1003 // statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1004 // statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1007 current_time_widget=manage(new Widget_Time);
1008 current_time_widget->set_value(get_time());
1009 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1010 current_time_widget->signal_value_changed().connect(
1011 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1014 statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1015 statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1016 statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1017 statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1018 statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1019 statusbar->set_has_resize_grip(false);
1022 refreshbutton->show();
1023 progressbar->show();
1024 stopbutton->set_sensitive(false);
1026 //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1027 //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1028 //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1030 refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1031 stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1034 statusbartable->show_all();
1035 return statusbartable;
1039 CanvasView::on_current_time_widget_changed()
1041 set_time(current_time_widget->get_value());
1045 CanvasView::create_children_tree()
1047 // Create the layer tree
1048 children_tree=manage(new class ChildrenTree());
1050 // Set up the layer tree
1051 //children_tree->set_model(children_tree_store());
1052 if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1053 if(children_tree)children_tree->show();
1056 if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1057 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1058 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1059 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1061 return children_tree;
1065 CanvasView::create_keyframe_tree()
1067 keyframe_tree=manage(new KeyframeTree());
1069 //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1070 //keyframe_tree->show();
1071 //keyframe_tree->set_model(keyframe_tree_store());
1072 keyframe_tree->set_editable(true);
1073 //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1075 keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1077 Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1078 scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1079 scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1080 scroll_layer_tree->add(*keyframe_tree);
1081 scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1082 //scroll_layer_tree->show();
1085 Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1086 layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1089 Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1091 NEW_SMALL_BUTTON(button_add,"gtk-add","New Keyframe");
1092 NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate Keyframe");
1093 NEW_SMALL_BUTTON(button_delete,"gtk-delete","Delete Keyframe");
1095 Gtk::HBox *hbox(manage(new Gtk::HBox()));
1096 layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1098 hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1099 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1100 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1103 button_raise->set_relief(Gtk::RELIEF_HALF);
1104 button_lower->set_relief(Gtk::RELIEF_HALF);
1105 button_duplicate->set_relief(Gtk::RELIEF_HALF);
1106 button_delete->set_relief(Gtk::RELIEF_HALF);
1109 button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1110 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1111 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1113 //layout_table->show_all();
1115 keyframe_tab_child=layout_table;
1118 layout_table->hide();
1120 return layout_table;
1124 CanvasView::create_layer_tree()
1126 // Create the layer tree
1127 layer_tree=manage(new class LayerTree());
1129 // Set up the layer tree
1130 //layer_tree->set_model(layer_tree_store());
1131 layer_tree->set_time_adjustment(time_adjustment());
1135 layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1136 layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1137 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1138 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1139 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1140 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1147 CanvasView::init_menus()
1150 mainmenu.set_accel_group(get_accel_group());
1151 mainmenu.set_accel_path("<Canvas-view>");
1153 filemenu.set_accel_group(get_accel_group());
1154 filemenu.set_accel_path("<Canvas-view>/File");
1156 editmenu.set_accel_group(get_accel_group());
1157 editmenu.set_accel_path("<Canvas-view>/Edit");
1159 layermenu.set_accel_group(get_accel_group());
1160 layermenu.set_accel_path("<Canvas-view>/Layer");
1162 //cache the position of desired widgets
1164 /*Menus to worry about:
1173 action_group = Gtk::ActionGroup::create();
1175 //action_group->add( Gtk::Action::create("MenuFile", "_File") );
1176 action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1177 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1179 action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1180 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1182 action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1183 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1185 action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1186 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1188 action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1189 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1191 action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1192 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1194 action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1195 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1197 action_group->add( Gtk::Action::create("import", _("Import")),
1198 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1200 action_group->add( Gtk::Action::create("render", _("Render")),
1201 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1203 action_group->add( Gtk::Action::create("preview", _("Preview")),
1204 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1206 action_group->add( Gtk::Action::create("sound", _("Sound File")),
1207 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1209 action_group->add( Gtk::Action::create("options", _("Options")),
1210 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1212 action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close")),
1213 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))
1216 //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1217 // SLOT_EVENT(EVENT_UNDO)
1220 //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1221 // SLOT_EVENT(EVENT_REDO)
1224 action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1225 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1228 action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1229 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1232 action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1233 SLOT_EVENT(EVENT_STOP)
1236 action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1237 SLOT_EVENT(EVENT_REFRESH)
1240 action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1241 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1244 // Preview Quality Menu
1247 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1249 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1255 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i), strprintf("Set Quality to %d",i)));
1257 action->property_value()=10;
1258 action_group->add( action,
1260 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1267 action_group->add( Gtk::Action::create("play", Gtk::StockID("synfig-play")),
1268 sigc::mem_fun(*this, &studio::CanvasView::play)
1271 action_group->add( Gtk::Action::create("dialog-flipbook", _("Flipbook Dialog")),
1272 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1275 action_group->add( Gtk::Action::create("toggle-grid-show", _("Toggle Grid Show")),
1276 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)
1278 action_group->add( Gtk::Action::create("toggle-grid-snap", _("Toggle Grid Snap")),
1279 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)
1281 action_group->add( Gtk::Action::create("toggle-guide-show", _("Toggle Guide Show")),
1282 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)
1284 action_group->add( Gtk::Action::create("toggle-low-res", _("Toggle Low-Res")),
1285 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)
1287 action_group->add( Gtk::Action::create("toggle-onion-skin", _("Toggle Onion Skin")),
1288 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_onion_skin)
1292 action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1293 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1295 action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1296 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1301 Glib::RefPtr<Gtk::Action> action;
1303 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1304 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1305 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1306 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1308 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Foward"),_("Seek Foward"));
1309 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1310 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1311 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1315 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1316 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1318 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1319 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1321 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1322 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1324 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1325 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1327 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1328 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1330 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1331 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1333 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1334 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1336 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1337 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1342 #define DUCK_MASK(lower,upper) \
1343 duck_mask_##lower=Gtk::ToggleAction::create("mask-" #lower "-ducks", _("Show "#lower" ducks")); \
1344 duck_mask_##lower->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper)); \
1345 action_group->add( duck_mask_##lower, \
1347 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask), \
1348 Duck::TYPE_##upper \
1351 DUCK_MASK(position,POSITION);
1352 DUCK_MASK(tangent,TANGENT);
1353 DUCK_MASK(vertex,VERTEX);
1354 DUCK_MASK(radius,RADIUS);
1355 DUCK_MASK(width,WIDTH);
1356 DUCK_MASK(angle,ANGLE);
1359 add_accel_group(App::ui_manager()->get_accel_group());
1361 /* // Here is where we add the actions that may have conflicting
1362 // keyboard accelerators.
1364 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1365 Glib::RefPtr<Gtk::Action> action;
1367 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1368 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1370 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1371 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1373 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1374 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1376 action=Gtk::Action::create("jump-prev-keyframe", Gtk::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1377 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1379 action=Gtk::Action::create("canvas-zoom-in", Gtk::StockID("gtk-zoom-in"));
1380 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1382 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1383 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1385 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1386 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1388 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1389 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1391 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1393 Glib::ustring ui_info =
1396 <accelerator action='seek-next-frame' />
1397 <accelerator action='seek-prev-frame' />
1398 <accelerator action='jump-next-keyframe' />
1399 <accelerator action='jump-prev-keyframe' />
1400 <accelerator action='canvas-zoom-in' />
1401 <accelerator action='canvas-zoom-out' />
1402 <accelerator action='time-zoom-in' />
1403 <accelerator action='time-zoom-out' />
1407 accel_ui_manager->add_ui_from_string(ui_info);
1408 add_accel_group(accel_ui_manager->get_accel_group());
1410 accel_ui_manager->insert_action_group(accel_action_group);
1411 set_ref_obj("accel_ui_manager",accel_ui_manager);
1412 set_ref_obj("accel_action_group",accel_action_group);
1420 //Test some key stuff
1422 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1423 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1424 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))));
1425 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))));
1426 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1428 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))));
1429 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))));
1430 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))));
1432 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1433 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))));
1434 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1435 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1436 sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1438 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1439 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1441 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1442 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1445 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1446 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1447 sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1449 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1450 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))));
1452 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1453 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1454 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1455 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1456 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1457 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1458 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1459 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)));
1460 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)));
1461 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1463 //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))));
1464 //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))));
1465 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)));
1466 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1467 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1468 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rotoscope_bline"),
1469 sigc::mem_fun(*this, &studio::CanvasView::do_rotoscope_bline)));
1470 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rotoscope_polygon"),
1471 sigc::mem_fun(*this, &studio::CanvasView::do_rotoscope_poly)));
1472 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-eyedrop"),
1473 sigc::mem_fun(*this, &studio::CanvasView::do_eyedrop)));
1474 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1475 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1476 sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1479 build_new_layer_menu(newlayermenu);
1480 layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New",newlayermenu));
1484 synfigapp::Action::ParamList param_list;
1485 param_list.add("canvas",Canvas::Handle(get_canvas()));
1486 param_list.add("canvas_interface",canvas_interface());
1487 add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1491 //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Keyframe Dialog",sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1496 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1498 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1499 duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1500 duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1501 duck_mask_position->signal_toggled().connect(
1503 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1508 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1509 duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1510 duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1511 duck_mask_vertex->signal_toggled().connect(
1513 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1518 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1519 duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1520 duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1521 duck_mask_tangent->signal_toggled().connect(
1523 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1528 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1529 duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1530 duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1531 duck_mask_radius->signal_toggled().connect(
1533 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1538 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1539 duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1540 duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1541 duck_mask_width->signal_toggled().connect(
1543 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1548 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1549 duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1550 duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1551 duck_mask_angle->signal_toggled().connect(
1553 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1558 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1561 // Preview Quality Menu
1564 qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1566 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1568 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1574 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1576 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1581 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1584 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-play"),
1585 sigc::mem_fun(*this, &studio::CanvasView::play)));
1586 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1587 sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1589 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1591 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1592 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1593 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1594 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1595 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1596 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1597 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1598 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1600 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1602 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1603 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1604 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1605 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1606 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1607 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1608 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1609 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
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(*this, &studio::CanvasView::time_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(*this, &studio::CanvasView::time_zoom_out)));
1617 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1618 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1619 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1620 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1622 mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1623 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_File",filemenu));
1624 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Edit",editmenu));
1625 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_View",viewmenu));
1626 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Canvas",canvasmenu));
1627 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Layer",layermenu));
1629 mainmenu.accelerate(*this);
1633 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Waypoint",NOT_IMPLEMENTED_SLOT));
1634 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete Waypoint",NOT_IMPLEMENTED_SLOT));
1635 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Export",NOT_IMPLEMENTED_SLOT));
1636 trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1637 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Properties",NOT_IMPLEMENTED_SLOT));
1645 keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1646 sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1650 get_accel_group()->unlock();
1652 //Set the accelerator paths for all the menus
1653 filemenu.set_accel_path("<synfig>/File");
1654 editmenu.set_accel_path("<synfig>/Edit");
1655 layermenu.set_accel_path("<synfig>/Layer");
1656 //mainmenu.set_accel_path("<synfig-main>");
1657 canvasmenu.set_accel_path("<synfig>/Canvas");
1658 viewmenu.set_accel_path("<synfig>/View");
1659 duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1664 CanvasView::on_unselect_layers()
1666 layer_tree->clear_selected_layers();
1670 CanvasView::show_keyframe_dialog()
1672 Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
1673 if(selection->get_selected())
1675 Gtk::TreeRow row(*selection->get_selected());
1677 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
1679 keyframe_dialog.set_keyframe(keyframe);
1680 keyframe_dialog.present();
1685 CanvasView::add_layer(synfig::String x)
1687 Canvas::Handle canvas;
1689 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1691 int target_depth(0);
1693 if(layer_list.empty())
1695 canvas=get_canvas();
1699 canvas=(*layer_list.begin())->get_canvas();
1700 target_depth=canvas->get_depth(*layer_list.begin());
1704 Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
1707 get_selection_manager()->clear_selected_layers();
1708 get_selection_manager()->set_selected_layer(layer);
1713 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
1715 //Gtk::Menu* menu(manage(new Gtk::Menu));
1716 Gtk::Menu* menu(¶mmenu);
1717 menu->items().clear();
1719 synfigapp::Action::ParamList param_list;
1720 param_list.add("time",canvas_interface()->get_time());
1721 param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
1722 param_list.add("canvas_interface",canvas_interface());
1723 param_list.add("layer",layer);
1725 //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
1726 //build_new_layer_menu(*newlayers);
1728 //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
1730 if(layer->get_name()=="PasteCanvas")
1732 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
1736 &studio::LayerTree::select_all_children_layers
1743 add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
1745 menu->popup(3,gtk_get_current_event_time());
1749 CanvasView::register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>* category_map)
1751 /* if(lyr.second.category==_("Do Not Use"))
1754 if(category_map->count(lyr.second.category)==0)
1755 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
1757 (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
1760 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
1769 CanvasView::build_new_layer_menu(Gtk::Menu &menu)
1772 std::map<synfig::String,Gtk::Menu*> category_map;
1775 synfig::Layer::book().begin(),
1776 synfig::Layer::book().end(),
1780 &studio::CanvasView::register_layer_type
1786 menu.items().clear();
1787 menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1789 std::map<synfig::String,Gtk::Menu*>::iterator iter;
1790 for(iter=category_map.begin();iter!=category_map.end();++iter)
1791 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
1798 CanvasView::popup_main_menu()
1800 //mainmenu.popup(0,gtk_get_current_event_time());
1801 Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
1804 //menu->set_accel_group(App::ui_manager()->get_accel_group());
1805 //menu->accelerate(*this);
1806 menu->popup(0,gtk_get_current_event_time());
1811 CanvasView::on_refresh_pressed()
1815 work_area->queue_render_preview();
1819 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
1821 get_selection_manager()->clear_selected_layers();
1823 get_selection_manager()->set_selected_layer(layer);
1828 CanvasView::refresh_rend_desc()
1830 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1834 //synfig::info("Canvasview: Refreshing render desc info");
1835 if(!get_time().is_equal(time_adjustment().get_value()))
1837 time_adjustment().set_value(get_time());
1838 time_adjustment().value_changed();
1841 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1842 if(length<DEFAULT_TIME_WINDOW_SIZE)
1844 time_window_adjustment().set_page_increment(length);
1845 time_window_adjustment().set_page_size(length);
1849 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
1850 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
1853 //set the FPS of the timeslider
1854 timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
1856 //set the beginning and ending time of the time slider
1857 Time begin_time=get_canvas()->rend_desc().get_time_start();
1858 Time end_time=get_canvas()->rend_desc().get_time_end();
1860 // Setup the time_window adjustment
1861 time_window_adjustment().set_lower(begin_time);
1862 time_window_adjustment().set_upper(end_time);
1863 time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1865 //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1866 if(length < time_window_adjustment().get_page_size())
1868 time_window_adjustment().set_page_increment(length);
1869 time_window_adjustment().set_page_size(length);
1872 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1873 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1874 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1875 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1878 time_window_adjustment().changed(); //only non-value stuff was changed
1880 // Setup the time adjustment
1882 //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
1883 //time_adjustment().set_lower(time_window_adjustment().get_value());
1884 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
1886 // time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
1887 // time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
1888 time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1889 time_adjustment().set_page_increment(synfig::Time(1.0));
1890 time_adjustment().set_page_size(0);
1892 time_adjustment().changed();
1894 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1895 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1896 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1897 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1900 if(begin_time==end_time)
1909 //clamp time to big bounds...
1910 if(time_adjustment().get_value() < begin_time)
1912 time_adjustment().set_value(begin_time);
1913 time_adjustment().value_changed();
1916 if(time_adjustment().get_value() > end_time)
1918 time_adjustment().set_value(end_time);
1919 time_adjustment().value_changed();
1922 /*synfig::info("Time stats: \n"
1923 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
1924 "t: %p - [%.3f,%.3f] %.3f",
1925 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1926 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1927 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
1928 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
1929 time_adjustment_.get_value()
1932 work_area->queue_render_preview();
1939 get_instance()->safe_close();
1944 CanvasView::create(loose_handle<Instance> instance,handle<Canvas> canvas)
1946 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
1947 instance->canvas_view_list().push_front(view);
1948 instance->signal_canvas_view_created()(view.get());
1953 CanvasView::update_title()
1957 title+=etl::basename(get_instance()->get_file_name())
1959 if(get_canvas()->get_name().empty())
1960 title+='"'+get_canvas()->get_id()+'"';
1962 title+='"'+get_canvas()->get_name()+'"';
1964 if(get_instance()->synfigapp::Instance::get_action_count())
1965 title+=_(" (Unsaved)");
1967 if(get_instance()->synfigapp::Instance::in_repository())
1970 if(get_instance()->synfigapp::Instance::is_modified())
1971 title+=_("-MODIFIED");
1972 if(get_instance()->synfigapp::Instance::is_updated())
1973 title+=_("-UPDATED");
1977 if(get_canvas()->is_root())
1978 title+=_(" (Root)");
1985 CanvasView::on_hide()
1988 Gtk::Window::on_hide();
1992 CanvasView::present()
1994 grab_focus();//on_focus_in_event(0);
1995 Gtk::Window::present();
1999 CanvasView::on_focus_in_event(GdkEventFocus*x)
2001 if(studio::App::get_selected_canvas_view()!=this)
2003 if(studio::App::get_selected_canvas_view())
2005 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2006 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2009 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2011 studio::App::set_selected_canvas_view(this);
2013 App::ui_manager()->insert_action_group(action_group);
2016 // HACK ... Questionable...?
2018 return Gtk::Window::on_focus_in_event(x);
2024 CanvasView::on_focus_out_event(GdkEventFocus*x)
2026 //App::ui_manager()->remove_action_group(action_group);
2027 //App::ui_manager()->ensure_update();
2028 return Gtk::Window::on_focus_out_event(x);
2032 CanvasView::refresh_tables()
2034 // if(layer_tree_store_)layer_tree_store_->refresh();
2035 // if(children_tree_store_)children_tree_store_->refresh();
2039 CanvasView::rebuild_tables()
2041 // layer_tree_store_->rebuild();
2042 // children_tree_store_->rebuild();
2046 CanvasView::build_tables()
2048 // layer_tree_store_->rebuild();
2049 // children_tree_store_->rebuild();
2053 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2055 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2061 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2062 if(!action->set_param("canvas_interface",canvas_interface()))
2063 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2064 synfig::error("LayerActivate didn't like CanvasInterface...?");
2065 action->set_param("time",get_time());
2066 action->set_param("layer",layer);
2067 action->set_param("new_status",!layer->active());
2069 assert(action->is_ready());
2071 canvas_interface()->get_instance()->perform_action(action);
2076 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location)
2078 parammenu.items().clear();
2079 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location);
2081 parammenu.popup(3,gtk_get_current_event_time());
2085 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2087 get_instance()->add_actions_to_menu(menu, param_list, category);
2091 CanvasView::on_layer_user_click(int button, Gtk::TreeRow row, LayerTree::ColumnID column_id)
2098 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2099 if(menu && menu->get_submenu())
2101 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2102 //menu->accelerate(*this);
2103 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2108 bool multiple_selected=true;
2110 if(layer_tree->get_selection()->count_selected_rows()<=1)
2111 multiple_selected=false;
2113 // If the clicked row is not selected, then unselect
2114 // everything that isn't selected and select this row
2115 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2117 layer_tree->get_selection()->unselect_all();
2118 layer_tree->get_selection()->select(row);
2119 multiple_selected=false;
2122 if(column_id==COLUMNID_TIME_TRACK)
2125 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2126 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2127 //ValueNode::Handle parent_value_node;
2128 //ValueBase value=row[layer_param_tree_model.value];
2132 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2136 Layer::Handle layer(row[layer_tree_model.layer]);
2137 synfigapp::Action::ParamList param_list;
2138 param_list.add("time",canvas_interface()->get_time());
2139 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2140 param_list.add("canvas_interface",canvas_interface());
2141 if(!multiple_selected)
2142 param_list.add("layer",layer);
2145 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2146 synfigapp::SelectionManager::LayerList::iterator iter;
2148 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2149 param_list.add("layer",Layer::Handle(*iter));
2152 parammenu.items().clear();
2154 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2155 build_new_layer_menu(*newlayers);
2157 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Layer",*newlayers));
2158 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2160 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2164 &studio::LayerTree::select_all_children_layers
2171 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2172 parammenu.popup(button,gtk_get_current_event_time());
2176 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2178 // Right-click on time track with animated
2179 // trackmenu.popup(0,0);
2184 if(!multiple_selected)
2186 popup_param_menu(value_desc);
2193 parammenu.items().clear();
2194 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Connect",
2195 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2197 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Disconnect",
2198 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2200 parammenu.popup(0,0);
2220 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2226 if(column_id==COLUMNID_TIME_TRACK)
2228 if(!(bool)row[children_tree_model.is_canvas])
2230 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2232 popup_param_menu(value_desc);
2246 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2250 case GDK_BUTTON_PRESS:
2251 switch(event->button.button)
2255 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2261 case GDK_MOTION_NOTIFY:
2263 case GDK_BUTTON_RELEASE:
2273 CanvasView::refresh_time_window()
2275 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2276 //time_adjustment().set_lower(time_window_adjustment().get_value());
2277 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2279 time_adjustment().set_page_increment(1.0); // One second
2280 time_adjustment().set_page_size(0);
2283 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2284 time_adjustment().changed();
2286 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2288 children_tree->queue_draw();
2292 CanvasView::on_time_changed()
2294 Time time(get_time());
2296 current_time_widget->set_value(time);
2298 get_canvas()->keyframe_list().find(time);
2299 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2301 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2304 if(get_time() != time_adjustment().get_value())
2307 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2308 if(time < time_window_adjustment().get_value() ||
2309 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2311 time_window_adjustment().set_value(
2312 time-time_window_adjustment().get_page_size()/2
2315 time_adjustment().set_value(time);
2316 time_adjustment().value_changed();
2318 // Shouldn't these trees just hook into
2319 // the time changed signal...?
2320 //YES THEY SHOULD...
2321 if(layer_tree)layer_tree->queue_draw();
2322 if(children_tree)children_tree->queue_draw();
2327 CanvasView::time_zoom_in()
2329 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2330 time_window_adjustment().changed();
2332 refresh_time_window();
2336 CanvasView::time_zoom_out()
2338 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2339 time_window_adjustment().changed();
2341 refresh_time_window();
2345 CanvasView::time_was_changed()
2347 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2352 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2354 canvas_interface()->change_value(value_desc,new_value);
2359 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2361 Gtk::TreePath path(path_string);
2363 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2365 assert((bool)row[children_tree_model.is_value_node]);
2367 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2370 on_edited_value(value_desc,value);
2375 CanvasView::on_id_changed()
2382 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2384 // If the aninimate flag was set in mode...
2385 if(mode&synfigapp::MODE_ANIMATE)
2388 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2389 animatebutton->remove();
2390 animatebutton->add(*icon);
2391 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2392 icon->set_padding(0,0);
2398 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2399 animatebutton->remove();
2400 animatebutton->add(*icon);
2401 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2402 icon->set_padding(0,0);
2406 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2409 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2410 keyframebutton->remove();
2411 keyframebutton->add(*icon);
2412 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2413 icon->set_padding(0,0);
2416 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2419 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2420 keyframebutton->remove();
2421 keyframebutton->add(*icon);
2422 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2423 icon->set_padding(0,0);
2426 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2429 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2430 keyframebutton->remove();
2431 keyframebutton->add(*icon);
2432 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2433 icon->set_padding(0,0);
2436 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2439 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2440 keyframebutton->remove();
2441 keyframebutton->add(*icon);
2442 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2443 icon->set_padding(0,0);
2447 work_area->queue_draw();
2451 CanvasView::on_animate_button_pressed()
2453 if(get_mode()&synfigapp::MODE_ANIMATE)
2454 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2456 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2460 CanvasView::on_keyframe_button_pressed()
2462 synfigapp::CanvasInterface::Mode mode(get_mode());
2464 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2466 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2468 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2470 set_mode(get_mode()-synfigapp::MODE_ANIMATE_PAST|synfigapp::MODE_ANIMATE_FUTURE);
2472 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2474 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2476 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2478 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2483 CanvasView::duck_change_param(const Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2485 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2489 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2491 switch(value_desc.get_value_type())
2493 case ValueBase::TYPE_REAL:
2494 return canvas_interface()->change_value(value_desc,value.mag());
2496 case ValueBase::TYPE_ANGLE:
2497 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2500 return canvas_interface()->change_value(value_desc,value);
2508 CanvasView::selected_layer_color_set(Color color)
2510 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2511 synfigapp::SelectionManager::LayerList::iterator iter;
2513 // Create the action group
2514 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2516 Layer::Handle layer;
2517 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2522 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2527 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2532 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2536 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2539 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2541 Layer::Handle layer(*iter);
2543 if(selected_list.count(layer))
2545 if(!curr_transform_stack_set)
2547 curr_transform_stack_set=true;
2548 curr_transform_stack=transform_stack;
2551 // This layer is currently selected.
2552 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2554 // do the bounding box thing
2555 bbox|=transform_stack.perform(layer->get_bounding_rect());
2557 // Grab the layer's list pf parameters
2558 Layer::ParamList paramlist(layer->get_param_list());
2560 // Grab the layer vocabulary
2561 Layer::Vocab vocab=layer->get_param_vocab();
2562 Layer::Vocab::iterator iter;
2564 for(iter=vocab.begin();iter!=vocab.end();iter++)
2566 if(!iter->get_hidden() && !iter->get_invisible_duck())
2568 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2569 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2570 if(value_desc.is_value_node())
2571 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2573 if(iter->get_name()=="color")
2576 if(!App::dialog_color->busy())
2578 App::dialog_color->reset();
2579 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2580 App::dialog_color->signal_edited().connect(
2583 &studio::CanvasView::selected_layer_color_set
2592 layer_name=layer->get_name();
2596 Transform::Handle trans(layer->get_transform());
2599 transform_stack.push(trans);
2603 /* // Add transforms onto the stack
2604 if(layer_name=="Translate")
2606 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2609 if(layer_name=="Zoom")
2612 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2613 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2616 if(layer_name=="stretch")
2618 Vector scale(layer->get_param("amount").get(Vector()));
2619 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2622 if(layer_name=="Rotate")
2624 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2630 // If this is a paste canvas layer, then we need to
2632 if(layer_name=="PasteCanvas")
2635 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2636 Vector origin(layer->get_param("origin").get(Vector()));
2638 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2640 if(!scale.is_equal_to(Vector(1,1)))
2641 transform_stack.push(new Transform_Scale(scale,origin));
2642 if(!scale.is_equal_to(Vector(0,0)))
2643 transform_stack.push(new Transform_Translate(origin));
2645 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2647 if(!scale.is_equal_to(Vector(0,0)))
2648 transform_stack.pop();
2649 if(!scale.is_equal_to(Vector(1,1)))
2650 transform_stack.pop();
2653 // Remove all of the transforms we have added
2654 while(transforms--) { transform_stack.pop(); }
2656 #undef QUEUE_REBUILD_DUCKS
2660 CanvasView::queue_rebuild_ducks()
2663 if(rebuild_ducks_queued)
2666 if(rebuild_ducks_queued)
2667 queue_rebuild_ducks_connection.disconnect();
2670 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2672 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2678 rebuild_ducks_queued=true;
2682 CanvasView::rebuild_ducks()
2687 synfig::info("%d",i/(i-i));
2690 rebuild_ducks_queued=false;
2691 //queue_rebuild_ducks_connection.disconnect();
2693 if(work_area->is_dragging())
2695 queue_rebuild_ducks();
2699 if(!duck_refresh_flag)
2701 duck_refresh_needed=true;
2707 work_area->clear_ducks();
2708 work_area->set_time(get_time());
2709 get_canvas()->set_time(get_time());
2710 curr_transform_stack.clear();
2711 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2712 curr_transform_stack_set=false;
2714 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2716 //get_canvas()->set_time(get_time());
2717 bool not_empty(false);
2719 // First do the layers...
2721 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2722 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2724 if(!layer_set.empty())
2727 synfig::TransformStack transform_stack;
2729 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2733 // Now do the children
2735 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2736 synfigapp::SelectionManager::ChildrenList::iterator iter;
2737 synfig::TransformStack transform_stack;
2739 if(selected_list.empty())
2746 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2748 work_area->add_to_ducks(*iter,this,transform_stack);
2752 work_area->refresh_selected_ducks();
2753 work_area->queue_draw_preview();
2757 CanvasView::on_dirty_preview()
2761 IsWorking is_working(*this);
2763 work_area->queue_render_preview();
2770 assert(get_canvas());
2772 // If we are already busy, don't play!
2773 if(working_depth)return;
2775 // Set us up as working
2776 IsWorking is_working(*this);
2780 time=work_area->get_time(),
2781 endtime=get_canvas()->rend_desc().get_time_end();
2783 // If we are already at the end of time, start over
2785 time=get_canvas()->rend_desc().get_time_start();
2789 work_area->clear_ducks();
2791 for(timer.reset(); time + timer() < endtime;)
2793 //Clamp the time window so we can see the time value as it races across the horizon
2794 bool timewindreset = false;
2796 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
2798 time_window_adjustment().set_value(
2800 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
2801 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
2803 timewindreset = true;
2806 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
2808 time_window_adjustment().set_value(
2810 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
2811 time_window_adjustment().get_lower())
2814 timewindreset = true;
2817 //we need to tell people that the value changed
2818 if(timewindreset) time_window_adjustment().value_changed();
2820 //update actual time to next step
2821 time_adjustment().set_value(time+timer());
2822 time_adjustment().value_changed();
2824 if(!work_area->sync_render_preview())
2827 studio::App::iteration(false);
2829 if(get_cancel_status())
2834 time_adjustment().set_value(endtime);
2835 time_adjustment().value_changed();
2839 CanvasView::show_tables()
2842 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
2843 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2845 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2846 treetogglebutton->remove();
2847 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
2848 treetogglebutton->show_all();
2855 CanvasView::hide_tables()
2858 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
2859 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2861 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2862 treetogglebutton->remove();
2863 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
2864 treetogglebutton->show_all();
2871 CanvasView::tables_are_visible()
2873 // return notebook->is_visible();
2878 CanvasView::toggle_tables()
2880 // if(tables_are_visible())
2887 CanvasView::do_rotoscope_bline()
2889 smach_.enter(&state_bline);
2893 CanvasView::do_rotoscope()
2895 smach_.enter(&state_draw);
2899 CanvasView::do_rotoscope_poly()
2901 smach_.enter(&state_polygon);
2905 CanvasView::do_eyedrop()
2907 smach_.enter(&state_eyedrop);
2911 CanvasView::show_timebar()
2914 current_time_widget->show();
2916 //keyframe_tab_child->show();
2918 layer_tree->set_show_timetrack(true);
2920 children_tree->set_show_timetrack(true);
2924 CanvasView::hide_timebar()
2927 current_time_widget->hide();
2928 //keyframe_tab_child->hide();
2930 layer_tree->set_show_timetrack(false);
2932 children_tree->set_show_timetrack(false);
2936 CanvasView::timebar_set_sensitive(bool sensitive)
2938 timebar->set_sensitive(sensitive);
2939 current_time_widget->set_sensitive(sensitive);
2940 //keyframe_tab_child->set_sensitive(sensitive);
2942 layer_tree->set_sensitive(sensitive);
2944 children_tree->set_sensitive(sensitive);
2949 CanvasView::on_waypoint_clicked(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint,int button)
2951 waypoint_dialog.set_value_desc(value_desc);
2952 waypoint_dialog.set_waypoint(waypoint);
2957 waypoint_dialog.show();
2961 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
2963 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-jump-to"),
2966 *canvas_interface(),
2967 &synfigapp::CanvasInterface::set_time
2973 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Edit Waypoint"),
2980 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-duplicate"),
2984 *canvas_interface(),
2985 &synfigapp::CanvasInterface::waypoint_duplicate
2992 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
2996 *canvas_interface(),
2997 &synfigapp::CanvasInterface::waypoint_remove
3004 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3013 CanvasView::on_waypoint_changed()
3015 synfigapp::Action::ParamList param_list;
3016 param_list.add("canvas",get_canvas());
3017 param_list.add("canvas_interface",canvas_interface());
3018 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3019 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3020 // param_list.add("time",canvas_interface()->get_time());
3022 get_instance()->process_action("waypoint_set_smart", param_list);
3026 CanvasView::on_waypoint_delete()
3028 synfigapp::Action::ParamList param_list;
3029 param_list.add("canvas",get_canvas());
3030 param_list.add("canvas_interface",canvas_interface());
3031 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3032 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3033 // param_list.add("time",canvas_interface()->get_time());
3035 get_instance()->process_action("waypoint_remove", param_list);
3039 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)
3041 // We will make this true once we have a solid drop
3042 bool success(false);
3043 //synfig::info("Droped data of type \"%s\"",selection_data.get_data_type());
3044 //synfig::info("Droped data of target \"%s\"",gdk_atom_name(selection_data->target));
3045 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3047 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3049 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3051 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3053 Layer::Handle layer(synfig::Layer::create("Text"));
3056 if(!layer->set_param("text",ValueBase(selection_data)))
3059 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3065 action->set_param("canvas",get_canvas());
3066 action->set_param("canvas_interface",canvas_interface());
3067 action->set_param("new",layer);
3069 if(!get_instance()->perform_action(action))
3072 // Ok, we have successfuly imported at least one item.
3074 } while(0); // END of "STRING"
3076 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3078 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3080 // For some reason, GTK hands us a list of URL's seperated
3081 // by not only Carrage-Returns, but also Line-Feeds.
3082 // Line-Feeds will mess us up. Remove all the line-feeds.
3083 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3084 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3086 std::stringstream stream(selection_data);
3088 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3091 synfig::String filename,URI;
3092 getline(stream,filename);
3094 // If we don't have a filename, move on.
3095 if(filename.empty())
3098 // Make sure this URL is of the "file://" type.
3099 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3102 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3106 // Strip the "file://" part from the filename
3107 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3110 try{ext=(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));}catch(...){continue;}
3112 // If this is a SIF file, then we need to do things slightly differently
3115 if(work_area->load_sketch(filename))
3118 work_area->queue_draw();
3123 if(canvas_interface()->import(filename))
3129 } // END of "text/plain"
3132 ui_interface_->error("Drop failed: bad selection data");
3135 context->drag_finish(success, false, time);
3139 CanvasView::on_keyframe_add_pressed()
3141 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3145 ui_interface_->error("I am unable to find the appropriate action");
3149 action->set_param("canvas",get_canvas());
3150 action->set_param("canvas_interface",canvas_interface());
3151 action->set_param("keyframe",Keyframe(get_time()));
3153 canvas_interface()->get_instance()->perform_action(action);
3157 CanvasView::on_keyframe_duplicate_pressed()
3159 const KeyframeTreeStore::Model model;
3160 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3164 ui_interface_->error("I am unable to duplicate the keyframe");
3167 keyframe=row[model.keyframe];
3169 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3173 ui_interface_->error("I am unable to find the appropriate action");
3177 action->set_param("canvas",get_canvas());
3178 action->set_param("canvas_interface",canvas_interface());
3179 action->set_param("keyframe",keyframe);
3180 action->set_param("time",get_time());
3182 canvas_interface()->get_instance()->perform_action(action);
3186 CanvasView::on_keyframe_remove_pressed()
3188 const KeyframeTreeStore::Model model;
3189 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3193 ui_interface_->error("I am unable to remove the keyframe");
3196 keyframe=row[model.keyframe];
3198 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3202 ui_interface_->error("I am unable to find the appropriate action");
3206 action->set_param("canvas",get_canvas());
3207 action->set_param("canvas_interface",canvas_interface());
3208 action->set_param("keyframe",keyframe);
3210 canvas_interface()->get_instance()->perform_action(action);
3215 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3217 bool is_currently_on(work_area->get_type_mask()&type);
3221 case Duck::TYPE_POSITION:
3222 if(duck_mask_position)
3223 duck_mask_position->set_active(!is_currently_on);
3226 case Duck::TYPE_VERTEX:
3227 if(duck_mask_vertex)
3228 duck_mask_vertex->set_active(!is_currently_on);
3231 case Duck::TYPE_TANGENT:
3232 if(duck_mask_tangent)
3233 duck_mask_tangent->set_active(!is_currently_on);
3236 case Duck::TYPE_RADIUS:
3237 if(duck_mask_radius)
3238 duck_mask_radius->set_active(!is_currently_on);
3241 case Duck::TYPE_WIDTH:
3243 duck_mask_width->set_active(!is_currently_on);
3246 case Duck::TYPE_ANGLE:
3248 duck_mask_angle->set_active(!is_currently_on);
3252 synfig::warning("CanvasView::toggle_duck_mask():Unknown duck type!");
3257 work_area->set_type_mask(work_area->get_type_mask()-type);
3259 work_area->set_type_mask(work_area->get_type_mask()|type);
3261 work_area->queue_draw();
3266 CanvasView::image_import()
3268 String filename(dirname(get_canvas()->get_file_name()));
3269 if(App::dialog_open_file(_("Import Image"), filename))
3270 canvas_interface()->import(filename);
3274 CanvasView::process_event_key(EventKey x)
3276 return smach_.process_event(x);
3280 CanvasView::on_input_device_changed(GdkDevice* device)
3284 get_smach().egress();
3288 synfigapp::InputDevice::Handle input_device;
3289 input_device=synfigapp::Main::select_input_device(device->name);
3290 App::toolbox->change_state(input_device->get_state());
3291 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3295 CanvasView::on_preview_option()
3297 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3299 Canvas::Handle canv = get_canvas();
3303 RendDesc &r = canv->rend_desc();
3304 if(r.get_frame_rate())
3306 float rate = 1/r.get_frame_rate();
3307 float beg = r.get_time_start() + r.get_frame_start()*rate;
3308 float end = r.get_time_start() + r.get_frame_end()*rate;
3312 po = new Dialog_PreviewOptions;
3313 po->set_zoom(work_area->get_zoom()/2);
3314 po->set_fps(r.get_frame_rate()/2);
3315 po->set_begintime(beg);
3316 po->set_begin_override(false);
3317 po->set_endtime(end);
3318 po->set_end_override(false);
3320 set_ext_widget("prevoptions",po);
3322 /*po->set_zoom(work_area->get_zoom()/2);
3323 po->set_fps(r.get_frame_rate()/2);
3324 po->set_begintime(beg);
3325 po->set_begin_override(false);
3326 po->set_endtime(end);
3327 po->set_end_override(false);*/
3329 po->set_global_fps(r.get_frame_rate());
3330 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3337 CanvasView::on_preview_create(const PreviewInfo &info)
3339 //set all the options
3340 etl::handle<Preview> prev = new Preview;
3342 prev->set_canvasview(this);
3343 prev->set_zoom(info.zoom);
3344 prev->set_fps(info.fps);
3345 prev->set_overbegin(info.overbegin);
3346 prev->set_begintime(info.begintime);
3347 prev->set_overend(info.overend);
3348 prev->set_endtime(info.endtime);
3349 prev->set_quality(work_area->get_quality());
3354 Dialog_Preview *pd = preview_dialog.get();
3357 pd->set_default_size(700,510);
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);