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_adjustment().get_value() < begin_time)
1985 time_adjustment().set_value(begin_time);
1986 time_adjustment().value_changed();
1989 if(time_adjustment().get_value() > end_time)
1991 time_adjustment().set_value(end_time);
1992 time_adjustment().value_changed();
1995 /*synfig::info("Time stats: \n"
1996 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
1997 "t: %p - [%.3f,%.3f] %.3f",
1998 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1999 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2000 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
2001 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
2002 time_adjustment_.get_value()
2005 work_area->queue_render_preview();
2009 CanvasView::close_view()
2011 if(get_instance()->get_visible_canvases()==1)
2018 static bool _close_instance(etl::handle<Instance> instance)
2020 etl::handle<Instance> argh(instance);
2021 instance->safe_close();
2022 synfig::info("closed");
2027 CanvasView::close_instance()
2029 #ifdef SINGLE_THREADED
2030 if (get_work_area()->get_updating())
2032 get_work_area()->stop_updating(true); // stop and mark as cancelled
2034 // give the workarea chances to stop updating
2035 Glib::signal_timeout().connect(
2036 sigc::mem_fun(*this, &CanvasView::close_instance),
2041 Glib::signal_timeout().connect(
2042 sigc::bind(sigc::ptr_fun(_close_instance),
2043 (etl::handle<Instance>)get_instance()),
2049 CanvasView::create(etl::loose_handle<Instance> instance, etl::handle<synfig::Canvas> canvas)
2051 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
2052 instance->canvas_view_list().push_front(view);
2053 instance->signal_canvas_view_created()(view.get());
2058 CanvasView::update_title()
2062 title = strprintf("%s%s\"%s\"",
2064 get_instance()->get_action_count()
2068 get_instance()->has_real_filename()
2069 ? (etl::basename(get_instance()->get_file_name()) + " : ").c_str()
2072 get_canvas()->get_name().empty()
2073 ? get_canvas()->get_id().c_str()
2074 : get_canvas()->get_name().c_str()
2077 if(get_instance()->synfigapp::Instance::in_repository())
2080 if(get_instance()->synfigapp::Instance::is_modified())
2081 title+=_("-MODIFIED");
2082 if(get_instance()->synfigapp::Instance::is_updated())
2083 title+=_("-UPDATED");
2087 if(get_canvas()->is_root())
2088 title+=_(" (Root)");
2094 CanvasView::on_hide()
2097 Gtk::Window::on_hide();
2101 CanvasView::present()
2103 grab_focus();//on_focus_in_event(0);
2104 Gtk::Window::present();
2108 CanvasView::on_focus_in_event(GdkEventFocus*x)
2110 if(studio::App::get_selected_canvas_view()!=this)
2112 if(studio::App::get_selected_canvas_view())
2114 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2115 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2118 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2120 studio::App::set_selected_canvas_view(this);
2122 App::ui_manager()->insert_action_group(action_group);
2125 // HACK ... Questionable...?
2127 return Gtk::Window::on_focus_in_event(x);
2133 CanvasView::on_focus_out_event(GdkEventFocus*x)
2135 //App::ui_manager()->remove_action_group(action_group);
2136 //App::ui_manager()->ensure_update();
2137 return Gtk::Window::on_focus_out_event(x);
2141 CanvasView::refresh_tables()
2143 // if(layer_tree_store_)layer_tree_store_->refresh();
2144 // if(children_tree_store_)children_tree_store_->refresh();
2148 CanvasView::rebuild_tables()
2150 // layer_tree_store_->rebuild();
2151 // children_tree_store_->rebuild();
2155 CanvasView::build_tables()
2157 // layer_tree_store_->rebuild();
2158 // children_tree_store_->rebuild();
2162 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2164 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2170 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2171 if(!action->set_param("canvas_interface",canvas_interface()))
2172 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2173 synfig::error("LayerActivate didn't like CanvasInterface...?");
2174 action->set_param("time",get_time());
2175 action->set_param("layer",layer);
2176 action->set_param("new_status",!layer->active());
2178 assert(action->is_ready());
2180 canvas_interface()->get_instance()->perform_action(action);
2184 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location, bool bezier)
2186 parammenu.items().clear();
2187 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location,bezier);
2189 parammenu.popup(3,gtk_get_current_event_time());
2193 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2195 get_instance()->add_actions_to_menu(menu, param_list, category);
2199 CanvasView::on_layer_user_click(int button, Gtk::TreeRow /*row*/, LayerTree::ColumnID /*column_id*/)
2205 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2206 if(menu && menu->get_submenu())
2208 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2209 //menu->accelerate(*this);
2210 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2214 bool multiple_selected=true;
2216 if(layer_tree->get_selection()->count_selected_rows()<=1)
2217 multiple_selected=false;
2219 // If the clicked row is not selected, then unselect
2220 // everything that isn't selected and select this row
2221 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2223 layer_tree->get_selection()->unselect_all();
2224 layer_tree->get_selection()->select(row);
2225 multiple_selected=false;
2228 if(column_id==COLUMNID_TIME_TRACK)
2231 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2232 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2233 //ValueNode::Handle parent_value_node;
2234 //ValueBase value=row[layer_param_tree_model.value];
2238 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2242 Layer::Handle layer(row[layer_tree_model.layer]);
2243 synfigapp::Action::ParamList param_list;
2244 param_list.add("time",canvas_interface()->get_time());
2245 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2246 param_list.add("canvas_interface",canvas_interface());
2247 if(!multiple_selected)
2248 param_list.add("layer",layer);
2251 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2252 synfigapp::SelectionManager::LayerList::iterator iter;
2254 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2255 param_list.add("layer",Layer::Handle(*iter));
2258 parammenu.items().clear();
2260 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2261 // do we need this? the code is all #ifdef'ed out anyway
2262 // newlayers->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), newlayers));
2263 build_new_layer_menu(*newlayers);
2265 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
2266 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2268 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2272 &studio::LayerTree::select_all_children_layers
2279 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2280 parammenu.popup(button,gtk_get_current_event_time());
2284 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2286 // Right-click on time track with animated
2287 // trackmenu.popup(0,0);
2292 if(!multiple_selected)
2294 popup_param_menu(value_desc);
2301 parammenu.items().clear();
2302 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Connect"),
2303 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2305 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Disconnect"),
2306 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2308 parammenu.popup(0,0);
2326 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2332 if(column_id==COLUMNID_TIME_TRACK)
2334 if(!(bool)row[children_tree_model.is_canvas])
2336 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2339 //! \todo fix properly -- what is the child dialog for?
2340 synfig::info("preventing child dialog right-click crash");
2344 popup_param_menu(value_desc);
2358 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2362 case GDK_BUTTON_PRESS:
2363 switch(event->button.button)
2367 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2373 case GDK_MOTION_NOTIFY:
2375 case GDK_BUTTON_RELEASE:
2384 CanvasView::refresh_time_window()
2386 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2387 //time_adjustment().set_lower(time_window_adjustment().get_value());
2388 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2390 time_adjustment().set_page_increment(1.0); // One second
2391 time_adjustment().set_page_size(0);
2394 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2395 time_adjustment().changed();
2397 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2399 children_tree->queue_draw();
2403 CanvasView::on_time_changed()
2405 Time time(get_time());
2407 current_time_widget->set_value(time);
2409 get_canvas()->keyframe_list().find(time);
2410 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2412 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2415 if(get_time() != time_adjustment().get_value())
2417 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2418 if(time < time_window_adjustment().get_value() ||
2419 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2421 time_window_adjustment().set_value(
2422 time-time_window_adjustment().get_page_size()/2
2425 time_adjustment().set_value(time);
2426 time_adjustment().value_changed();
2428 // Shouldn't these trees just hook into
2429 // the time changed signal...?
2430 //YES THEY SHOULD...
2431 if(layer_tree)layer_tree->queue_draw();
2432 if(children_tree)children_tree->queue_draw();
2437 CanvasView::time_zoom_in()
2439 float frame_rate = get_canvas()->rend_desc().get_frame_rate();
2440 Time min_page_size = 2/frame_rate;
2442 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2443 if (time_window_adjustment().get_page_size() < min_page_size)
2444 time_window_adjustment().set_page_size(min_page_size);
2445 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2446 time_window_adjustment().changed();
2448 refresh_time_window();
2452 CanvasView::time_zoom_out()
2454 Time length = (get_canvas()->rend_desc().get_time_end() -
2455 get_canvas()->rend_desc().get_time_start());
2457 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2458 if (time_window_adjustment().get_page_size() > length)
2459 time_window_adjustment().set_page_size(length);
2460 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2461 time_window_adjustment().changed();
2463 refresh_time_window();
2467 CanvasView::time_was_changed()
2469 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2474 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2476 canvas_interface()->change_value(value_desc,new_value);
2481 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2483 Gtk::TreePath path(path_string);
2485 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2487 assert((bool)row[children_tree_model.is_value_node]);
2489 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2492 on_edited_value(value_desc,value);
2497 CanvasView::on_id_changed()
2503 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2505 // If the animate flag was set in mode...
2506 if(mode&synfigapp::MODE_ANIMATE)
2509 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2510 animatebutton->remove();
2511 animatebutton->add(*icon);
2512 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2513 icon->set_padding(0,0);
2519 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2520 animatebutton->remove();
2521 animatebutton->add(*icon);
2522 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2523 icon->set_padding(0,0);
2527 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2530 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2531 keyframebutton->remove();
2532 keyframebutton->add(*icon);
2533 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2534 icon->set_padding(0,0);
2537 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2540 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2541 keyframebutton->remove();
2542 keyframebutton->add(*icon);
2543 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2544 icon->set_padding(0,0);
2547 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2550 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2551 keyframebutton->remove();
2552 keyframebutton->add(*icon);
2553 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2554 icon->set_padding(0,0);
2557 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2560 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2561 keyframebutton->remove();
2562 keyframebutton->add(*icon);
2563 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2564 icon->set_padding(0,0);
2568 work_area->queue_draw();
2572 CanvasView::on_animate_button_pressed()
2574 if(get_mode()&synfigapp::MODE_ANIMATE)
2575 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2577 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2581 CanvasView::on_keyframe_button_pressed()
2583 synfigapp::CanvasInterface::Mode mode(get_mode());
2585 // future && past --> past
2586 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2587 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2589 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2590 set_mode((get_mode()-synfigapp::MODE_ANIMATE_PAST)|synfigapp::MODE_ANIMATE_FUTURE);
2591 // future --> (nothing)
2592 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2593 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2594 // (nothing) --> future && past
2595 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2596 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2600 CanvasView::duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2602 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2606 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2608 if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
2610 Real old_width((*bline_width)(get_time()).get(Real()));
2611 Real new_width(value.mag());
2612 int scale_index(bline_width->get_link_index_from_name("scale"));
2613 Real scale((*(bline_width->get_link(scale_index)))(get_time()).get(Real()));
2614 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_width,scale_index), new_width * scale / old_width);
2617 if (ValueNode_BLineCalcVertex::Handle bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
2619 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")));
2621 Real amount = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
2622 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount);
2625 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2627 switch(value_desc.get_value_type())
2629 case ValueBase::TYPE_REAL:
2631 Real old_length = (*bline_tangent)(get_time()).get(Real());
2632 Real new_length = value.mag();
2633 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2634 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2635 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2636 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2638 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length);
2639 if (old_length == 0)
2641 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length);
2644 case ValueBase::TYPE_ANGLE:
2645 assert(0); // doesn't happen?
2648 case ValueBase::TYPE_VECTOR:
2650 Vector old_tangent = (*bline_tangent)(get_time()).get(Vector());
2651 Angle old_angle = old_tangent.angle();
2652 Real old_length = old_tangent.mag();
2653 Angle new_angle = value.angle();
2654 Real new_length = value.mag();
2655 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2656 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2657 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2658 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2659 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2660 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2663 if (!(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length)))
2666 else if (old_length != 0 && !(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length)))
2668 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + new_angle - old_angle);
2675 switch(value_desc.get_value_type())
2677 case ValueBase::TYPE_REAL:
2678 return canvas_interface()->change_value(value_desc,value.mag());
2679 case ValueBase::TYPE_ANGLE:
2680 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2682 return canvas_interface()->change_value(value_desc,value);
2687 CanvasView::on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc)
2689 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2691 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2692 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2693 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + rotation);
2696 // \todo will this really always be the case?
2697 assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
2698 return canvas_interface()->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
2702 CanvasView::selected_layer_color_set(synfig::Color color)
2704 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2705 synfigapp::SelectionManager::LayerList::iterator iter;
2707 // Create the action group
2708 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2710 Layer::Handle layer;
2711 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2716 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2721 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2726 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2730 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2733 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2735 Layer::Handle layer(*iter);
2737 if(selected_list.count(layer))
2739 if(!curr_transform_stack_set)
2741 curr_transform_stack_set=true;
2742 curr_transform_stack=transform_stack;
2745 // This layer is currently selected.
2746 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2748 // do the bounding box thing
2749 bbox|=transform_stack.perform(layer->get_bounding_rect());
2751 // Grab the layer's list of parameters
2752 Layer::ParamList paramlist(layer->get_param_list());
2754 // Grab the layer vocabulary
2755 Layer::Vocab vocab=layer->get_param_vocab();
2756 Layer::Vocab::iterator iter;
2758 for(iter=vocab.begin();iter!=vocab.end();iter++)
2760 if(!iter->get_hidden() && !iter->get_invisible_duck())
2762 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2763 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2764 if(value_desc.is_value_node())
2765 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2767 if(iter->get_name()=="color")
2770 if(!App::dialog_color->busy())
2772 App::dialog_color->reset();
2773 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2774 App::dialog_color->signal_edited().connect(
2777 &studio::CanvasView::selected_layer_color_set
2786 layer_name=layer->get_name();
2790 Transform::Handle trans(layer->get_transform());
2793 transform_stack.push(trans);
2797 /* // Add transforms onto the stack
2798 if(layer_name=="Translate")
2800 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2803 if(layer_name=="Zoom")
2806 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2807 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2810 if(layer_name=="stretch")
2812 Vector scale(layer->get_param("amount").get(Vector()));
2813 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2816 if(layer_name=="Rotate")
2818 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2824 // If this is a paste canvas layer, then we need to
2826 if(layer_name=="PasteCanvas")
2829 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2830 Vector origin(layer->get_param("origin").get(Vector()));
2832 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2834 if(!scale.is_equal_to(Vector(1,1)))
2835 transform_stack.push(new Transform_Scale(scale,origin));
2836 if(!scale.is_equal_to(Vector(0,0)))
2837 transform_stack.push(new Transform_Translate(origin));
2839 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2841 if(!scale.is_equal_to(Vector(0,0)))
2842 transform_stack.pop();
2843 if(!scale.is_equal_to(Vector(1,1)))
2844 transform_stack.pop();
2847 // Remove all of the transforms we have added
2848 while(transforms--) { transform_stack.pop(); }
2850 #undef QUEUE_REBUILD_DUCKS
2854 CanvasView::queue_rebuild_ducks()
2857 if(rebuild_ducks_queued)
2860 if(rebuild_ducks_queued)
2861 queue_rebuild_ducks_connection.disconnect();
2864 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2866 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2872 rebuild_ducks_queued=true;
2876 CanvasView::rebuild_ducks()
2881 synfig::info("%d",i/(i-i));
2884 rebuild_ducks_queued=false;
2885 //queue_rebuild_ducks_connection.disconnect();
2887 if(work_area->is_dragging())
2889 queue_rebuild_ducks();
2893 if(!duck_refresh_flag)
2895 duck_refresh_needed=true;
2901 work_area->clear_ducks();
2902 work_area->set_time(get_time());
2903 get_canvas()->set_time(get_time());
2904 curr_transform_stack.clear();
2905 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2906 curr_transform_stack_set=false;
2908 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2910 //get_canvas()->set_time(get_time());
2911 bool not_empty(false);
2913 // First do the layers...
2915 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2916 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2918 if(!layer_set.empty())
2921 synfig::TransformStack transform_stack;
2923 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2927 // Now do the children
2929 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2930 synfigapp::SelectionManager::ChildrenList::iterator iter;
2931 synfig::TransformStack transform_stack;
2933 if(selected_list.empty())
2940 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2942 work_area->add_to_ducks(*iter,this,transform_stack);
2946 work_area->refresh_selected_ducks();
2947 work_area->queue_draw_preview();
2951 CanvasView::decrease_low_res_pixel_size()
2953 list<int> sizes = CanvasView::get_pixel_sizes();
2954 int pixel_size = work_area->get_low_res_pixel_size();
2956 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2957 if (*iter == pixel_size)
2959 if (iter == sizes.begin())
2960 // we already have the smallest low-res pixels possible - turn off low-res instead
2961 work_area->set_low_resolution_flag(false);
2965 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
2966 action->activate(); // to make sure the radiobutton in the menu is updated too
2967 work_area->set_low_resolution_flag(true);
2974 CanvasView::increase_low_res_pixel_size()
2976 list<int> sizes = CanvasView::get_pixel_sizes();
2977 int pixel_size = work_area->get_low_res_pixel_size();
2979 if (!work_area->get_low_resolution_flag())
2981 work_area->set_low_resolution_flag(true);
2985 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
2986 if (*iter == pixel_size)
2989 if (iter != sizes.end())
2991 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
2992 action->activate(); // to make sure the radiobutton in the menu is updated too
2993 work_area->set_low_resolution_flag(true);
3000 CanvasView::on_dirty_preview()
3004 IsWorking is_working(*this);
3006 work_area->queue_render_preview();
3013 assert(get_canvas());
3015 // If we are already busy, don't play!
3016 if(working_depth)return;
3018 // Set us up as working
3019 IsWorking is_working(*this);
3023 time=work_area->get_time(),
3024 endtime=get_canvas()->rend_desc().get_time_end();
3026 // If we are already at the end of time, start over
3028 time=get_canvas()->rend_desc().get_time_start();
3032 work_area->clear_ducks();
3034 for(timer.reset(); time + timer() < endtime;)
3036 //Clamp the time window so we can see the time value as it races across the horizon
3037 bool timewindreset = false;
3039 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
3041 time_window_adjustment().set_value(
3043 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
3044 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
3046 timewindreset = true;
3049 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
3051 time_window_adjustment().set_value(
3053 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
3054 time_window_adjustment().get_lower())
3057 timewindreset = true;
3060 //we need to tell people that the value changed
3061 if(timewindreset) time_window_adjustment().value_changed();
3063 //update actual time to next step
3064 time_adjustment().set_value(time+timer());
3065 time_adjustment().value_changed();
3067 if(!work_area->sync_render_preview())
3070 // wait for the workarea to refresh itself
3071 while (studio::App::events_pending())
3072 studio::App::iteration(false);
3074 if(get_cancel_status())
3082 time_adjustment().set_value(endtime);
3083 time_adjustment().value_changed();
3087 CanvasView::show_tables()
3090 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
3091 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3093 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3094 treetogglebutton->remove();
3095 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
3096 treetogglebutton->show_all();
3103 CanvasView::hide_tables()
3106 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
3107 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3109 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3110 treetogglebutton->remove();
3111 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
3112 treetogglebutton->show_all();
3119 CanvasView::tables_are_visible()
3121 // return notebook->is_visible();
3126 CanvasView::toggle_tables()
3128 // if(tables_are_visible())
3135 CanvasView::show_timebar()
3138 current_time_widget->show();
3140 //keyframe_tab_child->show();
3142 layer_tree->set_show_timetrack(true);
3144 children_tree->set_show_timetrack(true);
3148 CanvasView::hide_timebar()
3151 current_time_widget->hide();
3152 //keyframe_tab_child->hide();
3154 layer_tree->set_show_timetrack(false);
3156 children_tree->set_show_timetrack(false);
3160 CanvasView::set_sensitive_timebar(bool sensitive)
3162 timebar->set_sensitive(sensitive);
3163 current_time_widget->set_sensitive(sensitive);
3164 //keyframe_tab_child->set_sensitive(sensitive);
3166 layer_tree->set_sensitive(sensitive);
3168 children_tree->set_sensitive(sensitive);
3172 set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3173 Waypoint::Model model,
3174 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3176 // Create the action group
3177 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Change Waypoint Group"));
3179 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3180 for(iter=waypoints.begin();iter!=waypoints.end();++iter)
3182 Waypoint waypoint(*iter);
3183 waypoint.apply_model(model);
3185 synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set"));
3189 action->set_param("canvas",canvas_interface->get_canvas());
3190 action->set_param("canvas_interface",canvas_interface);
3192 action->set_param("waypoint",waypoint);
3193 action->set_param("value_node",waypoint.get_parent_value_node());
3195 if(!canvas_interface->get_instance()->perform_action(action))
3204 duplicate_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3205 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3207 // Create the action group
3208 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Duplicate Waypoints"));
3210 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3211 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3213 Waypoint waypoint(*iter);
3214 ValueNode::Handle value_node(iter->get_parent_value_node());
3215 canvas_interface->waypoint_duplicate(value_node, waypoint);
3220 remove_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3221 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3223 // Create the action group
3224 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Remove Waypoints"));
3226 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3227 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3229 Waypoint waypoint(*iter);
3230 ValueNode::Handle value_node(iter->get_parent_value_node());
3231 canvas_interface->waypoint_remove(value_node, waypoint);
3236 CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc,
3237 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set,
3240 int size = waypoint_set.size();
3241 Waypoint waypoint(*(waypoint_set.begin()));
3242 Time time(waypoint.get_time());
3246 waypoint_dialog.set_value_desc(value_desc);
3247 waypoint_dialog.set_waypoint(waypoint);
3254 waypoint_dialog.show();
3258 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
3259 waypoint_menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), waypoint_menu));
3261 Gtk::Menu* interp_menu_in(manage(new Gtk::Menu()));
3262 Gtk::Menu* interp_menu_out(manage(new Gtk::Menu()));
3263 Gtk::Menu* interp_menu_both(manage(new Gtk::Menu()));
3266 Waypoint::Model model;
3268 model.reset(); model.set_before(INTERPOLATION_TCB);
3269 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3270 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3271 model.reset(); model.set_after(INTERPOLATION_TCB);
3272 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3273 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3274 model.set_before(INTERPOLATION_TCB);
3275 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3276 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3278 model.reset(); model.set_before(INTERPOLATION_LINEAR);
3279 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3280 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3281 model.reset(); model.set_after(INTERPOLATION_LINEAR);
3282 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3283 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3284 model.set_before(INTERPOLATION_LINEAR);
3285 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3286 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3288 model.reset(); model.set_before(INTERPOLATION_HALT);
3289 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In"),
3290 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3291 model.reset(); model.set_after(INTERPOLATION_HALT);
3292 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease Out"),
3293 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3294 model.set_before(INTERPOLATION_HALT);
3295 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In/Out"),
3296 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3298 model.reset(); model.set_before(INTERPOLATION_CONSTANT);
3299 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3300 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3301 model.reset(); model.set_after(INTERPOLATION_CONSTANT);
3302 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3303 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3304 model.set_before(INTERPOLATION_CONSTANT);
3305 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3306 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3309 // ------------------------------------------------------------------------
3310 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"),
3311 sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time)));
3313 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Duplicate"),
3314 sigc::bind(sigc::ptr_fun(duplicate_waypoints), waypoint_set, canvas_interface())));
3316 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem((size == 1) ? _("_Remove") : strprintf(_("_Remove %d Waypoints"), size),
3317 sigc::bind(sigc::ptr_fun(remove_waypoints), waypoint_set, canvas_interface())));
3319 if (size == 1 && value_desc.is_valid())
3320 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),
3321 sigc::mem_fun(waypoint_dialog,&Gtk::Widget::show)));
3323 // ------------------------------------------------------------------------
3324 waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
3326 // ------------------------------------------------------------------------
3327 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Both"), *interp_menu_both));
3328 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_In"), *interp_menu_in));
3329 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Out"), *interp_menu_out));
3331 // ------------------------------------------------------------------------
3332 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3342 CanvasView::on_waypoint_changed()
3344 synfigapp::Action::ParamList param_list;
3345 param_list.add("canvas",get_canvas());
3346 param_list.add("canvas_interface",canvas_interface());
3347 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3348 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3349 // param_list.add("time",canvas_interface()->get_time());
3351 get_instance()->process_action("waypoint_set_smart", param_list);
3355 CanvasView::on_waypoint_delete()
3357 synfigapp::Action::ParamList param_list;
3358 param_list.add("canvas",get_canvas());
3359 param_list.add("canvas_interface",canvas_interface());
3360 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3361 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3362 // param_list.add("time",canvas_interface()->get_time());
3364 get_instance()->process_action("waypoint_remove", param_list);
3368 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)
3370 // We will make this true once we have a solid drop
3371 bool success(false);
3372 //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
3373 //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
3374 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3376 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3378 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3380 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3382 Layer::Handle layer(synfig::Layer::create("Text"));
3385 if(!layer->set_param("text",ValueBase(selection_data)))
3388 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3394 action->set_param("canvas",get_canvas());
3395 action->set_param("canvas_interface",canvas_interface());
3396 action->set_param("new",layer);
3398 if(!get_instance()->perform_action(action))
3401 // Ok, we have successfully imported at least one item.
3403 } while(0); // END of "STRING"
3405 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3407 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3409 // For some reason, GTK hands us a list of URLs separated
3410 // by not only Carriage-Returns, but also Line-Feeds.
3411 // Line-Feeds will mess us up. Remove all the line-feeds.
3412 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3413 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3415 std::stringstream stream(selection_data);
3417 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3420 synfig::String filename,URI;
3421 getline(stream,filename);
3423 // If we don't have a filename, move on.
3424 if(filename.empty())
3427 // Make sure this URL is of the "file://" type.
3428 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3431 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3435 // Strip the "file://" part from the filename
3436 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3438 String ext(filename_extension(filename));
3439 if (ext.size()) ext = ext.substr(1); // skip initial '.'
3441 // If this is a SIF file, then we need to do things slightly differently
3444 if(work_area->load_sketch(filename))
3447 work_area->queue_draw();
3452 if(canvas_interface()->import(filename))
3458 } // END of "text/plain"
3461 ui_interface_->error("Drop failed: bad selection data");
3464 context->drag_finish(success, false, time);
3468 CanvasView::on_keyframe_add_pressed()
3470 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3474 ui_interface_->error("I am unable to find the appropriate action");
3478 action->set_param("canvas",get_canvas());
3479 action->set_param("canvas_interface",canvas_interface());
3480 action->set_param("keyframe",Keyframe(get_time()));
3482 canvas_interface()->get_instance()->perform_action(action);
3486 CanvasView::on_keyframe_duplicate_pressed()
3488 const KeyframeTreeStore::Model model;
3489 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3493 ui_interface_->error("I am unable to duplicate the keyframe");
3496 keyframe=row[model.keyframe];
3498 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3502 ui_interface_->error("I am unable to find the appropriate action");
3506 action->set_param("canvas",get_canvas());
3507 action->set_param("canvas_interface",canvas_interface());
3508 action->set_param("keyframe",keyframe);
3509 action->set_param("time",get_time());
3511 canvas_interface()->get_instance()->perform_action(action);
3515 CanvasView::on_keyframe_remove_pressed()
3517 const KeyframeTreeStore::Model model;
3518 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3522 ui_interface_->error("I am unable to remove the keyframe");
3525 keyframe=row[model.keyframe];
3527 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3531 ui_interface_->error("I am unable to find the appropriate action");
3535 action->set_param("canvas",get_canvas());
3536 action->set_param("canvas_interface",canvas_interface());
3537 action->set_param("keyframe",keyframe);
3539 canvas_interface()->get_instance()->perform_action(action);
3543 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3545 bool is_currently_on(work_area->get_type_mask()&type);
3548 work_area->set_type_mask(work_area->get_type_mask()-type);
3550 work_area->set_type_mask(work_area->get_type_mask()|type);
3552 work_area->queue_draw();
3556 CanvasView::image_import()
3558 // String filename(dirname(get_canvas()->get_file_name()));
3559 String filename("*.*");
3560 if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
3561 canvas_interface()->import(filename);
3565 CanvasView::process_event_key(EventKey x)
3567 return smach_.process_event(x);
3571 CanvasView::on_input_device_changed(GdkDevice* device)
3575 get_smach().egress();
3579 synfigapp::InputDevice::Handle input_device;
3580 input_device=synfigapp::Main::select_input_device(device->name);
3581 App::toolbox->change_state(input_device->get_state());
3582 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3586 CanvasView::on_preview_option()
3588 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3590 Canvas::Handle canv = get_canvas();
3594 RendDesc &r = canv->rend_desc();
3595 if(r.get_frame_rate())
3597 float rate = 1/r.get_frame_rate();
3598 float beg = r.get_time_start() + r.get_frame_start()*rate;
3599 float end = r.get_time_start() + r.get_frame_end()*rate;
3603 po = new Dialog_PreviewOptions;
3604 po->set_zoom(work_area->get_zoom()/2);
3605 po->set_fps(r.get_frame_rate()/2);
3606 po->set_begintime(beg);
3607 po->set_begin_override(false);
3608 po->set_endtime(end);
3609 po->set_end_override(false);
3611 set_ext_widget("prevoptions",po);
3613 /*po->set_zoom(work_area->get_zoom()/2);
3614 po->set_fps(r.get_frame_rate()/2);
3615 po->set_begintime(beg);
3616 po->set_begin_override(false);
3617 po->set_endtime(end);
3618 po->set_end_override(false);*/
3620 po->set_global_fps(r.get_frame_rate());
3621 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3628 CanvasView::on_preview_create(const PreviewInfo &info)
3630 //set all the options
3631 etl::handle<Preview> prev = new Preview;
3633 prev->set_canvasview(this);
3634 prev->set_zoom(info.zoom);
3635 prev->set_fps(info.fps);
3636 prev->set_overbegin(info.overbegin);
3637 prev->set_begintime(info.begintime);
3638 prev->set_overend(info.overend);
3639 prev->set_endtime(info.endtime);
3640 prev->set_quality(work_area->get_quality());
3645 Dialog_Preview *pd = preview_dialog.get();
3648 pd->set_default_size(700,510);
3649 pd->set_preview(prev.get());
3654 CanvasView::on_audio_option()
3656 synfig::warning("Launching Audio Options");
3657 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3658 sound_dialog->present();
3662 CanvasView::on_audio_file_change(const std::string &f)
3664 //save in meta data - always even when not valid...
3665 canvas_interface()->set_meta_data("audiofile",f);
3669 CanvasView::on_audio_offset_change(const synfig::Time &t)
3671 canvas_interface()->set_meta_data("audiooffset",t.get_string());
3675 CanvasView::on_audio_file_notify()
3677 std::string file(get_canvas()->get_meta_data("audiofile"));
3678 if(!file.c_str()) return;
3680 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3682 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3683 get_canvas()->erase_meta_data("audiofile");
3685 disp_audio->set_profile(etl::handle<AudioProfile>());
3688 //save in canvasview
3689 synfig::warning("Getting the profile of the music stuff");
3691 //profile specific stuff for the preview widget
3692 //similar for other attachments
3693 Dialog_Preview *pd = preview_dialog.get();
3694 pd->get_widget().set_audio(audio);
3696 handle<AudioProfile> prof = audio->get_profile();
3700 synfig::warning("Agh, I couldn't build the profile captain!");
3702 pd->get_widget().set_audioprofile(prof);
3704 disp_audio->set_profile(audio->get_profile());
3707 synfig::warning("successfully set the profiles and stuff");
3709 disp_audio->queue_draw();
3713 CanvasView::on_audio_offset_notify()
3715 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3716 audio->set_offset(t);
3717 sound_dialog->set_offset(t);
3718 disp_audio->queue_draw();
3720 // synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3724 CanvasView::play_audio(float t)
3728 synfig::info("Playing audio at %f s",t);
3734 CanvasView::stop_audio()
3743 CanvasView::on_audio_scrub()
3749 Glib::RefPtr<Glib::ObjectBase>
3750 CanvasView::get_ref_obj(const synfig::String& x)
3752 return ref_obj_book_[x];
3755 Glib::RefPtr<const Glib::ObjectBase>
3756 CanvasView::get_ref_obj(const synfig::String& x)const
3758 return ref_obj_book_.find(x)->second;
3762 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3767 Glib::RefPtr<Gtk::TreeModel>
3768 CanvasView::get_tree_model(const synfig::String& x)
3770 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3773 Glib::RefPtr<const Gtk::TreeModel>
3774 CanvasView::get_tree_model(const synfig::String& x)const
3776 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3780 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3782 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3786 CanvasView::get_ext_widget(const synfig::String& x)
3788 return ext_widget_book_[x];
3792 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3794 ext_widget_book_[x]=y;
3797 layer_tree=dynamic_cast<LayerTree*>(y);
3799 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3800 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3801 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3802 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3803 layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3807 children_tree=dynamic_cast<ChildrenTree*>(y);
3808 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3809 if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
3810 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3813 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3817 CanvasView::on_delete_event(GdkEventAny* event __attribute__ ((unused)))
3821 //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
3822 // Is there ever any need to pass on the delete event to the window here?
3823 // if(event) return Gtk::Window::on_delete_event(event);