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
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include <sigc++/adaptors/hide.h>
38 #include <gtkmm/paned.h>
39 #include <gtkmm/scale.h>
40 #include <gtkmm/dialog.h>
41 #include <gtkmm/messagedialog.h>
42 #include <gtkmm/treemodelsort.h>
43 #include <gtkmm/buttonbox.h>
45 #include <gtk/gtktreestore.h>
46 #include <gtk/gtkversion.h>
48 #include <synfig/valuenode_reference.h>
49 #include <synfig/valuenode_subtract.h>
50 #include <synfig/valuenode_linear.h>
51 #include <synfig/valuenode_timedswap.h>
52 #include <synfig/valuenode_scale.h>
53 #include <synfig/valuenode_dynamiclist.h>
54 #include <synfig/valuenode_twotone.h>
55 #include <synfig/valuenode_stripes.h>
56 #include <synfig/valuenode_blinecalctangent.h>
57 #include <synfig/valuenode_blinecalcvertex.h>
58 #include <synfig/valuenode_blinecalcwidth.h>
59 #include <synfig/valuenode_bline.h>
60 #include <synfig/layer.h>
62 #include <synfigapp/uimanager.h>
63 #include <synfigapp/canvasinterface.h>
64 #include <synfigapp/selectionmanager.h>
65 //#include <synfigapp/action_setwaypoint.h>
66 //#include <synfigapp/action_deletewaypoint.h>
68 #include <sigc++/retype_return.h>
69 #include <sigc++/retype.h>
70 //#include <sigc++/hide.h>
72 #include "canvasview.h"
75 #include "cellrenderer_value.h"
76 #include "cellrenderer_timetrack.h"
78 #include "dialog_color.h"
81 #include "state_polygon.h"
82 #include "state_bline.h"
83 #include "state_normal.h"
84 #include "state_eyedrop.h"
85 #include "state_draw.h"
87 #include "ducktransform_scale.h"
88 #include "ducktransform_translate.h"
89 #include "ducktransform_rotate.h"
91 #include "event_mouse.h"
92 #include "event_layerclick.h"
96 #include "dialog_preview.h"
97 #include "dialog_soundselect.h"
100 #include "audiocontainer.h"
101 #include "widget_timeslider.h"
103 #include <synfigapp/main.h>
104 #include <synfigapp/inputdevice.h>
110 /* === U S I N G =========================================================== */
114 using namespace synfig;
115 using namespace studio;
116 using namespace sigc;
118 /* === M A C R O S ========================================================= */
120 #define GRAB_HINT_DATA(y) { \
122 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
124 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
128 #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 ======================================================= */
162 class studio::UniversalScrubber
164 CanvasView *canvas_view;
167 etl::clock scrub_timer;
169 sigc::connection end_scrub_connection;
171 UniversalScrubber(CanvasView *canvas_view):
172 canvas_view(canvas_view),
175 canvas_view->canvas_interface()->signal_time_changed().connect(
176 sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
182 end_scrub_connection.disconnect();
185 void on_time_changed()
187 // Make sure we are changing the time quickly
188 // before we enable scrubbing
189 if(!scrubbing && scrub_timer()>1)
195 // If we aren't scrubbing already, enable it
199 audio_container()->start_scrubbing(canvas_view->get_time());
202 // Reset the scrubber ender
203 end_scrub_connection.disconnect();
204 end_scrub_connection=Glib::signal_timeout().connect(
206 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
213 audio_container()->scrub(canvas_view->get_time());
218 void end_of_scrubbing()
221 audio_container()->stop_scrubbing();
225 handle<AudioContainer> audio_container()
227 assert(canvas_view->audio);
228 return canvas_view->audio;
232 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
238 CanvasViewUIInterface(CanvasView *view):
241 view->statusbar->push(_("Idle"));
244 ~CanvasViewUIInterface()
246 //view->statusbar->pop();
247 //view->progressbar->set_fraction(0);
250 virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
253 //while(studio::App::events_pending())studio::App::iteration(false);
258 true // use_separator
260 Gtk::Label label(message);
263 dialog.get_vbox()->pack_start(label);
264 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
265 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
267 dialog.set_default_response(dflt);
269 return (Response)dialog.run();
271 virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
274 //while(studio::App::events_pending())studio::App::iteration(false);
279 true // use_separator
281 Gtk::Label label(message);
284 dialog.get_vbox()->pack_start(label);
285 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
286 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
287 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
289 dialog.set_default_response(dflt);
291 return (Response)dialog.run();
293 virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
296 //while(studio::App::events_pending())studio::App::iteration(false);
301 true // use_separator
303 Gtk::Label label(message);
306 dialog.get_vbox()->pack_start(label);
307 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
308 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
310 dialog.set_default_response(dflt);
312 return (Response)dialog.run();
316 task(const std::string &task)
318 if(!view->is_playing_)
320 view->statusbar->pop();
321 view->statusbar->push(task);
323 //while(studio::App::events_pending())studio::App::iteration(false);
324 if(view->cancel){return false;}
329 error(const std::string &err)
331 view->statusbar->push(_("ERROR"));
333 // If we are in the process of canceling,
334 // then just go ahead and return false --
335 // don't bother displaying a dialog
336 if(view->cancel)return false;
337 Gtk::MessageDialog dialog(*view, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
340 view->statusbar->pop();
345 warning(const std::string &err)
347 view->statusbar->pop();
348 view->statusbar->push(err);
350 //while(studio::App::events_pending())studio::App::iteration(false);
351 if(view->cancel)return false;
356 amount_complete(int current, int total)
358 if(!view->is_playing_)
360 if(!view->working_depth)
363 view->stopbutton->set_sensitive(true);
365 view->stopbutton->set_sensitive(false);
367 float x((float)current/(float)total);
370 view->progressbar->set_fraction(x);
372 //while(studio::App::events_pending())studio::App::iteration(false);
373 if(view->cancel){/*view->cancel=false;*/return false;}
380 error(_("Feature not yet implemented"));
384 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
387 CanvasView::LayerTreeModel layer_tree_model;
388 CanvasView::ChildrenTreeModel children_tree_model;
391 CanvasViewSelectionManager(CanvasView *view): view(view) { }
394 void _set_selected_layer(const synfig::Layer::Handle &layer)
396 view->layer_tree->select_layer(layer);
398 // Don't change the selection while we are busy
399 // I cannot remember exactly why I put this here...
400 // It musta been for some reason, but I cannot recall.
401 //if(App::Busy::count)
404 if(view->layer_tree->get_selection()->get_selected())
406 const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
408 // Don't do anything if that layer is already selected
409 if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
412 Gtk::TreeModel::Children::iterator iter;
413 if(view->layer_tree_store()->find_layer_row(layer,iter))
415 Gtk::TreePath path(iter);
416 for(int i=path.get_depth();i;i--)
419 path=Gtk::TreePath(iter);
422 view->layer_tree->get_tree_view().expand_row(path,false);
424 view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
425 view->layer_tree->get_selection()->select(iter);
431 //! Returns the number of layers selected.
432 virtual int get_selected_layer_count()const
434 return get_selected_layers().size();
437 //! Returns a list of the currently selected layers.
438 virtual LayerList get_selected_layers()const
440 // assert(view->layer_tree);
442 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
443 return view->layer_tree->get_selected_layers();
446 //! Returns the first layer selected or an empty handle if none are selected.
447 virtual synfig::Layer::Handle get_selected_layer()const
449 // assert(view->layer_tree);
451 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return 0; }
452 return view->layer_tree->get_selected_layer();
455 //! Sets which layers should be selected
456 virtual void set_selected_layers(const LayerList &layer_list)
458 // assert(view->layer_tree);
460 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
461 view->layer_tree->select_layers(layer_list);
462 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
464 //view->queue_rebuild_ducks();
467 //! Sets which layer should be selected.
468 virtual void set_selected_layer(const synfig::Layer::Handle &layer)
470 // assert(view->layer_tree);
472 if(!view->layer_tree) { synfig::error("canvas_view.layer_tree not defined!?"); return; }
473 view->layer_tree->select_layer(layer);
474 //view->queue_rebuild_ducks();
477 //! Clears the layer selection list
478 virtual void clear_selected_layers()
480 if(!view->layer_tree) return;
481 view->layer_tree->clear_selected_layers();
484 //! Returns the number of value_nodes selected.
485 virtual int get_selected_children_count()const
487 return get_selected_children().size();
490 static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
492 const CanvasView::ChildrenTreeModel children_tree_model;
493 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
495 ret->push_back(value_desc);
498 //! Returns a list of the currently selected value_nodes.
499 virtual ChildrenList get_selected_children()const
501 if(!view->children_tree) return ChildrenList();
503 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
506 return ChildrenList();
510 selection->selected_foreach_iter(
513 &studio::CanvasViewSelectionManager::__child_grabber
520 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
522 Gtk::TreeModel::Children children = iter->children();
523 for(iter = children.begin(); iter != children.end(); ++iter)
525 Gtk::TreeModel::Row row = *iter;
526 if(selection->is_selected(row))
527 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
533 //! Returns the first value_node selected or an empty handle if none are selected.
534 virtual ChildrenList::value_type get_selected_child()const
536 if(!view->children_tree) return ChildrenList::value_type();
538 ChildrenList children(get_selected_children());
541 return ChildrenList::value_type();
543 return children.front();
546 //! Sets which value_nodes should be selected
547 virtual void set_selected_children(const ChildrenList &/*children_list*/)
552 //! Sets which value_node should be selected. Empty handle if none.
553 virtual void set_selected_child(const ChildrenList::value_type &/*child*/)
558 //! Clears the value_node selection list
559 virtual void clear_selected_children()
564 int get_selected_layer_parameter_count()const
566 return get_selected_layer_parameters().size();
569 LayerParamList get_selected_layer_parameters()const
571 if(!view->layer_tree) return LayerParamList();
573 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
576 return LayerParamList();
580 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
581 Gtk::TreeModel::Children::iterator iter;
582 for(iter = children.begin(); iter != children.end(); ++iter)
584 Gtk::TreeModel::Row row = *iter;
585 Gtk::TreeModel::Children::iterator iter;
586 for(iter=row.children().begin();iter!=row.children().end();iter++)
588 Gtk::TreeModel::Row row = *iter;
589 if(selection->is_selected(row))
590 ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
596 LayerParam get_selected_layer_parameter() const
598 if(!view->layer_tree) return LayerParam();
599 return get_selected_layer_parameters().front();
602 void set_selected_layer_parameters(const LayerParamList &/*layer_param_list*/)
607 void set_selected_layer_param(const LayerParam &/*layer_param*/)
612 void clear_selected_layer_parameters()
617 }; // END of class SelectionManager
619 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
620 canvas_view_(canvas_view_)
622 if(!canvas_view_.working_depth)
623 canvas_view_.stopbutton->set_sensitive(true);
624 canvas_view_.working_depth++;
625 canvas_view_.cancel=false;
628 CanvasView::IsWorking::~IsWorking()
630 canvas_view_.working_depth--;
631 if(!canvas_view_.working_depth)
632 canvas_view_.stopbutton->set_sensitive(false);
635 CanvasView::IsWorking::operator bool()const
637 if(canvas_view_.cancel)
642 /* === M E T H O D S ======================================================= */
644 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
646 instance_ (instance),
647 canvas_interface_ (canvas_interface_),
648 //layer_tree_store_ (LayerTreeStore::create(canvas_interface_)),
649 //children_tree_store_ (ChildrenTreeStore::create(canvas_interface_)),
650 //keyframe_tree_store_ (KeyframeTreeStore::create(canvas_interface_)),
651 time_adjustment_ (0,0,25,0,0,0),
652 time_window_adjustment_ (0,0,25,0,0,0),
653 statusbar (manage(new class Gtk::Statusbar())),
655 timeslider (new Widget_Timeslider),
657 ui_interface_ (new CanvasViewUIInterface(this)),
658 selection_manager_ (new CanvasViewSelectionManager(this)),
664 canvas_properties (*this,canvas_interface_),
665 canvas_options (this),
666 render_settings (*this,canvas_interface_),
667 waypoint_dialog (*this,canvas_interface_->get_canvas()),
668 keyframe_dialog (*this,canvas_interface_),
669 preview_dialog (new Dialog_Preview),
670 sound_dialog (new Dialog_SoundSelect(*this,canvas_interface_))
674 duck_refresh_flag=true;
676 smach_.set_default_state(&state_normal);
678 disp_audio = new Widget_Sound();
680 //synfig::info("Canvasview: Entered constructor");
682 get_canvas()->set_time(0);
683 //layer_tree_store_->rebuild();
685 // Set up the UI and Selection managers
686 canvas_interface()->set_ui_interface(get_ui_interface());
687 canvas_interface()->set_selection_manager(get_selection_manager());
688 rebuild_ducks_queued=false;
690 //notebook=manage(new class Gtk::Notebook());
691 //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
692 //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
693 //vpaned->pack2(*notebook, Gtk::SHRINK);
694 //vpaned->show_all();
698 //notebook->append_page(*create_layer_tree(),_("Layers"));
699 //notebook->append_page(*create_children_tree(),_("Children"));
700 //notebook->append_page(*create_keyframe_tree(),_("Keyframes"));
702 //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
703 //create all allocated stuff for this canvas
704 audio = new AudioContainer();
706 Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
707 //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
708 layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
710 //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
712 layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
713 layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
717 layout_table->show();
720 //set_transient_for(*App::toolbox);
722 //synfig::info("Canvasview: Before Signals");
724 -- ** -- Signals -------------------------------------------------------------
727 canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
728 canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
730 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
732 //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
733 canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
734 canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
735 waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
736 waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
738 //MODIFIED TIME ADJUSTMENT STUFF....
739 time_window_adjustment().set_child_adjustment(&time_adjustment());
740 time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
741 time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
743 work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
744 work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
746 canvas_interface()->signal_canvas_added().connect(
748 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
751 canvas_interface()->signal_canvas_removed().connect(
753 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
757 canvas_interface()->signal_layer_param_changed().connect(
760 SLOT_EVENT(EVENT_REFRESH_DUCKS)
765 //MUCH TIME STUFF TAKES PLACE IN HERE
767 refresh_time_window();
769 /*! \todo We shouldn't need to do this at construction --
770 ** This should be performed at the first time the window
773 work_area->queue_render_preview();
775 // If the canvas is really big, zoom out so that we can fit it all in the window
776 /*! \todo In other words, this is a zoom-to-fit, and should be
777 ** in its own function.
779 int w=get_canvas()->rend_desc().get_w()+70;
780 int h=get_canvas()->rend_desc().get_h()+70;
781 while(w>700 || h>600)
785 // WorkArea::async_update_preview() =>
786 // WorkArea::set_zoom(float) =>
787 // WorkArea::async_update_preview() =>
788 // desc.set_time(cur_time), where cur_time isn't initialized
789 work_area->set_time(0);
790 work_area->zoom_out();
791 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
792 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
796 set_default_size(w,h);
797 property_window_position().set_value(Gtk::WIN_POS_NONE);
799 std::list<Gtk::TargetEntry> listTargets;
800 listTargets.push_back( Gtk::TargetEntry("STRING") );
801 listTargets.push_back( Gtk::TargetEntry("text/plain") );
802 listTargets.push_back( Gtk::TargetEntry("image") );
804 drag_dest_set(listTargets);
805 signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
808 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
811 time_window_adjustment().set_page_increment(length);
812 time_window_adjustment().set_page_size(length);
816 time_window_adjustment().set_page_increment(10.0);
817 time_window_adjustment().set_page_size(10.0);
821 //synfig::info("Canvasview: Before Sound Hookup");
822 //load sound info from meta data
824 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
826 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
827 on_audio_offset_notify();
829 //signal connection - since they are all associated with the canvas view
831 //hook in signals for sound options box
832 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
833 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
835 //attach to the preview when it's visible
836 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
837 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
839 //hook to metadata signals
840 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
841 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
843 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
846 //synfig::info("Canvasview: Before Final time set up");
848 time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
849 time_window_adjustment().value_changed();
851 GRAB_HINT_DATA("canvas_view");
854 set_skip_taskbar_hint(true);
855 set_skip_pager_hint(true);
856 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
864 //synfig::info("Canvasview: Constructor Done");
867 CanvasView::~CanvasView()
871 App::ui_manager()->remove_action_group(action_group);
873 // Shut down the smach
875 smach_.set_default_state(0);
877 // We want to ensure that the UI_Manager and
878 // the selection manager get destructed right now.
879 ui_interface_.reset();
880 selection_manager_.reset();
882 // Delete any external widgets
883 for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
885 if(ext_widget_book_.begin()->second)
886 delete ext_widget_book_.begin()->second;
894 // don't be calling on_dirty_preview once this object has been deleted;
895 // this was causing a crash before
896 canvas_interface()->signal_dirty_preview().clear();
898 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
899 synfig::info("CanvasView::~CanvasView(): Deleted");
903 CanvasView::get_pixel_sizes()
905 // prime factors of 120 are 2, 2, 2, 3, 5 - see TILE_SIZE in synfig-core/trunk/src/synfig/target_tile.h
906 static int pixel_size_array[] = {2,3,4,5,6,8,10,12,15,20,24,30,40,60,120};
907 static list<int> pixel_sizes = list<int>(pixel_size_array, pixel_size_array + sizeof(pixel_size_array) / sizeof(int));
913 CanvasView::create_time_bar()
917 Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
918 //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
919 //TIME BAR TEMPORARY POSITION
920 //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
922 timeslider->set_time_adjustment(&time_adjustment());
923 timeslider->set_bounds_adjustment(&time_window_adjustment());
924 //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
926 tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
927 tooltips.set_tip(*timeslider,_("Changes the current time"));
928 time_window_scroll->show();
930 time_window_scroll->set_flags(Gtk::CAN_FOCUS);
931 timeslider->set_flags(Gtk::CAN_FOCUS);
933 //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
934 //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
936 NORMAL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
937 animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
938 animatebutton->show();
940 NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all",_("All Keyframes Locked"));
941 keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
942 keyframebutton->show();
944 Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
946 //setup the audio display
947 disp_audio->set_size_request(-1,32); //disp_audio->show();
948 disp_audio->set_time_adjustment(&time_adjustment());
949 disp_audio->signal_start_scrubbing().connect(
950 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
952 disp_audio->signal_scrub().connect(
953 sigc::mem_fun(*audio,&AudioContainer::scrub)
955 disp_audio->signal_stop_scrubbing().connect(
956 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
959 table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
960 table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
961 table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
963 table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
964 table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
971 CanvasView::create_work_area()
973 work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
974 work_area->set_instance(get_instance());
975 work_area->set_canvas(get_canvas());
976 work_area->set_canvas_view(this);
977 work_area->set_progress_callback(get_ui_interface().get());
978 work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
980 return work_area.get();
984 CanvasView::create_status_bar()
987 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
990 // Create the status bar at the bottom of the window
991 Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
992 // statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
993 progressbar =manage(new class Gtk::ProgressBar());
994 SMALL_BUTTON(stopbutton,"gtk-stop",_("Stop"));
995 SMALL_BUTTON(refreshbutton,"gtk-refresh",_("Refresh"));
996 //SMALL_BUTTON(treetogglebutton,"gtk-go-down",_("Toggle Layer Tree"));
997 // NEW_SMALL_BUTTON(raisebutton,"gtk-go-up",_("Raise Layer"));
998 // NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down",_("Lower Layer"));
999 //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1000 // statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1001 // statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1003 current_time_widget=manage(new Widget_Time);
1004 current_time_widget->set_value(get_time());
1005 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1006 current_time_widget->signal_value_changed().connect(
1007 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1010 statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1011 statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1012 statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1013 statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1014 statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1015 statusbar->set_has_resize_grip(false);
1018 refreshbutton->show();
1019 progressbar->show();
1020 stopbutton->set_sensitive(false);
1022 //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1023 //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1024 //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1026 refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1027 stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1029 statusbartable->show_all();
1030 return statusbartable;
1034 CanvasView::on_current_time_widget_changed()
1036 set_time(current_time_widget->get_value());
1038 // show the value being used - it will have been rounded to nearest frame
1039 // this was already being done elsewhere, but only if the time was really changed;
1040 // if the current time was 6f and the user edited it to 6.1f, then the 6.1f would
1041 // be left in the display without the following line to fix it
1042 current_time_widget->set_value(get_time());
1043 current_time_widget->set_position(-1); // leave the cursor at the end
1047 // CanvasView::create_children_tree()
1049 // // Create the layer tree
1050 // children_tree=manage(new class ChildrenTree());
1052 // // Set up the layer tree
1053 // //children_tree->set_model(children_tree_store());
1054 // if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1055 // if(children_tree)children_tree->show();
1057 // // Connect Signals
1058 // if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1059 // if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1060 // if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1061 // if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1063 // return children_tree;
1067 // CanvasView::create_keyframe_tree()
1069 // keyframe_tree=manage(new KeyframeTree());
1071 // //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1072 // //keyframe_tree->show();
1073 // //keyframe_tree->set_model(keyframe_tree_store());
1074 // keyframe_tree->set_editable(true);
1075 // //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1077 // keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1079 // Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1080 // scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1081 // scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1082 // scroll_layer_tree->add(*keyframe_tree);
1083 // scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1084 // //scroll_layer_tree->show();
1087 // Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1088 // layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1090 // Gtk::Image *icon;
1091 // Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1093 // NEW_SMALL_BUTTON(button_add,"gtk-add",_("New Keyframe"));
1094 // NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate Keyframe"));
1095 // NEW_SMALL_BUTTON(button_delete,"gtk-delete",_("Delete Keyframe"));
1097 // Gtk::HBox *hbox(manage(new Gtk::HBox()));
1098 // layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1100 // hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1101 // hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1102 // hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1105 // button_raise->set_relief(Gtk::RELIEF_HALF);
1106 // button_lower->set_relief(Gtk::RELIEF_HALF);
1107 // button_duplicate->set_relief(Gtk::RELIEF_HALF);
1108 // button_delete->set_relief(Gtk::RELIEF_HALF);
1111 // button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1112 // button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1113 // button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1115 // //layout_table->show_all();
1117 // keyframe_tab_child=layout_table;
1120 // layout_table->hide();
1122 // return layout_table;
1126 // CanvasView::create_layer_tree()
1128 // // Create the layer tree
1129 // printf("CanvasView::create_layer_tree()\n");
1130 // layer_tree=manage(new class LayerTree());
1132 // // Set up the layer tree
1133 // //layer_tree->set_model(layer_tree_store());
1134 // layer_tree->set_time_adjustment(time_adjustment());
1135 // layer_tree->show();
1137 // // Connect Signals
1138 // layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1139 // layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1140 // layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1141 // layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1142 // layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1143 // layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1145 // layer_tree->hide();
1146 // return layer_tree;
1150 CanvasView::init_menus()
1153 mainmenu.set_accel_group(get_accel_group());
1154 mainmenu.set_accel_path("<Canvas-view>");
1156 filemenu.set_accel_group(get_accel_group());
1157 filemenu.set_accel_path("<Canvas-view>/File");
1159 editmenu.set_accel_group(get_accel_group());
1160 editmenu.set_accel_path("<Canvas-view>/Edit");
1162 layermenu.set_accel_group(get_accel_group());
1163 layermenu.set_accel_path("<Canvas-view>/Layer");
1165 //cache the position of desired widgets
1167 /*Menus to worry about:
1176 action_group = Gtk::ActionGroup::create();
1178 //action_group->add( Gtk::Action::create("MenuFile", _("_File")) );
1179 action_group->add( Gtk::Action::create("new", Gtk::Stock::NEW),
1180 sigc::hide_return(sigc::ptr_fun(&studio::App::new_instance))
1182 action_group->add( Gtk::Action::create("open", Gtk::Stock::OPEN),
1183 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::open))
1185 action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1186 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1188 action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1189 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1191 action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1192 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1194 action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1195 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1197 action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1198 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1200 action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1201 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1203 action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1204 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1206 action_group->add( Gtk::Action::create("import", _("Import")),
1207 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1209 action_group->add( Gtk::Action::create("render", _("Render")),
1210 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1212 action_group->add( Gtk::Action::create("preview", _("Preview")),
1213 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1215 action_group->add( Gtk::Action::create("sound", _("Sound File")),
1216 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1218 action_group->add( Gtk::Action::create("options", _("Options")),
1219 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1221 action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close"), _("Close Window")),
1222 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1224 action_group->add( Gtk::Action::create("close-document", Gtk::StockID("gtk-close"), _("Close Document")),
1225 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_instance))
1227 action_group->add( Gtk::Action::create("quit", Gtk::StockID("gtk-quit"), _("Quit")),
1228 sigc::hide_return(sigc::ptr_fun(&studio::App::quit))
1231 //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1232 // SLOT_EVENT(EVENT_UNDO)
1235 //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1236 // SLOT_EVENT(EVENT_REDO)
1239 action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1240 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1243 action_group->add( Gtk::Action::create("unselect-all-ducks", _("Unselect All Ducks")),
1244 sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)
1247 action_group->add( Gtk::Action::create("select-all-layers", _("Select All Layers")),
1248 sigc::mem_fun(*this,&CanvasView::on_select_layers)
1251 action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1252 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1255 action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1256 SLOT_EVENT(EVENT_STOP)
1259 action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1260 SLOT_EVENT(EVENT_REFRESH)
1263 action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1264 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1267 // Preview Quality Menu
1270 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1272 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1279 if (i == 1) note = _(" (best)");
1280 if (i == 10) note = _(" (fastest)");
1281 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i),
1282 strprintf(_("Set Quality to %d"),i) + note));
1283 if (i==8) // default quality
1285 action->set_active();
1286 work_area->set_quality(i);
1288 action_group->add( action,
1290 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1297 // Low-Res Quality Menu
1300 for(list<int>::iterator iter = CanvasView::get_pixel_sizes().begin(); iter != CanvasView::get_pixel_sizes().end(); iter++)
1303 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(low_res_pixel_size_group,strprintf("lowres-pixel-%d",i),
1304 strprintf(_("Set Low-Res pixel size to %d"),i)));
1305 if(i==2) // default pixel size
1307 action->set_active();
1308 work_area->set_low_res_pixel_size(i);
1310 action_group->add( action,
1312 sigc::mem_fun(*work_area, &studio::WorkArea::set_low_res_pixel_size),
1318 Glib::RefPtr<Gtk::Action> action;
1320 action=Gtk::Action::create("decrease-low-res-pixel-size", _("Decrease Low-Res Pixel Size"));
1321 action_group->add( action,sigc::mem_fun(this, &studio::CanvasView::decrease_low_res_pixel_size));
1323 action=Gtk::Action::create("increase-low-res-pixel-size", _("Increase Low-Res Pixel Size"));
1324 action_group->add( action, sigc::mem_fun(this, &studio::CanvasView::increase_low_res_pixel_size));
1328 action_group->add( Gtk::Action::create("play", Gtk::Stock::MEDIA_PLAY),
1329 sigc::mem_fun(*this, &studio::CanvasView::play)
1332 action_group->add( Gtk::Action::create("dialog-flipbook", _("Flipbook Dialog")),
1333 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1337 Glib::RefPtr<Gtk::ToggleAction> action;
1339 grid_show_toggle = Gtk::ToggleAction::create("toggle-grid-show", _("Show Grid"));
1340 grid_show_toggle->set_active(work_area->grid_status());
1341 action_group->add(grid_show_toggle, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid));
1343 grid_snap_toggle = Gtk::ToggleAction::create("toggle-grid-snap", _("Snap to Grid"));
1344 grid_snap_toggle->set_active(work_area->get_grid_snap());
1345 action_group->add(grid_snap_toggle, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap));
1347 action = Gtk::ToggleAction::create("toggle-guide-show", _("Show Guides"));
1348 action->set_active(work_area->get_show_guides());
1349 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap));
1351 action = Gtk::ToggleAction::create("toggle-low-res", _("Use Low-Res"));
1352 action->set_active(work_area->get_low_resolution_flag());
1353 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag));
1355 action = Gtk::ToggleAction::create("toggle-onion-skin", _("Show Onion Skin"));
1356 action->set_active(work_area->get_onion_skin());
1357 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_onion_skin));
1360 action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1361 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1363 action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1364 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1368 Glib::RefPtr<Gtk::Action> action;
1370 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1371 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1372 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1373 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1375 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Forward"),_("Seek Forward"));
1376 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1377 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1378 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1380 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1381 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1383 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1384 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1386 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1387 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1389 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1390 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1392 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1393 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1395 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1396 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1398 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1399 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1401 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1402 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1407 Glib::RefPtr<Gtk::ToggleAction> action;
1409 #define DUCK_MASK(lower,upper,string) \
1410 action=Gtk::ToggleAction::create("mask-" #lower "-ducks", string); \
1411 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper)); \
1412 action_group->add(action, \
1414 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask), \
1415 Duck::TYPE_##upper))
1417 DUCK_MASK(position,POSITION,_("Show Position Ducks"));
1418 DUCK_MASK(tangent,TANGENT,_("Show Tangent Ducks"));
1419 DUCK_MASK(vertex,VERTEX,_("Show Vertex Ducks"));
1420 DUCK_MASK(radius,RADIUS,_("Show Radius Ducks"));
1421 DUCK_MASK(width,WIDTH,_("Show Width Ducks"));
1422 DUCK_MASK(angle,ANGLE,_("Show Angle Ducks"));
1427 add_accel_group(App::ui_manager()->get_accel_group());
1429 /* // Here is where we add the actions that may have conflicting
1430 // keyboard accelerators.
1432 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1433 Glib::RefPtr<Gtk::Action> action;
1435 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1436 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1438 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1439 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1441 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1442 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1444 action=Gtk::Action::create("jump-prev-keyframe", Gtk::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1445 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1447 action=Gtk::Action::create("canvas-zoom-in", Gtk::StockID("gtk-zoom-in"));
1448 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1450 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1451 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1453 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1454 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1456 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1457 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1459 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1461 Glib::ustring ui_info =
1464 <accelerator action='seek-next-frame' />
1465 <accelerator action='seek-prev-frame' />
1466 <accelerator action='jump-next-keyframe' />
1467 <accelerator action='jump-prev-keyframe' />
1468 <accelerator action='canvas-zoom-in' />
1469 <accelerator action='canvas-zoom-out' />
1470 <accelerator action='time-zoom-in' />
1471 <accelerator action='time-zoom-out' />
1475 accel_ui_manager->add_ui_from_string(ui_info);
1476 add_accel_group(accel_ui_manager->get_accel_group());
1478 accel_ui_manager->insert_action_group(accel_action_group);
1479 set_ref_obj("accel_ui_manager",accel_ui_manager);
1480 set_ref_obj("accel_action_group",accel_action_group);
1486 // //Test some key stuff
1488 // filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1489 // hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1490 // 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))));
1491 // 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))));
1492 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1494 // 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))));
1495 // 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))));
1496 // 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))));
1498 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1499 // 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))));
1500 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1501 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1502 // sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1504 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1505 // sigc::mem_fun(*this,&CanvasView::on_preview_option)
1507 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1508 // sigc::mem_fun(*this,&CanvasView::on_audio_option)
1511 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1512 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1513 // sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1515 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1516 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close View"),
1517 // sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1519 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close Document"),
1520 // sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_document))
1523 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1524 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1525 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1526 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1527 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1528 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1529 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1530 // 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)));
1531 // editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Unselect All Ducks"),Gtk::AccelKey('E',Gdk::CONTROL_MASK),sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)));
1532 // editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Layers"),Gtk::AccelKey('A',Gdk::CONTROL_MASK),sigc::mem_fun(*this,&CanvasView::on_select_layers)));
1533 // 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)));
1534 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1536 // //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))));
1537 // //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))));
1538 // 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)));
1539 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1540 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1541 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1542 // sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1545 // build_new_layer_menu(newlayermenu);
1546 // layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New"),newlayermenu));
1550 // synfigapp::Action::ParamList param_list;
1551 // param_list.add("canvas",Canvas::Handle(get_canvas()));
1552 // param_list.add("canvas_interface",canvas_interface());
1553 // add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1557 // //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Keyframe Dialog"),sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1559 // // Duck Mask Menu
1562 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1564 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1565 // duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1566 // duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1567 // duck_mask_position->signal_toggled().connect(
1569 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1570 // Duck::TYPE_POSITION
1574 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1575 // duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1576 // duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1577 // duck_mask_vertex->signal_toggled().connect(
1579 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1580 // Duck::TYPE_VERTEX
1584 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1585 // duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1586 // duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1587 // duck_mask_tangent->signal_toggled().connect(
1589 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1590 // Duck::TYPE_TANGENT
1594 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1595 // duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1596 // duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1597 // duck_mask_radius->signal_toggled().connect(
1599 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1600 // Duck::TYPE_RADIUS
1604 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1605 // duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1606 // duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1607 // duck_mask_width->signal_toggled().connect(
1609 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1614 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1615 // duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1616 // duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1617 // duck_mask_angle->signal_toggled().connect(
1619 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1624 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1627 // // Preview Quality Menu
1630 // qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1632 // qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1634 // sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1638 // for(i=1;i<=10;i++)
1640 // qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1642 // sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1647 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1650 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::MEDIA_PLAY,
1651 // sigc::mem_fun(*this, &studio::CanvasView::play)));
1652 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1653 // sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1655 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1657 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1658 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1659 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1660 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1661 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1662 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1663 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1664 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1666 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1668 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1669 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1670 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1671 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1672 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1673 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1674 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1675 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
1676 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1678 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('+',static_cast<Gdk::ModifierType>(0)),
1679 // sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in)));
1680 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('_',static_cast<Gdk::ModifierType>(0)),
1681 // sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out)));
1683 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1684 // sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1685 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1686 // sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1688 // mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1689 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_File"),filemenu));
1690 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),editmenu));
1691 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_View"),viewmenu));
1692 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Canvas"),canvasmenu));
1693 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Layer"),layermenu));
1695 // mainmenu.accelerate(*this);
1700 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Waypoint"),NOT_IMPLEMENTED_SLOT));
1701 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Delete Waypoint"),NOT_IMPLEMENTED_SLOT));
1702 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Export"),NOT_IMPLEMENTED_SLOT));
1703 // trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1704 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Properties"),NOT_IMPLEMENTED_SLOT));
1710 // canvasmenu.show();
1711 // layermenu.show();
1713 // keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1714 // sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1718 // get_accel_group()->unlock();
1720 // //Set the accelerator paths for all the menus
1721 // filemenu.set_accel_path("<synfig>/File");
1722 // editmenu.set_accel_path("<synfig>/Edit");
1723 // layermenu.set_accel_path("<synfig>/Layer");
1724 // //mainmenu.set_accel_path("<synfig-main>");
1725 // canvasmenu.set_accel_path("<synfig>/Canvas");
1726 // viewmenu.set_accel_path("<synfig>/View");
1727 // duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1732 CanvasView::on_select_layers()
1734 Canvas::Handle canvas(get_canvas());
1735 for (CanvasBase::iterator iter = canvas->begin(); iter != canvas->end(); iter++)
1736 layer_tree->select_all_children_layers(*iter);
1740 CanvasView::on_unselect_layers()
1742 layer_tree->clear_selected_layers();
1746 CanvasView::show_keyframe_dialog()
1748 Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
1749 if(selection->get_selected())
1751 Gtk::TreeRow row(*selection->get_selected());
1753 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
1755 keyframe_dialog.set_keyframe(keyframe);
1756 keyframe_dialog.present();
1761 CanvasView::add_layer(synfig::String x)
1763 Canvas::Handle canvas;
1765 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1767 int target_depth(0);
1769 if(layer_list.empty())
1771 canvas=get_canvas();
1775 canvas=(*layer_list.begin())->get_canvas();
1776 target_depth=canvas->get_depth(*layer_list.begin());
1779 Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
1782 get_selection_manager()->clear_selected_layers();
1783 get_selection_manager()->set_selected_layer(layer);
1788 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
1790 //Gtk::Menu* menu(manage(new Gtk::Menu));
1791 Gtk::Menu* menu(¶mmenu);
1792 menu->items().clear();
1794 synfigapp::Action::ParamList param_list;
1795 param_list.add("time",canvas_interface()->get_time());
1796 param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
1797 param_list.add("canvas_interface",canvas_interface());
1798 param_list.add("layer",layer);
1800 //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
1801 //build_new_layer_menu(*newlayers);
1803 //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
1805 if(layer->get_name()=="PasteCanvas")
1807 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
1811 &studio::LayerTree::select_all_children_layers
1818 add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
1820 menu->popup(3,gtk_get_current_event_time());
1824 CanvasView::register_layer_type(synfig::Layer::Book::value_type &/*lyr*/,std::map<synfig::String,Gtk::Menu*>* /*category_map*/)
1826 /* if(lyr.second.category==CATEGORY_DO_NOT_USE)
1829 if(category_map->count(lyr.second.category)==0)
1830 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
1832 (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
1835 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
1844 CanvasView::build_new_layer_menu(Gtk::Menu &/*menu*/)
1847 std::map<synfig::String,Gtk::Menu*> category_map;
1850 synfig::Layer::book().begin(),
1851 synfig::Layer::book().end(),
1855 &studio::CanvasView::register_layer_type
1861 menu.items().clear();
1862 menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1864 std::map<synfig::String,Gtk::Menu*>::iterator iter;
1865 for(iter=category_map.begin();iter!=category_map.end();++iter)
1866 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
1873 CanvasView::popup_main_menu()
1875 //mainmenu.popup(0,gtk_get_current_event_time());
1876 Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
1879 //menu->set_accel_group(App::ui_manager()->get_accel_group());
1880 //menu->accelerate(*this);
1881 menu->popup(0,gtk_get_current_event_time());
1886 CanvasView::on_refresh_pressed()
1890 work_area->queue_render_preview();
1894 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
1896 get_selection_manager()->clear_selected_layers();
1898 get_selection_manager()->set_selected_layer(layer);
1902 CanvasView::refresh_rend_desc()
1904 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1907 //synfig::info("Canvasview: Refreshing render desc info");
1908 if(!get_time().is_equal(time_adjustment().get_value()))
1910 time_adjustment().set_value(get_time());
1911 time_adjustment().value_changed();
1914 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1915 if(length<DEFAULT_TIME_WINDOW_SIZE)
1917 time_window_adjustment().set_page_increment(length);
1918 time_window_adjustment().set_page_size(length);
1922 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
1923 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
1926 //set the FPS of the timeslider
1927 timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
1929 //set the beginning and ending time of the time slider
1930 Time begin_time=get_canvas()->rend_desc().get_time_start();
1931 Time end_time=get_canvas()->rend_desc().get_time_end();
1933 // Setup the time_window adjustment
1934 time_window_adjustment().set_lower(begin_time);
1935 time_window_adjustment().set_upper(end_time);
1936 time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1938 //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1939 if(length < time_window_adjustment().get_page_size())
1941 time_window_adjustment().set_page_increment(length);
1942 time_window_adjustment().set_page_size(length);
1945 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1946 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1947 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1948 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1951 time_window_adjustment().changed(); //only non-value stuff was changed
1953 // Setup the time adjustment
1955 //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
1956 //time_adjustment().set_lower(time_window_adjustment().get_value());
1957 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
1959 // time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
1960 // time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
1961 time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1962 time_adjustment().set_page_increment(synfig::Time(1.0));
1963 time_adjustment().set_page_size(0);
1965 time_adjustment().changed();
1967 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1968 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1969 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1970 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1973 if(begin_time==end_time)
1982 //clamp time to big bounds...
1983 if(time_window_adjustment().get_value() < begin_time)
1985 time_window_adjustment().set_value(begin_time);
1986 time_window_adjustment().value_changed();
1989 if(time_window_adjustment().get_value() + time_window_adjustment().get_page_size() > end_time)
1991 time_window_adjustment().set_value(end_time - time_window_adjustment().get_page_size());
1992 time_window_adjustment().value_changed();
1995 if(time_adjustment().get_value() < begin_time)
1997 time_adjustment().set_value(begin_time);
1998 time_adjustment().value_changed();
2001 if(time_adjustment().get_value() > end_time)
2003 time_adjustment().set_value(end_time);
2004 time_adjustment().value_changed();
2007 /*synfig::info("Time stats: \n"
2008 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
2009 "t: %p - [%.3f,%.3f] %.3f",
2010 &time_window_adjustment_, time_window_adjustment_.get_lower(),
2011 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2012 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
2013 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
2014 time_adjustment_.get_value()
2017 work_area->queue_render_preview();
2021 CanvasView::close_view()
2023 if(get_instance()->get_visible_canvases()==1)
2030 static bool _close_instance(etl::handle<Instance> instance)
2032 etl::handle<Instance> argh(instance);
2033 instance->safe_close();
2034 synfig::info("closed");
2039 CanvasView::close_instance()
2041 #ifdef SINGLE_THREADED
2042 if (get_work_area()->get_updating())
2044 get_work_area()->stop_updating(true); // stop and mark as cancelled
2046 // give the workarea chances to stop updating
2047 Glib::signal_timeout().connect(
2048 sigc::mem_fun(*this, &CanvasView::close_instance),
2053 Glib::signal_timeout().connect(
2054 sigc::bind(sigc::ptr_fun(_close_instance),
2055 (etl::handle<Instance>)get_instance()),
2061 CanvasView::create(etl::loose_handle<Instance> instance, etl::handle<synfig::Canvas> canvas)
2063 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
2064 instance->canvas_view_list().push_front(view);
2065 instance->signal_canvas_view_created()(view.get());
2070 CanvasView::update_title()
2074 title = strprintf("%s%s\"%s\"",
2076 get_instance()->get_action_count()
2080 get_instance()->has_real_filename()
2081 ? (etl::basename(get_instance()->get_file_name()) + " : ").c_str()
2084 get_canvas()->get_name().empty()
2085 ? get_canvas()->get_id().c_str()
2086 : get_canvas()->get_name().c_str()
2089 if(get_instance()->synfigapp::Instance::in_repository())
2092 if(get_instance()->synfigapp::Instance::is_modified())
2093 title+=_("-MODIFIED");
2094 if(get_instance()->synfigapp::Instance::is_updated())
2095 title+=_("-UPDATED");
2099 if(get_canvas()->is_root())
2100 title+=_(" (Root)");
2106 CanvasView::on_hide()
2109 Gtk::Window::on_hide();
2113 CanvasView::present()
2115 grab_focus();//on_focus_in_event(0);
2116 Gtk::Window::present();
2120 CanvasView::on_focus_in_event(GdkEventFocus*x)
2122 if(studio::App::get_selected_canvas_view()!=this)
2124 if(studio::App::get_selected_canvas_view())
2126 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2127 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2130 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2132 studio::App::set_selected_canvas_view(this);
2134 App::ui_manager()->insert_action_group(action_group);
2137 // HACK ... Questionable...?
2139 return Gtk::Window::on_focus_in_event(x);
2145 CanvasView::on_focus_out_event(GdkEventFocus*x)
2147 //App::ui_manager()->remove_action_group(action_group);
2148 //App::ui_manager()->ensure_update();
2149 return Gtk::Window::on_focus_out_event(x);
2153 CanvasView::refresh_tables()
2155 // if(layer_tree_store_)layer_tree_store_->refresh();
2156 // if(children_tree_store_)children_tree_store_->refresh();
2160 CanvasView::rebuild_tables()
2162 // layer_tree_store_->rebuild();
2163 // children_tree_store_->rebuild();
2167 CanvasView::build_tables()
2169 // layer_tree_store_->rebuild();
2170 // children_tree_store_->rebuild();
2174 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2176 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2182 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2183 if(!action->set_param("canvas_interface",canvas_interface()))
2184 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2185 synfig::error("LayerActivate didn't like CanvasInterface...?");
2186 action->set_param("time",get_time());
2187 action->set_param("layer",layer);
2188 action->set_param("new_status",!layer->active());
2190 assert(action->is_ready());
2192 canvas_interface()->get_instance()->perform_action(action);
2196 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location, bool bezier)
2198 parammenu.items().clear();
2199 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location,bezier);
2201 parammenu.popup(3,gtk_get_current_event_time());
2205 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2207 get_instance()->add_actions_to_menu(menu, param_list, category);
2211 CanvasView::on_layer_user_click(int button, Gtk::TreeRow /*row*/, LayerTree::ColumnID /*column_id*/)
2217 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2218 if(menu && menu->get_submenu())
2220 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2221 //menu->accelerate(*this);
2222 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2226 bool multiple_selected=true;
2228 if(layer_tree->get_selection()->count_selected_rows()<=1)
2229 multiple_selected=false;
2231 // If the clicked row is not selected, then unselect
2232 // everything that isn't selected and select this row
2233 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2235 layer_tree->get_selection()->unselect_all();
2236 layer_tree->get_selection()->select(row);
2237 multiple_selected=false;
2240 if(column_id==COLUMNID_TIME_TRACK)
2243 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2244 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2245 //ValueNode::Handle parent_value_node;
2246 //ValueBase value=row[layer_param_tree_model.value];
2250 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2254 Layer::Handle layer(row[layer_tree_model.layer]);
2255 synfigapp::Action::ParamList param_list;
2256 param_list.add("time",canvas_interface()->get_time());
2257 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2258 param_list.add("canvas_interface",canvas_interface());
2259 if(!multiple_selected)
2260 param_list.add("layer",layer);
2263 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2264 synfigapp::SelectionManager::LayerList::iterator iter;
2266 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2267 param_list.add("layer",Layer::Handle(*iter));
2270 parammenu.items().clear();
2272 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2273 // do we need this? the code is all #ifdef'ed out anyway
2274 // newlayers->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), newlayers));
2275 build_new_layer_menu(*newlayers);
2277 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
2278 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2280 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2284 &studio::LayerTree::select_all_children_layers
2291 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2292 parammenu.popup(button,gtk_get_current_event_time());
2296 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2298 // Right-click on time track with animated
2299 // trackmenu.popup(0,0);
2304 if(!multiple_selected)
2306 popup_param_menu(value_desc);
2313 parammenu.items().clear();
2314 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Connect"),
2315 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2317 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Disconnect"),
2318 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2320 parammenu.popup(0,0);
2338 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2344 if(column_id==COLUMNID_TIME_TRACK)
2346 if(!(bool)row[children_tree_model.is_canvas])
2348 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2351 //! \todo fix properly -- what is the child dialog for?
2352 synfig::info("preventing child dialog right-click crash");
2356 popup_param_menu(value_desc);
2370 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2374 case GDK_BUTTON_PRESS:
2375 switch(event->button.button)
2379 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2385 case GDK_MOTION_NOTIFY:
2387 case GDK_BUTTON_RELEASE:
2396 CanvasView::refresh_time_window()
2398 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2399 //time_adjustment().set_lower(time_window_adjustment().get_value());
2400 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2402 time_adjustment().set_page_increment(1.0); // One second
2403 time_adjustment().set_page_size(0);
2406 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2407 time_adjustment().changed();
2409 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2411 children_tree->queue_draw();
2415 CanvasView::on_time_changed()
2417 Time time(get_time());
2419 current_time_widget->set_value(time);
2421 get_canvas()->keyframe_list().find(time);
2422 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2424 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2427 if(get_time() != time_adjustment().get_value())
2429 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2430 if(time < time_window_adjustment().get_value() ||
2431 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2433 time_window_adjustment().set_value(
2434 time-time_window_adjustment().get_page_size()/2
2437 time_adjustment().set_value(time);
2438 time_adjustment().value_changed();
2440 // Shouldn't these trees just hook into
2441 // the time changed signal...?
2442 //YES THEY SHOULD...
2443 if(layer_tree)layer_tree->queue_draw();
2444 if(children_tree)children_tree->queue_draw();
2449 CanvasView::time_zoom_in()
2451 float frame_rate = get_canvas()->rend_desc().get_frame_rate();
2452 Time min_page_size = 2/frame_rate;
2454 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2455 if (time_window_adjustment().get_page_size() < min_page_size)
2456 time_window_adjustment().set_page_size(min_page_size);
2457 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2458 time_window_adjustment().changed();
2460 refresh_time_window();
2464 CanvasView::time_zoom_out()
2466 Time length = (get_canvas()->rend_desc().get_time_end() -
2467 get_canvas()->rend_desc().get_time_start());
2469 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2470 if (time_window_adjustment().get_page_size() > length)
2471 time_window_adjustment().set_page_size(length);
2472 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2473 time_window_adjustment().changed();
2475 refresh_time_window();
2479 CanvasView::time_was_changed()
2481 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2486 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2488 canvas_interface()->change_value(value_desc,new_value);
2493 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2495 Gtk::TreePath path(path_string);
2497 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2499 assert((bool)row[children_tree_model.is_value_node]);
2501 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2504 on_edited_value(value_desc,value);
2509 CanvasView::on_id_changed()
2515 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2517 // If the animate flag was set in mode...
2518 if(mode&synfigapp::MODE_ANIMATE)
2521 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2522 animatebutton->remove();
2523 animatebutton->add(*icon);
2524 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2525 icon->set_padding(0,0);
2531 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2532 animatebutton->remove();
2533 animatebutton->add(*icon);
2534 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2535 icon->set_padding(0,0);
2539 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2542 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2543 keyframebutton->remove();
2544 keyframebutton->add(*icon);
2545 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2546 icon->set_padding(0,0);
2549 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2552 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2553 keyframebutton->remove();
2554 keyframebutton->add(*icon);
2555 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2556 icon->set_padding(0,0);
2559 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2562 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2563 keyframebutton->remove();
2564 keyframebutton->add(*icon);
2565 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2566 icon->set_padding(0,0);
2569 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2572 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2573 keyframebutton->remove();
2574 keyframebutton->add(*icon);
2575 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2576 icon->set_padding(0,0);
2580 work_area->queue_draw();
2584 CanvasView::on_animate_button_pressed()
2586 if(get_mode()&synfigapp::MODE_ANIMATE)
2587 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2589 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2593 CanvasView::on_keyframe_button_pressed()
2595 synfigapp::CanvasInterface::Mode mode(get_mode());
2597 // future && past --> past
2598 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2599 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2601 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2602 set_mode((get_mode()-synfigapp::MODE_ANIMATE_PAST)|synfigapp::MODE_ANIMATE_FUTURE);
2603 // future --> (nothing)
2604 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2605 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2606 // (nothing) --> future && past
2607 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2608 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2612 CanvasView::duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2614 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2618 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2620 if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
2622 Real old_width((*bline_width)(get_time()).get(Real()));
2623 Real new_width(value.mag());
2624 int scale_index(bline_width->get_link_index_from_name("scale"));
2625 Real scale((*(bline_width->get_link(scale_index)))(get_time()).get(Real()));
2626 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_width,scale_index), new_width * scale / old_width);
2629 if (ValueNode_BLineCalcVertex::Handle bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
2631 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")));
2633 Real amount = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
2634 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount);
2637 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2639 switch(value_desc.get_value_type())
2641 case ValueBase::TYPE_REAL:
2643 Real old_length = (*bline_tangent)(get_time()).get(Real());
2644 Real new_length = value.mag();
2645 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2646 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2647 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2648 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2650 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length);
2651 if (old_length == 0)
2653 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length);
2656 case ValueBase::TYPE_ANGLE:
2657 assert(0); // doesn't happen?
2660 case ValueBase::TYPE_VECTOR:
2662 Vector old_tangent = (*bline_tangent)(get_time()).get(Vector());
2663 Angle old_angle = old_tangent.angle();
2664 Real old_length = old_tangent.mag();
2665 Angle new_angle = value.angle();
2666 Real new_length = value.mag();
2667 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2668 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2669 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2670 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2671 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2672 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2675 if (!(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length)))
2678 else if (old_length != 0 && !(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length)))
2680 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + new_angle - old_angle);
2687 switch(value_desc.get_value_type())
2689 case ValueBase::TYPE_REAL:
2690 return canvas_interface()->change_value(value_desc,value.mag());
2691 case ValueBase::TYPE_ANGLE:
2692 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2694 return canvas_interface()->change_value(value_desc,value);
2699 CanvasView::on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc)
2701 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2703 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2704 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2705 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + rotation);
2708 // \todo will this really always be the case?
2709 assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
2710 return canvas_interface()->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
2714 CanvasView::selected_layer_color_set(synfig::Color color)
2716 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2717 synfigapp::SelectionManager::LayerList::iterator iter;
2719 // Create the action group
2720 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2722 Layer::Handle layer;
2723 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2728 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2733 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2738 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2742 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2745 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2747 Layer::Handle layer(*iter);
2749 if(selected_list.count(layer))
2751 if(!curr_transform_stack_set)
2753 curr_transform_stack_set=true;
2754 curr_transform_stack=transform_stack;
2757 // This layer is currently selected.
2758 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2760 // do the bounding box thing
2761 bbox|=transform_stack.perform(layer->get_bounding_rect());
2763 // Grab the layer's list of parameters
2764 Layer::ParamList paramlist(layer->get_param_list());
2766 // Grab the layer vocabulary
2767 Layer::Vocab vocab=layer->get_param_vocab();
2768 Layer::Vocab::iterator iter;
2770 for(iter=vocab.begin();iter!=vocab.end();iter++)
2772 if(!iter->get_hidden() && !iter->get_invisible_duck())
2774 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2775 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2776 if(value_desc.is_value_node())
2777 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2779 if(iter->get_name()=="color")
2782 if(!App::dialog_color->busy())
2784 App::dialog_color->reset();
2785 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2786 App::dialog_color->signal_edited().connect(
2789 &studio::CanvasView::selected_layer_color_set
2798 layer_name=layer->get_name();
2802 Transform::Handle trans(layer->get_transform());
2805 transform_stack.push(trans);
2809 /* // Add transforms onto the stack
2810 if(layer_name=="Translate")
2812 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2815 if(layer_name=="Zoom")
2818 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2819 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2822 if(layer_name=="stretch")
2824 Vector scale(layer->get_param("amount").get(Vector()));
2825 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2828 if(layer_name=="Rotate")
2830 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2836 // If this is a paste canvas layer, then we need to
2838 if(layer_name=="PasteCanvas")
2841 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2842 Vector origin(layer->get_param("origin").get(Vector()));
2844 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2846 if(!scale.is_equal_to(Vector(1,1)))
2847 transform_stack.push(new Transform_Scale(scale,origin));
2848 if(!scale.is_equal_to(Vector(0,0)))
2849 transform_stack.push(new Transform_Translate(origin));
2851 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2853 if(!scale.is_equal_to(Vector(0,0)))
2854 transform_stack.pop();
2855 if(!scale.is_equal_to(Vector(1,1)))
2856 transform_stack.pop();
2859 // Remove all of the transforms we have added
2860 while(transforms--) { transform_stack.pop(); }
2862 #undef QUEUE_REBUILD_DUCKS
2866 CanvasView::queue_rebuild_ducks()
2869 if(rebuild_ducks_queued)
2872 if(rebuild_ducks_queued)
2873 queue_rebuild_ducks_connection.disconnect();
2876 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2878 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2884 rebuild_ducks_queued=true;
2888 CanvasView::rebuild_ducks()
2893 synfig::info("%d",i/(i-i));
2896 rebuild_ducks_queued=false;
2897 //queue_rebuild_ducks_connection.disconnect();
2899 if(work_area->is_dragging())
2901 queue_rebuild_ducks();
2905 if(!duck_refresh_flag)
2907 duck_refresh_needed=true;
2913 work_area->clear_ducks();
2914 work_area->set_time(get_time());
2915 get_canvas()->set_time(get_time());
2916 curr_transform_stack.clear();
2917 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2918 curr_transform_stack_set=false;
2920 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2922 //get_canvas()->set_time(get_time());
2923 bool not_empty(false);
2925 // First do the layers...
2927 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2928 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2930 if(!layer_set.empty())
2933 synfig::TransformStack transform_stack;
2935 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2939 // Now do the children
2941 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2942 synfigapp::SelectionManager::ChildrenList::iterator iter;
2943 synfig::TransformStack transform_stack;
2945 if(selected_list.empty())
2952 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2954 work_area->add_to_ducks(*iter,this,transform_stack);
2958 work_area->refresh_selected_ducks();
2959 work_area->queue_draw_preview();
2963 CanvasView::decrease_low_res_pixel_size()
2965 list<int> sizes = CanvasView::get_pixel_sizes();
2966 int pixel_size = work_area->get_low_res_pixel_size();
2968 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2969 if (*iter == pixel_size)
2971 if (iter == sizes.begin())
2972 // we already have the smallest low-res pixels possible - turn off low-res instead
2973 work_area->set_low_resolution_flag(false);
2977 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
2978 action->activate(); // to make sure the radiobutton in the menu is updated too
2979 work_area->set_low_resolution_flag(true);
2986 CanvasView::increase_low_res_pixel_size()
2988 list<int> sizes = CanvasView::get_pixel_sizes();
2989 int pixel_size = work_area->get_low_res_pixel_size();
2991 if (!work_area->get_low_resolution_flag())
2993 work_area->set_low_resolution_flag(true);
2997 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2998 if (*iter == pixel_size)
3001 if (iter != sizes.end())
3003 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
3004 action->activate(); // to make sure the radiobutton in the menu is updated too
3005 work_area->set_low_resolution_flag(true);
3012 CanvasView::on_dirty_preview()
3016 IsWorking is_working(*this);
3018 work_area->queue_render_preview();
3025 assert(get_canvas());
3027 // If we are already busy, don't play!
3028 if(working_depth)return;
3030 // Set us up as working
3031 IsWorking is_working(*this);
3035 time=work_area->get_time(),
3036 endtime=get_canvas()->rend_desc().get_time_end();
3038 // If we are already at the end of time, start over
3040 time=get_canvas()->rend_desc().get_time_start();
3044 work_area->clear_ducks();
3046 for(timer.reset(); time + timer() < endtime;)
3048 //Clamp the time window so we can see the time value as it races across the horizon
3049 bool timewindreset = false;
3051 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
3053 time_window_adjustment().set_value(
3055 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
3056 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
3058 timewindreset = true;
3061 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
3063 time_window_adjustment().set_value(
3065 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
3066 time_window_adjustment().get_lower())
3069 timewindreset = true;
3072 //we need to tell people that the value changed
3073 if(timewindreset) time_window_adjustment().value_changed();
3075 //update actual time to next step
3076 time_adjustment().set_value(time+timer());
3077 time_adjustment().value_changed();
3079 if(!work_area->sync_render_preview())
3082 // wait for the workarea to refresh itself
3083 while (studio::App::events_pending())
3084 studio::App::iteration(false);
3086 if(get_cancel_status())
3094 time_adjustment().set_value(endtime);
3095 time_adjustment().value_changed();
3099 CanvasView::show_tables()
3102 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
3103 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3105 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3106 treetogglebutton->remove();
3107 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
3108 treetogglebutton->show_all();
3115 CanvasView::hide_tables()
3118 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
3119 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3121 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3122 treetogglebutton->remove();
3123 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
3124 treetogglebutton->show_all();
3131 CanvasView::tables_are_visible()
3133 // return notebook->is_visible();
3138 CanvasView::toggle_tables()
3140 // if(tables_are_visible())
3147 CanvasView::show_timebar()
3150 current_time_widget->show();
3152 //keyframe_tab_child->show();
3154 layer_tree->set_show_timetrack(true);
3156 children_tree->set_show_timetrack(true);
3160 CanvasView::hide_timebar()
3163 current_time_widget->hide();
3164 //keyframe_tab_child->hide();
3166 layer_tree->set_show_timetrack(false);
3168 children_tree->set_show_timetrack(false);
3172 CanvasView::set_sensitive_timebar(bool sensitive)
3174 timebar->set_sensitive(sensitive);
3175 current_time_widget->set_sensitive(sensitive);
3176 //keyframe_tab_child->set_sensitive(sensitive);
3178 layer_tree->set_sensitive(sensitive);
3180 children_tree->set_sensitive(sensitive);
3184 set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3185 Waypoint::Model model,
3186 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3188 // Create the action group
3189 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Change Waypoint Group"));
3191 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3192 for(iter=waypoints.begin();iter!=waypoints.end();++iter)
3194 Waypoint waypoint(*iter);
3195 waypoint.apply_model(model);
3197 synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set"));
3201 action->set_param("canvas",canvas_interface->get_canvas());
3202 action->set_param("canvas_interface",canvas_interface);
3204 action->set_param("waypoint",waypoint);
3205 action->set_param("value_node",waypoint.get_parent_value_node());
3207 if(!canvas_interface->get_instance()->perform_action(action))
3216 duplicate_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3217 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3219 // Create the action group
3220 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Duplicate Waypoints"));
3222 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3223 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3225 Waypoint waypoint(*iter);
3226 ValueNode::Handle value_node(iter->get_parent_value_node());
3227 canvas_interface->waypoint_duplicate(value_node, waypoint);
3232 remove_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3233 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3235 // Create the action group
3236 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Remove Waypoints"));
3238 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3239 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3241 Waypoint waypoint(*iter);
3242 ValueNode::Handle value_node(iter->get_parent_value_node());
3243 canvas_interface->waypoint_remove(value_node, waypoint);
3248 CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc,
3249 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set,
3252 int size = waypoint_set.size();
3253 Waypoint waypoint(*(waypoint_set.begin()));
3254 Time time(waypoint.get_time());
3258 waypoint_dialog.set_value_desc(value_desc);
3259 waypoint_dialog.set_waypoint(waypoint);
3266 waypoint_dialog.show();
3270 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
3271 waypoint_menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), waypoint_menu));
3273 Gtk::Menu* interp_menu_in(manage(new Gtk::Menu()));
3274 Gtk::Menu* interp_menu_out(manage(new Gtk::Menu()));
3275 Gtk::Menu* interp_menu_both(manage(new Gtk::Menu()));
3278 Waypoint::Model model;
3280 model.reset(); model.set_before(INTERPOLATION_TCB);
3281 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3282 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3283 model.reset(); model.set_after(INTERPOLATION_TCB);
3284 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3285 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3286 model.set_before(INTERPOLATION_TCB);
3287 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3288 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3290 model.reset(); model.set_before(INTERPOLATION_LINEAR);
3291 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3292 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3293 model.reset(); model.set_after(INTERPOLATION_LINEAR);
3294 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3295 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3296 model.set_before(INTERPOLATION_LINEAR);
3297 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3298 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3300 model.reset(); model.set_before(INTERPOLATION_HALT);
3301 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In"),
3302 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3303 model.reset(); model.set_after(INTERPOLATION_HALT);
3304 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease Out"),
3305 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3306 model.set_before(INTERPOLATION_HALT);
3307 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In/Out"),
3308 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3310 model.reset(); model.set_before(INTERPOLATION_CONSTANT);
3311 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3312 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3313 model.reset(); model.set_after(INTERPOLATION_CONSTANT);
3314 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3315 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3316 model.set_before(INTERPOLATION_CONSTANT);
3317 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3318 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3321 // ------------------------------------------------------------------------
3322 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"),
3323 sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time)));
3325 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Duplicate"),
3326 sigc::bind(sigc::ptr_fun(duplicate_waypoints), waypoint_set, canvas_interface())));
3328 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem((size == 1) ? _("_Remove") : strprintf(_("_Remove %d Waypoints"), size),
3329 sigc::bind(sigc::ptr_fun(remove_waypoints), waypoint_set, canvas_interface())));
3331 if (size == 1 && value_desc.is_valid())
3332 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),
3333 sigc::mem_fun(waypoint_dialog,&Gtk::Widget::show)));
3335 // ------------------------------------------------------------------------
3336 waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
3338 // ------------------------------------------------------------------------
3339 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Both"), *interp_menu_both));
3340 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_In"), *interp_menu_in));
3341 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Out"), *interp_menu_out));
3343 // ------------------------------------------------------------------------
3344 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3354 CanvasView::on_waypoint_changed()
3356 synfigapp::Action::ParamList param_list;
3357 param_list.add("canvas",get_canvas());
3358 param_list.add("canvas_interface",canvas_interface());
3359 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3360 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3361 // param_list.add("time",canvas_interface()->get_time());
3363 get_instance()->process_action("waypoint_set_smart", param_list);
3367 CanvasView::on_waypoint_delete()
3369 synfigapp::Action::ParamList param_list;
3370 param_list.add("canvas",get_canvas());
3371 param_list.add("canvas_interface",canvas_interface());
3372 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3373 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3374 // param_list.add("time",canvas_interface()->get_time());
3376 get_instance()->process_action("waypoint_remove", param_list);
3380 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)
3382 // We will make this true once we have a solid drop
3383 bool success(false);
3384 //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
3385 //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
3386 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3388 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3390 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3392 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3394 Layer::Handle layer(synfig::Layer::create("Text"));
3397 if(!layer->set_param("text",ValueBase(selection_data)))
3400 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3406 action->set_param("canvas",get_canvas());
3407 action->set_param("canvas_interface",canvas_interface());
3408 action->set_param("new",layer);
3410 if(!get_instance()->perform_action(action))
3413 // Ok, we have successfully imported at least one item.
3415 } while(0); // END of "STRING"
3417 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3419 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3421 // For some reason, GTK hands us a list of URLs separated
3422 // by not only Carriage-Returns, but also Line-Feeds.
3423 // Line-Feeds will mess us up. Remove all the line-feeds.
3424 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3425 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3427 std::stringstream stream(selection_data);
3429 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3432 synfig::String filename,URI;
3433 getline(stream,filename);
3435 // If we don't have a filename, move on.
3436 if(filename.empty())
3439 // Make sure this URL is of the "file://" type.
3440 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3443 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3447 // Strip the "file://" part from the filename
3448 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3450 String ext(filename_extension(filename));
3451 if (ext.size()) ext = ext.substr(1); // skip initial '.'
3453 // If this is a SIF file, then we need to do things slightly differently
3456 if(work_area->load_sketch(filename))
3459 work_area->queue_draw();
3464 String errors, warnings;
3465 if(canvas_interface()->import(filename, errors, warnings, App::resize_imported_images))
3468 App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
3473 } // END of "text/plain"
3476 ui_interface_->error("Drop failed: bad selection data");
3479 context->drag_finish(success, false, time);
3483 CanvasView::on_keyframe_add_pressed()
3485 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3489 ui_interface_->error("I am unable to find the appropriate action");
3493 action->set_param("canvas",get_canvas());
3494 action->set_param("canvas_interface",canvas_interface());
3495 action->set_param("keyframe",Keyframe(get_time()));
3497 canvas_interface()->get_instance()->perform_action(action);
3501 CanvasView::on_keyframe_duplicate_pressed()
3503 const KeyframeTreeStore::Model model;
3504 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3508 ui_interface_->error("I am unable to duplicate the keyframe");
3511 keyframe=row[model.keyframe];
3513 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3517 ui_interface_->error("I am unable to find the appropriate action");
3521 action->set_param("canvas",get_canvas());
3522 action->set_param("canvas_interface",canvas_interface());
3523 action->set_param("keyframe",keyframe);
3524 action->set_param("time",get_time());
3526 canvas_interface()->get_instance()->perform_action(action);
3530 CanvasView::on_keyframe_remove_pressed()
3532 const KeyframeTreeStore::Model model;
3533 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3537 ui_interface_->error("I am unable to remove the keyframe");
3540 keyframe=row[model.keyframe];
3542 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3546 ui_interface_->error("I am unable to find the appropriate action");
3550 action->set_param("canvas",get_canvas());
3551 action->set_param("canvas_interface",canvas_interface());
3552 action->set_param("keyframe",keyframe);
3554 canvas_interface()->get_instance()->perform_action(action);
3558 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3560 bool is_currently_on(work_area->get_type_mask()&type);
3563 work_area->set_type_mask(work_area->get_type_mask()-type);
3565 work_area->set_type_mask(work_area->get_type_mask()|type);
3567 work_area->queue_draw();
3571 CanvasView::image_import()
3573 // String filename(dirname(get_canvas()->get_file_name()));
3574 String filename("*.*");
3575 String errors, warnings;
3576 if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
3578 canvas_interface()->import(filename, errors, warnings, App::resize_imported_images);
3580 App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
3585 CanvasView::process_event_key(EventKey x)
3587 return smach_.process_event(x);
3591 CanvasView::on_input_device_changed(GdkDevice* device)
3595 get_smach().egress();
3599 synfigapp::InputDevice::Handle input_device;
3600 input_device=synfigapp::Main::select_input_device(device->name);
3601 App::toolbox->change_state(input_device->get_state());
3602 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3606 CanvasView::on_preview_option()
3608 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3610 Canvas::Handle canv = get_canvas();
3614 RendDesc &r = canv->rend_desc();
3615 if(r.get_frame_rate())
3617 float rate = 1/r.get_frame_rate();
3618 float beg = r.get_time_start() + r.get_frame_start()*rate;
3619 float end = r.get_time_start() + r.get_frame_end()*rate;
3623 po = new Dialog_PreviewOptions;
3624 po->set_zoom(work_area->get_zoom()/2);
3625 po->set_fps(r.get_frame_rate()/2);
3626 po->set_begintime(beg);
3627 po->set_begin_override(false);
3628 po->set_endtime(end);
3629 po->set_end_override(false);
3631 set_ext_widget("prevoptions",po);
3633 /*po->set_zoom(work_area->get_zoom()/2);
3634 po->set_fps(r.get_frame_rate()/2);
3635 po->set_begintime(beg);
3636 po->set_begin_override(false);
3637 po->set_endtime(end);
3638 po->set_end_override(false);*/
3640 po->set_global_fps(r.get_frame_rate());
3641 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3648 CanvasView::on_preview_create(const PreviewInfo &info)
3650 //set all the options
3651 etl::handle<Preview> prev = new Preview;
3653 prev->set_canvasview(this);
3654 prev->set_zoom(info.zoom);
3655 prev->set_fps(info.fps);
3656 prev->set_overbegin(info.overbegin);
3657 prev->set_begintime(info.begintime);
3658 prev->set_overend(info.overend);
3659 prev->set_endtime(info.endtime);
3660 prev->set_quality(work_area->get_quality());
3665 Dialog_Preview *pd = preview_dialog.get();
3668 pd->set_default_size(700,510);
3669 pd->set_preview(prev.get());
3674 CanvasView::on_audio_option()
3676 synfig::warning("Launching Audio Options");
3677 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3678 sound_dialog->present();
3682 CanvasView::on_audio_file_change(const std::string &f)
3684 //save in meta data - always even when not valid...
3685 canvas_interface()->set_meta_data("audiofile",f);
3689 CanvasView::on_audio_offset_change(const synfig::Time &t)
3691 canvas_interface()->set_meta_data("audiooffset",t.get_string());
3695 CanvasView::on_audio_file_notify()
3697 std::string file(get_canvas()->get_meta_data("audiofile"));
3698 if(!file.c_str()) return;
3700 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3702 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3703 get_canvas()->erase_meta_data("audiofile");
3705 disp_audio->set_profile(etl::handle<AudioProfile>());
3708 //save in canvasview
3709 synfig::warning("Getting the profile of the music stuff");
3711 //profile specific stuff for the preview widget
3712 //similar for other attachments
3713 Dialog_Preview *pd = preview_dialog.get();
3714 pd->get_widget().set_audio(audio);
3716 handle<AudioProfile> prof = audio->get_profile();
3720 synfig::warning("Agh, I couldn't build the profile captain!");
3722 pd->get_widget().set_audioprofile(prof);
3724 disp_audio->set_profile(audio->get_profile());
3727 synfig::warning("successfully set the profiles and stuff");
3729 disp_audio->queue_draw();
3733 CanvasView::on_audio_offset_notify()
3735 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3736 audio->set_offset(t);
3737 sound_dialog->set_offset(t);
3738 disp_audio->queue_draw();
3740 // synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3744 CanvasView::play_audio(float t)
3748 synfig::info("Playing audio at %f s",t);
3754 CanvasView::stop_audio()
3763 CanvasView::on_audio_scrub()
3769 Glib::RefPtr<Glib::ObjectBase>
3770 CanvasView::get_ref_obj(const synfig::String& x)
3772 return ref_obj_book_[x];
3775 Glib::RefPtr<const Glib::ObjectBase>
3776 CanvasView::get_ref_obj(const synfig::String& x)const
3778 return ref_obj_book_.find(x)->second;
3782 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3787 Glib::RefPtr<Gtk::TreeModel>
3788 CanvasView::get_tree_model(const synfig::String& x)
3790 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3793 Glib::RefPtr<const Gtk::TreeModel>
3794 CanvasView::get_tree_model(const synfig::String& x)const
3796 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3800 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3802 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3806 CanvasView::get_ext_widget(const synfig::String& x)
3808 return ext_widget_book_[x];
3812 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3814 ext_widget_book_[x]=y;
3817 layer_tree=dynamic_cast<LayerTree*>(y);
3819 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3820 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3821 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3822 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3823 layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3827 children_tree=dynamic_cast<ChildrenTree*>(y);
3828 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3829 if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3830 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3833 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3837 CanvasView::on_delete_event(GdkEventAny* event __attribute__ ((unused)))
3841 //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
3842 // Is there ever any need to pass on the delete event to the window here?
3843 // if(event) return Gtk::Window::on_delete_event(event);