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 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/layer.h>
58 #include <synfigapp/uimanager.h>
59 #include <synfigapp/canvasinterface.h>
60 #include <synfigapp/selectionmanager.h>
61 //#include <synfigapp/action_setwaypoint.h>
62 //#include <synfigapp/action_deletewaypoint.h>
64 #include <sigc++/retype_return.h>
65 #include <sigc++/retype.h>
66 //#include <sigc++/hide.h>
68 #include "canvasview.h"
71 #include "cellrenderer_value.h"
72 #include "cellrenderer_timetrack.h"
74 #include "dialog_color.h"
77 #include "state_polygon.h"
78 #include "state_bline.h"
79 #include "state_normal.h"
80 #include "state_eyedrop.h"
81 #include "state_draw.h"
83 #include "ducktransform_scale.h"
84 #include "ducktransform_translate.h"
85 #include "ducktransform_rotate.h"
87 #include "event_mouse.h"
88 #include "event_layerclick.h"
92 #include "dialog_preview.h"
93 #include "dialog_soundselect.h"
96 #include "audiocontainer.h"
97 #include "widget_timeslider.h"
99 #include <synfigapp/main.h>
100 #include <synfigapp/inputdevice.h>
104 /* === U S I N G =========================================================== */
108 using namespace synfig;
109 using namespace studio;
110 using namespace SigC;
112 /* === M A C R O S ========================================================= */
114 #define GRAB_HINT_DATA(y) { \
116 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
118 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
122 #define DEFAULT_TIME_WINDOW_SIZE (10.0)
132 #define SMALL_BUTTON(button,stockid,tooltip) \
133 button = manage(new class Gtk::Button()); \
134 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
135 button->add(*icon); \
136 tooltips.set_tip(*button,tooltip); \
137 icon->set_padding(0,0);\
139 button->set_relief(Gtk::RELIEF_NONE); \
143 #ifndef NORMAL_BUTTON
144 #define NORMAL_BUTTON(button,stockid,tooltip) \
145 button = manage(new class Gtk::Button()); \
146 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
147 button->add(*icon); \
148 tooltips.set_tip(*button,tooltip); \
149 icon->set_padding(0,0);\
151 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
155 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
157 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
159 #define SLOT_EVENT(x) sigc::hide_return(sigc::bind(sigc::mem_fun(*this,&studio::CanvasView::process_event_key),x))
161 /* === C L A S S E S ======================================================= */
164 class studio::UniversalScrubber
166 CanvasView *canvas_view;
169 etl::clock scrub_timer;
171 sigc::connection end_scrub_connection;
173 UniversalScrubber(CanvasView *canvas_view):
174 canvas_view(canvas_view),
177 canvas_view->canvas_interface()->signal_time_changed().connect(
178 sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
184 end_scrub_connection.disconnect();
187 void on_time_changed()
189 // Make sure we are changing the time quickly
190 // before we enable scrubbing
191 if(!scrubbing && scrub_timer()>1)
197 // If we aren't scrubbing already, enable it
201 audio_container()->start_scrubbing(canvas_view->get_time());
204 // Reset the scrubber ender
205 end_scrub_connection.disconnect();
206 end_scrub_connection=Glib::signal_timeout().connect(
208 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
215 audio_container()->scrub(canvas_view->get_time());
220 void end_of_scrubbing()
223 audio_container()->stop_scrubbing();
227 handle<AudioContainer> audio_container()
229 assert(canvas_view->audio);
230 return canvas_view->audio;
235 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
241 CanvasViewUIInterface(CanvasView *view):
245 view->statusbar->push("Idle");
248 ~CanvasViewUIInterface()
250 //view->statusbar->pop();
251 //view->progressbar->set_fraction(0);
254 virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
257 //while(studio::App::events_pending())studio::App::iteration(false);
262 true // use_separator
264 Gtk::Label label(message);
267 dialog.get_vbox()->pack_start(label);
268 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
269 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
271 dialog.set_default_response(dflt);
273 return (Response)dialog.run();
275 virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
278 //while(studio::App::events_pending())studio::App::iteration(false);
283 true // use_separator
285 Gtk::Label label(message);
288 dialog.get_vbox()->pack_start(label);
289 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
290 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
291 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
293 dialog.set_default_response(dflt);
295 return (Response)dialog.run();
297 virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
300 //while(studio::App::events_pending())studio::App::iteration(false);
305 true // use_separator
307 Gtk::Label label(message);
310 dialog.get_vbox()->pack_start(label);
311 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
312 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
314 dialog.set_default_response(dflt);
316 return (Response)dialog.run();
320 task(const std::string &task)
322 if(!view->is_playing_)
324 view->statusbar->pop();
325 view->statusbar->push(task);
327 //while(studio::App::events_pending())studio::App::iteration(false);
328 if(view->cancel){return false;}
333 error(const std::string &err)
335 view->statusbar->push("ERROR");
337 // If we are in the process of canceling,
338 // then just go ahead and return false --
339 // don't bother displaying a dialog
340 if(view->cancel)return false;
341 Gtk::MessageDialog dialog(*view, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
344 view->statusbar->pop();
349 warning(const std::string &err)
351 view->statusbar->pop();
352 view->statusbar->push(err);
354 //while(studio::App::events_pending())studio::App::iteration(false);
355 if(view->cancel)return false;
360 amount_complete(int current, int total)
362 if(!view->is_playing_)
364 if(!view->working_depth)
367 view->stopbutton->set_sensitive(true);
369 view->stopbutton->set_sensitive(false);
371 float x((float)current/(float)total);
374 view->progressbar->set_fraction(x);
376 //while(studio::App::events_pending())studio::App::iteration(false);
377 if(view->cancel){/*view->cancel=false;*/return false;}
384 error("Feature not yet implemented");
388 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
391 CanvasView::LayerTreeModel layer_tree_model;
392 CanvasView::ChildrenTreeModel children_tree_model;
395 CanvasViewSelectionManager(CanvasView *view): view(view)
402 void _set_selected_layer(const synfig::Layer::Handle &layer)
404 view->layer_tree->select_layer(layer);
406 // Don't change the selection while we are busy
407 // I cannot remember exactly why I put this here...
408 // It musta been for some reason, but I cannot recall.
409 //if(App::Busy::count)
412 if(view->layer_tree->get_selection()->get_selected())
414 const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
416 // Don't do anything if that layer is already selected
417 if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
420 Gtk::TreeModel::Children::iterator iter;
421 if(view->layer_tree_store()->find_layer_row(layer,iter))
423 Gtk::TreePath path(iter);
424 for(int i=path.get_depth();i;i--)
427 path=Gtk::TreePath(iter);
430 view->layer_tree->get_tree_view().expand_row(path,false);
432 view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
433 view->layer_tree->get_selection()->select(iter);
439 //! Returns the number of layers selected.
440 virtual int get_selected_layer_count()const
442 return get_selected_layers().size();
445 //! Returns a list of the currently selected layers.
446 virtual LayerList get_selected_layers()const
448 // assert(view->layer_tree);
450 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
451 return view->layer_tree->get_selected_layers();
454 //! Returns the first layer selected or an empty handle if none are selected.
455 virtual synfig::Layer::Handle get_selected_layer()const
457 // assert(view->layer_tree);
459 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return 0; }
460 return view->layer_tree->get_selected_layer();
463 //! Sets which layers should be selected
464 virtual void set_selected_layers(const LayerList &layer_list)
466 // assert(view->layer_tree);
468 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
469 view->layer_tree->select_layers(layer_list);
470 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
472 //view->queue_rebuild_ducks();
475 //! Sets which layer should be selected.
476 virtual void set_selected_layer(const synfig::Layer::Handle &layer)
478 // assert(view->layer_tree);
480 if(!view->layer_tree) { DEBUGPOINT(); synfig::error("canvas_view.layer_tree not defined!?"); return; }
481 view->layer_tree->select_layer(layer);
482 //view->queue_rebuild_ducks();
485 //! Clears the layer selection list
486 virtual void clear_selected_layers()
488 if(!view->layer_tree) return;
489 view->layer_tree->clear_selected_layers();
494 //! Returns the number of value_nodes selected.
495 virtual int get_selected_children_count()const
497 return get_selected_children().size();
500 static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
502 const CanvasView::ChildrenTreeModel children_tree_model;
503 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
505 ret->push_back(value_desc);
508 //! Returns a list of the currently selected value_nodes.
509 virtual ChildrenList get_selected_children()const
511 if(!view->children_tree) return ChildrenList();
513 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
516 return ChildrenList();
520 selection->selected_foreach_iter(
523 &studio::CanvasViewSelectionManager::__child_grabber
530 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
532 Gtk::TreeModel::Children children = iter->children();
533 for(iter = children.begin(); iter != children.end(); ++iter)
535 Gtk::TreeModel::Row row = *iter;
536 if(selection->is_selected(row))
537 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
543 //! Returns the first value_node selected or an empty handle if none are selected.
544 virtual ChildrenList::value_type get_selected_child()const
546 if(!view->children_tree) return ChildrenList::value_type();
548 ChildrenList children(get_selected_children());
551 return ChildrenList::value_type();
553 return children.front();
556 //! Sets which value_nodes should be selected
557 virtual void set_selected_children(const ChildrenList &/*children_list*/)
562 //! Sets which value_node should be selected. Empty handle if none.
563 virtual void set_selected_child(const ChildrenList::value_type &/*child*/)
568 //! Clears the value_node selection list
569 virtual void clear_selected_children()
576 int get_selected_layer_parameter_count()const
578 return get_selected_layer_parameters().size();
581 LayerParamList get_selected_layer_parameters()const
583 if(!view->layer_tree) return LayerParamList();
585 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
588 return LayerParamList();
592 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
593 Gtk::TreeModel::Children::iterator iter;
594 for(iter = children.begin(); iter != children.end(); ++iter)
596 Gtk::TreeModel::Row row = *iter;
597 Gtk::TreeModel::Children::iterator iter;
598 for(iter=row.children().begin();iter!=row.children().end();iter++)
600 Gtk::TreeModel::Row row = *iter;
601 if(selection->is_selected(row))
602 ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
608 LayerParam get_selected_layer_parameter() const
610 if(!view->layer_tree) return LayerParam();
611 return get_selected_layer_parameters().front();
614 void set_selected_layer_parameters(const LayerParamList &/*layer_param_list*/)
619 void set_selected_layer_param(const LayerParam &/*layer_param*/)
624 void clear_selected_layer_parameters()
629 }; // END of class SelectionManager
632 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
633 canvas_view_(canvas_view_)
635 if(!canvas_view_.working_depth)
636 canvas_view_.stopbutton->set_sensitive(true);
637 canvas_view_.working_depth++;
638 canvas_view_.cancel=false;
641 CanvasView::IsWorking::~IsWorking()
643 canvas_view_.working_depth--;
644 if(!canvas_view_.working_depth)
645 canvas_view_.stopbutton->set_sensitive(false);
648 CanvasView::IsWorking::operator bool()const
650 if(canvas_view_.cancel)
655 /* === M E T H O D S ======================================================= */
657 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
659 instance_ (instance),
660 canvas_interface_ (canvas_interface_),
661 //layer_tree_store_ (LayerTreeStore::create(canvas_interface_)),
662 //children_tree_store_ (ChildrenTreeStore::create(canvas_interface_)),
663 //keyframe_tree_store_ (KeyframeTreeStore::create(canvas_interface_)),
664 time_adjustment_ (0,0,25,0,0,0),
665 time_window_adjustment_ (0,0,25,0,0,0),
666 statusbar (manage(new class Gtk::Statusbar())),
668 timeslider (new Widget_Timeslider),
670 ui_interface_ (new CanvasViewUIInterface(this)),
671 selection_manager_ (new CanvasViewSelectionManager(this)),
677 canvas_properties (*this,canvas_interface_),
678 canvas_options (this),
679 render_settings (*this,canvas_interface_),
680 waypoint_dialog (*this,canvas_interface_->get_canvas()),
681 keyframe_dialog (*this,canvas_interface_),
682 preview_dialog (new Dialog_Preview),
683 sound_dialog (new Dialog_SoundSelect(*this,canvas_interface_))
687 duck_refresh_flag=true;
689 smach_.set_default_state(&state_normal);
691 disp_audio = new Widget_Sound();
693 //synfig::info("Canvasview: Entered constructor");
695 get_canvas()->set_time(0);
696 //layer_tree_store_->rebuild();
698 // Set up the UI and Selection managers
699 canvas_interface()->set_ui_interface(get_ui_interface());
700 canvas_interface()->set_selection_manager(get_selection_manager());
701 rebuild_ducks_queued=false;
703 //notebook=manage(new class Gtk::Notebook());
704 //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
705 //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
706 //vpaned->pack2(*notebook, Gtk::SHRINK);
707 //vpaned->show_all();
712 //notebook->append_page(*create_layer_tree(),"Layers");
713 //notebook->append_page(*create_children_tree(),"Children");
714 //notebook->append_page(*create_keyframe_tree(),"Keyframes");
716 //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
717 //create all allocated stuff for this canvas
718 audio = new AudioContainer();
720 Gtk::Table *layout_table= manage(new class Gtk::Table(1, 3, false));
721 //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
722 layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
724 //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
727 layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
728 layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
732 layout_table->show();
735 //set_transient_for(*App::toolbox);
737 //synfig::info("Canvasview: Before Signals");
739 -- ** -- Signals -------------------------------------------------------------
742 canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
743 canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
745 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
747 //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
748 canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
749 canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
750 waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
751 waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
753 //MODIFIED TIME ADJUSTMENT STUFF....
754 time_window_adjustment().set_child_adjustment(&time_adjustment());
755 time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
756 time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
759 work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
760 work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
762 canvas_interface()->signal_canvas_added().connect(
764 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
767 canvas_interface()->signal_canvas_removed().connect(
769 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
773 canvas_interface()->signal_layer_param_changed().connect(
776 SLOT_EVENT(EVENT_REFRESH_DUCKS)
782 //MUCH TIME STUFF TAKES PLACE IN HERE
784 refresh_time_window();
786 /*! \todo We shouldn't need to do this at construction --
787 ** This should be preformed at the first time the window
790 work_area->queue_render_preview();
792 // If the canvas is really big, zoom out so that we can fit it all in the window
793 /*! \todo In other words, this is a zoom-to-fit, and should be
794 ** in its own function.
796 int w=get_canvas()->rend_desc().get_w()+70;
797 int h=get_canvas()->rend_desc().get_h()+70;
798 while(w>700 || h>600)
802 // WorkArea::async_update_preview() =>
803 // WorkArea::set_zoom(float) =>
804 // WorkArea::async_update_preview() =>
805 // desc.set_time(cur_time), where cur_time isn't initialised
806 work_area->set_time(0);
807 work_area->zoom_out();
808 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
809 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
813 set_default_size(w,h);
814 property_window_position().set_value(Gtk::WIN_POS_NONE);
819 std::list<Gtk::TargetEntry> listTargets;
820 listTargets.push_back( Gtk::TargetEntry("STRING") );
821 listTargets.push_back( Gtk::TargetEntry("text/plain") );
822 listTargets.push_back( Gtk::TargetEntry("image") );
824 drag_dest_set(listTargets);
825 signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
829 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
832 time_window_adjustment().set_page_increment(length);
833 time_window_adjustment().set_page_size(length);
837 time_window_adjustment().set_page_increment(10.0);
838 time_window_adjustment().set_page_size(10.0);
842 //synfig::info("Canvasview: Before Sound Hookup");
843 //load sound info from meta data
845 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
847 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
848 on_audio_offset_notify();
850 //signal connection - since they are all associated with the canvas view
852 //hook in signals for sound options box
853 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
854 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
856 //attach to the preview when it's visible
857 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
858 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
860 //hook to metadata signals
861 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
862 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
864 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
867 //synfig::info("Canvasview: Before Final time set up");
869 time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
870 time_window_adjustment().value_changed();
873 GRAB_HINT_DATA("canvas_view");
876 set_skip_taskbar_hint(true);
877 set_skip_pager_hint(true);
878 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
886 //synfig::info("Canvasview: Constructor Done");
889 CanvasView::~CanvasView()
893 App::ui_manager()->remove_action_group(action_group);
895 // Shut down the smach
897 smach_.set_default_state(0);
899 // We want to ensure that the UI_Manager and
900 // the selection manager get destructed right now.
901 ui_interface_.reset();
902 selection_manager_.reset();
904 // Delete any external widgets
905 for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
907 if(ext_widget_book_.begin()->second)
908 delete ext_widget_book_.begin()->second;
916 // don't be calling on_dirty_preview once this object has been deleted;
917 // this was causing a crash before
918 canvas_interface()->signal_dirty_preview().clear();
920 synfig::info("CanvasView:~CanvasView(): Destructor Finished");
926 CanvasView::create_time_bar()
930 Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
931 //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
932 //TIME BAR TEMPORARY POSITION
933 //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
935 timeslider->set_time_adjustment(&time_adjustment());
936 timeslider->set_bounds_adjustment(&time_window_adjustment());
937 //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
940 tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
941 tooltips.set_tip(*timeslider,_("Changes the current time"));
942 time_window_scroll->show();
944 time_window_scroll->set_flags(Gtk::CAN_FOCUS);
945 timeslider->set_flags(Gtk::CAN_FOCUS);
947 //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
948 //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
950 NORMAL_BUTTON(animatebutton,"gtk-yes","Animate");
951 animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
952 animatebutton->show();
954 NORMAL_BUTTON(keyframebutton,"synfig-keyframe_lock_all","All Keyframes Locked");
955 keyframebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
956 keyframebutton->show();
958 Gtk::Table *table= manage(new class Gtk::Table(2, 3, false));
960 //setup the audio display
961 disp_audio->set_size_request(-1,32); //disp_audio->show();
962 disp_audio->set_time_adjustment(&time_adjustment());
963 disp_audio->signal_start_scrubbing().connect(
964 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
966 disp_audio->signal_scrub().connect(
967 sigc::mem_fun(*audio,&AudioContainer::scrub)
969 disp_audio->signal_stop_scrubbing().connect(
970 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
973 table->attach(*manage(disp_audio), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
974 table->attach(*timeslider, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
975 table->attach(*time_window_scroll, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
977 table->attach(*animatebutton, 1, 2, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
978 table->attach(*keyframebutton, 2, 3, 0, 3, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
985 CanvasView::create_work_area()
987 work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
988 work_area->set_instance(get_instance());
989 work_area->set_canvas(get_canvas());
990 work_area->set_canvas_view(this);
991 work_area->set_progress_callback(get_ui_interface().get());
992 work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
994 return work_area.get();
999 CanvasView::create_status_bar()
1002 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
1005 // Create the status bar at the bottom of the window
1006 Gtk::Table *statusbartable= manage(new class Gtk::Table(7, 1, false));
1007 // statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
1008 progressbar =manage(new class Gtk::ProgressBar());
1009 SMALL_BUTTON(stopbutton,"gtk-stop","Stop");
1010 SMALL_BUTTON(refreshbutton,"gtk-refresh","Refresh");
1011 //SMALL_BUTTON(treetogglebutton,"gtk-go-down","Toggle Layer Tree");
1012 // NEW_SMALL_BUTTON(raisebutton,"gtk-go-up","Raise Layer");
1013 // NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down","Lower Layer");
1014 //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1015 // statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1016 // statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1019 current_time_widget=manage(new Widget_Time);
1020 current_time_widget->set_value(get_time());
1021 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1022 current_time_widget->signal_value_changed().connect(
1023 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1026 statusbartable->attach(*current_time_widget, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1027 statusbartable->attach(*statusbar, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1028 statusbartable->attach(*progressbar, 4, 5, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1029 statusbartable->attach(*refreshbutton, 5, 6, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1030 statusbartable->attach(*stopbutton, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1031 statusbar->set_has_resize_grip(false);
1034 refreshbutton->show();
1035 progressbar->show();
1036 stopbutton->set_sensitive(false);
1038 //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1039 //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1040 //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1042 refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1043 stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1046 statusbartable->show_all();
1047 return statusbartable;
1051 CanvasView::on_current_time_widget_changed()
1053 set_time(current_time_widget->get_value());
1057 CanvasView::create_children_tree()
1059 // Create the layer tree
1060 children_tree=manage(new class ChildrenTree());
1062 // Set up the layer tree
1063 //children_tree->set_model(children_tree_store());
1064 if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1065 if(children_tree)children_tree->show();
1068 if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1069 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1070 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1071 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1073 return children_tree;
1077 CanvasView::create_keyframe_tree()
1079 keyframe_tree=manage(new KeyframeTree());
1081 //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1082 //keyframe_tree->show();
1083 //keyframe_tree->set_model(keyframe_tree_store());
1084 keyframe_tree->set_editable(true);
1085 //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1087 keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1089 Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1090 scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1091 scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1092 scroll_layer_tree->add(*keyframe_tree);
1093 scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1094 //scroll_layer_tree->show();
1097 Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1098 layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1101 Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1103 NEW_SMALL_BUTTON(button_add,"gtk-add","New Keyframe");
1104 NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate","Duplicate Keyframe");
1105 NEW_SMALL_BUTTON(button_delete,"gtk-delete","Delete Keyframe");
1107 Gtk::HBox *hbox(manage(new Gtk::HBox()));
1108 layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1110 hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1111 hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1112 hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1115 button_raise->set_relief(Gtk::RELIEF_HALF);
1116 button_lower->set_relief(Gtk::RELIEF_HALF);
1117 button_duplicate->set_relief(Gtk::RELIEF_HALF);
1118 button_delete->set_relief(Gtk::RELIEF_HALF);
1121 button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1122 button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1123 button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1125 //layout_table->show_all();
1127 keyframe_tab_child=layout_table;
1130 layout_table->hide();
1132 return layout_table;
1136 CanvasView::create_layer_tree()
1138 // Create the layer tree
1139 layer_tree=manage(new class LayerTree());
1141 // Set up the layer tree
1142 //layer_tree->set_model(layer_tree_store());
1143 layer_tree->set_time_adjustment(time_adjustment());
1147 layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1148 layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1149 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1150 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1151 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
1152 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1159 CanvasView::init_menus()
1162 mainmenu.set_accel_group(get_accel_group());
1163 mainmenu.set_accel_path("<Canvas-view>");
1165 filemenu.set_accel_group(get_accel_group());
1166 filemenu.set_accel_path("<Canvas-view>/File");
1168 editmenu.set_accel_group(get_accel_group());
1169 editmenu.set_accel_path("<Canvas-view>/Edit");
1171 layermenu.set_accel_group(get_accel_group());
1172 layermenu.set_accel_path("<Canvas-view>/Layer");
1174 //cache the position of desired widgets
1176 /*Menus to worry about:
1185 action_group = Gtk::ActionGroup::create();
1187 //action_group->add( Gtk::Action::create("MenuFile", "_File") );
1188 action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1189 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1191 action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1192 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1194 action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1195 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1197 action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1198 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1200 action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1201 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1203 action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1204 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1206 action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1207 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1209 action_group->add( Gtk::Action::create("import", _("Import")),
1210 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1212 action_group->add( Gtk::Action::create("render", _("Render")),
1213 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1215 action_group->add( Gtk::Action::create("preview", _("Preview")),
1216 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1218 action_group->add( Gtk::Action::create("sound", _("Sound File")),
1219 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1221 action_group->add( Gtk::Action::create("options", _("Options")),
1222 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1224 action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close")),
1225 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))
1228 //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1229 // SLOT_EVENT(EVENT_UNDO)
1232 //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1233 // SLOT_EVENT(EVENT_REDO)
1236 action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1237 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1240 action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1241 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1244 action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1245 SLOT_EVENT(EVENT_STOP)
1248 action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1249 SLOT_EVENT(EVENT_REFRESH)
1252 action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1253 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1256 // Preview Quality Menu
1259 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1261 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1267 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i), strprintf("Set Quality to %d",i)));
1270 action->set_active();
1271 work_area->set_quality(i);
1273 action_group->add( action,
1275 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1282 action_group->add( Gtk::Action::create("play", Gtk::Stock::MEDIA_PLAY),
1283 sigc::mem_fun(*this, &studio::CanvasView::play)
1286 action_group->add( Gtk::Action::create("dialog-flipbook", _("Flipbook Dialog")),
1287 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1290 action_group->add( Gtk::Action::create("toggle-grid-show", _("Toggle Grid Show")),
1291 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)
1293 action_group->add( Gtk::Action::create("toggle-grid-snap", _("Toggle Grid Snap")),
1294 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)
1296 action_group->add( Gtk::Action::create("toggle-guide-show", _("Toggle Guide Show")),
1297 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)
1299 action_group->add( Gtk::Action::create("toggle-low-res", _("Toggle Low-Res")),
1300 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)
1302 action_group->add( Gtk::Action::create("toggle-onion-skin", _("Toggle Onion Skin")),
1303 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_onion_skin)
1307 action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1308 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1310 action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1311 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1316 Glib::RefPtr<Gtk::Action> action;
1318 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1319 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1320 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1321 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1323 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Forward"),_("Seek Forward"));
1324 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1325 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1326 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1328 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1329 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1331 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1332 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1334 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1335 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1337 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1338 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1340 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1341 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1343 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1344 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1346 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1347 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1349 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1350 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1355 #define DUCK_MASK(lower,upper) \
1356 duck_mask_##lower=Gtk::ToggleAction::create("mask-" #lower "-ducks", _("Show "#lower" ducks")); \
1357 duck_mask_##lower->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper)); \
1358 action_group->add( duck_mask_##lower, \
1360 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask), \
1361 Duck::TYPE_##upper \
1364 DUCK_MASK(position,POSITION);
1365 DUCK_MASK(tangent,TANGENT);
1366 DUCK_MASK(vertex,VERTEX);
1367 DUCK_MASK(radius,RADIUS);
1368 DUCK_MASK(width,WIDTH);
1369 DUCK_MASK(angle,ANGLE);
1372 add_accel_group(App::ui_manager()->get_accel_group());
1374 /* // Here is where we add the actions that may have conflicting
1375 // keyboard accelerators.
1377 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1378 Glib::RefPtr<Gtk::Action> action;
1380 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1381 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1383 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1384 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1386 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1387 accel_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::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1390 accel_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::StockID("gtk-zoom-in"));
1393 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1395 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1396 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1398 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1399 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1401 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1402 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1404 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1406 Glib::ustring ui_info =
1409 <accelerator action='seek-next-frame' />
1410 <accelerator action='seek-prev-frame' />
1411 <accelerator action='jump-next-keyframe' />
1412 <accelerator action='jump-prev-keyframe' />
1413 <accelerator action='canvas-zoom-in' />
1414 <accelerator action='canvas-zoom-out' />
1415 <accelerator action='time-zoom-in' />
1416 <accelerator action='time-zoom-out' />
1420 accel_ui_manager->add_ui_from_string(ui_info);
1421 add_accel_group(accel_ui_manager->get_accel_group());
1423 accel_ui_manager->insert_action_group(accel_action_group);
1424 set_ref_obj("accel_ui_manager",accel_ui_manager);
1425 set_ref_obj("accel_action_group",accel_action_group);
1433 //Test some key stuff
1435 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1436 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1437 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))));
1438 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))));
1439 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1441 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))));
1442 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))));
1443 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))));
1445 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1446 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))));
1447 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1448 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1449 sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1451 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1452 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1454 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1455 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1458 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1459 filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1460 sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1462 filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1463 filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close))));
1465 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1466 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1467 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1468 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1469 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1470 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1471 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1472 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)));
1473 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)));
1474 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1476 //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))));
1477 //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))));
1478 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)));
1479 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1480 editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1481 editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1482 sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1485 build_new_layer_menu(newlayermenu);
1486 layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New",newlayermenu));
1490 synfigapp::Action::ParamList param_list;
1491 param_list.add("canvas",Canvas::Handle(get_canvas()));
1492 param_list.add("canvas_interface",canvas_interface());
1493 add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1497 //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Keyframe Dialog",sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1502 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1504 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1505 duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1506 duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1507 duck_mask_position->signal_toggled().connect(
1509 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1514 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1515 duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1516 duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1517 duck_mask_vertex->signal_toggled().connect(
1519 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1524 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1525 duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1526 duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1527 duck_mask_tangent->signal_toggled().connect(
1529 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1534 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1535 duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1536 duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1537 duck_mask_radius->signal_toggled().connect(
1539 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1544 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1545 duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1546 duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1547 duck_mask_width->signal_toggled().connect(
1549 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1554 duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1555 duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1556 duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1557 duck_mask_angle->signal_toggled().connect(
1559 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1564 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1567 // Preview Quality Menu
1570 qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1572 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1574 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1580 qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1582 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1587 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1590 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::MEDIA_PLAY,
1591 sigc::mem_fun(*this, &studio::CanvasView::play)));
1592 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1593 sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1595 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1597 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1598 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1599 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1600 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1601 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1602 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1603 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1604 sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1606 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1608 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1609 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1610 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1611 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1612 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1613 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1614 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1615 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
1616 viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1618 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('+',static_cast<Gdk::ModifierType>(0)),
1619 sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in)));
1620 viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('_',static_cast<Gdk::ModifierType>(0)),
1621 sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out)));
1623 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1624 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1625 viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1626 sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1628 mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1629 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_File",filemenu));
1630 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Edit",editmenu));
1631 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_View",viewmenu));
1632 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Canvas",canvasmenu));
1633 mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("_Layer",layermenu));
1635 mainmenu.accelerate(*this);
1639 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Waypoint",NOT_IMPLEMENTED_SLOT));
1640 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete Waypoint",NOT_IMPLEMENTED_SLOT));
1641 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Export",NOT_IMPLEMENTED_SLOT));
1642 trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1643 trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Properties",NOT_IMPLEMENTED_SLOT));
1651 keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1652 sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1656 get_accel_group()->unlock();
1658 //Set the accelerator paths for all the menus
1659 filemenu.set_accel_path("<synfig>/File");
1660 editmenu.set_accel_path("<synfig>/Edit");
1661 layermenu.set_accel_path("<synfig>/Layer");
1662 //mainmenu.set_accel_path("<synfig-main>");
1663 canvasmenu.set_accel_path("<synfig>/Canvas");
1664 viewmenu.set_accel_path("<synfig>/View");
1665 duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1670 CanvasView::on_unselect_layers()
1672 layer_tree->clear_selected_layers();
1676 CanvasView::show_keyframe_dialog()
1678 Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
1679 if(selection->get_selected())
1681 Gtk::TreeRow row(*selection->get_selected());
1683 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
1685 keyframe_dialog.set_keyframe(keyframe);
1686 keyframe_dialog.present();
1691 CanvasView::add_layer(synfig::String x)
1693 Canvas::Handle canvas;
1695 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
1697 int target_depth(0);
1699 if(layer_list.empty())
1701 canvas=get_canvas();
1705 canvas=(*layer_list.begin())->get_canvas();
1706 target_depth=canvas->get_depth(*layer_list.begin());
1710 Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
1713 get_selection_manager()->clear_selected_layers();
1714 get_selection_manager()->set_selected_layer(layer);
1719 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
1721 //Gtk::Menu* menu(manage(new Gtk::Menu));
1722 Gtk::Menu* menu(¶mmenu);
1723 menu->items().clear();
1725 synfigapp::Action::ParamList param_list;
1726 param_list.add("time",canvas_interface()->get_time());
1727 param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
1728 param_list.add("canvas_interface",canvas_interface());
1729 param_list.add("layer",layer);
1731 //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
1732 //build_new_layer_menu(*newlayers);
1734 //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
1736 if(layer->get_name()=="PasteCanvas")
1738 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
1742 &studio::LayerTree::select_all_children_layers
1749 add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
1751 menu->popup(3,gtk_get_current_event_time());
1755 CanvasView::register_layer_type(synfig::Layer::Book::value_type &/*lyr*/,std::map<synfig::String,Gtk::Menu*>* /*category_map*/)
1757 /* if(lyr.second.category==_("Do Not Use"))
1760 if(category_map->count(lyr.second.category)==0)
1761 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
1763 (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
1766 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
1775 CanvasView::build_new_layer_menu(Gtk::Menu &/*menu*/)
1778 std::map<synfig::String,Gtk::Menu*> category_map;
1781 synfig::Layer::book().begin(),
1782 synfig::Layer::book().end(),
1786 &studio::CanvasView::register_layer_type
1792 menu.items().clear();
1793 menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1795 std::map<synfig::String,Gtk::Menu*>::iterator iter;
1796 for(iter=category_map.begin();iter!=category_map.end();++iter)
1797 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
1804 CanvasView::popup_main_menu()
1806 //mainmenu.popup(0,gtk_get_current_event_time());
1807 Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
1810 //menu->set_accel_group(App::ui_manager()->get_accel_group());
1811 //menu->accelerate(*this);
1812 menu->popup(0,gtk_get_current_event_time());
1817 CanvasView::on_refresh_pressed()
1821 work_area->queue_render_preview();
1825 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
1827 get_selection_manager()->clear_selected_layers();
1829 get_selection_manager()->set_selected_layer(layer);
1834 CanvasView::refresh_rend_desc()
1836 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1840 //synfig::info("Canvasview: Refreshing render desc info");
1841 if(!get_time().is_equal(time_adjustment().get_value()))
1843 time_adjustment().set_value(get_time());
1844 time_adjustment().value_changed();
1847 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1848 if(length<DEFAULT_TIME_WINDOW_SIZE)
1850 time_window_adjustment().set_page_increment(length);
1851 time_window_adjustment().set_page_size(length);
1855 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
1856 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
1859 //set the FPS of the timeslider
1860 timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
1862 //set the beginning and ending time of the time slider
1863 Time begin_time=get_canvas()->rend_desc().get_time_start();
1864 Time end_time=get_canvas()->rend_desc().get_time_end();
1866 // Setup the time_window adjustment
1867 time_window_adjustment().set_lower(begin_time);
1868 time_window_adjustment().set_upper(end_time);
1869 time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1871 //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
1872 if(length < time_window_adjustment().get_page_size())
1874 time_window_adjustment().set_page_increment(length);
1875 time_window_adjustment().set_page_size(length);
1878 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1879 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1880 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1881 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1884 time_window_adjustment().changed(); //only non-value stuff was changed
1886 // Setup the time adjustment
1888 //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
1889 //time_adjustment().set_lower(time_window_adjustment().get_value());
1890 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
1892 // time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
1893 // time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
1894 time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
1895 time_adjustment().set_page_increment(synfig::Time(1.0));
1896 time_adjustment().set_page_size(0);
1898 time_adjustment().changed();
1900 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
1901 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1902 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1903 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
1906 if(begin_time==end_time)
1915 //clamp time to big bounds...
1916 if(time_adjustment().get_value() < begin_time)
1918 time_adjustment().set_value(begin_time);
1919 time_adjustment().value_changed();
1922 if(time_adjustment().get_value() > end_time)
1924 time_adjustment().set_value(end_time);
1925 time_adjustment().value_changed();
1928 /*synfig::info("Time stats: \n"
1929 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
1930 "t: %p - [%.3f,%.3f] %.3f",
1931 &time_window_adjustment_, time_window_adjustment_.get_lower(),
1932 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
1933 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
1934 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
1935 time_adjustment_.get_value()
1938 work_area->queue_render_preview();
1945 if (get_work_area()->get_updating())
1947 get_work_area()->stop_updating(true); // stop and mark as cancelled
1949 // give the workarea chances to stop updating
1950 Glib::signal_timeout().connect(sigc::mem_fun(*this, &CanvasView::close_instance_when_safe) ,250);
1954 close_instance_when_safe();
1959 CanvasView::create(loose_handle<Instance> instance,handle<Canvas> canvas)
1961 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
1962 instance->canvas_view_list().push_front(view);
1963 instance->signal_canvas_view_created()(view.get());
1968 CanvasView::update_title()
1972 title+=etl::basename(get_instance()->get_file_name())
1974 if(get_canvas()->get_name().empty())
1975 title+='"'+get_canvas()->get_id()+'"';
1977 title+='"'+get_canvas()->get_name()+'"';
1979 if(get_instance()->synfigapp::Instance::get_action_count())
1980 title+=_(" (Unsaved)");
1982 if(get_instance()->synfigapp::Instance::in_repository())
1985 if(get_instance()->synfigapp::Instance::is_modified())
1986 title+=_("-MODIFIED");
1987 if(get_instance()->synfigapp::Instance::is_updated())
1988 title+=_("-UPDATED");
1992 if(get_canvas()->is_root())
1993 title+=_(" (Root)");
2000 CanvasView::on_hide()
2003 Gtk::Window::on_hide();
2007 CanvasView::present()
2009 grab_focus();//on_focus_in_event(0);
2010 Gtk::Window::present();
2014 CanvasView::on_focus_in_event(GdkEventFocus*x)
2016 if(studio::App::get_selected_canvas_view()!=this)
2018 if(studio::App::get_selected_canvas_view())
2020 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2021 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2024 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2026 studio::App::set_selected_canvas_view(this);
2028 App::ui_manager()->insert_action_group(action_group);
2031 // HACK ... Questionable...?
2033 return Gtk::Window::on_focus_in_event(x);
2039 CanvasView::on_focus_out_event(GdkEventFocus*x)
2041 //App::ui_manager()->remove_action_group(action_group);
2042 //App::ui_manager()->ensure_update();
2043 return Gtk::Window::on_focus_out_event(x);
2047 CanvasView::refresh_tables()
2049 // if(layer_tree_store_)layer_tree_store_->refresh();
2050 // if(children_tree_store_)children_tree_store_->refresh();
2054 CanvasView::rebuild_tables()
2056 // layer_tree_store_->rebuild();
2057 // children_tree_store_->rebuild();
2061 CanvasView::build_tables()
2063 // layer_tree_store_->rebuild();
2064 // children_tree_store_->rebuild();
2068 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2070 synfigapp::Action::Handle action(synfigapp::Action::create("layer_activate"));
2076 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2077 if(!action->set_param("canvas_interface",canvas_interface()))
2078 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2079 synfig::error("LayerActivate didn't like CanvasInterface...?");
2080 action->set_param("time",get_time());
2081 action->set_param("layer",layer);
2082 action->set_param("new_status",!layer->active());
2084 assert(action->is_ready());
2086 canvas_interface()->get_instance()->perform_action(action);
2091 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location)
2093 parammenu.items().clear();
2094 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location);
2096 parammenu.popup(3,gtk_get_current_event_time());
2100 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2102 get_instance()->add_actions_to_menu(menu, param_list, category);
2106 CanvasView::on_layer_user_click(int button, Gtk::TreeRow /*row*/, LayerTree::ColumnID /*column_id*/)
2113 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2114 if(menu && menu->get_submenu())
2116 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2117 //menu->accelerate(*this);
2118 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2123 bool multiple_selected=true;
2125 if(layer_tree->get_selection()->count_selected_rows()<=1)
2126 multiple_selected=false;
2128 // If the clicked row is not selected, then unselect
2129 // everything that isn't selected and select this row
2130 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2132 layer_tree->get_selection()->unselect_all();
2133 layer_tree->get_selection()->select(row);
2134 multiple_selected=false;
2137 if(column_id==COLUMNID_TIME_TRACK)
2140 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2141 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2142 //ValueNode::Handle parent_value_node;
2143 //ValueBase value=row[layer_param_tree_model.value];
2147 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2151 Layer::Handle layer(row[layer_tree_model.layer]);
2152 synfigapp::Action::ParamList param_list;
2153 param_list.add("time",canvas_interface()->get_time());
2154 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2155 param_list.add("canvas_interface",canvas_interface());
2156 if(!multiple_selected)
2157 param_list.add("layer",layer);
2160 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2161 synfigapp::SelectionManager::LayerList::iterator iter;
2163 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2164 param_list.add("layer",Layer::Handle(*iter));
2167 parammenu.items().clear();
2169 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2170 build_new_layer_menu(*newlayers);
2172 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("New Layer",*newlayers));
2173 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2175 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2179 &studio::LayerTree::select_all_children_layers
2186 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2187 parammenu.popup(button,gtk_get_current_event_time());
2191 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2193 // Right-click on time track with animated
2194 // trackmenu.popup(0,0);
2199 if(!multiple_selected)
2201 popup_param_menu(value_desc);
2208 parammenu.items().clear();
2209 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Connect",
2210 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2212 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem("Disconnect",
2213 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2215 parammenu.popup(0,0);
2235 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2241 if(column_id==COLUMNID_TIME_TRACK)
2243 if(!(bool)row[children_tree_model.is_canvas])
2245 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2248 //! \todo fix properly -- what is the child dialog for?
2249 synfig::info("preventing child dialog right-click crash");
2253 popup_param_menu(value_desc);
2267 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2271 case GDK_BUTTON_PRESS:
2272 switch(event->button.button)
2276 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2282 case GDK_MOTION_NOTIFY:
2284 case GDK_BUTTON_RELEASE:
2294 CanvasView::refresh_time_window()
2296 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2297 //time_adjustment().set_lower(time_window_adjustment().get_value());
2298 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2300 time_adjustment().set_page_increment(1.0); // One second
2301 time_adjustment().set_page_size(0);
2304 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2305 time_adjustment().changed();
2307 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2309 children_tree->queue_draw();
2313 CanvasView::on_time_changed()
2315 Time time(get_time());
2317 current_time_widget->set_value(time);
2319 get_canvas()->keyframe_list().find(time);
2320 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2322 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2325 if(get_time() != time_adjustment().get_value())
2328 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2329 if(time < time_window_adjustment().get_value() ||
2330 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2332 time_window_adjustment().set_value(
2333 time-time_window_adjustment().get_page_size()/2
2336 time_adjustment().set_value(time);
2337 time_adjustment().value_changed();
2339 // Shouldn't these trees just hook into
2340 // the time changed signal...?
2341 //YES THEY SHOULD...
2342 if(layer_tree)layer_tree->queue_draw();
2343 if(children_tree)children_tree->queue_draw();
2348 CanvasView::time_zoom_in()
2350 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2351 time_window_adjustment().changed();
2353 refresh_time_window();
2357 CanvasView::time_zoom_out()
2359 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2360 time_window_adjustment().changed();
2362 refresh_time_window();
2366 CanvasView::time_was_changed()
2368 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2373 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2375 canvas_interface()->change_value(value_desc,new_value);
2380 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2382 Gtk::TreePath path(path_string);
2384 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2386 assert((bool)row[children_tree_model.is_value_node]);
2388 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2391 on_edited_value(value_desc,value);
2396 CanvasView::on_id_changed()
2403 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2405 // If the aninimate flag was set in mode...
2406 if(mode&synfigapp::MODE_ANIMATE)
2409 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),Gtk::ICON_SIZE_BUTTON));
2410 animatebutton->remove();
2411 animatebutton->add(*icon);
2412 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2413 icon->set_padding(0,0);
2419 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),Gtk::ICON_SIZE_BUTTON));
2420 animatebutton->remove();
2421 animatebutton->add(*icon);
2422 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2423 icon->set_padding(0,0);
2427 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2430 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2431 keyframebutton->remove();
2432 keyframebutton->add(*icon);
2433 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2434 icon->set_padding(0,0);
2437 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2440 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2441 keyframebutton->remove();
2442 keyframebutton->add(*icon);
2443 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2444 icon->set_padding(0,0);
2447 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2450 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2451 keyframebutton->remove();
2452 keyframebutton->add(*icon);
2453 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2454 icon->set_padding(0,0);
2457 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2460 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2461 keyframebutton->remove();
2462 keyframebutton->add(*icon);
2463 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2464 icon->set_padding(0,0);
2468 work_area->queue_draw();
2472 CanvasView::on_animate_button_pressed()
2474 if(get_mode()&synfigapp::MODE_ANIMATE)
2475 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2477 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2481 CanvasView::on_keyframe_button_pressed()
2483 synfigapp::CanvasInterface::Mode mode(get_mode());
2485 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2487 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2489 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2491 set_mode(get_mode()-synfigapp::MODE_ANIMATE_PAST|synfigapp::MODE_ANIMATE_FUTURE);
2493 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2495 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2497 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2499 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2504 CanvasView::duck_change_param(const Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2506 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2510 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2512 switch(value_desc.get_value_type())
2514 case ValueBase::TYPE_REAL:
2515 return canvas_interface()->change_value(value_desc,value.mag());
2517 case ValueBase::TYPE_ANGLE:
2518 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2521 return canvas_interface()->change_value(value_desc,value);
2529 CanvasView::selected_layer_color_set(Color color)
2531 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2532 synfigapp::SelectionManager::LayerList::iterator iter;
2534 // Create the action group
2535 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
2537 Layer::Handle layer;
2538 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2543 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
2548 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
2553 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
2557 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
2560 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
2562 Layer::Handle layer(*iter);
2564 if(selected_list.count(layer))
2566 if(!curr_transform_stack_set)
2568 curr_transform_stack_set=true;
2569 curr_transform_stack=transform_stack;
2572 // This layer is currently selected.
2573 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2575 // do the bounding box thing
2576 bbox|=transform_stack.perform(layer->get_bounding_rect());
2578 // Grab the layer's list pf parameters
2579 Layer::ParamList paramlist(layer->get_param_list());
2581 // Grab the layer vocabulary
2582 Layer::Vocab vocab=layer->get_param_vocab();
2583 Layer::Vocab::iterator iter;
2585 for(iter=vocab.begin();iter!=vocab.end();iter++)
2587 if(!iter->get_hidden() && !iter->get_invisible_duck())
2589 synfigapp::ValueDesc value_desc(layer,iter->get_name());
2590 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
2591 if(value_desc.is_value_node())
2592 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
2594 if(iter->get_name()=="color")
2597 if(!App::dialog_color->busy())
2599 App::dialog_color->reset();
2600 App::dialog_color->set_color(layer->get_param("color").get(Color()));
2601 App::dialog_color->signal_edited().connect(
2604 &studio::CanvasView::selected_layer_color_set
2613 layer_name=layer->get_name();
2617 Transform::Handle trans(layer->get_transform());
2620 transform_stack.push(trans);
2624 /* // Add transforms onto the stack
2625 if(layer_name=="Translate")
2627 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
2630 if(layer_name=="Zoom")
2633 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
2634 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2637 if(layer_name=="stretch")
2639 Vector scale(layer->get_param("amount").get(Vector()));
2640 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
2643 if(layer_name=="Rotate")
2645 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
2651 // If this is a paste canvas layer, then we need to
2653 if(layer_name=="PasteCanvas")
2656 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
2657 Vector origin(layer->get_param("origin").get(Vector()));
2659 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
2661 if(!scale.is_equal_to(Vector(1,1)))
2662 transform_stack.push(new Transform_Scale(scale,origin));
2663 if(!scale.is_equal_to(Vector(0,0)))
2664 transform_stack.push(new Transform_Translate(origin));
2666 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
2668 if(!scale.is_equal_to(Vector(0,0)))
2669 transform_stack.pop();
2670 if(!scale.is_equal_to(Vector(1,1)))
2671 transform_stack.pop();
2674 // Remove all of the transforms we have added
2675 while(transforms--) { transform_stack.pop(); }
2677 #undef QUEUE_REBUILD_DUCKS
2681 CanvasView::queue_rebuild_ducks()
2684 if(rebuild_ducks_queued)
2687 if(rebuild_ducks_queued)
2688 queue_rebuild_ducks_connection.disconnect();
2691 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
2693 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
2699 rebuild_ducks_queued=true;
2703 CanvasView::rebuild_ducks()
2708 synfig::info("%d",i/(i-i));
2711 rebuild_ducks_queued=false;
2712 //queue_rebuild_ducks_connection.disconnect();
2714 if(work_area->is_dragging())
2716 queue_rebuild_ducks();
2720 if(!duck_refresh_flag)
2722 duck_refresh_needed=true;
2728 work_area->clear_ducks();
2729 work_area->set_time(get_time());
2730 get_canvas()->set_time(get_time());
2731 curr_transform_stack.clear();
2732 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
2733 curr_transform_stack_set=false;
2735 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
2737 //get_canvas()->set_time(get_time());
2738 bool not_empty(false);
2740 // First do the layers...
2742 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
2743 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
2745 if(!layer_set.empty())
2748 synfig::TransformStack transform_stack;
2750 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
2754 // Now do the children
2756 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
2757 synfigapp::SelectionManager::ChildrenList::iterator iter;
2758 synfig::TransformStack transform_stack;
2760 if(selected_list.empty())
2767 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
2769 work_area->add_to_ducks(*iter,this,transform_stack);
2773 work_area->refresh_selected_ducks();
2774 work_area->queue_draw_preview();
2778 CanvasView::on_dirty_preview()
2782 IsWorking is_working(*this);
2784 work_area->queue_render_preview();
2791 assert(get_canvas());
2793 // If we are already busy, don't play!
2794 if(working_depth)return;
2796 // Set us up as working
2797 IsWorking is_working(*this);
2801 time=work_area->get_time(),
2802 endtime=get_canvas()->rend_desc().get_time_end();
2804 // If we are already at the end of time, start over
2806 time=get_canvas()->rend_desc().get_time_start();
2810 work_area->clear_ducks();
2812 for(timer.reset(); time + timer() < endtime;)
2814 //Clamp the time window so we can see the time value as it races across the horizon
2815 bool timewindreset = false;
2817 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
2819 time_window_adjustment().set_value(
2821 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
2822 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
2824 timewindreset = true;
2827 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
2829 time_window_adjustment().set_value(
2831 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
2832 time_window_adjustment().get_lower())
2835 timewindreset = true;
2838 //we need to tell people that the value changed
2839 if(timewindreset) time_window_adjustment().value_changed();
2841 //update actual time to next step
2842 time_adjustment().set_value(time+timer());
2843 time_adjustment().value_changed();
2845 if(!work_area->sync_render_preview())
2848 // wait for the workarea to refresh itself
2849 while (studio::App::events_pending())
2850 studio::App::iteration(false);
2852 if(get_cancel_status())
2860 time_adjustment().set_value(endtime);
2861 time_adjustment().value_changed();
2865 CanvasView::show_tables()
2868 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
2869 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2871 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2872 treetogglebutton->remove();
2873 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
2874 treetogglebutton->show_all();
2881 CanvasView::hide_tables()
2884 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
2885 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
2887 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2888 treetogglebutton->remove();
2889 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
2890 treetogglebutton->show_all();
2897 CanvasView::tables_are_visible()
2899 // return notebook->is_visible();
2904 CanvasView::toggle_tables()
2906 // if(tables_are_visible())
2913 CanvasView::show_timebar()
2916 current_time_widget->show();
2918 //keyframe_tab_child->show();
2920 layer_tree->set_show_timetrack(true);
2922 children_tree->set_show_timetrack(true);
2926 CanvasView::hide_timebar()
2929 current_time_widget->hide();
2930 //keyframe_tab_child->hide();
2932 layer_tree->set_show_timetrack(false);
2934 children_tree->set_show_timetrack(false);
2938 CanvasView::set_sensitive_timebar(bool sensitive)
2940 timebar->set_sensitive(sensitive);
2941 current_time_widget->set_sensitive(sensitive);
2942 //keyframe_tab_child->set_sensitive(sensitive);
2944 layer_tree->set_sensitive(sensitive);
2946 children_tree->set_sensitive(sensitive);
2951 CanvasView::on_waypoint_clicked(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint,int button)
2953 waypoint_dialog.set_value_desc(value_desc);
2954 waypoint_dialog.set_waypoint(waypoint);
2959 waypoint_dialog.show();
2963 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
2965 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-jump-to"),
2968 *canvas_interface(),
2969 &synfigapp::CanvasInterface::set_time
2975 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Edit Waypoint"),
2982 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-duplicate"),
2986 *canvas_interface(),
2987 &synfigapp::CanvasInterface::waypoint_duplicate
2994 waypoint_menu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
2998 *canvas_interface(),
2999 &synfigapp::CanvasInterface::waypoint_remove
3006 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3015 CanvasView::on_waypoint_changed()
3017 synfigapp::Action::ParamList param_list;
3018 param_list.add("canvas",get_canvas());
3019 param_list.add("canvas_interface",canvas_interface());
3020 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3021 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3022 // param_list.add("time",canvas_interface()->get_time());
3024 get_instance()->process_action("waypoint_set_smart", param_list);
3028 CanvasView::on_waypoint_delete()
3030 synfigapp::Action::ParamList param_list;
3031 param_list.add("canvas",get_canvas());
3032 param_list.add("canvas_interface",canvas_interface());
3033 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3034 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3035 // param_list.add("time",canvas_interface()->get_time());
3037 get_instance()->process_action("waypoint_remove", param_list);
3041 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)
3043 // We will make this true once we have a solid drop
3044 bool success(false);
3045 //synfig::info("Droped data of type \"%s\"",selection_data.get_data_type());
3046 //synfig::info("Droped data of target \"%s\"",gdk_atom_name(selection_data->target));
3047 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3049 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3051 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3053 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3055 Layer::Handle layer(synfig::Layer::create("Text"));
3058 if(!layer->set_param("text",ValueBase(selection_data)))
3061 synfigapp::Action::Handle action(synfigapp::Action::create("layer_add"));
3067 action->set_param("canvas",get_canvas());
3068 action->set_param("canvas_interface",canvas_interface());
3069 action->set_param("new",layer);
3071 if(!get_instance()->perform_action(action))
3074 // Ok, we have successfully imported at least one item.
3076 } while(0); // END of "STRING"
3078 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3080 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3082 // For some reason, GTK hands us a list of URL's seperated
3083 // by not only Carrage-Returns, but also Line-Feeds.
3084 // Line-Feeds will mess us up. Remove all the line-feeds.
3085 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3086 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3088 std::stringstream stream(selection_data);
3090 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3093 synfig::String filename,URI;
3094 getline(stream,filename);
3096 // If we don't have a filename, move on.
3097 if(filename.empty())
3100 // Make sure this URL is of the "file://" type.
3101 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3104 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3108 // Strip the "file://" part from the filename
3109 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3112 try{ext=(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));}catch(...){continue;}
3114 // If this is a SIF file, then we need to do things slightly differently
3117 if(work_area->load_sketch(filename))
3120 work_area->queue_draw();
3125 if(canvas_interface()->import(filename))
3131 } // END of "text/plain"
3134 ui_interface_->error("Drop failed: bad selection data");
3137 context->drag_finish(success, false, time);
3141 CanvasView::on_keyframe_add_pressed()
3143 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
3147 ui_interface_->error("I am unable to find the appropriate action");
3151 action->set_param("canvas",get_canvas());
3152 action->set_param("canvas_interface",canvas_interface());
3153 action->set_param("keyframe",Keyframe(get_time()));
3155 canvas_interface()->get_instance()->perform_action(action);
3159 CanvasView::on_keyframe_duplicate_pressed()
3161 const KeyframeTreeStore::Model model;
3162 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3166 ui_interface_->error("I am unable to duplicate the keyframe");
3169 keyframe=row[model.keyframe];
3171 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_duplicate"));
3175 ui_interface_->error("I am unable to find the appropriate action");
3179 action->set_param("canvas",get_canvas());
3180 action->set_param("canvas_interface",canvas_interface());
3181 action->set_param("keyframe",keyframe);
3182 action->set_param("time",get_time());
3184 canvas_interface()->get_instance()->perform_action(action);
3188 CanvasView::on_keyframe_remove_pressed()
3190 const KeyframeTreeStore::Model model;
3191 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3195 ui_interface_->error("I am unable to remove the keyframe");
3198 keyframe=row[model.keyframe];
3200 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_remove"));
3204 ui_interface_->error("I am unable to find the appropriate action");
3208 action->set_param("canvas",get_canvas());
3209 action->set_param("canvas_interface",canvas_interface());
3210 action->set_param("keyframe",keyframe);
3212 canvas_interface()->get_instance()->perform_action(action);
3217 CanvasView::toggle_duck_mask(Duckmatic::Type type)
3219 bool is_currently_on(work_area->get_type_mask()&type);
3223 case Duck::TYPE_POSITION:
3224 if(duck_mask_position)
3225 duck_mask_position->set_active(!is_currently_on);
3228 case Duck::TYPE_VERTEX:
3229 if(duck_mask_vertex)
3230 duck_mask_vertex->set_active(!is_currently_on);
3233 case Duck::TYPE_TANGENT:
3234 if(duck_mask_tangent)
3235 duck_mask_tangent->set_active(!is_currently_on);
3238 case Duck::TYPE_RADIUS:
3239 if(duck_mask_radius)
3240 duck_mask_radius->set_active(!is_currently_on);
3243 case Duck::TYPE_WIDTH:
3245 duck_mask_width->set_active(!is_currently_on);
3248 case Duck::TYPE_ANGLE:
3250 duck_mask_angle->set_active(!is_currently_on);
3254 synfig::warning("CanvasView::toggle_duck_mask():Unknown duck type!");
3259 work_area->set_type_mask(work_area->get_type_mask()-type);
3261 work_area->set_type_mask(work_area->get_type_mask()|type);
3263 work_area->queue_draw();
3268 CanvasView::image_import()
3270 String filename(dirname(get_canvas()->get_file_name()));
3271 if(App::dialog_open_file(_("Import Image"), filename))
3272 canvas_interface()->import(filename);
3276 CanvasView::process_event_key(EventKey x)
3278 return smach_.process_event(x);
3282 CanvasView::on_input_device_changed(GdkDevice* device)
3286 get_smach().egress();
3290 synfigapp::InputDevice::Handle input_device;
3291 input_device=synfigapp::Main::select_input_device(device->name);
3292 App::toolbox->change_state(input_device->get_state());
3293 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
3297 CanvasView::on_preview_option()
3299 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
3301 Canvas::Handle canv = get_canvas();
3305 RendDesc &r = canv->rend_desc();
3306 if(r.get_frame_rate())
3308 float rate = 1/r.get_frame_rate();
3309 float beg = r.get_time_start() + r.get_frame_start()*rate;
3310 float end = r.get_time_start() + r.get_frame_end()*rate;
3314 po = new Dialog_PreviewOptions;
3315 po->set_zoom(work_area->get_zoom()/2);
3316 po->set_fps(r.get_frame_rate()/2);
3317 po->set_begintime(beg);
3318 po->set_begin_override(false);
3319 po->set_endtime(end);
3320 po->set_end_override(false);
3322 set_ext_widget("prevoptions",po);
3324 /*po->set_zoom(work_area->get_zoom()/2);
3325 po->set_fps(r.get_frame_rate()/2);
3326 po->set_begintime(beg);
3327 po->set_begin_override(false);
3328 po->set_endtime(end);
3329 po->set_end_override(false);*/
3331 po->set_global_fps(r.get_frame_rate());
3332 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
3339 CanvasView::on_preview_create(const PreviewInfo &info)
3341 //set all the options
3342 etl::handle<Preview> prev = new Preview;
3344 prev->set_canvasview(this);
3345 prev->set_zoom(info.zoom);
3346 prev->set_fps(info.fps);
3347 prev->set_overbegin(info.overbegin);
3348 prev->set_begintime(info.begintime);
3349 prev->set_overend(info.overend);
3350 prev->set_endtime(info.endtime);
3351 prev->set_quality(work_area->get_quality());
3356 Dialog_Preview *pd = preview_dialog.get();
3359 pd->set_default_size(700,510);
3360 pd->set_preview(prev.get());
3365 CanvasView::on_audio_option()
3367 synfig::warning("Launching Audio Options");
3368 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
3369 sound_dialog->present();
3373 CanvasView::on_audio_file_change(const std::string &f)
3375 //save in meta data - always even when not valid...
3376 canvas_interface()->set_meta_data("audiofile",f);
3380 CanvasView::on_audio_offset_change(const Time &t)
3382 canvas_interface()->set_meta_data("audiooffset",t.get_string());
3386 CanvasView::on_audio_file_notify()
3388 std::string file(get_canvas()->get_meta_data("audiofile"));
3389 if(!file.c_str()) return;
3391 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
3393 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
3394 get_canvas()->erase_meta_data("audiofile");
3396 disp_audio->set_profile(etl::handle<AudioProfile>());
3399 //save in canvasview
3400 synfig::warning("Getting the profile of the music stuff");
3402 //profile specific stuff for the preview widget
3403 //similar for other attachments
3404 Dialog_Preview *pd = preview_dialog.get();
3405 pd->get_widget().set_audio(audio);
3407 handle<AudioProfile> prof = audio->get_profile();
3411 synfig::warning("Agh, I couldn't build the profile captain!");
3413 pd->get_widget().set_audioprofile(prof);
3415 disp_audio->set_profile(audio->get_profile());
3418 synfig::warning("successfully set the profiles and stuff");
3420 disp_audio->queue_draw();
3424 CanvasView::on_audio_offset_notify()
3426 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
3427 audio->set_offset(t);
3428 sound_dialog->set_offset(t);
3429 disp_audio->queue_draw();
3431 // synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
3435 CanvasView::play_audio(float t)
3439 synfig::info("Playing audio at %f s",t);
3445 CanvasView::stop_audio()
3454 CanvasView::on_audio_scrub()
3462 Glib::RefPtr<Glib::ObjectBase>
3463 CanvasView::get_ref_obj(const synfig::String& x)
3465 return ref_obj_book_[x];
3468 Glib::RefPtr<const Glib::ObjectBase>
3469 CanvasView::get_ref_obj(const synfig::String& x)const
3471 return ref_obj_book_.find(x)->second;
3475 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
3480 Glib::RefPtr<Gtk::TreeModel>
3481 CanvasView::get_tree_model(const synfig::String& x)
3483 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
3486 Glib::RefPtr<const Gtk::TreeModel>
3487 CanvasView::get_tree_model(const synfig::String& x)const
3489 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
3493 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
3495 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
3499 CanvasView::get_ext_widget(const synfig::String& x)
3501 return ext_widget_book_[x];
3505 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
3507 ext_widget_book_[x]=y;
3510 layer_tree=dynamic_cast<LayerTree*>(y);
3512 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
3513 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3514 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
3515 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3516 layer_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3520 children_tree=dynamic_cast<ChildrenTree*>(y);
3521 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
3522 if(children_tree)children_tree->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked));
3523 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
3526 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
3529 static bool _close_instance(etl::handle<Instance> instance)
3531 etl::handle<Instance> argh(instance);
3532 instance->safe_close();
3533 synfig::info("closed");
3538 CanvasView::close_instance_when_safe()
3540 if (get_work_area()->get_updating())
3543 if(get_instance()->get_visible_canvases()==1)
3544 // Schedule a close to occur in a few moments
3545 Glib::signal_timeout().connect(
3547 sigc::ptr_fun(_close_instance),
3548 (etl::handle<Instance>)get_instance()
3557 CanvasView::on_delete_event(GdkEventAny* event)
3561 //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
3562 // Is there ever any need to pass on the delete event to the window here?
3563 // if(event) return Gtk::Window::on_delete_event(event);