1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasview.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
10 ** Copyright (c) 2009 Carlos López
11 ** Copyright (c) 2009 Nikita Kitaev
13 ** This package is free software; you can redistribute it and/or
14 ** modify it under the terms of the GNU General Public License as
15 ** published by the Free Software Foundation; either version 2 of
16 ** the License, or (at your option) any later version.
18 ** This package is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ** General Public License for more details.
24 /* ========================================================================= */
26 /* === H E A D E R S ======================================================= */
35 #include <sigc++/adaptors/hide.h>
41 #include <gtkmm/paned.h>
42 #include <gtkmm/scale.h>
43 #include <gtkmm/dialog.h>
44 #include <gtkmm/messagedialog.h>
45 #include <gtkmm/treemodelsort.h>
46 #include <gtkmm/buttonbox.h>
47 #include <gtkmm/separator.h>
49 #include <gtk/gtktreestore.h>
50 #include <gtk/gtkversion.h>
52 #include <synfig/valuenode_reference.h>
53 #include <synfig/valuenode_subtract.h>
54 #include <synfig/valuenode_linear.h>
55 #include <synfig/valuenode_timedswap.h>
56 #include <synfig/valuenode_scale.h>
57 #include <synfig/valuenode_range.h>
58 #include <synfig/valuenode_dynamiclist.h>
59 #include <synfig/valuenode_twotone.h>
60 #include <synfig/valuenode_stripes.h>
61 #include <synfig/valuenode_blinecalctangent.h>
62 #include <synfig/valuenode_blinecalcvertex.h>
63 #include <synfig/valuenode_blinecalcwidth.h>
64 #include <synfig/valuenode_bline.h>
65 #include <synfig/layer.h>
67 #include <synfigapp/uimanager.h>
68 #include <synfigapp/canvasinterface.h>
69 #include <synfigapp/selectionmanager.h>
70 //#include <synfigapp/action_setwaypoint.h>
71 //#include <synfigapp/action_deletewaypoint.h>
73 #include <sigc++/retype_return.h>
74 #include <sigc++/retype.h>
75 //#include <sigc++/hide.h>
77 #include "canvasview.h"
80 #include "cellrenderer_value.h"
81 #include "cellrenderer_timetrack.h"
83 #include "dialog_color.h"
86 #include "state_polygon.h"
87 #include "state_bline.h"
88 #include "state_normal.h"
89 #include "state_eyedrop.h"
90 #include "state_draw.h"
92 #include "ducktransform_scale.h"
93 #include "ducktransform_translate.h"
94 #include "ducktransform_rotate.h"
96 #include "event_mouse.h"
97 #include "event_layerclick.h"
101 #include "dialog_preview.h"
102 #include "dialog_soundselect.h"
105 #include "audiocontainer.h"
106 #include "widget_timeslider.h"
107 #include "keyframedial.h"
109 #include <synfigapp/main.h>
110 #include <synfigapp/inputdevice.h>
116 /* === U S I N G =========================================================== */
120 using namespace synfig;
121 using namespace studio;
122 using namespace sigc;
124 /* === M A C R O S ========================================================= */
126 #define GRAB_HINT_DATA(y) { \
128 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
130 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
134 #define DEFAULT_TIME_WINDOW_SIZE (10.0)
137 #define SMALL_BUTTON(button,stockid,tooltip) \
138 button = manage(new class Gtk::Button()); \
139 icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize)); \
140 button->add(*icon); \
141 tooltips.set_tip(*button,tooltip); \
142 icon->set_padding(0,0);\
144 button->set_relief(Gtk::RELIEF_NONE); \
148 #ifndef NORMAL_BUTTON
149 #define NORMAL_BUTTON(button,stockid,tooltip) \
150 button = manage(new class Gtk::Button()); \
151 icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON)); \
152 button->add(*icon); \
153 tooltips.set_tip(*button,tooltip); \
154 icon->set_padding(0,0);\
156 /*button->set_relief(Gtk::RELIEF_NONE);*/ \
160 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
162 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
164 #define SLOT_EVENT(x) sigc::hide_return(sigc::bind(sigc::mem_fun(*this,&studio::CanvasView::process_event_key),x))
166 /* === C L A S S E S ======================================================= */
168 class studio::UniversalScrubber
170 CanvasView *canvas_view;
173 etl::clock scrub_timer;
175 sigc::connection end_scrub_connection;
177 UniversalScrubber(CanvasView *canvas_view):
178 canvas_view(canvas_view),
181 canvas_view->canvas_interface()->signal_time_changed().connect(
182 sigc::mem_fun(*this,&studio::UniversalScrubber::on_time_changed)
188 end_scrub_connection.disconnect();
191 void on_time_changed()
193 // Make sure we are changing the time quickly
194 // before we enable scrubbing
195 if(!scrubbing && scrub_timer()>1)
201 // If we aren't scrubbing already, enable it
205 audio_container()->start_scrubbing(canvas_view->get_time());
208 // Reset the scrubber ender
209 end_scrub_connection.disconnect();
210 end_scrub_connection=Glib::signal_timeout().connect(
212 sigc::mem_fun(*this,&UniversalScrubber::end_of_scrubbing),
219 audio_container()->scrub(canvas_view->get_time());
224 void end_of_scrubbing()
227 audio_container()->stop_scrubbing();
231 handle<AudioContainer> audio_container()
233 assert(canvas_view->audio);
234 return canvas_view->audio;
238 class studio::CanvasViewUIInterface : public synfigapp::UIInterface
244 CanvasViewUIInterface(CanvasView *view):
247 view->statusbar->push(_("Idle"));
250 ~CanvasViewUIInterface()
252 //view->statusbar->pop();
253 //view->progressbar->set_fraction(0);
256 virtual Response confirmation(const std::string &title,
257 const std::string &primaryText,
258 const std::string &secondaryText,
259 const std::string &confirmPhrase,
260 const std::string &cancelPhrase,
261 Response defaultResponse=RESPONSE_OK)
264 //while(studio::App::events_pending())studio::App::iteration(false);
265 Gtk::MessageDialog dialog(
267 primaryText, // Message
269 Gtk::MESSAGE_WARNING, // Type
270 Gtk::BUTTONS_NONE, // Buttons
275 dialog.set_title(title);
276 if (! secondaryText.empty())
277 dialog.set_secondary_text(secondaryText);
279 dialog.add_button(cancelPhrase, RESPONSE_CANCEL);
280 dialog.add_button(confirmPhrase, RESPONSE_OK);
281 dialog.set_default_response(defaultResponse);
284 return (Response) dialog.run();
287 virtual Response yes_no(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
290 //while(studio::App::events_pending())studio::App::iteration(false);
295 true // use_separator
297 Gtk::Label label(message);
300 dialog.get_vbox()->pack_start(label);
301 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
302 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
304 dialog.set_default_response(dflt);
306 return (Response)dialog.run();
308 virtual Response yes_no_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_YES)
311 //while(studio::App::events_pending())studio::App::iteration(false);
316 true // use_separator
318 Gtk::Label label(message);
321 dialog.get_vbox()->pack_start(label);
322 dialog.add_button(Gtk::StockID("gtk-yes"),RESPONSE_YES);
323 dialog.add_button(Gtk::StockID("gtk-no"),RESPONSE_NO);
324 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
326 dialog.set_default_response(dflt);
328 return (Response)dialog.run();
330 virtual Response ok_cancel(const std::string &title, const std::string &message,Response dflt=RESPONSE_OK)
333 //while(studio::App::events_pending())studio::App::iteration(false);
338 true // use_separator
340 Gtk::Label label(message);
343 dialog.get_vbox()->pack_start(label);
344 dialog.add_button(Gtk::StockID("gtk-ok"),RESPONSE_OK);
345 dialog.add_button(Gtk::StockID("gtk-cancel"),RESPONSE_CANCEL);
347 dialog.set_default_response(dflt);
349 return (Response)dialog.run();
353 task(const std::string &task)
355 if(!view->is_playing_)
357 view->statusbar->pop();
358 view->statusbar->push(task);
360 //while(studio::App::events_pending())studio::App::iteration(false);
361 if(view->cancel){return false;}
366 error(const std::string &err)
368 view->statusbar->push(_("ERROR"));
370 // If we are in the process of canceling,
371 // then just go ahead and return false --
372 // don't bother displaying a dialog
373 if(view->cancel)return false;
374 Gtk::MessageDialog dialog(*view, err, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
377 view->statusbar->pop();
382 warning(const std::string &err)
384 view->statusbar->pop();
385 view->statusbar->push(err);
387 //while(studio::App::events_pending())studio::App::iteration(false);
388 if(view->cancel)return false;
393 amount_complete(int current, int total)
395 if(!view->is_playing_)
397 if(!view->working_depth)
400 view->stopbutton->set_sensitive(true);
402 view->stopbutton->set_sensitive(false);
404 float x((float)current/(float)total);
407 view->progressbar->set_fraction(x);
409 //while(studio::App::events_pending())studio::App::iteration(false);
410 if(view->cancel){/*view->cancel=false;*/return false;}
417 error(_("Feature not yet implemented"));
421 class studio::CanvasViewSelectionManager : public synfigapp::SelectionManager
424 CanvasView::LayerTreeModel layer_tree_model;
425 CanvasView::ChildrenTreeModel children_tree_model;
428 CanvasViewSelectionManager(CanvasView *view): view(view) { }
431 void _set_selected_layer(const synfig::Layer::Handle &layer)
433 view->layer_tree->select_layer(layer);
435 // Don't change the selection while we are busy
436 // I cannot remember exactly why I put this here...
437 // It musta been for some reason, but I cannot recall.
438 //if(App::Busy::count)
441 if(view->layer_tree->get_selection()->get_selected())
443 const Gtk::TreeRow row = *(view->layer_tree->get_selection()->get_selected());
445 // Don't do anything if that layer is already selected
446 if(layer == static_cast<synfig::Layer::Handle>(row[layer_tree_model.layer]))
449 Gtk::TreeModel::Children::iterator iter;
450 if(view->layer_tree_store()->find_layer_row(layer,iter))
452 Gtk::TreePath path(iter);
453 for(int i=path.get_depth();i;i--)
456 path=Gtk::TreePath(iter);
459 view->layer_tree->get_tree_view().expand_row(path,false);
461 view->layer_tree->get_tree_view().scroll_to_row(Gtk::TreePath(iter));
462 view->layer_tree->get_selection()->select(iter);
468 //! Returns the number of layers selected.
469 virtual int get_selected_layer_count()const
471 return get_selected_layers().size();
474 //! Returns a list of the currently selected layers.
475 virtual LayerList get_selected_layers()const
477 // assert(view->layer_tree);
479 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return LayerList(); }
480 return view->layer_tree->get_selected_layers();
483 //! Returns the first layer selected or an empty handle if none are selected.
484 virtual synfig::Layer::Handle get_selected_layer()const
486 // assert(view->layer_tree);
488 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return 0; }
489 return view->layer_tree->get_selected_layer();
492 //! Sets which layers should be selected
493 virtual void set_selected_layers(const LayerList &layer_list)
495 // assert(view->layer_tree);
497 if(!view->layer_tree) { synfig::error("%s:%d canvas_view.layer_tree not defined!?", __FILE__, __LINE__); return; }
498 view->layer_tree->select_layers(layer_list);
499 //view->get_smach().process_event(EVENT_REFRESH_DUCKS);
501 //view->queue_rebuild_ducks();
504 //! Sets which layer should be selected.
505 virtual void set_selected_layer(const synfig::Layer::Handle &layer)
507 // assert(view->layer_tree);
509 if(!view->layer_tree) { synfig::error("canvas_view.layer_tree not defined!?"); return; }
510 view->layer_tree->select_layer(layer);
511 //view->queue_rebuild_ducks();
514 //! Clears the layer selection list
515 virtual void clear_selected_layers()
517 if(!view->layer_tree) return;
518 view->layer_tree->clear_selected_layers();
521 //! Returns the number of value_nodes selected.
522 virtual int get_selected_children_count()const
524 return get_selected_children().size();
527 static inline void __child_grabber(const Gtk::TreeModel::iterator& iter, ChildrenList* ret)
529 const CanvasView::ChildrenTreeModel children_tree_model;
530 synfigapp::ValueDesc value_desc((*iter)[children_tree_model.value_desc]);
532 ret->push_back(value_desc);
535 //! Returns a list of the currently selected value_nodes.
536 virtual ChildrenList get_selected_children()const
538 if(!view->children_tree) return ChildrenList();
540 Glib::RefPtr<Gtk::TreeSelection> selection=view->children_tree->get_selection();
543 return ChildrenList();
547 selection->selected_foreach_iter(
550 &studio::CanvasViewSelectionManager::__child_grabber
557 Gtk::TreeModel::Children::iterator iter(view->children_tree_store()->children().begin());
559 Gtk::TreeModel::Children children = iter->children();
560 for(iter = children.begin(); iter != children.end(); ++iter)
562 Gtk::TreeModel::Row row = *iter;
563 if(selection->is_selected(row))
564 ret.push_back((synfigapp::ValueDesc)row[children_tree_model.value_desc]);
570 //! Returns the first value_node selected or an empty handle if none are selected.
571 virtual ChildrenList::value_type get_selected_child()const
573 if(!view->children_tree) return ChildrenList::value_type();
575 ChildrenList children(get_selected_children());
578 return ChildrenList::value_type();
580 return children.front();
583 //! Sets which value_nodes should be selected
584 virtual void set_selected_children(const ChildrenList &/*children_list*/)
589 //! Sets which value_node should be selected. Empty handle if none.
590 virtual void set_selected_child(const ChildrenList::value_type &/*child*/)
595 //! Clears the value_node selection list
596 virtual void clear_selected_children()
601 int get_selected_layer_parameter_count()const
603 return get_selected_layer_parameters().size();
606 LayerParamList get_selected_layer_parameters()const
608 if(!view->layer_tree) return LayerParamList();
610 Glib::RefPtr<Gtk::TreeSelection> selection=view->layer_tree->get_selection();
613 return LayerParamList();
617 Gtk::TreeModel::Children children = const_cast<CanvasView*>(view)->layer_tree_store()->children();
618 Gtk::TreeModel::Children::iterator iter;
619 for(iter = children.begin(); iter != children.end(); ++iter)
621 Gtk::TreeModel::Row row = *iter;
622 Gtk::TreeModel::Children::iterator iter;
623 for(iter=row.children().begin();iter!=row.children().end();iter++)
625 Gtk::TreeModel::Row row = *iter;
626 if(selection->is_selected(row))
627 ret.push_back(LayerParam(row[layer_tree_model.layer],(Glib::ustring)row[layer_tree_model.id]));
633 LayerParam get_selected_layer_parameter() const
635 if(!view->layer_tree) return LayerParam();
636 return get_selected_layer_parameters().front();
639 void set_selected_layer_parameters(const LayerParamList &/*layer_param_list*/)
644 void set_selected_layer_param(const LayerParam &/*layer_param*/)
649 void clear_selected_layer_parameters()
654 }; // END of class SelectionManager
656 CanvasView::IsWorking::IsWorking(CanvasView &canvas_view_):
657 canvas_view_(canvas_view_)
659 if(!canvas_view_.working_depth)
660 canvas_view_.stopbutton->set_sensitive(true);
661 canvas_view_.working_depth++;
662 canvas_view_.cancel=false;
665 CanvasView::IsWorking::~IsWorking()
667 canvas_view_.working_depth--;
668 if(!canvas_view_.working_depth)
669 canvas_view_.stopbutton->set_sensitive(false);
672 CanvasView::IsWorking::operator bool()const
674 if(canvas_view_.cancel)
679 /* === M E T H O D S ======================================================= */
681 CanvasView::CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface_):
683 instance_ (instance),
684 canvas_interface_ (canvas_interface_),
685 //layer_tree_store_ (LayerTreeStore::create(canvas_interface_)),
686 //children_tree_store_ (ChildrenTreeStore::create(canvas_interface_)),
687 //keyframe_tree_store_ (KeyframeTreeStore::create(canvas_interface_)),
688 time_adjustment_ (0,0,25,0,0,0),
689 time_window_adjustment_ (0,0,25,0,0,0),
690 statusbar (manage(new class Gtk::Statusbar())),
691 quality_adjustment_ (8,1,10,1,1,0),
692 future_onion_adjustment_ (0,0,2,1,1,0),
693 past_onion_adjustment_ (0,0,2,1,1,0),
695 timeslider (new Widget_Timeslider),
696 widget_kf_list (new Widget_Keyframe_List),
698 ui_interface_ (new CanvasViewUIInterface(this)),
699 selection_manager_ (new CanvasViewSelectionManager(this)),
705 canvas_properties (*this,canvas_interface_),
706 canvas_options (this),
707 render_settings (*this,canvas_interface_),
708 waypoint_dialog (*this,canvas_interface_->get_canvas()),
709 keyframe_dialog (*this,canvas_interface_),
710 preview_dialog (new Dialog_Preview),
711 sound_dialog (new Dialog_SoundSelect(*this,canvas_interface_))
715 duck_refresh_flag=true;
716 toggling_ducks_=false;
717 changing_resolution_=false;
718 updating_quality_=false;
719 toggling_show_grid=false;
720 toggling_snap_grid=false;
721 toggling_onion_skin=false;
723 disp_audio = new Widget_Sound();
725 //synfig::info("Canvasview: Entered constructor");
727 get_canvas()->set_time(0);
728 //layer_tree_store_->rebuild();
730 // Set up the UI and Selection managers
731 canvas_interface()->set_ui_interface(get_ui_interface());
732 canvas_interface()->set_selection_manager(get_selection_manager());
733 rebuild_ducks_queued=false;
735 //notebook=manage(new class Gtk::Notebook());
736 //Gtk::VPaned *vpaned = manage(new class Gtk::VPaned());
737 //vpaned->pack1(*create_work_area(), Gtk::EXPAND|Gtk::SHRINK);
738 //vpaned->pack2(*notebook, Gtk::SHRINK);
739 //vpaned->show_all();
743 //notebook->append_page(*create_layer_tree(),_("Layers"));
744 //notebook->append_page(*create_children_tree(),_("Children"));
745 //notebook->append_page(*create_keyframe_tree(),_("Keyframes"));
747 //synfig::info("Canvasview: Before big chunk of allocation and tabling stuff");
748 //create all allocated stuff for this canvas
749 audio = new AudioContainer();
751 Gtk::Table *layout_table= manage(new class Gtk::Table(1, 4, false));
752 //layout_table->attach(*vpaned, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
753 layout_table->attach(*create_work_area(), 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
754 layout_table->attach(*create_display_bar(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
756 //layout_table->attach(*App::ui_manager()->get_widget("/menu-main"), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
758 layout_table->attach(*create_time_bar(), 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
759 layout_table->attach(*create_status_bar(), 0, 1, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
763 layout_table->show();
766 //set_transient_for(*App::toolbox);
768 smach_.set_default_state(&state_normal);
770 //synfig::info("Canvasview: Before Signals");
772 -- ** -- Signals -------------------------------------------------------------
775 canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::CanvasView::on_dirty_preview));
776 canvas_interface()->signal_mode_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_mode_changed));
778 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_time_changed));
780 //canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_tables));
781 canvas_interface()->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_id_changed));
782 canvas_interface()->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_rend_desc));
783 waypoint_dialog.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_changed));
784 waypoint_dialog.signal_delete().connect(sigc::mem_fun(*this,&studio::CanvasView::on_waypoint_delete));
786 //MODIFIED TIME ADJUSTMENT STUFF....
787 time_window_adjustment().set_child_adjustment(&time_adjustment());
788 time_window_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::refresh_time_window));
789 time_adjustment().signal_value_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::time_was_changed));
791 work_area->signal_layer_selected().connect(sigc::mem_fun(*this,&studio::CanvasView::workarea_layer_selected));
792 work_area->signal_input_device_changed().connect(sigc::mem_fun(*this,&studio::CanvasView::on_input_device_changed));
794 canvas_interface()->signal_canvas_added().connect(
796 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
799 canvas_interface()->signal_canvas_removed().connect(
801 sigc::mem_fun(*instance,&studio::Instance::refresh_canvas_tree)
805 canvas_interface()->signal_layer_param_changed().connect(
808 SLOT_EVENT(EVENT_REFRESH_DUCKS)
813 //MUCH TIME STUFF TAKES PLACE IN HERE
815 refresh_time_window();
817 /*! \todo We shouldn't need to do this at construction --
818 ** This should be performed at the first time the window
821 work_area->queue_render_preview();
823 // If the canvas is really big, zoom out so that we can fit it all in the window
824 /*! \todo In other words, this is a zoom-to-fit, and should be
825 ** in its own function.
827 int w=get_canvas()->rend_desc().get_w()+70;
828 int h=get_canvas()->rend_desc().get_h()+70;
829 while(w>700 || h>600)
833 // WorkArea::async_update_preview() =>
834 // WorkArea::set_zoom(float) =>
835 // WorkArea::async_update_preview() =>
836 // desc.set_time(cur_time), where cur_time isn't initialized
837 work_area->set_time(0);
838 work_area->zoom_out();
839 w=round_to_int(get_canvas()->rend_desc().get_w()*work_area->get_zoom()+70);
840 h=round_to_int(get_canvas()->rend_desc().get_h()*work_area->get_zoom()+70);
844 set_default_size(w,h);
845 property_window_position().set_value(Gtk::WIN_POS_NONE);
847 std::list<Gtk::TargetEntry> listTargets;
848 listTargets.push_back( Gtk::TargetEntry("STRING") );
849 listTargets.push_back( Gtk::TargetEntry("text/plain") );
850 listTargets.push_back( Gtk::TargetEntry("image") );
852 drag_dest_set(listTargets);
853 signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::CanvasView::on_drop_drag_data_received) );
856 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
859 time_window_adjustment().set_page_increment(length);
860 time_window_adjustment().set_page_size(length);
864 time_window_adjustment().set_page_increment(10.0);
865 time_window_adjustment().set_page_size(10.0);
869 //synfig::info("Canvasview: Before Sound Hookup");
870 //load sound info from meta data
872 //synfig::warning("Should load Audio: %s with %s offset",apath.c_str(),aoffset.c_str());
874 on_audio_file_notify(); //redundant setting of the metadata, but oh well, it's no big deal :)
875 on_audio_offset_notify();
877 //signal connection - since they are all associated with the canvas view
879 //hook in signals for sound options box
880 sound_dialog->signal_file_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_change));
881 sound_dialog->signal_offset_changed().connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_change));
883 //attach to the preview when it's visible
884 //preview_dialog->get_widget().signal_play().connect(sigc::mem_fun(*this,&CanvasView::play_audio));
885 //preview_dialog->get_widget().signal_stop().connect(sigc::mem_fun(*this,&CanvasView::stop_audio));
887 //hook to metadata signals
888 get_canvas()->signal_meta_data_changed("audiofile").connect(sigc::mem_fun(*this,&CanvasView::on_audio_file_notify));
889 get_canvas()->signal_meta_data_changed("audiooffset").connect(sigc::mem_fun(*this,&CanvasView::on_audio_offset_notify));
891 //universal_scrubber=std::auto_ptr<UniversalScrubber>(new UniversalScrubber(this));
894 //synfig::info("Canvasview: Before Final time set up");
896 time_window_adjustment().set_value(get_canvas()->rend_desc().get_time_start());
897 time_window_adjustment().value_changed();
899 GRAB_HINT_DATA("canvas_view");
902 set_skip_taskbar_hint(true);
903 set_skip_pager_hint(true);
904 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
912 //synfig::info("Canvasview: Constructor Done");
915 CanvasView::~CanvasView()
919 App::ui_manager()->remove_action_group(action_group);
921 // Shut down the smach
923 smach_.set_default_state(0);
925 // We want to ensure that the UI_Manager and
926 // the selection manager get destructed right now.
927 ui_interface_.reset();
928 selection_manager_.reset();
930 // Delete any external widgets
931 for(;!ext_widget_book_.empty();ext_widget_book_.erase(ext_widget_book_.begin()))
933 if(ext_widget_book_.begin()->second)
934 delete ext_widget_book_.begin()->second;
942 // don't be calling on_dirty_preview once this object has been deleted;
943 // this was causing a crash before
944 canvas_interface()->signal_dirty_preview().clear();
946 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
947 synfig::info("CanvasView::~CanvasView(): Deleted");
951 CanvasView::get_pixel_sizes()
953 // prime factors of 120 are 2, 2, 2, 3, 5 - see TILE_SIZE in synfig-core/trunk/src/synfig/target_tile.h
954 static int pixel_size_array[] = {2,3,4,5,6,8,10,12,15,20,24,30,40,60,120};
955 static list<int> pixel_sizes = list<int>(pixel_size_array, pixel_size_array + sizeof(pixel_size_array) / sizeof(int));
961 CanvasView::create_time_bar()
965 //Setup the Time Slider and the Time window scroll
966 Gtk::HScrollbar *time_window_scroll = manage(new class Gtk::HScrollbar(time_window_adjustment()));
967 //Gtk::HScrollbar *time_scroll = manage(new class Gtk::HScrollbar(time_adjustment()));
968 //TIME BAR TEMPORARY POSITION
969 //Widget_Timeslider *time_scroll = manage(new Widget_Timeslider);
970 timeslider->set_time_adjustment(&time_adjustment());
971 timeslider->set_bounds_adjustment(&time_window_adjustment());
972 //layout_table->attach(*timeslider, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
973 //Setup the keyframe list widget
974 widget_kf_list->set_time_adjustment(&time_adjustment());
975 widget_kf_list->set_canvas_interface(canvas_interface());
976 widget_kf_list->show();
978 tooltips.set_tip(*time_window_scroll,_("Moves the time window"));
979 tooltips.set_tip(*timeslider,_("Changes the current time"));
980 time_window_scroll->show();
982 //time_window_scroll->set_flags(Gtk::CAN_FOCUS); // Uncomment this produce bad render of the HScroll
983 timeslider->set_flags(Gtk::CAN_FOCUS);
985 //time_scroll->signal_value_changed().connect(sigc::mem_fun(*work_area, &studio::WorkArea::render_preview_hook));
986 //time_scroll->set_update_policy(Gtk::UPDATE_DISCONTINUOUS);
988 //Setup the Animation Mode Button and the Keyframe Lock button
989 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
990 SMALL_BUTTON(animatebutton,"gtk-yes",_("Animate"));
991 animatebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_animate_button_pressed));
992 animatebutton->show();
994 //Setup the audio display
995 disp_audio->set_size_request(-1,32); //disp_audio->show();
996 disp_audio->set_time_adjustment(&time_adjustment());
997 disp_audio->signal_start_scrubbing().connect(
998 sigc::mem_fun(*audio,&AudioContainer::start_scrubbing)
1000 disp_audio->signal_scrub().connect(
1001 sigc::mem_fun(*audio,&AudioContainer::scrub)
1003 disp_audio->signal_stop_scrubbing().connect(
1004 sigc::mem_fun(*audio,&AudioContainer::stop_scrubbing)
1006 //Setup the current time widget
1007 current_time_widget=manage(new Widget_Time);
1008 current_time_widget->set_value(get_time());
1009 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
1010 current_time_widget->signal_value_changed().connect(
1011 sigc::mem_fun(*this,&CanvasView::on_current_time_widget_changed)
1013 current_time_widget->set_size_request(0,-1); // request horizontal shrink
1014 tooltips.set_tip(*current_time_widget,_("Current time"));
1015 current_time_widget->show();
1017 //Setup the FrameDial widget
1018 framedial = manage(new class FrameDial());
1019 framedial->signal_seek_begin().connect(
1020 sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time), Time::begin())
1022 framedial->signal_seek_prev_frame().connect(
1023 sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame), -1)
1025 framedial->signal_play_stop().connect(
1026 sigc::mem_fun(*this, &studio::CanvasView::on_play_stop_pressed)
1028 framedial->signal_seek_next_frame().connect(
1029 sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame), 1)
1031 framedial->signal_seek_end().connect(
1032 sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time), Time::end())
1036 //Setup the KeyFrameDial widget
1037 KeyFrameDial *keyframedial = Gtk::manage(new class KeyFrameDial());
1038 keyframedial->signal_seek_prev_keyframe().connect(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1039 keyframedial->signal_seek_next_keyframe().connect(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1040 keyframedial->signal_lock_keyframe().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_button_pressed));
1041 keyframedial->show();
1042 keyframebutton=keyframedial->get_lock_button();
1044 timebar = Gtk::manage(new class Gtk::Table(5, 4, false));
1046 //Adjust both widgets to be the same as the
1047 int header_height = 0;
1048 if(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"))
1049 header_height = atoi(getenv("SYNFIG_TIMETRACK_HEADER_HEIGHT"));
1050 if (header_height < 3)
1052 timeslider->set_size_request(-1,header_height-header_height/3+1);
1053 widget_kf_list->set_size_request(-1,header_height/3+1);
1055 //Attach widgets to the timebar
1056 //timebar->attach(*manage(disp_audio), 1, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
1057 timebar->attach(*current_time_widget, 0, 1, 0, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
1058 timebar->attach(*framedial, 0, 1, 2, 3, Gtk::SHRINK, Gtk::SHRINK);
1059 timebar->attach(*timeslider, 1, 3, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::FILL|Gtk::SHRINK);
1060 timebar->attach(*widget_kf_list, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::SHRINK);
1061 timebar->attach(*time_window_scroll, 1, 3, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
1062 timebar->attach(*keyframedial, 3, 4, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
1063 timebar->attach(*animatebutton, 4, 5, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
1064 //timebar->attach(*keyframebutton, 1, 2, 3, 4, Gtk::SHRINK, Gtk::SHRINK);
1072 CanvasView::create_work_area()
1074 work_area=std::auto_ptr<WorkArea>(new class studio::WorkArea(canvas_interface_));
1075 work_area->set_instance(get_instance());
1076 work_area->set_canvas(get_canvas());
1077 work_area->set_canvas_view(this);
1078 work_area->set_progress_callback(get_ui_interface().get());
1079 work_area->signal_popup_menu().connect(sigc::mem_fun(*this, &studio::CanvasView::popup_main_menu));
1081 return work_area.get();
1085 CanvasView::create_status_bar()
1088 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
1091 // Create the status bar at the bottom of the window
1092 Gtk::Table *statusbartable= manage(new class Gtk::Table(5, 1, false));
1093 // statusbar = manage(new class Gtk::Statusbar()); // This is already done at construction
1094 progressbar =manage(new class Gtk::ProgressBar());
1095 SMALL_BUTTON(stopbutton,"gtk-stop",_("Stop"));
1096 SMALL_BUTTON(refreshbutton,"gtk-refresh",_("Refresh"));
1097 //SMALL_BUTTON(treetogglebutton,"gtk-go-down",_("Toggle Layer Tree"));
1098 // NEW_SMALL_BUTTON(raisebutton,"gtk-go-up",_("Raise Layer"));
1099 // NEW_SMALL_BUTTON(lowerbutton,"gtk-go-down",_("Lower Layer"));
1100 //statusbartable->attach(*treetogglebutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1101 // statusbartable->attach(*lowerbutton, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1102 // statusbartable->attach(*raisebutton, 1, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1104 statusbartable->attach(*statusbar, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1105 statusbartable->attach(*progressbar, 2, 3, 0, 1, Gtk::SHRINK, Gtk::EXPAND|Gtk::FILL, 0, 0);
1106 statusbartable->attach(*refreshbutton, 3, 4, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1107 statusbartable->attach(*stopbutton, 4, 5, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
1108 statusbar->set_has_resize_grip(false);
1111 refreshbutton->show();
1112 progressbar->show();
1113 stopbutton->set_sensitive(false);
1115 //refreshbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_refresh_pressed));
1116 //stopbutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::stop));
1117 //treetogglebutton->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::toggle_tables));
1119 refreshbutton->signal_clicked().connect(SLOT_EVENT(EVENT_REFRESH));
1120 stopbutton->signal_clicked().connect(SLOT_EVENT(EVENT_STOP));
1122 statusbartable->show_all();
1123 return statusbartable;
1127 CanvasView::create_display_bar()
1129 displaybar = manage(new class Gtk::Table(16, 1, false));
1130 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon_16x16");
1131 // Setup the ToggleDuckDial widget
1132 toggleducksdial = Gtk::manage(new class ToggleDucksDial(iconsize));
1134 Duck::Type m = work_area->get_type_mask();
1135 toggleducksdial->update_toggles(m);
1137 toggleducksdial->signal_ducks_position().connect(
1138 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_POSITION)
1140 toggleducksdial->signal_ducks_vertex().connect(
1141 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_VERTEX)
1143 toggleducksdial->signal_ducks_tangent().connect(
1144 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_TANGENT)
1146 toggleducksdial->signal_ducks_radius().connect(
1147 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_RADIUS)
1149 toggleducksdial->signal_ducks_width().connect(
1150 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_WIDTH)
1152 toggleducksdial->signal_ducks_angle().connect(
1153 sigc::bind(sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),Duck::TYPE_ANGLE)
1155 toggleducksdial->show();
1157 // Set up the ResolutionDial widget
1158 resolutiondial=Gtk::manage(new class ResolutionDial(iconsize));
1160 resolutiondial->update_lowres(work_area->get_low_resolution_flag());
1161 resolutiondial->signal_increase_resolution().connect(
1162 sigc::mem_fun(*this, &studio::CanvasView::decrease_low_res_pixel_size));
1163 resolutiondial->signal_decrease_resolution().connect(
1164 sigc::mem_fun(*this, &studio::CanvasView::increase_low_res_pixel_size));
1165 resolutiondial->signal_use_low_resolution().connect(
1166 sigc::mem_fun(*this, &studio::CanvasView::toggle_low_res_pixel_flag));
1167 resolutiondial->show();
1169 // Set up some separators
1170 Gtk::VSeparator *separator1 = Gtk::manage(new class Gtk::VSeparator());
1172 Gtk::VSeparator *separator2 = Gtk::manage(new class Gtk::VSeparator());
1174 Gtk::VSeparator *separator3 = Gtk::manage(new class Gtk::VSeparator());
1176 Gtk::VSeparator *separator4 = Gtk::manage(new class Gtk::VSeparator());
1178 Gtk::VSeparator *separator5 = Gtk::manage(new class Gtk::VSeparator());
1181 // Set up quality spin button
1182 quality_spin=Gtk::manage(new class Gtk::SpinButton(quality_adjustment_));
1183 quality_spin->signal_value_changed().connect(
1184 sigc::mem_fun(*this, &studio::CanvasView::update_quality));
1185 tooltips.set_tip(*quality_spin, _("Quality (lower is better)"));
1186 quality_spin->show();
1188 // Set up the show grid toggle button
1189 show_grid = Gtk::manage(new class Gtk::ToggleButton());
1190 show_grid->set_active(work_area->grid_status());
1191 Gtk::Image *icon = manage(new Gtk::Image(Gtk::StockID("synfig-toggle_show_grid"), iconsize));
1192 icon->set_padding(0, 0);
1194 show_grid->add(*icon);
1195 show_grid->signal_toggled().connect(
1196 sigc::mem_fun(*this, &studio::CanvasView::toggle_show_grid));
1197 tooltips.set_tip(*show_grid, _("Show grid when enabled"));
1198 show_grid->set_relief(Gtk::RELIEF_NONE);
1201 // Set up the snap to grid toggle button
1202 snap_grid = Gtk::manage(new class Gtk::ToggleButton());
1203 snap_grid->set_active(work_area->grid_status());
1204 Gtk::Image *icon2 = manage(new Gtk::Image(Gtk::StockID("synfig-toggle_snap_grid"), iconsize));
1205 icon2->set_padding(0, 0);
1207 snap_grid->add(*icon2);
1208 snap_grid->signal_toggled().connect(
1209 sigc::mem_fun(*this, &studio::CanvasView::toggle_snap_grid));
1210 tooltips.set_tip(*snap_grid, _("Snap grid when enabled"));
1211 snap_grid->set_relief(Gtk::RELIEF_NONE);
1214 // Set up the onion skin toggle button
1215 onion_skin = Gtk::manage(new class Gtk::ToggleButton());
1216 onion_skin->set_active(work_area->get_onion_skin());
1217 Gtk::Image *icon3 = manage(new Gtk::Image(Gtk::StockID("synfig-toggle_onion_skin"), iconsize));
1218 icon3->set_padding(0, 0);
1220 onion_skin->add(*icon3);
1221 onion_skin->signal_toggled().connect(
1222 sigc::mem_fun(*this, &studio::CanvasView::toggle_onion_skin));
1223 tooltips.set_tip(*onion_skin, _("Shows onion skin when enabled"));
1224 onion_skin->set_relief(Gtk::RELIEF_NONE);
1227 // Set up past onion skin spin button
1228 past_onion_spin=Gtk::manage(new class Gtk::SpinButton(past_onion_adjustment_));
1229 past_onion_spin->signal_value_changed().connect(
1230 sigc::mem_fun(*this, &studio::CanvasView::set_onion_skins));
1231 tooltips.set_tip(*past_onion_spin, _("Past onion skins"));
1232 past_onion_spin->show();
1234 // Set up future onion skin spin button
1235 future_onion_spin=Gtk::manage(new class Gtk::SpinButton(future_onion_adjustment_));
1236 future_onion_spin->signal_value_changed().connect(
1237 sigc::mem_fun(*this, &studio::CanvasView::set_onion_skins));
1238 tooltips.set_tip(*future_onion_spin, _("Future onion skins"));
1239 future_onion_spin->show();
1241 // Setup render options dialog button
1242 render_options_button = Gtk::manage(new class Gtk::Button());
1243 Gtk::Image *icon4 = manage(new Gtk::Image(Gtk::StockID("synfig-render_options"), iconsize));
1244 icon4->set_padding(0, 0);
1246 render_options_button->add(*icon4);
1247 render_options_button->signal_clicked().connect(
1248 sigc::mem_fun0(render_settings,&studio::RenderSettings::present));
1249 tooltips.set_tip(*render_options_button, _("Shows the Render Settings Dialog"));
1250 render_options_button->set_relief(Gtk::RELIEF_NONE);
1251 render_options_button->show();
1253 // Setup preview options dialog button
1254 preview_options_button = Gtk::manage(new class Gtk::Button());
1255 Gtk::Image *icon5 = manage(new Gtk::Image(Gtk::StockID("synfig-preview_options"), iconsize));
1256 icon5->set_padding(0, 0);
1258 preview_options_button->add(*icon5);
1259 preview_options_button->signal_clicked().connect(
1260 sigc::mem_fun(*this,&CanvasView::on_preview_option));
1261 tooltips.set_tip(*preview_options_button, _("Shows the Preview Settings Dialog"));
1262 preview_options_button->set_relief(Gtk::RELIEF_NONE);
1263 preview_options_button->show();
1266 displaybar->attach(*toggleducksdial, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1267 displaybar->attach(*separator1, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
1268 displaybar->attach(*resolutiondial, 2, 3, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1269 displaybar->attach(*separator2, 3, 4, 0, 1, Gtk::FILL, Gtk::FILL);
1270 displaybar->attach(*quality_spin, 4, 5, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1271 displaybar->attach(*separator3, 5, 6, 0, 1, Gtk::FILL, Gtk::FILL);
1272 displaybar->attach(*show_grid, 6, 7, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1273 displaybar->attach(*snap_grid, 7, 8, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1274 displaybar->attach(*separator4, 8, 9, 0, 1, Gtk::FILL, Gtk::FILL);
1275 displaybar->attach(*past_onion_spin, 9, 10, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1276 displaybar->attach(*onion_skin, 10, 11, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1277 displaybar->attach(*future_onion_spin, 11, 12, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1278 displaybar->attach(*separator5, 12, 13, 0, 1, Gtk::FILL, Gtk::FILL);
1279 displaybar->attach(*render_options_button, 13, 14, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1280 displaybar->attach(*preview_options_button, 14, 15, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
1289 CanvasView::on_current_time_widget_changed()
1291 set_time(current_time_widget->get_value());
1293 // show the value being used - it will have been rounded to nearest frame
1294 // this was already being done elsewhere, but only if the time was really changed;
1295 // if the current time was 6f and the user edited it to 6.1f, then the 6.1f would
1296 // be left in the display without the following line to fix it
1297 current_time_widget->set_value(get_time());
1298 current_time_widget->set_position(-1); // leave the cursor at the end
1302 // CanvasView::create_children_tree()
1304 // // Create the layer tree
1305 // children_tree=manage(new class ChildrenTree());
1307 // // Set up the layer tree
1308 // //children_tree->set_model(children_tree_store());
1309 // if(children_tree)children_tree->set_time_adjustment(time_adjustment());
1310 // if(children_tree)children_tree->show();
1312 // // Connect Signals
1313 // if(children_tree)children_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1314 // if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1315 // if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1316 // if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1318 // return children_tree;
1322 // CanvasView::create_keyframe_tree()
1324 // keyframe_tree=manage(new KeyframeTree());
1326 // //keyframe_tree->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1327 // //keyframe_tree->show();
1328 // //keyframe_tree->set_model(keyframe_tree_store());
1329 // keyframe_tree->set_editable(true);
1330 // //keyframe_tree->signal_edited().connect(sigc::hide_return(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::update_keyframe)));
1332 // keyframe_tree->signal_event().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_tree_event));
1334 // Gtk::ScrolledWindow *scroll_layer_tree = manage(new class Gtk::ScrolledWindow());
1335 // scroll_layer_tree->set_flags(Gtk::CAN_FOCUS);
1336 // scroll_layer_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
1337 // scroll_layer_tree->add(*keyframe_tree);
1338 // scroll_layer_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
1339 // //scroll_layer_tree->show();
1342 // Gtk::Table *layout_table= manage(new Gtk::Table(1, 2, false));
1343 // layout_table->attach(*scroll_layer_tree, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
1345 // Gtk::Image *icon;
1346 // Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
1348 // NEW_SMALL_BUTTON(button_add,"gtk-add",_("New Keyframe"));
1349 // NEW_SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate Keyframe"));
1350 // NEW_SMALL_BUTTON(button_delete,"gtk-delete",_("Delete Keyframe"));
1352 // Gtk::HBox *hbox(manage(new Gtk::HBox()));
1353 // layout_table->attach(*hbox, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
1355 // hbox->pack_start(*button_add,Gtk::PACK_SHRINK);
1356 // hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
1357 // hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
1360 // button_raise->set_relief(Gtk::RELIEF_HALF);
1361 // button_lower->set_relief(Gtk::RELIEF_HALF);
1362 // button_duplicate->set_relief(Gtk::RELIEF_HALF);
1363 // button_delete->set_relief(Gtk::RELIEF_HALF);
1366 // button_add->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_add_pressed));
1367 // button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_duplicate_pressed));
1368 // button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasView::on_keyframe_remove_pressed));
1370 // //layout_table->show_all();
1372 // keyframe_tab_child=layout_table;
1375 // layout_table->hide();
1377 // return layout_table;
1381 // CanvasView::create_layer_tree()
1383 // // Create the layer tree
1384 // printf("CanvasView::create_layer_tree()\n");
1385 // layer_tree=manage(new class LayerTree());
1387 // // Set up the layer tree
1388 // //layer_tree->set_model(layer_tree_store());
1389 // layer_tree->set_time_adjustment(time_adjustment());
1390 // layer_tree->show();
1392 // // Connect Signals
1393 // layer_tree->signal_layer_toggle().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_toggle));
1394 // layer_tree->signal_edited_value().connect(sigc::mem_fun(*this, &studio::CanvasView::on_edited_value));
1395 // layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
1396 // layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
1397 // layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
1398 // layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
1400 // layer_tree->hide();
1401 // return layer_tree;
1405 CanvasView::init_menus()
1408 mainmenu.set_accel_group(get_accel_group());
1409 mainmenu.set_accel_path("<Canvas-view>");
1411 filemenu.set_accel_group(get_accel_group());
1412 filemenu.set_accel_path("<Canvas-view>/File");
1414 editmenu.set_accel_group(get_accel_group());
1415 editmenu.set_accel_path("<Canvas-view>/Edit");
1417 layermenu.set_accel_group(get_accel_group());
1418 layermenu.set_accel_path("<Canvas-view>/Layer");
1420 //cache the position of desired widgets
1422 /*Menus to worry about:
1431 action_group = Gtk::ActionGroup::create("canvasview");
1433 //action_group->add( Gtk::Action::create("MenuFile", _("_File")) );
1434 action_group->add( Gtk::Action::create("new", Gtk::Stock::NEW),
1435 sigc::hide_return(sigc::ptr_fun(&studio::App::new_instance))
1437 action_group->add( Gtk::Action::create("open", Gtk::Stock::OPEN),
1438 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::open))
1440 action_group->add( Gtk::Action::create("save", Gtk::Stock::SAVE),
1441 hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))
1443 action_group->add( Gtk::Action::create("save-as", Gtk::Stock::SAVE_AS),
1444 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::dialog_save_as))
1446 action_group->add( Gtk::Action::create("revert", Gtk::Stock::REVERT_TO_SAVED),
1447 sigc::hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::safe_revert))
1449 action_group->add( Gtk::Action::create("cvs-add", Gtk::StockID("synfig-cvs_add")),
1450 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_add))
1452 action_group->add( Gtk::Action::create("cvs-update", Gtk::StockID("synfig-cvs_update")),
1453 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_update))
1455 action_group->add( Gtk::Action::create("cvs-revert", Gtk::StockID("synfig-cvs_revert")),
1456 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_revert))
1458 action_group->add( Gtk::Action::create("cvs-commit", Gtk::StockID("synfig-cvs_commit")),
1459 sigc::hide_return(sigc::mem_fun(*get_instance(), &studio::Instance::dialog_cvs_commit))
1461 action_group->add( Gtk::Action::create("import", _("Import")),
1462 sigc::hide_return(sigc::mem_fun(*this, &studio::CanvasView::image_import))
1464 action_group->add( Gtk::Action::create("render", _("Render")),
1465 sigc::mem_fun0(render_settings,&studio::RenderSettings::present)
1467 action_group->add( Gtk::Action::create("preview", _("Preview")),
1468 sigc::mem_fun(*this,&CanvasView::on_preview_option)
1470 action_group->add( Gtk::Action::create("sound", _("Sound File")),
1471 sigc::mem_fun(*this,&CanvasView::on_audio_option)
1473 action_group->add( Gtk::Action::create("options", _("Options")),
1474 sigc::mem_fun0(canvas_options,&studio::CanvasOptions::present)
1476 action_group->add( Gtk::Action::create("close", Gtk::StockID("gtk-close"), _("Close Window")),
1477 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1479 action_group->add( Gtk::Action::create("close-document", Gtk::StockID("gtk-close"), _("Close Document")),
1480 sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_instance))
1482 action_group->add( Gtk::Action::create("quit", Gtk::StockID("gtk-quit"), _("Quit")),
1483 sigc::hide_return(sigc::ptr_fun(&studio::App::quit))
1486 //action_group->add( Gtk::Action::create("undo", Gtk::StockID("gtk-undo")),
1487 // SLOT_EVENT(EVENT_UNDO)
1490 //action_group->add( Gtk::Action::create("redo", Gtk::StockID("gtk-redo")),
1491 // SLOT_EVENT(EVENT_REDO)
1494 action_group->add( Gtk::Action::create("select-all-ducks", _("Select All Ducks")),
1495 sigc::mem_fun(*work_area,&studio::WorkArea::select_all_ducks)
1498 action_group->add( Gtk::Action::create("unselect-all-ducks", _("Unselect All Ducks")),
1499 sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)
1502 action_group->add( Gtk::Action::create("select-all-layers", _("Select All Layers")),
1503 sigc::mem_fun(*this,&CanvasView::on_select_layers)
1506 action_group->add( Gtk::Action::create("unselect-all-layers", _("Unselect All Layers")),
1507 sigc::mem_fun(*this,&CanvasView::on_unselect_layers)
1510 action_group->add( Gtk::Action::create("stop", Gtk::StockID("gtk-stop")),
1511 SLOT_EVENT(EVENT_STOP)
1514 action_group->add( Gtk::Action::create("refresh", Gtk::StockID("gtk-refresh")),
1515 SLOT_EVENT(EVENT_REFRESH)
1518 action_group->add( Gtk::Action::create("properties", Gtk::StockID("gtk-properties")),
1519 sigc::mem_fun0(canvas_properties,&studio::CanvasProperties::present)
1522 // Preview Quality Menu
1525 action_group->add( Gtk::RadioAction::create(quality_group,"quality-00", _("Use Parametric Renderer")),
1527 sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1534 if (i == 1) note = _(" (best)");
1535 if (i == 10) note = _(" (fastest)");
1536 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(quality_group,strprintf("quality-%02d",i),
1537 strprintf(_("Set Quality to %d"),i) + note));
1538 if (i==8) // default quality
1540 action->set_active();
1541 work_area->set_quality(i);
1543 action_group->add( action,
1545 sigc::mem_fun(*this, &studio::CanvasView::set_quality),
1552 // Low-Res Quality Menu
1555 for(list<int>::iterator iter = CanvasView::get_pixel_sizes().begin(); iter != CanvasView::get_pixel_sizes().end(); iter++)
1558 Glib::RefPtr<Gtk::RadioAction> action(Gtk::RadioAction::create(low_res_pixel_size_group,strprintf("lowres-pixel-%d",i),
1559 strprintf(_("Set Low-Res pixel size to %d"),i)));
1560 if(i==2) // default pixel size
1562 action->set_active();
1563 work_area->set_low_res_pixel_size(i);
1565 action_group->add( action,
1567 sigc::mem_fun(*work_area, &studio::WorkArea::set_low_res_pixel_size),
1573 Glib::RefPtr<Gtk::Action> action;
1575 action=Gtk::Action::create("decrease-low-res-pixel-size", _("Decrease Low-Res Pixel Size"));
1576 action_group->add( action,sigc::mem_fun(this, &studio::CanvasView::decrease_low_res_pixel_size));
1578 action=Gtk::Action::create("increase-low-res-pixel-size", _("Increase Low-Res Pixel Size"));
1579 action_group->add( action, sigc::mem_fun(this, &studio::CanvasView::increase_low_res_pixel_size));
1583 action_group->add( Gtk::Action::create("play", Gtk::Stock::MEDIA_PLAY),
1584 sigc::mem_fun(*this, &studio::CanvasView::play)
1587 action_group->add( Gtk::Action::create("dialog-flipbook", _("Preview Window")),
1588 sigc::mem_fun0(*preview_dialog, &studio::Dialog_Preview::present)
1592 Glib::RefPtr<Gtk::ToggleAction> action;
1594 grid_show_toggle = Gtk::ToggleAction::create("toggle-grid-show", _("Show Grid"));
1595 grid_show_toggle->set_active(work_area->grid_status());
1596 action_group->add(grid_show_toggle, sigc::mem_fun(*this, &studio::CanvasView::toggle_show_grid));
1598 grid_snap_toggle = Gtk::ToggleAction::create("toggle-grid-snap", _("Snap to Grid"));
1599 grid_snap_toggle->set_active(work_area->get_grid_snap());
1600 action_group->add(grid_snap_toggle, sigc::mem_fun(*this, &studio::CanvasView::toggle_snap_grid));
1602 action = Gtk::ToggleAction::create("toggle-guide-show", _("Show Guides"));
1603 action->set_active(work_area->get_show_guides());
1604 action_group->add(action, sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap));
1606 action = Gtk::ToggleAction::create("toggle-low-res", _("Use Low-Res"));
1607 action->set_active(work_area->get_low_resolution_flag());
1608 action_group->add(action, sigc::mem_fun(*this, &studio::CanvasView::toggle_low_res_pixel_flag));
1610 action = Gtk::ToggleAction::create("toggle-onion-skin", _("Show Onion Skin"));
1611 action->set_active(work_area->get_onion_skin());
1612 action_group->add(action, sigc::mem_fun(*this, &studio::CanvasView::toggle_onion_skin));
1615 action_group->add( Gtk::Action::create("canvas-zoom-fit", Gtk::StockID("gtk-zoom-fit")),
1616 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)
1618 action_group->add( Gtk::Action::create("canvas-zoom-100", Gtk::StockID("gtk-zoom-100")),
1619 sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)
1623 Glib::RefPtr<Gtk::Action> action;
1625 action=Gtk::Action::create("seek-next-frame", Gtk::Stock::GO_FORWARD,_("Next Frame"),_("Next Frame"));
1626 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),1));
1627 action=Gtk::Action::create("seek-prev-frame", Gtk::Stock::GO_BACK,_("Prev Frame"),_("Prev Frame"));
1628 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_frame),-1));
1630 action=Gtk::Action::create("seek-next-second", Gtk::Stock::GO_FORWARD,_("Seek Forward"),_("Seek Forward"));
1631 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(1)));
1632 action=Gtk::Action::create("seek-prev-second", Gtk::Stock::GO_BACK,_("Seek Backward"),_("Seek Backward"));
1633 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time(-1)));
1635 action=Gtk::Action::create("seek-end", Gtk::Stock::GOTO_LAST,_("Seek to End"),_("Seek to End"));
1636 action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::end()));
1638 action=Gtk::Action::create("seek-begin", Gtk::Stock::GOTO_FIRST,_("Seek to Begin"),_("Seek to Begin"));
1639 action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek_time),Time::begin()));
1641 action=Gtk::Action::create("jump-next-keyframe", Gtk::Stock::GO_FORWARD,_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1642 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1644 action=Gtk::Action::create("jump-prev-keyframe", Gtk::Stock::GO_BACK,_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1645 action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1647 action=Gtk::Action::create("canvas-zoom-in", Gtk::Stock::ZOOM_IN);
1648 action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1650 action=Gtk::Action::create("canvas-zoom-out", Gtk::Stock::ZOOM_OUT);
1651 action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1653 action=Gtk::Action::create("time-zoom-in", Gtk::Stock::ZOOM_IN, _("Zoom In on Timeline"));
1654 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1656 action=Gtk::Action::create("time-zoom-out", Gtk::Stock::ZOOM_OUT, _("Zoom Out on Timeline"));
1657 action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1662 Glib::RefPtr<Gtk::ToggleAction> action;
1664 #define DUCK_MASK(lower,upper,string) \
1665 action=Gtk::ToggleAction::create("mask-" #lower "-ducks", string); \
1666 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_##upper)); \
1667 action_group->add(action, \
1669 sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask), \
1670 Duck::TYPE_##upper))
1672 DUCK_MASK(position,POSITION,_("Show Position Ducks"));
1673 DUCK_MASK(tangent,TANGENT,_("Show Tangent Ducks"));
1674 DUCK_MASK(vertex,VERTEX,_("Show Vertex Ducks"));
1675 DUCK_MASK(radius,RADIUS,_("Show Radius Ducks"));
1676 DUCK_MASK(width,WIDTH,_("Show Width Ducks"));
1677 DUCK_MASK(angle,ANGLE,_("Show Angle Ducks"));
1682 add_accel_group(App::ui_manager()->get_accel_group());
1684 /* // Here is where we add the actions that may have conflicting
1685 // keyboard accelerators.
1687 Glib::RefPtr<Gtk::ActionGroup> accel_action_group(Gtk::ActionGroup::create("canvas_view"));
1688 Glib::RefPtr<Gtk::Action> action;
1690 action=Gtk::Action::create("seek-next-frame", Gtk::StockID("gtk-forward"),_("Next Frame"),_("Next Frame"));
1691 accel_action_group->add(action,sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),1));
1693 action=Gtk::Action::create("seek-prev-frame", Gtk::StockID("gtk-forward"),_("Prev Frame"),_("Prev Frame"));
1694 accel_action_group->add( action, sigc::bind(sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::seek),-1));
1696 action=Gtk::Action::create("jump-next-keyframe", Gtk::StockID("gtk-forward"),_("Jump to Next Keyframe"),_("Jump to Next Keyframe"));
1697 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe));
1699 action=Gtk::Action::create("jump-prev-keyframe", Gtk::StockID("gtk-back"),_("Jump to Prev Keyframe"),_("Jump to Prev Keyframe"));
1700 accel_action_group->add( action,sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe));
1702 action=Gtk::Action::create("canvas-zoom-in", Gtk::StockID("gtk-zoom-in"));
1703 accel_action_group->add( action,sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in));
1705 action=Gtk::Action::create("canvas-zoom-out", Gtk::StockID("gtk-zoom-out"));
1706 accel_action_group->add( action, sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out) );
1708 action=Gtk::Action::create("time-zoom-in", Gtk::StockID("gtk-zoom-in"), _("Zoom In on Timeline"));
1709 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in) );
1711 action=Gtk::Action::create("time-zoom-out", Gtk::StockID("gtk-zoom-out"), _("Zoom Out on Timeline"));
1712 accel_action_group->add( action, sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out) );
1714 Glib::RefPtr<Gtk::UIManager> accel_ui_manager(Gtk::UIManager::create());
1716 Glib::ustring ui_info =
1719 <accelerator action='seek-next-frame' />
1720 <accelerator action='seek-prev-frame' />
1721 <accelerator action='jump-next-keyframe' />
1722 <accelerator action='jump-prev-keyframe' />
1723 <accelerator action='canvas-zoom-in' />
1724 <accelerator action='canvas-zoom-out' />
1725 <accelerator action='time-zoom-in' />
1726 <accelerator action='time-zoom-out' />
1730 accel_ui_manager->add_ui_from_string(ui_info);
1731 add_accel_group(accel_ui_manager->get_accel_group());
1733 accel_ui_manager->insert_action_group(accel_action_group);
1734 set_ref_obj("accel_ui_manager",accel_ui_manager);
1735 set_ref_obj("accel_action_group",accel_action_group);
1741 // //Test some key stuff
1743 // filemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-save"),
1744 // hide_return(sigc::mem_fun(*get_instance().get(), &studio::Instance::save))));
1745 // 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))));
1746 // 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))));
1747 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1749 // 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))));
1750 // 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))));
1751 // 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))));
1753 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1754 // 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))));
1755 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1756 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Render"),Gtk::AccelKey("F9"),
1757 // sigc::mem_fun(render_settings,&studio::RenderSettings::present)
1759 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview"),Gtk::AccelKey("F11"),
1760 // sigc::mem_fun(*this,&CanvasView::on_preview_option)
1762 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Sound File"),
1763 // sigc::mem_fun(*this,&CanvasView::on_audio_option)
1766 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1767 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Options"),Gtk::AccelKey("F12"),
1768 // sigc::mem_fun(canvas_options,&studio::CanvasOptions::present)
1770 // filemenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1771 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close View"),
1772 // sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_view))
1774 // filemenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Close Document"),
1775 // sigc::hide_return(sigc::mem_fun(*this,&studio::CanvasView::close_document))
1778 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-undo"),Gtk::AccelKey('Z',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_UNDO)));
1779 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-redo"),Gtk::AccelKey('R',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REDO)));
1780 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1781 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-cut"),NOT_IMPLEMENTED_SLOT));
1782 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-copy"),NOT_IMPLEMENTED_SLOT));
1783 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-paste"),NOT_IMPLEMENTED_SLOT));
1784 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1785 // 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)));
1786 // editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Unselect All Ducks"),Gtk::AccelKey('E',Gdk::CONTROL_MASK),sigc::mem_fun(*work_area,&studio::WorkArea::unselect_all_ducks)));
1787 // editmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Layers"),Gtk::AccelKey('A',Gdk::CONTROL_MASK),sigc::mem_fun(*this,&CanvasView::on_select_layers)));
1788 // 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)));
1789 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1791 // //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))));
1792 // //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))));
1793 // 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)));
1794 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-refresh"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),SLOT_EVENT(EVENT_REFRESH)));
1795 // editmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1796 // editmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),Gtk::AccelKey("F8"),
1797 // sigc::mem_fun(canvas_properties,&studio::CanvasProperties::present)
1800 // build_new_layer_menu(newlayermenu);
1801 // layermenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New"),newlayermenu));
1805 // synfigapp::Action::ParamList param_list;
1806 // param_list.add("canvas",Canvas::Handle(get_canvas()));
1807 // param_list.add("canvas_interface",canvas_interface());
1808 // add_actions_to_menu(&canvasmenu, param_list,synfigapp::Action::CATEGORY_CANVAS);
1812 // //canvasmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Keyframe Dialog"),sigc::mem_fun(keyframe_dialog,&studio::Dialog_Keyframe::present)));
1814 // // Duck Mask Menu
1817 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1819 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Position Ducks"),Gtk::AccelKey('1',Gdk::MOD1_MASK)));
1820 // duck_mask_position=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1821 // duck_mask_position->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
1822 // duck_mask_position->signal_toggled().connect(
1824 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1825 // Duck::TYPE_POSITION
1829 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Vertex Ducks"),Gtk::AccelKey('2',Gdk::MOD1_MASK)));
1830 // duck_mask_vertex=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1831 // duck_mask_vertex->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
1832 // duck_mask_vertex->signal_toggled().connect(
1834 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1835 // Duck::TYPE_VERTEX
1839 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Tangent Ducks"),Gtk::AccelKey('3',Gdk::MOD1_MASK)));
1840 // duck_mask_tangent=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1841 // duck_mask_tangent->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
1842 // duck_mask_tangent->signal_toggled().connect(
1844 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1845 // Duck::TYPE_TANGENT
1849 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Radius Ducks"),Gtk::AccelKey('4',Gdk::MOD1_MASK)));
1850 // duck_mask_radius=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1851 // duck_mask_radius->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
1852 // duck_mask_radius->signal_toggled().connect(
1854 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1855 // Duck::TYPE_RADIUS
1859 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Width Ducks"),Gtk::AccelKey('5',Gdk::MOD1_MASK)));
1860 // duck_mask_width=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1861 // duck_mask_width->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
1862 // duck_mask_width->signal_toggled().connect(
1864 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1869 // duckmaskmenu.items().push_back(Gtk::Menu_Helpers::CheckMenuElem(_("Angle Ducks"),Gtk::AccelKey('6',Gdk::MOD1_MASK)));
1870 // duck_mask_angle=static_cast<Gtk::CheckMenuItem*>(&duckmaskmenu.items().back());
1871 // duck_mask_angle->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
1872 // duck_mask_angle->signal_toggled().connect(
1874 // sigc::mem_fun(*this, &studio::CanvasView::toggle_duck_mask),
1879 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Mask Ducks"),duckmaskmenu));
1882 // // Preview Quality Menu
1885 // qualitymenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1887 // qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Use Parametric Renderer"),0),
1889 // sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1893 // for(i=1;i<=10;i++)
1895 // qualitymenu.items().push_back(Gtk::Menu_Helpers::MenuElem(strprintf(_("Set Quality to %d"),i),Gtk::AccelKey('0'+(i%10),Gdk::CONTROL_MASK),
1897 // sigc::mem_fun(*work_area, &studio::WorkArea::set_quality),
1902 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Preview Quality"),qualitymenu));
1905 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::MEDIA_PLAY,
1906 // sigc::mem_fun(*this, &studio::CanvasView::play)));
1907 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("Flipbook Dialog"),
1908 // sigc::mem_fun(*preview_dialog, &studio::Dialog_Preview::present)));
1910 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1912 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Show"),Gtk::AccelKey('g',Gdk::CONTROL_MASK),
1913 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid)));
1914 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Grid Snap"),Gtk::AccelKey('l',Gdk::CONTROL_MASK),
1915 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_grid_snap)));
1916 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Guide Snap"),Gtk::AccelKey('k',Gdk::CONTROL_MASK),
1917 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_guide_snap)));
1918 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Toggle Low-Res"),Gtk::AccelKey('`',Gdk::CONTROL_MASK),
1919 // sigc::mem_fun(*work_area, &studio::WorkArea::toggle_low_resolution_flag)));
1921 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1923 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('=',static_cast<Gdk::ModifierType>(0)),
1924 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_in)));
1925 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('-',static_cast<Gdk::ModifierType>(0)),
1926 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_out)));
1927 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-fit"),
1928 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_fit)));
1929 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-100"),Gtk::AccelKey('`',static_cast<Gdk::ModifierType>(0)),
1930 // sigc::mem_fun(*work_area, &studio::WorkArea::zoom_norm)));
1931 // viewmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1933 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-in"),Gtk::AccelKey('+',static_cast<Gdk::ModifierType>(0)),
1934 // sigc::mem_fun(*this, &studio::CanvasView::time_zoom_in)));
1935 // viewmenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-zoom-out"),Gtk::AccelKey('_',static_cast<Gdk::ModifierType>(0)),
1936 // sigc::mem_fun(*this, &studio::CanvasView::time_zoom_out)));
1938 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Next Keyframe"),Gtk::AccelKey(']',static_cast<Gdk::ModifierType>(0)),
1939 // sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_next_keyframe)));
1940 // viewmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Jump to Prev Keyframe"),Gtk::AccelKey('[',static_cast<Gdk::ModifierType>(0)),
1941 // sigc::mem_fun(*canvas_interface().get(), &synfigapp::CanvasInterface::jump_to_prev_keyframe)));
1943 // mainmenu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
1944 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_File"),filemenu));
1945 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),editmenu));
1946 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_View"),viewmenu));
1947 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Canvas"),canvasmenu));
1948 // mainmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Layer"),layermenu));
1950 // mainmenu.accelerate(*this);
1955 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Waypoint"),NOT_IMPLEMENTED_SLOT));
1956 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Delete Waypoint"),NOT_IMPLEMENTED_SLOT));
1957 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Export"),NOT_IMPLEMENTED_SLOT));
1958 // trackmenu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
1959 // trackmenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Properties"),NOT_IMPLEMENTED_SLOT));
1965 // canvasmenu.show();
1966 // layermenu.show();
1968 // keyframemenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-properties"),
1969 // sigc::mem_fun(*this,&studio::CanvasView::show_keyframe_dialog)
1973 // get_accel_group()->unlock();
1975 // //Set the accelerator paths for all the menus
1976 // filemenu.set_accel_path("<synfig>/File");
1977 // editmenu.set_accel_path("<synfig>/Edit");
1978 // layermenu.set_accel_path("<synfig>/Layer");
1979 // //mainmenu.set_accel_path("<synfig-main>");
1980 // canvasmenu.set_accel_path("<synfig>/Canvas");
1981 // viewmenu.set_accel_path("<synfig>/View");
1982 // duckmaskmenu.set_accel_path("<synfig>/DuckMask");
1987 CanvasView::on_select_layers()
1989 Canvas::Handle canvas(get_canvas());
1990 for (CanvasBase::iterator iter = canvas->begin(); iter != canvas->end(); iter++)
1991 layer_tree->select_all_children_layers(*iter);
1995 CanvasView::on_unselect_layers()
1997 layer_tree->clear_selected_layers();
2001 CanvasView::show_keyframe_dialog()
2003 Glib::RefPtr<Gtk::TreeSelection> selection(keyframe_tree->get_selection());
2004 if(selection->get_selected())
2006 Gtk::TreeRow row(*selection->get_selected());
2008 Keyframe keyframe(row[keyframe_tree->model.keyframe]);
2010 keyframe_dialog.set_keyframe(keyframe);
2011 keyframe_dialog.present();
2016 CanvasView::add_layer(synfig::String x)
2018 Canvas::Handle canvas;
2020 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2022 int target_depth(0);
2024 if(layer_list.empty())
2026 canvas=get_canvas();
2030 canvas=(*layer_list.begin())->get_canvas();
2031 target_depth=canvas->get_depth(*layer_list.begin());
2034 Layer::Handle layer(canvas_interface()->add_layer_to(x,canvas,target_depth));
2037 get_selection_manager()->clear_selected_layers();
2038 get_selection_manager()->set_selected_layer(layer);
2043 CanvasView::popup_layer_menu(synfig::Layer::Handle layer)
2045 //Gtk::Menu* menu(manage(new Gtk::Menu));
2046 Gtk::Menu* menu(¶mmenu);
2047 menu->items().clear();
2049 synfigapp::Action::ParamList param_list;
2050 param_list.add("time",canvas_interface()->get_time());
2051 param_list.add("canvas",Canvas::Handle(layer->get_canvas()));
2052 param_list.add("canvas_interface",canvas_interface());
2053 param_list.add("layer",layer);
2055 //Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2056 //build_new_layer_menu(*newlayers);
2058 //parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
2060 if(layer->get_name()=="PasteCanvas")
2062 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2066 &studio::LayerTree::select_all_children_layers
2073 add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_LAYER);
2075 menu->popup(3,gtk_get_current_event_time());
2079 CanvasView::register_layer_type(synfig::Layer::Book::value_type &/*lyr*/,std::map<synfig::String,Gtk::Menu*>* /*category_map*/)
2081 /* if(lyr.second.category==CATEGORY_DO_NOT_USE)
2084 if(category_map->count(lyr.second.category)==0)
2085 (*category_map)[lyr.second.category]=manage(new Gtk::Menu());
2087 (*category_map)[lyr.second.category]->items().push_back(Gtk::Menu_Helpers::MenuElem(lyr.second.local_name,
2090 sigc::mem_fun(*this,&studio::CanvasView::add_layer),
2099 CanvasView::build_new_layer_menu(Gtk::Menu &/*menu*/)
2102 std::map<synfig::String,Gtk::Menu*> category_map;
2105 synfig::Layer::book().begin(),
2106 synfig::Layer::book().end(),
2110 &studio::CanvasView::register_layer_type
2116 menu.items().clear();
2117 menu.items().push_back(Gtk::Menu_Helpers::TearoffMenuElem());
2119 std::map<synfig::String,Gtk::Menu*>::iterator iter;
2120 for(iter=category_map.begin();iter!=category_map.end();++iter)
2121 menu.items().push_back(Gtk::Menu_Helpers::MenuElem(iter->first,*iter->second));
2128 CanvasView::popup_main_menu()
2130 //mainmenu.popup(0,gtk_get_current_event_time());
2131 Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(App::ui_manager()->get_widget("/menu-main"));
2134 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2135 //menu->accelerate(*this);
2136 menu->popup(0,gtk_get_current_event_time());
2141 CanvasView::on_refresh_pressed()
2145 work_area->queue_render_preview();
2149 CanvasView::workarea_layer_selected(synfig::Layer::Handle layer)
2151 get_selection_manager()->clear_selected_layers();
2153 get_selection_manager()->set_selected_layer(layer);
2157 CanvasView::refresh_rend_desc()
2159 current_time_widget->set_fps(get_canvas()->rend_desc().get_frame_rate());
2162 //synfig::info("Canvasview: Refreshing render desc info");
2163 if(!get_time().is_equal(time_adjustment().get_value()))
2165 time_adjustment().set_value(get_time());
2166 time_adjustment().value_changed();
2169 Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
2170 if(length<DEFAULT_TIME_WINDOW_SIZE)
2172 time_window_adjustment().set_page_increment(length);
2173 time_window_adjustment().set_page_size(length);
2177 time_window_adjustment().set_page_increment(DEFAULT_TIME_WINDOW_SIZE);
2178 time_window_adjustment().set_page_size(DEFAULT_TIME_WINDOW_SIZE);
2181 //set the FPS of the timeslider
2182 timeslider->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
2184 //set the beginning and ending time of the time slider
2185 Time begin_time=get_canvas()->rend_desc().get_time_start();
2186 Time end_time=get_canvas()->rend_desc().get_time_end();
2188 // Setup the time_window adjustment
2189 time_window_adjustment().set_lower(begin_time);
2190 time_window_adjustment().set_upper(end_time);
2191 time_window_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
2193 //Time length(get_canvas()->rend_desc().get_time_end()-get_canvas()->rend_desc().get_time_start());
2194 if(length < time_window_adjustment().get_page_size())
2196 time_window_adjustment().set_page_increment(length);
2197 time_window_adjustment().set_page_size(length);
2200 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
2201 &time_window_adjustment_, time_window_adjustment_.get_lower(),
2202 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2203 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
2206 time_window_adjustment().changed(); //only non-value stuff was changed
2208 // Setup the time adjustment
2210 //NOTE THESE TWO SHOULD BE CHANGED BY THE changed() CALL ABOVE
2211 //time_adjustment().set_lower(time_window_adjustment().get_value());
2212 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2214 // time_adjustment().set_lower(get_canvas()->rend_desc().get_time_start());
2215 // time_adjustment().set_upper(get_canvas()->rend_desc().get_time_end());
2216 time_adjustment().set_step_increment(synfig::Time(1.0/get_canvas()->rend_desc().get_frame_rate()));
2217 time_adjustment().set_page_increment(synfig::Time(1.0));
2218 time_adjustment().set_page_size(0);
2220 time_adjustment().changed();
2222 /*synfig::info("w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n",
2223 &time_window_adjustment_, time_window_adjustment_.get_lower(),
2224 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2225 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment()
2228 if(begin_time==end_time)
2237 //clamp time to big bounds...
2238 if(time_window_adjustment().get_value() < begin_time)
2240 time_window_adjustment().set_value(begin_time);
2241 time_window_adjustment().value_changed();
2244 if(time_window_adjustment().get_value() + time_window_adjustment().get_page_size() > end_time)
2246 time_window_adjustment().set_value(end_time - time_window_adjustment().get_page_size());
2247 time_window_adjustment().value_changed();
2250 if(time_adjustment().get_value() < begin_time)
2252 time_adjustment().set_value(begin_time);
2253 time_adjustment().value_changed();
2256 if(time_adjustment().get_value() > end_time)
2258 time_adjustment().set_value(end_time);
2259 time_adjustment().value_changed();
2262 /*synfig::info("Time stats: \n"
2263 "w: %p - [%.3f,%.3f] (%.3f,%.3f) child: %p\n"
2264 "t: %p - [%.3f,%.3f] %.3f",
2265 &time_window_adjustment_, time_window_adjustment_.get_lower(),
2266 time_window_adjustment_.get_upper(),time_window_adjustment_.get_value(),
2267 time_window_adjustment_.get_page_size(),time_window_adjustment_.get_child_adjustment(),
2268 &time_adjustment_,time_adjustment_.get_lower(),time_adjustment_.get_upper(),
2269 time_adjustment_.get_value()
2272 work_area->queue_render_preview();
2276 CanvasView::close_view()
2278 if(get_instance()->get_visible_canvases()==1)
2285 static bool _close_instance(etl::handle<Instance> instance)
2287 etl::handle<Instance> argh(instance);
2288 instance->safe_close();
2289 synfig::info("closed");
2294 CanvasView::close_instance()
2296 #ifdef SINGLE_THREADED
2297 if (get_work_area()->get_updating())
2299 get_work_area()->stop_updating(true); // stop and mark as cancelled
2301 // give the workarea chances to stop updating
2302 Glib::signal_timeout().connect(
2303 sigc::mem_fun(*this, &CanvasView::close_instance),
2308 Glib::signal_timeout().connect(
2309 sigc::bind(sigc::ptr_fun(_close_instance),
2310 (etl::handle<Instance>)get_instance()),
2316 CanvasView::create(etl::loose_handle<Instance> instance, etl::handle<synfig::Canvas> canvas)
2318 etl::handle<studio::CanvasView> view(new CanvasView(instance,instance->synfigapp::Instance::find_canvas_interface(canvas)));
2319 instance->canvas_view_list().push_front(view);
2320 instance->signal_canvas_view_created()(view.get());
2325 CanvasView::update_title()
2329 title = strprintf("%s%s\"%s\"",
2331 get_instance()->get_action_count()
2335 get_instance()->has_real_filename()
2336 ? (etl::basename(get_instance()->get_file_name()) + " : ").c_str()
2339 get_canvas()->get_name().empty()
2340 ? get_canvas()->get_id().c_str()
2341 : get_canvas()->get_name().c_str()
2344 if(get_instance()->synfigapp::Instance::in_repository())
2347 if(get_instance()->synfigapp::Instance::is_modified())
2348 title+=_("-MODIFIED");
2349 if(get_instance()->synfigapp::Instance::is_updated())
2350 title+=_("-UPDATED");
2354 if(get_canvas()->is_root())
2355 title+=_(" (Root)");
2361 CanvasView::on_hide()
2364 Gtk::Window::on_hide();
2368 CanvasView::present()
2370 grab_focus();//on_focus_in_event(0);
2371 Gtk::Window::present();
2375 CanvasView::on_focus_in_event(GdkEventFocus*x)
2377 if(studio::App::get_selected_canvas_view()!=this)
2379 if(studio::App::get_selected_canvas_view())
2381 studio::App::get_selected_canvas_view()->get_smach().process_event(EVENT_YIELD_TOOL_OPTIONS);
2382 App::ui_manager()->remove_action_group(App::get_selected_canvas_view()->action_group);
2385 get_smach().process_event(EVENT_REFRESH_TOOL_OPTIONS);
2387 studio::App::set_selected_canvas_view(this);
2389 App::ui_manager()->insert_action_group(action_group);
2392 // HACK ... Questionable...?
2394 return Gtk::Window::on_focus_in_event(x);
2400 CanvasView::on_focus_out_event(GdkEventFocus*x)
2402 //App::ui_manager()->remove_action_group(action_group);
2403 //App::ui_manager()->ensure_update();
2404 return Gtk::Window::on_focus_out_event(x);
2408 CanvasView::refresh_tables()
2410 // if(layer_tree_store_)layer_tree_store_->refresh();
2411 // if(children_tree_store_)children_tree_store_->refresh();
2415 CanvasView::rebuild_tables()
2417 // layer_tree_store_->rebuild();
2418 // children_tree_store_->rebuild();
2422 CanvasView::build_tables()
2424 // layer_tree_store_->rebuild();
2425 // children_tree_store_->rebuild();
2429 CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
2431 synfigapp::Action::Handle action(synfigapp::Action::create("LayerActivate"));
2437 action->set_param("canvas",Canvas::Handle(layer->get_canvas()));
2438 if(!action->set_param("canvas_interface",canvas_interface()))
2439 // if(!action->set_param("canvas_interface",get_instance()->find_canvas_interface(layer->get_canvas())))
2440 synfig::error("LayerActivate didn't like CanvasInterface...?");
2441 action->set_param("time",get_time());
2442 action->set_param("layer",layer);
2443 action->set_param("new_status",!layer->active());
2445 assert(action->is_ready());
2447 canvas_interface()->get_instance()->perform_action(action);
2451 CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location, bool bezier)
2453 parammenu.items().clear();
2454 get_instance()->make_param_menu(¶mmenu,get_canvas(),value_desc,location,bezier);
2456 parammenu.popup(3,gtk_get_current_event_time());
2460 CanvasView::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list,synfigapp::Action::Category category)const
2462 get_instance()->add_actions_to_menu(menu, param_list, category);
2466 CanvasView::on_layer_user_click(int button, Gtk::TreeRow /*row*/, LayerTree::ColumnID /*column_id*/)
2472 Gtk::MenuItem* menu = dynamic_cast<Gtk::MenuItem*>(App::ui_manager()->get_widget("/menu-main/menu-layer"));
2473 if(menu && menu->get_submenu())
2475 //menu->set_accel_group(App::ui_manager()->get_accel_group());
2476 //menu->accelerate(*this);
2477 menu->get_submenu()->popup(button,gtk_get_current_event_time());
2481 bool multiple_selected=true;
2483 if(layer_tree->get_selection()->count_selected_rows()<=1)
2484 multiple_selected=false;
2486 // If the clicked row is not selected, then unselect
2487 // everything that isn't selected and select this row
2488 if(multiple_selected && !layer_tree->get_selection()->is_selected(row))
2490 layer_tree->get_selection()->unselect_all();
2491 layer_tree->get_selection()->select(row);
2492 multiple_selected=false;
2495 if(column_id==COLUMNID_TIME_TRACK)
2498 //synfigapp::ValueDesc value_desc(row[layer_param_tree_model.value_desc]);
2499 //ValueNode::Handle value_node(row[layer_param_tree_model.value_node]);
2500 //ValueNode::Handle parent_value_node;
2501 //ValueBase value=row[layer_param_tree_model.value];
2505 // parent_value_node=(*row.parent())[layer_tree_model.value_node];
2509 Layer::Handle layer(row[layer_tree_model.layer]);
2510 synfigapp::Action::ParamList param_list;
2511 param_list.add("time",canvas_interface()->get_time());
2512 param_list.add("canvas",Canvas::Handle(row[layer_tree_model.canvas]));
2513 param_list.add("canvas_interface",canvas_interface());
2514 if(!multiple_selected)
2515 param_list.add("layer",layer);
2518 synfigapp::SelectionManager::LayerList layer_list(get_selection_manager()->get_selected_layers());
2519 synfigapp::SelectionManager::LayerList::iterator iter;
2521 for(iter=layer_list.begin();iter!=layer_list.end();++iter)
2522 param_list.add("layer",Layer::Handle(*iter));
2525 parammenu.items().clear();
2527 Gtk::Menu *newlayers(manage(new Gtk::Menu()));
2528 // do we need this? the code is all #ifdef'ed out anyway
2529 // newlayers->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), newlayers));
2530 build_new_layer_menu(*newlayers);
2532 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("New Layer"),*newlayers));
2533 if(!multiple_selected && layer->get_name()=="PasteCanvas")
2535 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Select All Children"),
2539 &studio::LayerTree::select_all_children_layers
2546 add_actions_to_menu(¶mmenu, param_list,synfigapp::Action::CATEGORY_LAYER);
2547 parammenu.popup(button,gtk_get_current_event_time());
2551 else if(column_id==LayerTree::COLUMNID_TIME_TRACK && value_node && handle<synfig::ValueNode_Animated>::cast_dynamic(value_node))
2553 // Right-click on time track with animated
2554 // trackmenu.popup(0,0);
2559 if(!multiple_selected)
2561 popup_param_menu(value_desc);
2568 parammenu.items().clear();
2569 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Connect"),
2570 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::connect_selected_layer_params))
2572 parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Disconnect"),
2573 hide_return(sigc::mem_fun(*canvas_interface().get(),&synfigapp::CanvasInterface::disconnect_selected_layer_params))
2575 parammenu.popup(0,0);
2593 CanvasView::on_children_user_click(int button, Gtk::TreeRow row, ChildrenTree::ColumnID column_id)
2599 if(column_id==COLUMNID_TIME_TRACK)
2601 if(!(bool)row[children_tree_model.is_canvas])
2603 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2606 //! \todo fix properly -- what is the child dialog for?
2607 synfig::info("preventing child dialog right-click crash");
2611 popup_param_menu(value_desc);
2625 CanvasView::on_keyframe_tree_event(GdkEvent *event)
2629 case GDK_BUTTON_PRESS:
2630 switch(event->button.button)
2634 //keyframemenu.popup(event->button.button,gtk_get_current_event_time());
2640 case GDK_MOTION_NOTIFY:
2642 case GDK_BUTTON_RELEASE:
2651 CanvasView::refresh_time_window()
2653 //THESE SHOULD AUTOMATICALLY BE TAKEN CARE OF
2654 //time_adjustment().set_lower(time_window_adjustment().get_value());
2655 //time_adjustment().set_upper(time_window_adjustment().get_value()+time_window_adjustment().get_page_size());
2657 time_adjustment().set_page_increment(1.0); // One second
2658 time_adjustment().set_page_size(0);
2661 time_adjustment().set_step_increment(1.0/get_canvas()->rend_desc().get_frame_rate());
2662 time_adjustment().changed();
2664 //NOTE THIS SHOULD HOOK INTO THE CORRECT SIGNALS...
2666 children_tree->queue_draw();
2670 CanvasView::on_time_changed()
2672 Time time(get_time());
2674 current_time_widget->set_value(time);
2676 get_canvas()->keyframe_list().find(time);
2677 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#FF0000"));
2679 current_time_widget->modify_text(Gtk::STATE_NORMAL,Gdk::Color("#000000"));
2682 if(get_time() != time_adjustment().get_value())
2684 //Recenters the window, causing it to jump (possibly undesirably... but whatever)
2685 if(time < time_window_adjustment().get_value() ||
2686 time > time_window_adjustment().get_value()+time_window_adjustment().get_page_size())
2688 time_window_adjustment().set_value(
2689 time-time_window_adjustment().get_page_size()/2
2692 time_adjustment().set_value(time);
2693 time_adjustment().value_changed();
2695 // Shouldn't these trees just hook into
2696 // the time changed signal...?
2697 //YES THEY SHOULD...
2698 if(layer_tree)layer_tree->queue_draw();
2699 if(children_tree)children_tree->queue_draw();
2704 CanvasView::time_zoom_in()
2706 float frame_rate = get_canvas()->rend_desc().get_frame_rate();
2707 Time min_page_size = 2/frame_rate;
2709 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()*0.75);
2710 if (time_window_adjustment().get_page_size() < min_page_size)
2711 time_window_adjustment().set_page_size(min_page_size);
2712 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2713 time_window_adjustment().changed();
2715 refresh_time_window();
2719 CanvasView::time_zoom_out()
2721 Time length = (get_canvas()->rend_desc().get_time_end() -
2722 get_canvas()->rend_desc().get_time_start());
2724 time_window_adjustment().set_page_size(time_window_adjustment().get_page_size()/0.75);
2725 if (time_window_adjustment().get_page_size() > length)
2726 time_window_adjustment().set_page_size(length);
2727 time_window_adjustment().set_page_increment(time_window_adjustment().get_page_size());
2728 time_window_adjustment().changed();
2730 refresh_time_window();
2734 CanvasView::time_was_changed()
2736 synfig::Time time((synfig::Time)(double)time_adjustment().get_value());
2741 CanvasView::on_edited_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value)
2743 canvas_interface()->change_value(value_desc,new_value);
2748 CanvasView::on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
2750 Gtk::TreePath path(path_string);
2752 const Gtk::TreeRow row = *(children_tree->get_model()->get_iter(path));
2754 assert((bool)row[children_tree_model.is_value_node]);
2756 synfigapp::ValueDesc value_desc=row[children_tree_model.value_desc];
2759 on_edited_value(value_desc,value);
2764 CanvasView::on_id_changed()
2770 CanvasView::on_mode_changed(synfigapp::CanvasInterface::Mode mode)
2772 // If the animate flag was set in mode...
2773 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
2774 if(mode&synfigapp::MODE_ANIMATE)
2777 icon=manage(new Gtk::Image(Gtk::StockID("gtk-no"),iconsize));
2778 animatebutton->remove();
2779 animatebutton->add(*icon);
2780 tooltips.set_tip(*animatebutton,_("In Animate Editing Mode"));
2781 icon->set_padding(0,0);
2787 icon=manage(new Gtk::Image(Gtk::StockID("gtk-yes"),iconsize));
2788 animatebutton->remove();
2789 animatebutton->add(*icon);
2790 tooltips.set_tip(*animatebutton,_("Not in Animate Editing Mode"));
2791 icon->set_padding(0,0);
2795 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2798 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_all"),Gtk::ICON_SIZE_BUTTON));
2799 keyframebutton->remove();
2800 keyframebutton->add(*icon);
2801 tooltips.set_tip(*keyframebutton,_("All Keyframes Locked"));
2802 icon->set_padding(0,0);
2805 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2808 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_future"),Gtk::ICON_SIZE_BUTTON));
2809 keyframebutton->remove();
2810 keyframebutton->add(*icon);
2811 tooltips.set_tip(*keyframebutton,_("Future Keyframes Locked"));
2812 icon->set_padding(0,0);
2815 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2818 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_past"),Gtk::ICON_SIZE_BUTTON));
2819 keyframebutton->remove();
2820 keyframebutton->add(*icon);
2821 tooltips.set_tip(*keyframebutton,_("Past Keyframes Locked"));
2822 icon->set_padding(0,0);
2825 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2828 icon=manage(new Gtk::Image(Gtk::StockID("synfig-keyframe_lock_none"),Gtk::ICON_SIZE_BUTTON));
2829 keyframebutton->remove();
2830 keyframebutton->add(*icon);
2831 tooltips.set_tip(*keyframebutton,_("No Keyframes Locked"));
2832 icon->set_padding(0,0);
2836 work_area->queue_draw();
2840 CanvasView::on_animate_button_pressed()
2842 if(get_mode()&synfigapp::MODE_ANIMATE)
2843 set_mode(get_mode()-synfigapp::MODE_ANIMATE);
2845 set_mode(get_mode()|synfigapp::MODE_ANIMATE);
2849 CanvasView::on_keyframe_button_pressed()
2851 synfigapp::CanvasInterface::Mode mode(get_mode());
2853 // future && past --> past
2854 if((mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2855 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2857 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && (mode&synfigapp::MODE_ANIMATE_PAST))
2858 set_mode((get_mode()-synfigapp::MODE_ANIMATE_PAST)|synfigapp::MODE_ANIMATE_FUTURE);
2859 // future --> (nothing)
2860 else if((mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2861 set_mode(get_mode()-synfigapp::MODE_ANIMATE_FUTURE);
2862 // (nothing) --> future && past
2863 else if(!(mode&synfigapp::MODE_ANIMATE_FUTURE) && !(mode&synfigapp::MODE_ANIMATE_PAST))
2864 set_mode(get_mode()|synfigapp::MODE_ANIMATE_FUTURE|synfigapp::MODE_ANIMATE_PAST);
2868 CanvasView::duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name)
2870 return canvas_interface()->change_value(synfigapp::ValueDesc(layer,param_name),value);
2874 CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
2876 if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
2878 Real old_width((*bline_width)(get_time()).get(Real()));
2879 Real new_width(value.mag());
2880 int scale_index(bline_width->get_link_index_from_name("scale"));
2881 Real scale((*(bline_width->get_link(scale_index)))(get_time()).get(Real()));
2882 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_width,scale_index), new_width * scale / old_width);
2885 if (ValueNode_BLineCalcVertex::Handle bline_vertex = ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_desc.get_value_node()))
2887 ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link("bline"));
2889 if (((*(bline_vertex->get_link("loop")))(get_time()).get(bool()))){
2890 Real amount_old((*(bline_vertex->get_link("amount")))(get_time()).get(Real()));
2891 Real amount_new = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
2892 Real difference = fmod( fmod(amount_new - amount_old, 1.0) + 1.0 , 1.0);
2893 //fmod is called twice to avoid negative values
2894 if (difference > 0.5) difference=difference-1.0;
2895 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount_old+difference);
2898 Real amount = synfig::find_closest_point((*bline)(get_time()), value, radius, bline->get_loop());
2899 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_vertex,bline_vertex->get_link_index_from_name("amount")), amount);
2903 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2905 switch(value_desc.get_value_type())
2907 case ValueBase::TYPE_REAL:
2909 Real old_length = (*bline_tangent)(get_time()).get(Real());
2910 Real new_length = value.mag();
2911 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2912 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2913 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2914 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2916 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length);
2917 if (old_length == 0)
2919 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length);
2922 case ValueBase::TYPE_ANGLE:
2923 assert(0); // doesn't happen?
2926 case ValueBase::TYPE_VECTOR:
2928 Vector old_tangent = (*bline_tangent)(get_time()).get(Vector());
2929 Angle old_angle = old_tangent.angle();
2930 Real old_length = old_tangent.mag();
2931 Angle new_angle = value.angle();
2932 Real new_length = value.mag();
2933 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2934 int scale_index(bline_tangent->get_link_index_from_name("scale"));
2935 int fixed_length_index(bline_tangent->get_link_index_from_name("fixed_length"));
2936 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2937 Real scale((*(bline_tangent->get_link(scale_index)))(get_time()).get(Real()));
2938 bool fixed_length((*(bline_tangent->get_link(fixed_length_index)))(get_time()).get(bool()));
2941 if (!(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length)))
2944 else if (old_length != 0 && !(canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,scale_index), new_length * scale / old_length)))
2946 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + new_angle - old_angle);
2953 if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
2955 int link_index(scale_value_node->get_link_index_from_name("link"));
2956 if(scale_value_node->is_invertible(get_time()))
2957 return canvas_interface()->change_value(
2958 synfigapp::ValueDesc(scale_value_node,link_index),
2959 scale_value_node->get_inverse(get_time(), value)
2965 if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
2967 int link_index(range_value_node->get_link_index_from_name("link"));
2968 return canvas_interface()->change_value(
2969 synfigapp::ValueDesc(range_value_node,link_index),
2970 range_value_node->get_inverse(get_time(), value)
2974 switch(value_desc.get_value_type())
2976 case ValueBase::TYPE_REAL:
2977 return canvas_interface()->change_value(value_desc,value.mag());
2978 case ValueBase::TYPE_ANGLE:
2979 return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
2981 return canvas_interface()->change_value(value_desc,value);
2986 CanvasView::on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc)
2988 if (ValueNode_BLineCalcTangent::Handle bline_tangent = ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_desc.get_value_node()))
2990 int offset_index(bline_tangent->get_link_index_from_name("offset"));
2991 Angle old_offset((*(bline_tangent->get_link(offset_index)))(get_time()).get(Angle()));
2992 return canvas_interface()->change_value(synfigapp::ValueDesc(bline_tangent,offset_index), old_offset + rotation);
2995 if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
2997 int link_index(scale_value_node->get_link_index_from_name("link"));
2998 if(scale_value_node->is_invertible(get_time()))
2999 return canvas_interface()->change_value(
3000 synfigapp::ValueDesc(scale_value_node,link_index),
3001 scale_value_node->get_inverse(get_time(), rotation)
3007 if (ValueNode_Range::Handle range_value_node = ValueNode_Range::Handle::cast_dynamic(value_desc.get_value_node()))
3009 int link_index(range_value_node->get_link_index_from_name("link"));
3010 return canvas_interface()->change_value(
3011 synfigapp::ValueDesc(range_value_node,link_index),
3012 range_value_node->get_inverse(get_time(), rotation)
3015 // \todo will this really always be the case?
3016 assert(value_desc.get_value_type() == ValueBase::TYPE_ANGLE);
3017 return canvas_interface()->change_value(value_desc, value_desc.get_value(get_time()).get(Angle()) + rotation);
3021 CanvasView::selected_layer_color_set(synfig::Color color)
3023 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
3024 synfigapp::SelectionManager::LayerList::iterator iter;
3026 // Create the action group
3027 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Set Colors"));
3029 Layer::Handle layer;
3030 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
3035 on_edited_value(synfigapp::ValueDesc(layer,"color"),color);
3040 CanvasView::rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list)
3045 #define QUEUE_REBUILD_DUCKS sigc::mem_fun(*this,&CanvasView::queue_rebuild_ducks)
3049 synfig::warning("CanvasView::rebuild_ducks_layer_(): Layer doesn't have canvas set");
3052 for(Canvas::iterator iter(canvas->begin());iter!=canvas->end();++iter)
3054 Layer::Handle layer(*iter);
3056 if(selected_list.count(layer))
3058 if(!curr_transform_stack_set)
3060 curr_transform_stack_set=true;
3061 curr_transform_stack=transform_stack;
3064 // This layer is currently selected.
3065 duck_changed_connections.push_back(layer->signal_changed().connect(QUEUE_REBUILD_DUCKS));
3067 // do the bounding box thing
3068 bbox|=transform_stack.perform(layer->get_bounding_rect());
3070 // Grab the layer's list of parameters
3071 Layer::ParamList paramlist(layer->get_param_list());
3073 // Grab the layer vocabulary
3074 Layer::Vocab vocab=layer->get_param_vocab();
3075 Layer::Vocab::iterator iter;
3077 for(iter=vocab.begin();iter!=vocab.end();iter++)
3079 if(!iter->get_hidden() && !iter->get_invisible_duck())
3081 synfigapp::ValueDesc value_desc(layer,iter->get_name());
3082 work_area->add_to_ducks(value_desc,this,transform_stack,&*iter);
3083 if(value_desc.is_value_node())
3084 duck_changed_connections.push_back(value_desc.get_value_node()->signal_changed().connect(QUEUE_REBUILD_DUCKS));
3086 if(iter->get_name()=="color")
3089 if(!App::dialog_color->busy())
3091 App::dialog_color->reset();
3092 App::dialog_color->set_color(layer->get_param("color").get(Color()));
3093 App::dialog_color->signal_edited().connect(
3096 &studio::CanvasView::selected_layer_color_set
3105 layer_name=layer->get_name();
3109 Transform::Handle trans(layer->get_transform());
3112 transform_stack.push(trans);
3116 /* // Add transforms onto the stack
3117 if(layer_name=="Translate")
3119 transform_stack.push(synfig::Transform_Translate(layer->get_param("origin").get(Vector())));
3122 if(layer_name=="Zoom")
3125 scale[0]=scale[1]=exp(layer->get_param("amount").get(Real()));
3126 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
3129 if(layer_name=="stretch")
3131 Vector scale(layer->get_param("amount").get(Vector()));
3132 transform_stack.push(synfig::Transform_Scale(scale,layer->get_param("center").get(Vector())));
3135 if(layer_name=="Rotate")
3137 transform_stack.push(synfig::Transform_Rotate(layer->get_param("amount").get(Angle()),layer->get_param("origin").get(Vector())));
3143 // If this is a paste canvas layer, then we need to
3145 if(layer_name=="PasteCanvas")
3148 scale[0]=scale[1]=exp(layer->get_param("zoom").get(Real()));
3149 Vector origin(layer->get_param("origin").get(Vector()));
3151 Canvas::Handle child_canvas(layer->get_param("canvas").get(Canvas::Handle()));
3152 Vector focus(layer->get_param("focus").get(Vector()));
3154 if(!scale.is_equal_to(Vector(1,1)))
3155 transform_stack.push(new Transform_Scale(layer->get_guid(), scale,origin+focus));
3156 if(!origin.is_equal_to(Vector(0,0)))
3157 transform_stack.push(new Transform_Translate(layer->get_guid(), origin));
3159 rebuild_ducks_layer_(transform_stack,child_canvas,selected_list);
3161 if(!origin.is_equal_to(Vector(0,0)))
3162 transform_stack.pop();
3163 if(!scale.is_equal_to(Vector(1,1)))
3164 transform_stack.pop();
3167 // Remove all of the transforms we have added
3168 while(transforms--) { transform_stack.pop(); }
3170 #undef QUEUE_REBUILD_DUCKS
3174 CanvasView::queue_rebuild_ducks()
3177 if(rebuild_ducks_queued)
3180 if(rebuild_ducks_queued)
3181 queue_rebuild_ducks_connection.disconnect();
3184 queue_rebuild_ducks_connection=Glib::signal_timeout().connect(
3186 sigc::mem_fun(*this,&CanvasView::rebuild_ducks),
3192 rebuild_ducks_queued=true;
3196 CanvasView::rebuild_ducks()
3201 synfig::info("%d",i/(i-i));
3204 rebuild_ducks_queued=false;
3205 //queue_rebuild_ducks_connection.disconnect();
3207 if(work_area->is_dragging())
3209 queue_rebuild_ducks();
3213 if(!duck_refresh_flag)
3215 duck_refresh_needed=true;
3221 work_area->clear_ducks();
3222 work_area->set_time(get_time());
3223 get_canvas()->set_time(get_time());
3224 curr_transform_stack.clear();
3225 //curr_transform_stack.push(new Transform_Translate(Point(0,0)));
3226 curr_transform_stack_set=false;
3228 for(;!duck_changed_connections.empty();duck_changed_connections.pop_back())duck_changed_connections.back().disconnect();
3230 //get_canvas()->set_time(get_time());
3231 bool not_empty(false);
3233 // First do the layers...
3235 synfigapp::SelectionManager::LayerList selected_list(get_selection_manager()->get_selected_layers());
3236 std::set<synfig::Layer::Handle> layer_set(selected_list.begin(),selected_list.end());
3238 if(!layer_set.empty())
3241 synfig::TransformStack transform_stack;
3243 rebuild_ducks_layer_(transform_stack, get_canvas(), layer_set);
3247 // Now do the children
3249 synfigapp::SelectionManager::ChildrenList selected_list(get_selection_manager()->get_selected_children());
3250 synfigapp::SelectionManager::ChildrenList::iterator iter;
3251 synfig::TransformStack transform_stack;
3253 if(selected_list.empty())
3260 for(iter=selected_list.begin();iter!=selected_list.end();++iter)
3262 work_area->add_to_ducks(*iter,this,transform_stack);
3266 work_area->refresh_selected_ducks();
3267 work_area->queue_draw_preview();
3271 CanvasView::decrease_low_res_pixel_size()
3273 if(changing_resolution_)
3275 changing_resolution_=true;
3276 list<int> sizes = CanvasView::get_pixel_sizes();
3277 int pixel_size = work_area->get_low_res_pixel_size();
3278 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
3279 if (*iter == pixel_size)
3281 if (iter == sizes.begin())
3282 // we already have the smallest low-res pixels possible - turn off low-res instead
3283 work_area->set_low_resolution_flag(false);
3287 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
3288 action->activate(); // to make sure the radiobutton in the menu is updated too
3289 work_area->set_low_resolution_flag(true);
3293 // Update the "toggle-low-res" action
3294 Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
3295 action->set_active(work_area->get_low_resolution_flag());
3296 // Update toggle low res button
3297 resolutiondial->update_lowres(work_area->get_low_resolution_flag());
3298 changing_resolution_=false;
3302 CanvasView::increase_low_res_pixel_size()
3304 if(changing_resolution_)
3306 changing_resolution_=true;
3307 list<int> sizes = CanvasView::get_pixel_sizes();
3308 int pixel_size = work_area->get_low_res_pixel_size();
3309 if (!work_area->get_low_resolution_flag())
3311 // We were using "hi res" so change it to low res.
3312 work_area->set_low_resolution_flag(true);
3313 // Update the "toggle-low-res" action
3314 Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
3315 action->set_active(true);
3316 // Update the toggle low res button
3317 resolutiondial->update_lowres(true);
3318 changing_resolution_=false;
3322 for (list<int>::iterator iter = sizes.begin(); iter != sizes.end(); iter++)
3323 if (*iter == pixel_size)
3326 if (iter != sizes.end())
3328 Glib::RefPtr<Gtk::Action> action = action_group->get_action(strprintf("lowres-pixel-%d", *iter));
3329 action->activate(); // to make sure the radiobutton in the menu is updated too
3330 work_area->set_low_resolution_flag(true);
3334 // Update the "toggle-low-res" action
3335 Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
3336 action->set_active(work_area->get_low_resolution_flag());
3337 // Update toggle low res button
3338 resolutiondial->update_lowres(work_area->get_low_resolution_flag());
3339 changing_resolution_=false;
3343 CanvasView::toggle_low_res_pixel_flag()
3345 if(changing_resolution_)
3347 changing_resolution_=true;
3348 work_area->toggle_low_resolution_flag();
3349 // Update the toggle low res button
3350 resolutiondial->update_lowres(work_area->get_low_resolution_flag());
3351 // Update the "toggle-low-res" action
3352 Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-low-res"));
3353 action->set_active(work_area->get_low_resolution_flag());
3354 changing_resolution_=false;
3358 CanvasView::update_quality()
3362 if(updating_quality_)
3364 updating_quality_=true;
3365 work_area->set_quality((int) quality_spin->get_value());
3366 // Update Quality Radio actions
3367 Glib::RefPtr<Gtk::RadioAction> action=Glib::RefPtr<Gtk::RadioAction>::cast_dynamic(
3368 action_group->get_action(strprintf("quality-%02d",(int) quality_spin->get_value()))
3370 action->set_active();
3372 updating_quality_=false;
3376 CanvasView::set_quality(int x)
3378 if(updating_quality_)
3380 work_area->set_quality(x);
3381 // Update the quality spin button
3382 quality_spin->set_value(x);
3386 CanvasView::set_onion_skins()
3388 if(toggling_onion_skin)
3391 onion_skins[0]=past_onion_spin->get_value();
3392 onion_skins[1]=future_onion_spin->get_value();
3393 work_area->set_onion_skins(onion_skins);
3397 CanvasView::toggle_show_grid()
3399 if(toggling_show_grid)
3401 toggling_show_grid=true;
3402 work_area->toggle_grid();
3403 // Update the toggle grid show action
3404 set_grid_show_toggle(work_area->grid_status());
3405 // Update the toggle grid show check button
3406 show_grid->set_active(work_area->grid_status());
3407 toggling_show_grid=false;
3411 CanvasView::toggle_snap_grid()
3413 if(toggling_snap_grid)
3415 toggling_snap_grid=true;
3416 work_area->toggle_grid_snap();
3417 // Update the toggle grid snap action
3418 set_grid_snap_toggle(work_area->get_grid_snap());
3419 // Update the toggle grid snap check button
3420 snap_grid->set_active(work_area->get_grid_snap());
3421 toggling_snap_grid=false;
3425 CanvasView::toggle_onion_skin()
3427 if(toggling_onion_skin)
3429 toggling_onion_skin=true;
3430 work_area->toggle_onion_skin();
3431 // Update the toggle onion skin action
3432 Glib::RefPtr<Gtk::ToggleAction> action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("toggle-onion-skin"));
3433 action->set_active(work_area->get_onion_skin());
3434 // Update the toggle grid snap check button
3435 onion_skin->set_active(work_area->get_onion_skin());
3436 toggling_onion_skin=false;
3440 CanvasView::on_dirty_preview()
3444 IsWorking is_working(*this);
3446 work_area->queue_render_preview();
3453 assert(get_canvas());
3455 // If we are already busy, don't play!
3456 if(working_depth)return;
3458 // Set us up as working
3459 IsWorking is_working(*this);
3463 time=work_area->get_time(),
3464 endtime=get_canvas()->rend_desc().get_time_end();
3466 // If we are already at the end of time, start over
3468 time=get_canvas()->rend_desc().get_time_start();
3472 work_area->clear_ducks();
3474 for(timer.reset(); time + timer() < endtime;)
3476 //Clamp the time window so we can see the time value as it races across the horizon
3477 bool timewindreset = false;
3479 while( time + timer() > Time(time_window_adjustment().get_sub_upper()) )
3481 time_window_adjustment().set_value(
3483 time_window_adjustment().get_value()+time_window_adjustment().get_page_size()/2,
3484 time_window_adjustment().get_upper()-time_window_adjustment().get_page_size() )
3486 timewindreset = true;
3489 while( time + timer() < Time(time_window_adjustment().get_sub_lower()) )
3491 time_window_adjustment().set_value(
3493 time_window_adjustment().get_value()-time_window_adjustment().get_page_size()/2,
3494 time_window_adjustment().get_lower())
3497 timewindreset = true;
3500 //we need to tell people that the value changed
3501 if(timewindreset) time_window_adjustment().value_changed();
3503 //update actual time to next step
3504 time_adjustment().set_value(time+timer());
3505 time_adjustment().value_changed();
3507 if(!work_area->sync_render_preview())
3510 // wait for the workarea to refresh itself
3511 while (studio::App::events_pending())
3512 studio::App::iteration(false);
3514 if(get_cancel_status())
3520 on_play_stop_pressed();
3522 time_adjustment().set_value(endtime);
3523 time_adjustment().value_changed();
3527 CanvasView::show_tables()
3530 Smach::event_result x(process_event_key(EVENT_TABLES_SHOW));
3531 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3533 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3534 treetogglebutton->remove();
3535 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-down"),iconsize)));
3536 treetogglebutton->show_all();
3543 CanvasView::hide_tables()
3546 Smach::event_result x(process_event_key(EVENT_TABLES_HIDE));
3547 if(x==Smach::RESULT_OK || x==Smach::RESULT_ACCEPT)
3549 Gtk::IconSize iconsize=Gtk::IconSize::from_name("synfig-small_icon");
3550 treetogglebutton->remove();
3551 treetogglebutton->add(*manage(new Gtk::Image(Gtk::StockID("gtk-go-up"),iconsize)));
3552 treetogglebutton->show_all();
3559 CanvasView::tables_are_visible()
3561 // return notebook->is_visible();
3566 CanvasView::toggle_tables()
3568 // if(tables_are_visible())
3575 CanvasView::show_timebar()
3578 //current_time_widget->show(); // not needed now that belongs to the timebar
3580 //keyframe_tab_child->show();
3582 layer_tree->set_show_timetrack(true);
3584 children_tree->set_show_timetrack(true);
3588 CanvasView::hide_timebar()
3591 //current_time_widget->hide(); // not needed now that belongs to the timebar
3592 //keyframe_tab_child->hide();
3594 layer_tree->set_show_timetrack(false);
3596 children_tree->set_show_timetrack(false);
3600 CanvasView::set_sensitive_timebar(bool sensitive)
3602 timebar->set_sensitive(sensitive);
3603 //current_time_widget->set_sensitive(sensitive); //not needed now that belongs to timebar
3604 //keyframe_tab_child->set_sensitive(sensitive);
3606 layer_tree->set_sensitive(sensitive);
3608 children_tree->set_sensitive(sensitive);
3612 set_waypoint_model(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3613 Waypoint::Model model,
3614 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3616 // Create the action group
3617 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Change Waypoint Group"));
3619 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3620 for(iter=waypoints.begin();iter!=waypoints.end();++iter)
3622 Waypoint waypoint(*iter);
3623 waypoint.apply_model(model);
3625 synfigapp::Action::Handle action(synfigapp::Action::create("WaypointSet"));
3629 action->set_param("canvas",canvas_interface->get_canvas());
3630 action->set_param("canvas_interface",canvas_interface);
3632 action->set_param("waypoint",waypoint);
3633 action->set_param("value_node",waypoint.get_parent_value_node());
3635 if(!canvas_interface->get_instance()->perform_action(action))
3644 duplicate_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3645 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3647 // Create the action group
3648 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Duplicate Waypoints"));
3650 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3651 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3653 Waypoint waypoint(*iter);
3654 ValueNode::Handle value_node(iter->get_parent_value_node());
3655 canvas_interface->waypoint_duplicate(value_node, waypoint);
3660 remove_waypoints(std::set<synfig::Waypoint, std::less<UniqueID> > waypoints,
3661 etl::loose_handle<synfigapp::CanvasInterface> canvas_interface)
3663 // Create the action group
3664 synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Remove Waypoints"));
3666 std::set<synfig::Waypoint, std::less<UniqueID> >::const_iterator iter;
3667 for (iter = waypoints.begin(); iter != waypoints.end(); iter++)
3669 Waypoint waypoint(*iter);
3670 ValueNode::Handle value_node(iter->get_parent_value_node());
3671 canvas_interface->waypoint_remove(value_node, waypoint);
3676 CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc,
3677 std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set,
3680 int size = waypoint_set.size();
3681 Waypoint waypoint(*(waypoint_set.begin()));
3682 Time time(waypoint.get_time());
3686 waypoint_dialog.set_value_desc(value_desc);
3687 waypoint_dialog.set_waypoint(waypoint);
3694 waypoint_dialog.show();
3698 Gtk::Menu* waypoint_menu(manage(new Gtk::Menu()));
3699 waypoint_menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), waypoint_menu));
3701 Gtk::Menu* interp_menu_in(manage(new Gtk::Menu()));
3702 Gtk::Menu* interp_menu_out(manage(new Gtk::Menu()));
3703 Gtk::Menu* interp_menu_both(manage(new Gtk::Menu()));
3706 Waypoint::Model model;
3708 model.reset(); model.set_before(INTERPOLATION_TCB);
3709 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3710 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3711 model.reset(); model.set_after(INTERPOLATION_TCB);
3712 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3713 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3714 model.set_before(INTERPOLATION_TCB);
3715 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_TCB"),
3716 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3718 model.reset(); model.set_before(INTERPOLATION_LINEAR);
3719 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3720 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3721 model.reset(); model.set_after(INTERPOLATION_LINEAR);
3722 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3723 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3724 model.set_before(INTERPOLATION_LINEAR);
3725 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Linear"),
3726 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3728 model.reset(); model.set_before(INTERPOLATION_HALT);
3729 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In"),
3730 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3731 model.reset(); model.set_after(INTERPOLATION_HALT);
3732 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease Out"),
3733 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3734 model.set_before(INTERPOLATION_HALT);
3735 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Ease In/Out"),
3736 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3738 model.reset(); model.set_before(INTERPOLATION_CONSTANT);
3739 interp_menu_in->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3740 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3741 model.reset(); model.set_after(INTERPOLATION_CONSTANT);
3742 interp_menu_out->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3743 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3744 model.set_before(INTERPOLATION_CONSTANT);
3745 interp_menu_both->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Constant"),
3746 sigc::bind(sigc::ptr_fun(set_waypoint_model), waypoint_set, model, canvas_interface())));
3749 // ------------------------------------------------------------------------
3752 const synfigapp::ValueDesc value_desc(synfig::ValueNode_Animated::Handle::cast_reinterpret(waypoint.get_parent_value_node()), time);
3753 get_instance()->make_param_menu(waypoint_menu,canvas_interface()->get_canvas(),value_desc,0.5f);
3755 // ------------------------------------------------------------------------
3756 waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
3759 // ------------------------------------------------------------------------
3760 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"),
3761 sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time)));
3763 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Duplicate"),
3764 sigc::bind(sigc::ptr_fun(duplicate_waypoints), waypoint_set, canvas_interface())));
3766 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem((size == 1) ? _("_Remove") : strprintf(_("_Remove %d Waypoints"), size),
3767 sigc::bind(sigc::ptr_fun(remove_waypoints), waypoint_set, canvas_interface())));
3769 if (size == 1 && value_desc.is_valid())
3770 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Edit"),
3771 sigc::mem_fun(waypoint_dialog,&Gtk::Widget::show)));
3773 // ------------------------------------------------------------------------
3774 waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
3776 // ------------------------------------------------------------------------
3777 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Both"), *interp_menu_both));
3778 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_In"), *interp_menu_in));
3779 waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Out"), *interp_menu_out));
3781 // ------------------------------------------------------------------------
3782 waypoint_menu->popup(button+1,gtk_get_current_event_time());
3792 CanvasView::on_waypoint_changed()
3794 synfigapp::Action::ParamList param_list;
3795 param_list.add("canvas",get_canvas());
3796 param_list.add("canvas_interface",canvas_interface());
3797 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3798 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3799 // param_list.add("time",canvas_interface()->get_time());
3801 get_instance()->process_action("WaypointSetSmart", param_list);
3805 CanvasView::on_waypoint_delete()
3807 synfigapp::Action::ParamList param_list;
3808 param_list.add("canvas",get_canvas());
3809 param_list.add("canvas_interface",canvas_interface());
3810 param_list.add("value_node",waypoint_dialog.get_value_desc().get_value_node());
3811 param_list.add("waypoint",waypoint_dialog.get_waypoint());
3812 // param_list.add("time",canvas_interface()->get_time());
3814 get_instance()->process_action("WaypointRemove", param_list);
3818 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)
3820 // We will make this true once we have a solid drop
3821 bool success(false);
3822 //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
3823 //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
3824 //synfig::info("selection=\"%s\"",gdk_atom_name(selection_data->selection));
3826 if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
3828 if(synfig::String(selection_data_.get_data_type())=="STRING")do
3830 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3832 Layer::Handle layer(synfig::Layer::create("Text"));
3835 if(!layer->set_param("text",ValueBase(selection_data)))
3838 synfigapp::Action::Handle action(synfigapp::Action::create("LayerAdd"));
3844 action->set_param("canvas",get_canvas());
3845 action->set_param("canvas_interface",canvas_interface());
3846 action->set_param("new",layer);
3848 if(!get_instance()->perform_action(action))
3851 // Ok, we have successfully imported at least one item.
3853 } while(0); // END of "STRING"
3855 if(synfig::String(selection_data_.get_data_type())=="text/plain")
3857 synfig::String selection_data((gchar *)(selection_data_.get_data()));
3859 // For some reason, GTK hands us a list of URLs separated
3860 // by not only Carriage-Returns, but also Line-Feeds.
3861 // Line-Feeds will mess us up. Remove all the line-feeds.
3862 while(selection_data.find_first_of('\r')!=synfig::String::npos)
3863 selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
3865 std::stringstream stream(selection_data);
3867 //synfigapp::PassiveGrouper group(canvas_interface()->get_instance(),_("Insert Image"));
3870 synfig::String filename,URI;
3871 getline(stream,filename);
3873 // If we don't have a filename, move on.
3874 if(filename.empty())
3877 // Make sure this URL is of the "file://" type.
3878 URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
3881 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
3885 // Strip the "file://" part from the filename
3886 filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
3888 String ext(filename_extension(filename));
3889 if (ext.size()) ext = ext.substr(1); // skip initial '.'
3891 // If this is a SIF file, then we need to do things slightly differently
3894 if(work_area->load_sketch(filename))
3897 work_area->queue_draw();
3902 String errors, warnings;
3903 if(canvas_interface()->import(filename, errors, warnings, App::resize_imported_images))
3906 App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
3911 } // END of "text/plain"
3914 ui_interface_->error("Drop failed: bad selection data");
3917 context->drag_finish(success, false, time);
3921 CanvasView::on_keyframe_add_pressed()
3923 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeAdd"));
3927 ui_interface_->error("I am unable to find the appropriate action");
3931 action->set_param("canvas",get_canvas());
3932 action->set_param("canvas_interface",canvas_interface());
3933 action->set_param("keyframe",Keyframe(get_time()));
3935 canvas_interface()->get_instance()->perform_action(action);
3939 CanvasView::on_keyframe_duplicate_pressed()
3941 const KeyframeTreeStore::Model model;
3942 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3946 ui_interface_->error("I am unable to duplicate the keyframe");
3949 keyframe=row[model.keyframe];
3951 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeDuplicate"));
3955 ui_interface_->error("I am unable to find the appropriate action");
3959 action->set_param("canvas",get_canvas());
3960 action->set_param("canvas_interface",canvas_interface());
3961 action->set_param("keyframe",keyframe);
3962 action->set_param("time",get_time());
3964 canvas_interface()->get_instance()->perform_action(action);
3968 CanvasView::on_keyframe_remove_pressed()
3970 const KeyframeTreeStore::Model model;
3971 const Gtk::TreeRow row(*keyframe_tree->get_selection()->get_selected());
3975 ui_interface_->error("I am unable to remove the keyframe");
3978 keyframe=row[model.keyframe];
3980 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeRemove"));
3984 ui_interface_->error("I am unable to find the appropriate action");
3988 action->set_param("canvas",get_canvas());
3989 action->set_param("canvas_interface",canvas_interface());
3990 action->set_param("keyframe",keyframe);
3992 canvas_interface()->get_instance()->perform_action(action);
3996 CanvasView::toggle_duck_mask(Duckmatic::Type type)
4000 toggling_ducks_=true;
4001 bool is_currently_on(work_area->get_type_mask()&type);
4004 work_area->set_type_mask(work_area->get_type_mask()-type);
4006 work_area->set_type_mask(work_area->get_type_mask()|type);
4008 work_area->queue_draw();
4011 // Update the toggle ducks actions
4012 Glib::RefPtr<Gtk::ToggleAction> action;
4013 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-position-ducks"));
4014 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_POSITION));
4015 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-tangent-ducks"));
4016 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_TANGENT));
4017 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-vertex-ducks"));
4018 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_VERTEX));
4019 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-radius-ducks"));
4020 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_RADIUS));
4021 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-width-ducks"));
4022 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_WIDTH));
4023 action = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(action_group->get_action("mask-angle-ducks"));
4024 action->set_active((bool)(work_area->get_type_mask()&Duck::TYPE_ANGLE));
4025 // Update toggle ducks buttons
4026 toggleducksdial->update_toggles(work_area->get_type_mask());
4030 toggling_ducks_=false;
4032 toggling_ducks_=false;
4036 CanvasView::image_import()
4038 // String filename(dirname(get_canvas()->get_file_name()));
4039 String filename("*.*");
4040 String errors, warnings;
4041 if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
4043 canvas_interface()->import(filename, errors, warnings, App::resize_imported_images);
4045 App::dialog_warning_blocking(_("Warnings"), strprintf("%s:\n\n%s", _("Warnings"), warnings.c_str()));
4050 CanvasView::process_event_key(EventKey x)
4052 return smach_.process_event(x);
4056 CanvasView::on_input_device_changed(GdkDevice* device)
4060 get_smach().egress();
4064 synfigapp::InputDevice::Handle input_device;
4065 input_device=synfigapp::Main::select_input_device(device->name);
4066 App::toolbox->change_state(input_device->get_state());
4067 process_event_key(EVENT_INPUT_DEVICE_CHANGED);
4071 CanvasView::on_preview_option()
4073 Dialog_PreviewOptions *po = dynamic_cast<Dialog_PreviewOptions *>(get_ext_widget("prevoptions"));
4075 Canvas::Handle canv = get_canvas();
4079 RendDesc &r = canv->rend_desc();
4080 if(r.get_frame_rate())
4082 float rate = 1/r.get_frame_rate();
4083 float beg = r.get_time_start() + r.get_frame_start()*rate;
4084 float end = r.get_time_start() + r.get_frame_end()*rate;
4088 po = new Dialog_PreviewOptions;
4089 po->set_zoom(work_area->get_zoom()/2);
4090 po->set_fps(r.get_frame_rate()/2);
4091 po->set_begintime(beg);
4092 po->set_begin_override(false);
4093 po->set_endtime(end);
4094 po->set_end_override(false);
4096 set_ext_widget("prevoptions",po);
4098 /*po->set_zoom(work_area->get_zoom()/2);
4099 po->set_fps(r.get_frame_rate()/2);
4100 po->set_begintime(beg);
4101 po->set_begin_override(false);
4102 po->set_endtime(end);
4103 po->set_end_override(false);*/
4105 po->set_global_fps(r.get_frame_rate());
4106 po->signal_finish().connect(sigc::mem_fun(*this,&CanvasView::on_preview_create));
4113 CanvasView::on_preview_create(const PreviewInfo &info)
4115 //set all the options
4116 etl::handle<Preview> prev = new Preview;
4118 prev->set_canvasview(this);
4119 prev->set_zoom(info.zoom);
4120 prev->set_fps(info.fps);
4121 prev->set_overbegin(info.overbegin);
4122 prev->set_begintime(info.begintime);
4123 prev->set_overend(info.overend);
4124 prev->set_endtime(info.endtime);
4125 prev->set_quality(work_area->get_quality());
4130 Dialog_Preview *pd = preview_dialog.get();
4133 pd->set_default_size(700,510);
4134 pd->set_preview(prev.get());
4139 CanvasView::on_audio_option()
4141 synfig::warning("Launching Audio Options");
4142 sound_dialog->set_global_fps(get_canvas()->rend_desc().get_frame_rate());
4143 sound_dialog->present();
4147 CanvasView::on_audio_file_change(const std::string &f)
4149 //save in meta data - always even when not valid...
4150 canvas_interface()->set_meta_data("audiofile",f);
4154 CanvasView::on_audio_offset_change(const synfig::Time &t)
4156 canvas_interface()->set_meta_data("audiooffset",t.get_string());
4160 CanvasView::on_audio_file_notify()
4162 std::string file(get_canvas()->get_meta_data("audiofile"));
4163 if(!file.c_str()) return;
4165 if(!audio->load(file,dirname(get_canvas()->get_file_name())+string("/")))
4167 if(file != "") synfig::warning("Could not load the file: %s", file.c_str());
4168 get_canvas()->erase_meta_data("audiofile");
4170 disp_audio->set_profile(etl::handle<AudioProfile>());
4173 //save in canvasview
4174 synfig::warning("Getting the profile of the music stuff");
4176 //profile specific stuff for the preview widget
4177 //similar for other attachments
4178 Dialog_Preview *pd = preview_dialog.get();
4179 pd->get_widget().set_audio(audio);
4181 handle<AudioProfile> prof = audio->get_profile();
4185 synfig::warning("Agh, I couldn't build the profile captain!");
4187 pd->get_widget().set_audioprofile(prof);
4189 disp_audio->set_profile(audio->get_profile());
4192 synfig::warning("successfully set the profiles and stuff");
4194 disp_audio->queue_draw();
4198 CanvasView::on_audio_offset_notify()
4200 Time t(get_canvas()->get_meta_data("audiooffset"),get_canvas()->rend_desc().get_frame_rate());
4201 audio->set_offset(t);
4202 sound_dialog->set_offset(t);
4203 disp_audio->queue_draw();
4205 // synfig::info("CanvasView::on_audio_offset_notify(): offset time set to %s",t.get_string(get_canvas()->rend_desc().get_frame_rate()).c_str());
4209 CanvasView::play_audio(float t)
4213 synfig::info("Playing audio at %f s",t);
4219 CanvasView::stop_audio()
4228 CanvasView::on_audio_scrub()
4234 Glib::RefPtr<Glib::ObjectBase>
4235 CanvasView::get_ref_obj(const synfig::String& x)
4237 return ref_obj_book_[x];
4240 Glib::RefPtr<const Glib::ObjectBase>
4241 CanvasView::get_ref_obj(const synfig::String& x)const
4243 return ref_obj_book_.find(x)->second;
4247 CanvasView::set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y)
4252 Glib::RefPtr<Gtk::TreeModel>
4253 CanvasView::get_tree_model(const synfig::String& x)
4255 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_["_tree_model_"+x]);
4258 Glib::RefPtr<const Gtk::TreeModel>
4259 CanvasView::get_tree_model(const synfig::String& x)const
4261 return Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(ref_obj_book_.find("_tree_model_"+x)->second);
4265 CanvasView::set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y)
4267 ref_obj_book_["_tree_model_"+x]=Glib::RefPtr<Glib::ObjectBase>::cast_static(y);
4271 CanvasView::get_ext_widget(const synfig::String& x)
4273 return ext_widget_book_[x];
4277 CanvasView::set_ext_widget(const synfig::String& x, Gtk::Widget* y)
4279 ext_widget_book_[x]=y;
4282 layer_tree=dynamic_cast<LayerTree*>(y);
4284 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_LAYER_SELECTION_CHANGED));
4285 layer_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
4286 layer_tree->signal_layer_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_layer_user_click));
4287 layer_tree->signal_param_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
4288 layer_tree->signal_waypoint_clicked_layertree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
4292 children_tree=dynamic_cast<ChildrenTree*>(y);
4293 if(children_tree)children_tree->signal_user_click().connect(sigc::mem_fun(*this, &studio::CanvasView::on_children_user_click));
4294 if(children_tree)children_tree->signal_waypoint_clicked_childrentree().connect(sigc::mem_fun(*this, &studio::CanvasView::on_waypoint_clicked_canvasview));
4295 if(children_tree)children_tree->get_selection()->signal_changed().connect(SLOT_EVENT(EVENT_REFRESH_DUCKS));
4298 keyframe_tree=dynamic_cast<KeyframeTree*>(y);
4302 CanvasView::on_delete_event(GdkEventAny* event __attribute__ ((unused)))
4306 //! \todo This causes the window to be deleted straight away - but what if we prompt 'save?' and the user cancels?
4307 // Is there ever any need to pass on the delete event to the window here?
4308 // if(event) return Gtk::Window::on_delete_event(event);
4313 //! Modify the play stop button apearence and play stop the animation
4315 CanvasView::on_play_stop_pressed()
4318 Gtk::Button *stop_button;
4319 stop_button=framedial->get_play_button();
4323 icon = manage(new Gtk::Image(Gtk::Stock::MEDIA_STOP, Gtk::IconSize::from_name("synfig-small_icon")));
4324 stop_button->set_relief(Gtk::RELIEF_NORMAL);
4329 icon = manage(new Gtk::Image(Gtk::Stock::MEDIA_PLAY, Gtk::IconSize::from_name("synfig-small_icon")));
4330 stop_button->set_relief(Gtk::RELIEF_NONE);
4333 stop_button->remove();
4334 stop_button->add(*icon);
4335 icon->set_padding(0, 0);
4337 if(play_flag) play(); else stop();