1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
27 #define __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
29 /* === H E A D E R S ======================================================= */
31 #include <gtkmm/window.h>
32 #include <gtkmm/image.h>
33 #include <gtkmm/tooltips.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/statusbar.h>
36 #include <gtkmm/progressbar.h>
37 #include <gtkmm/button.h>
38 #include <gtkmm/menu.h>
39 #include <gtkmm/treeview.h>
40 #include <gtkmm/treestore.h>
41 #include <gtkmm/scrolledwindow.h>
42 #include <gtkmm/notebook.h>
43 #include <gdkmm/device.h>
45 #include <synfigapp/canvasinterface.h>
46 #include <synfigapp/selectionmanager.h>
48 #include <synfig/canvas.h>
49 #include <synfig/string.h>
50 #include <synfig/time.h>
53 #include "canvasproperties.h"
54 #include "canvasoptions.h"
56 #include "cellrenderer_timetrack.h"
59 #include "layertreestore.h"
60 #include "layertree.h"
61 #include "childrentreestore.h"
62 #include "childrentree.h"
63 #include "keyframetreestore.h"
64 #include "keyframetree.h"
66 #include "dialog_waypoint.h"
67 #include "dialog_keyframe.h"
68 #include "framedial.h"
69 #include "toggleducksdial.h"
70 #include "resolutiondial.h"
72 #include "duckmatic.h"
73 #include <gtkmm/scale.h>
75 #include <gtkmm/uimanager.h>
82 #include <gtkmm/toggleaction.h>
83 #include <gtkmm/radioaction.h>
84 #include <synfig/rect.h>
86 #include "adjust_window.h"
88 #include <synfig/transform.h>
90 /* === M A C R O S ========================================================= */
92 #ifndef DEBUGPOINT_CLASS
94 #define DEBUGPOINT_CLASS(x) struct debugpointclass_ ## x { debugpointclass_ ## x () { DEBUGPOINT(); } ~debugpointclass_ ## x () { DEBUGPOINT(); } } badfthguae_ ## x ;
96 #define DEBUGPOINT_CLASS(x)
100 /* === T Y P E D E F S ===================================================== */
102 /* === C L A S S E S & S T R U C T S ======================================= */
105 class TransformStack;
110 class CanvasViewUIInterface;
111 class CanvasViewSelectionManager;
113 class CellRenderer_TimeTrack;
114 class CellRenderer_ValueBase;
115 class UniversalScrubber;
122 class AudioContainer;
125 class Widget_Timeslider;
128 class Dialog_SoundSelect;
129 class Dialog_Preview;
133 class Dock_Keyframes;
135 class CanvasView : public Gtk::Window, public etl::shared_object
137 friend class UniversalScrubber;
138 friend class Dock_Layers;
139 friend class Dock_Children;
140 friend class Dock_Keyframes;
142 friend class CanvasViewUIInterface;
143 friend class CanvasViewSelectionManager;
145 friend class Duckmatic;
148 -- ** -- P U B L I C T Y P E S ---------------------------------------------
153 typedef etl::handle<CanvasView> Handle;
155 typedef etl::handle<const CanvasView> ConstHandle;
157 typedef etl::loose_handle<CanvasView> LooseHandle;
159 typedef LayerTreeStore::Model LayerTreeModel;
161 typedef ChildrenTreeStore::Model ChildrenTreeModel;
163 //! Create an instance of this class whenever doing a longer task.
164 /*! Make sure that you check the bool value of this class occasionally
165 ** to make sure the action has not been canceled. */
168 CanvasView &canvas_view_;
171 IsWorking(CanvasView &canvas_view_);
173 operator bool()const;
175 friend class IsWorking;
177 typedef synfigapp::CanvasInterface::Mode Mode;
179 void set_grid_snap_toggle(bool flag) { grid_snap_toggle->set_active(flag); }
180 void set_grid_show_toggle(bool flag) { grid_show_toggle->set_active(flag); }
183 -- ** -- P R I V A T E D A T A ---------------------------------------------
187 std::auto_ptr<WorkArea> work_area;
189 WorkArea* get_work_area() { return work_area.get(); }
192 synfig::TransformStack curr_transform_stack;
193 bool curr_transform_stack_set;
197 // DEBUGPOINT_CLASS(1);
202 // DEBUGPOINT_CLASS(2);
204 etl::loose_handle<Instance> instance_;
205 etl::handle<synfigapp::CanvasInterface> canvas_interface_;
207 // DEBUGPOINT_CLASS(3);
209 //! Sound and information to play it
210 etl::handle<AudioContainer> audio;
211 studio::Widget_Sound *disp_audio; //should this be put into thing too?
213 sigc::connection playcon;
214 sigc::connection stopcon;
216 std::auto_ptr<UniversalScrubber> universal_scrubber;
218 //! Tooltip controller
219 Gtk::Tooltips tooltips;
221 // DEBUGPOINT_CLASS(4);
223 //! TreeModel for the layers
224 LayerTreeModel layer_tree_model;
226 //! TreeModel for the the children
227 ChildrenTreeModel children_tree_model;
229 //Glib::RefPtr<LayerTreeStore> layer_tree_store_;
231 //Glib::RefPtr<ChildrenTreeStore> children_tree_store_;
233 //Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store_;
235 // DEBUGPOINT_CLASS(5);
237 //std::map<synfig::String,Glib::RefPtr<Gtk::TreeModel> > tree_model_book_;
238 std::map<synfig::String,Glib::RefPtr<Glib::ObjectBase> > ref_obj_book_;
239 std::map<synfig::String,Gtk::Widget*> ext_widget_book_;
241 //! The time adjustment's scope is defined by the time_window adjustment
242 Gtk::Adjustment time_adjustment_;
244 //! The time_window adjustment governs the position of the time window on the whole time line
245 //Gtk::Adjustment time_window_adjustment_;
246 studio::Adjust_Window time_window_adjustment_;
248 LayerTree *layer_tree;
250 ChildrenTree *children_tree;
252 KeyframeTree *keyframe_tree;
254 Gtk::Widget *keyframe_tab_child;
256 Gtk::ProgressBar *progressbar;
257 Gtk::Statusbar *statusbar;
259 Gtk::TreeRow children_canvas_row;
260 Gtk::TreeRow children_valuenode_row;
262 Gtk::Button *stopbutton;
263 Gtk::Button *refreshbutton;
264 Gtk::Button *treetogglebutton; // not used
265 Gtk::Notebook *notebook; // not used
267 Gtk::Table *displaybar;
268 Gtk::Button *animatebutton;
269 Gtk::Button *keyframebutton;
270 FrameDial *framedial;
271 ToggleDucksDial *toggleducksdial;
272 bool toggling_ducks_;
273 ResolutionDial *resolutiondial;
274 bool changing_resolution_;
277 //! Shows current time and allows edition
278 Widget_Time *current_time_widget;
279 void on_current_time_widget_changed();
281 //! Time slider class. Same than the Time track panel
282 std::auto_ptr<Widget_Timeslider> timeslider;
284 std::list<sigc::connection> duck_changed_connections;
286 /* DEBUGPOINT_CLASS(8);
288 Gtk::Menu duckmaskmenu;
289 DEBUGPOINT_CLASS(77);
290 Gtk::Menu qualitymenu;
294 DEBUGPOINT_CLASS(777);
296 DEBUGPOINT_CLASS(71);
297 Gtk::Menu canvasmenu;
298 DEBUGPOINT_CLASS(73);
302 DEBUGPOINT_CLASS(74);
303 Gtk::Menu newlayermenu;
304 DEBUGPOINT_CLASS(76);
307 DEBUGPOINT_CLASS(99);
308 Gtk::Menu keyframemenu;
315 Gtk::CheckMenuItem* duck_mask_position;
316 Gtk::CheckMenuItem* duck_mask_vertex;
317 Gtk::CheckMenuItem* duck_mask_tangent;
318 Gtk::CheckMenuItem* duck_mask_radius;
319 Gtk::CheckMenuItem* duck_mask_width;
320 Gtk::CheckMenuItem* duck_mask_angle;
325 Glib::RefPtr<Gtk::ToggleAction> grid_snap_toggle;
326 Glib::RefPtr<Gtk::ToggleAction> grid_show_toggle;
328 Gtk::RadioButtonGroup quality_group;
329 Gtk::RadioButtonGroup low_res_pixel_size_group;
331 Glib::RefPtr<Gtk::ActionGroup> action_group;
333 etl::handle<synfigapp::UIInterface> ui_interface_;
334 etl::handle<synfigapp::SelectionManager> selection_manager_;
338 sigc::signal<void> signal_deleted_;
340 bool rebuild_ducks_queued;
341 sigc::connection queue_rebuild_ducks_connection;
344 -- ** -- P U B L I C D A T A -----------------------------------------------
348 void queue_rebuild_ducks();
349 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
353 bool duck_refresh_flag;
354 bool duck_refresh_needed;
356 //! This is for the IsWorking class.
362 -- ** -- D I A L O G S -------------------------------------------------------
367 CanvasProperties canvas_properties;
368 CanvasOptions canvas_options;
369 RenderSettings render_settings;
370 Dialog_Waypoint waypoint_dialog;
371 Dialog_Keyframe keyframe_dialog;
373 std::auto_ptr<Dialog_Preview> preview_dialog;
374 //std::auto_ptr<Dialog_PreviewOptions> previewoption_dialog;
375 std::auto_ptr<Dialog_SoundSelect> sound_dialog;
378 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
383 // Constructor is private to force the use of the "create()" constructor
384 CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface);
386 //! Constructor Helper
387 // Gtk::Widget* create_layer_tree();
389 //! Constructor Helper
390 // Gtk::Widget* create_children_tree();
392 //! Constructor Helper
393 // Gtk::Widget* create_keyframe_tree();
395 //! Constructor Helper
396 Gtk::Widget* create_status_bar();
398 //! Constructor Helper - Initializes all of the menus
401 bool duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name);
403 void refresh_time_window();
405 void time_was_changed();
407 void refresh_rend_desc();
409 void toggle_duck_mask(Duckmatic::Type type);
411 Gtk::Widget *create_work_area();
413 Gtk::Widget *create_time_bar();
415 Gtk::Widget *create_display_bar();
417 //! Pop up menu for the bezier (bline, draw) tool (?)
418 void popup_param_menu_bezier(float location, synfigapp::ValueDesc value_desc)
419 { popup_param_menu(value_desc,location,true); }
421 //! Pop up menu for the tools but not the bezier ones.
422 void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0, bool bezier=false);
424 void workarea_layer_selected(synfig::Layer::Handle layer);
426 void selected_layer_color_set(synfig::Color color);
428 void register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>*);
430 //! Rebuilds the "new layer" menu
431 void build_new_layer_menu(Gtk::Menu &menu);
433 void rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list);
435 void decrease_low_res_pixel_size();
436 void increase_low_res_pixel_size();
437 void toggle_low_res_pixel_flag();
440 -- ** -- P U B L I C M E T H O D S -----------------------------------------
444 const synfig::TransformStack& get_curr_transform_stack()const { return curr_transform_stack; }
446 const synfig::Rect& get_bbox()const { return bbox; }
448 Glib::RefPtr<Glib::ObjectBase> get_ref_obj(const synfig::String& x);
449 Glib::RefPtr<const Glib::ObjectBase> get_ref_obj(const synfig::String& x)const;
450 void set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y);
452 Glib::RefPtr<Gtk::TreeModel> get_tree_model(const synfig::String& x);
453 Glib::RefPtr<const Gtk::TreeModel> get_tree_model(const synfig::String& x)const;
454 void set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y);
456 Gtk::Widget* get_ext_widget(const synfig::String& x);
457 void set_ext_widget(const synfig::String& x, Gtk::Widget* y);
459 //std::map<synfig::String,Gtk::Widget*>& tree_view_book() { return tree_view_book_; }
460 //std::map<synfig::String,Gtk::Widget*>& ext_widget_book() { return tree_view_book_; }
462 void popup_main_menu();
464 Smach& get_smach() { return smach_; }
466 const Smach& get_smach()const { return smach_; }
468 Smach::event_result process_event_key(EventKey x);
470 void popup_layer_menu(synfig::Layer::Handle layer);
472 virtual ~CanvasView();
474 void set_mode(Mode x) { canvas_interface()->set_mode(x); }
476 Mode get_mode()const { return canvas_interface()->get_mode(); }
478 Gtk::Adjustment &time_adjustment() { return time_adjustment_; }
480 const Gtk::Adjustment &time_adjustment()const { return time_adjustment_; }
482 studio::Adjust_Window &time_window_adjustment() { return time_window_adjustment_; }
484 const studio::Adjust_Window &time_window_adjustment()const { return time_window_adjustment_; }
486 etl::handle<synfigapp::UIInterface> get_ui_interface() { return ui_interface_;}
488 etl::handle<synfigapp::SelectionManager> get_selection_manager() { return selection_manager_; }
490 Glib::RefPtr<Gtk::TreeModel> layer_tree_store() { return get_tree_model("layers"); }
492 Glib::RefPtr<const Gtk::TreeModel> layer_tree_store()const { return get_tree_model("layers"); }
494 Glib::RefPtr<Gtk::TreeModel> children_tree_store() { return get_tree_model("children"); }
496 Glib::RefPtr<const Gtk::TreeModel> children_tree_store()const { return get_tree_model("children"); }
498 Glib::RefPtr<Gtk::TreeModel> keyframe_tree_store() { return get_tree_model("keyframes"); }
500 Glib::RefPtr<const Gtk::TreeModel> keyframe_tree_store()const { return get_tree_model("keyframes"); }
502 void set_time(synfig::Time t) { canvas_interface_->set_time(t); }
504 synfig::Time get_time() { return canvas_interface_->get_time(); }
506 etl::handle<synfig::Canvas> get_canvas()const { return canvas_interface_->get_canvas(); }
508 etl::handle<Instance> get_instance()const { return instance_; }
510 etl::handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
512 etl::handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
514 void add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
516 //! Updates the title of the window
519 //! Closes this document
520 bool close_instance();
522 //! Closes this canvas view
525 //! Stops the currently executing action
526 /*! \see get_cancel_status(), reset_cancel_status(), IsWorking */
527 void stop() { cancel=true; }
529 //! Returns the cancel status
530 /*! \see stop(), reset_cancel_status(), IsWorking */
531 bool get_cancel_status()const { return cancel; }
533 //! Resets the cancel status
534 /*! \see stop(), get_cancel_status(), IsWorking */
535 void reset_cancel_status() { cancel=false; }
537 void new_child_canvas();
539 //! Rebuilds layer_tree_store_ from the Canvas. Maintains selected items.
540 void rebuild_tables();
542 //! Builds layer_tree_store_ from the Canvas. Does not maintain selected items.
545 //! Refreshes the data for the tables
546 void refresh_tables();
548 //void rebuild_layer_table();
549 //void build_layer_table();
550 //void refresh_layer_table();
552 // void rebuild_canvas_table();
553 // void build_canvas_table();
554 // void refresh_canvas_table();
556 // void rebuild_valuenode_table();
557 // void build_valuenode_table();
558 // void refresh_valuenode_table();
561 void rebuild_ducks();
563 //bool add_to_ducks(synfigapp::ValueDesc value_desc, synfig::ParamDesc *param_desc=NULL);
565 //! Starts "playing" the animation in real-time
568 //! Shows the tables (Layer/Children)
571 //! Hides the tables (Layer/Children)
574 //! Toggles the tables
575 void toggle_tables();
577 //! Gets the table status
578 bool tables_are_visible();
580 //! Shows the time bar
583 //! Hides the time bar
586 //t Enables or disables interaction with the timebar
587 void set_sensitive_timebar(bool sensitive);
590 void time_zoom_out();
592 void add_layer(synfig::String x);
594 void show_keyframe_dialog();
596 void play_audio(float t);
601 void on_waypoint_clicked_canvasview(synfigapp::ValueDesc,std::set<synfig::Waypoint,std::less<synfig::UniqueID> >, int button);
603 void preview_option() {on_preview_option();}
607 bool is_playing() { return is_playing_; }
610 -- ** -- S I G N A L T E R M I N A L S -------------------------------------
615 void on_select_layers();
616 void on_unselect_layers();
618 void on_input_device_changed(GdkDevice*);
620 virtual void on_hide();
622 virtual bool on_focus_in_event(GdkEventFocus*);
623 virtual bool on_focus_out_event(GdkEventFocus*);
625 //bool on_children_tree_event(GdkEvent *event);
627 bool on_keyframe_tree_event(GdkEvent *event);
629 //void on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value);
631 void on_dirty_preview();
633 bool on_children_user_click(int, Gtk::TreeRow, ChildrenTree::ColumnID);
635 bool on_layer_user_click(int, Gtk::TreeRow, LayerTree::ColumnID);
637 // void on_layer_toggle(const Glib::ustring& path_string, Gtk::TreeModelColumn<bool> column);
639 void on_mode_changed(synfigapp::CanvasInterface::Mode mode);
641 // void on_layer_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
643 //void on_children_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
645 void on_waypoint_changed();
647 void on_waypoint_delete();
649 void on_refresh_pressed();
651 void on_id_changed();
653 void on_time_changed();
656 void on_layer_raise_pressed();
657 void on_layer_lower_pressed();
658 void on_layer_duplicate_pressed();
659 void on_layer_delete_pressed();
662 void on_keyframe_add_pressed();
664 void on_keyframe_duplicate_pressed();
666 void on_keyframe_remove_pressed();
668 void on_animate_button_pressed();
670 void on_keyframe_button_pressed();
672 void on_preview_option();
673 void on_preview_create(const PreviewInfo &);
675 void on_audio_option();
676 void on_audio_file_change(const std::string &f);
677 void on_audio_offset_change(const synfig::Time &t);
679 void on_audio_file_notify();
680 void on_audio_offset_notify();
682 bool on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc);
683 bool on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc);
685 void on_layer_toggle(synfig::Layer::Handle);
687 void on_edited_value(synfigapp::ValueDesc,synfig::ValueBase);
689 void on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time);
691 //void on_audio_play();
692 bool on_audio_scrub();
694 void on_play_stop_pressed();
697 bool close_instance_when_safe();
698 bool on_delete_event(GdkEventAny* event);
701 -- ** -- S T A T I C P U B L I C M E T H O D S ---------------------------
706 static etl::handle<studio::CanvasView> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
707 static std::list<int>& get_pixel_sizes();
709 }; // END of class CanvasView
711 }; // END of namespace studio
713 /* === E N D =============================================================== */