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
10 ** Copyright (c) 2009 Carlos López
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
28 #define __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
30 /* === H E A D E R S ======================================================= */
32 #include <gtkmm/window.h>
33 #include <gtkmm/image.h>
34 #include <gtkmm/tooltips.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/statusbar.h>
37 #include <gtkmm/progressbar.h>
38 #include <gtkmm/button.h>
39 #include <gtkmm/menu.h>
40 #include <gtkmm/treeview.h>
41 #include <gtkmm/treestore.h>
42 #include <gtkmm/scrolledwindow.h>
43 #include <gtkmm/notebook.h>
44 #include <gdkmm/device.h>
45 #include <gtkmm/spinbutton.h>
47 #include <synfigapp/canvasinterface.h>
48 #include <synfigapp/selectionmanager.h>
50 #include <synfig/canvas.h>
51 #include <synfig/string.h>
52 #include <synfig/time.h>
55 #include "canvasproperties.h"
56 #include "canvasoptions.h"
58 #include "cellrenderer_timetrack.h"
61 #include "layertreestore.h"
62 #include "layertree.h"
63 #include "childrentreestore.h"
64 #include "childrentree.h"
65 #include "keyframetreestore.h"
66 #include "keyframetree.h"
68 #include "dialog_waypoint.h"
69 #include "dialog_keyframe.h"
70 #include "framedial.h"
71 #include "toggleducksdial.h"
72 #include "resolutiondial.h"
74 #include "duckmatic.h"
75 #include <gtkmm/scale.h>
77 #include <gtkmm/uimanager.h>
84 #include <gtkmm/toggleaction.h>
85 #include <gtkmm/radioaction.h>
86 #include <synfig/rect.h>
88 #include "adjust_window.h"
90 #include <synfig/transform.h>
92 /* === M A C R O S ========================================================= */
94 #ifndef DEBUGPOINT_CLASS
96 #define DEBUGPOINT_CLASS(x) struct debugpointclass_ ## x { debugpointclass_ ## x () { DEBUGPOINT(); } ~debugpointclass_ ## x () { DEBUGPOINT(); } } badfthguae_ ## x ;
98 #define DEBUGPOINT_CLASS(x)
102 /* === T Y P E D E F S ===================================================== */
104 /* === C L A S S E S & S T R U C T S ======================================= */
107 class TransformStack;
112 class CanvasViewUIInterface;
113 class CanvasViewSelectionManager;
115 class CellRenderer_TimeTrack;
116 class CellRenderer_ValueBase;
117 class UniversalScrubber;
124 class AudioContainer;
127 class Widget_Timeslider;
130 class Dialog_SoundSelect;
131 class Dialog_Preview;
135 class Dock_Keyframes;
137 class CanvasView : public Gtk::Window, public etl::shared_object
139 friend class UniversalScrubber;
140 friend class Dock_Layers;
141 friend class Dock_Children;
142 friend class Dock_Keyframes;
144 friend class CanvasViewUIInterface;
145 friend class CanvasViewSelectionManager;
147 friend class Duckmatic;
150 -- ** -- P U B L I C T Y P E S ---------------------------------------------
155 typedef etl::handle<CanvasView> Handle;
157 typedef etl::handle<const CanvasView> ConstHandle;
159 typedef etl::loose_handle<CanvasView> LooseHandle;
161 typedef LayerTreeStore::Model LayerTreeModel;
163 typedef ChildrenTreeStore::Model ChildrenTreeModel;
165 //! Create an instance of this class whenever doing a longer task.
166 /*! Make sure that you check the bool value of this class occasionally
167 ** to make sure the action has not been canceled. */
170 CanvasView &canvas_view_;
173 IsWorking(CanvasView &canvas_view_);
175 operator bool()const;
177 friend class IsWorking;
179 typedef synfigapp::CanvasInterface::Mode Mode;
181 void set_grid_snap_toggle(bool flag) { grid_snap_toggle->set_active(flag); }
182 void set_grid_show_toggle(bool flag) { grid_show_toggle->set_active(flag); }
185 -- ** -- P R I V A T E D A T A ---------------------------------------------
189 std::auto_ptr<WorkArea> work_area;
191 WorkArea* get_work_area() { return work_area.get(); }
194 synfig::TransformStack curr_transform_stack;
195 bool curr_transform_stack_set;
199 // DEBUGPOINT_CLASS(1);
204 // DEBUGPOINT_CLASS(2);
206 etl::loose_handle<Instance> instance_;
207 etl::handle<synfigapp::CanvasInterface> canvas_interface_;
209 // DEBUGPOINT_CLASS(3);
211 //! Sound and information to play it
212 etl::handle<AudioContainer> audio;
213 studio::Widget_Sound *disp_audio; //should this be put into thing too?
215 sigc::connection playcon;
216 sigc::connection stopcon;
218 std::auto_ptr<UniversalScrubber> universal_scrubber;
220 //! Tooltip controller
221 Gtk::Tooltips tooltips;
223 // DEBUGPOINT_CLASS(4);
225 //! TreeModel for the layers
226 LayerTreeModel layer_tree_model;
228 //! TreeModel for the the children
229 ChildrenTreeModel children_tree_model;
231 //Glib::RefPtr<LayerTreeStore> layer_tree_store_;
233 //Glib::RefPtr<ChildrenTreeStore> children_tree_store_;
235 //Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store_;
237 // DEBUGPOINT_CLASS(5);
239 //std::map<synfig::String,Glib::RefPtr<Gtk::TreeModel> > tree_model_book_;
240 std::map<synfig::String,Glib::RefPtr<Glib::ObjectBase> > ref_obj_book_;
241 std::map<synfig::String,Gtk::Widget*> ext_widget_book_;
243 //! The time adjustment's scope is defined by the time_window adjustment
244 Gtk::Adjustment time_adjustment_;
246 //! The time_window adjustment governs the position of the time window on the whole time line
247 //Gtk::Adjustment time_window_adjustment_;
248 studio::Adjust_Window time_window_adjustment_;
250 LayerTree *layer_tree;
252 ChildrenTree *children_tree;
254 KeyframeTree *keyframe_tree;
256 Gtk::Widget *keyframe_tab_child;
258 Gtk::ProgressBar *progressbar;
259 Gtk::Statusbar *statusbar;
261 Gtk::TreeRow children_canvas_row;
262 Gtk::TreeRow children_valuenode_row;
264 Gtk::Button *stopbutton;
265 Gtk::Button *refreshbutton;
266 Gtk::Button *treetogglebutton; // not used
267 Gtk::Notebook *notebook; // not used
269 Gtk::Table *displaybar;
270 Gtk::Button *animatebutton;
271 Gtk::Button *keyframebutton;
272 FrameDial *framedial;
273 ToggleDucksDial *toggleducksdial;
274 bool toggling_ducks_;
275 ResolutionDial *resolutiondial;
276 bool changing_resolution_;
277 Gtk::Adjustment quality_adjustment_;
278 Gtk::SpinButton *quality_spin;
279 bool updating_quality_;
280 Gtk::ToggleButton *show_grid;
281 Gtk::ToggleButton *snap_grid;
282 bool toggling_show_grid;
283 bool toggling_snap_grid;
284 //! Shows current time and allows edition
285 Widget_Time *current_time_widget;
286 void on_current_time_widget_changed();
288 //! Time slider class. Same than the Time track panel
289 std::auto_ptr<Widget_Timeslider> timeslider;
291 std::list<sigc::connection> duck_changed_connections;
293 /* DEBUGPOINT_CLASS(8);
295 Gtk::Menu duckmaskmenu;
296 DEBUGPOINT_CLASS(77);
297 Gtk::Menu qualitymenu;
301 DEBUGPOINT_CLASS(777);
303 DEBUGPOINT_CLASS(71);
304 Gtk::Menu canvasmenu;
305 DEBUGPOINT_CLASS(73);
309 DEBUGPOINT_CLASS(74);
310 Gtk::Menu newlayermenu;
311 DEBUGPOINT_CLASS(76);
314 DEBUGPOINT_CLASS(99);
315 Gtk::Menu keyframemenu;
322 Gtk::CheckMenuItem* duck_mask_position;
323 Gtk::CheckMenuItem* duck_mask_vertex;
324 Gtk::CheckMenuItem* duck_mask_tangent;
325 Gtk::CheckMenuItem* duck_mask_radius;
326 Gtk::CheckMenuItem* duck_mask_width;
327 Gtk::CheckMenuItem* duck_mask_angle;
332 Glib::RefPtr<Gtk::ToggleAction> grid_snap_toggle;
333 Glib::RefPtr<Gtk::ToggleAction> grid_show_toggle;
335 Gtk::RadioButtonGroup quality_group;
336 Gtk::RadioButtonGroup low_res_pixel_size_group;
338 Glib::RefPtr<Gtk::ActionGroup> action_group;
340 etl::handle<synfigapp::UIInterface> ui_interface_;
341 etl::handle<synfigapp::SelectionManager> selection_manager_;
345 sigc::signal<void> signal_deleted_;
347 bool rebuild_ducks_queued;
348 sigc::connection queue_rebuild_ducks_connection;
351 -- ** -- P U B L I C D A T A -----------------------------------------------
355 void queue_rebuild_ducks();
356 sigc::signal<void>& signal_deleted() { return signal_deleted_; }
360 bool duck_refresh_flag;
361 bool duck_refresh_needed;
363 //! This is for the IsWorking class.
369 -- ** -- D I A L O G S -------------------------------------------------------
374 CanvasProperties canvas_properties;
375 CanvasOptions canvas_options;
376 RenderSettings render_settings;
377 Dialog_Waypoint waypoint_dialog;
378 Dialog_Keyframe keyframe_dialog;
380 std::auto_ptr<Dialog_Preview> preview_dialog;
381 //std::auto_ptr<Dialog_PreviewOptions> previewoption_dialog;
382 std::auto_ptr<Dialog_SoundSelect> sound_dialog;
385 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
390 // Constructor is private to force the use of the "create()" constructor
391 CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface);
393 //! Constructor Helper
394 // Gtk::Widget* create_layer_tree();
396 //! Constructor Helper
397 // Gtk::Widget* create_children_tree();
399 //! Constructor Helper
400 // Gtk::Widget* create_keyframe_tree();
402 //! Constructor Helper
403 Gtk::Widget* create_status_bar();
405 //! Constructor Helper - Initializes all of the menus
408 bool duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name);
410 void refresh_time_window();
412 void time_was_changed();
414 void refresh_rend_desc();
416 void toggle_duck_mask(Duckmatic::Type type);
418 Gtk::Widget *create_work_area();
420 Gtk::Widget *create_time_bar();
422 Gtk::Widget *create_display_bar();
424 //! Pop up menu for the bezier (bline, draw) tool (?)
425 void popup_param_menu_bezier(float location, synfigapp::ValueDesc value_desc)
426 { popup_param_menu(value_desc,location,true); }
428 //! Pop up menu for the tools but not the bezier ones.
429 void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0, bool bezier=false);
431 void workarea_layer_selected(synfig::Layer::Handle layer);
433 void selected_layer_color_set(synfig::Color color);
435 void register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>*);
437 //! Rebuilds the "new layer" menu
438 void build_new_layer_menu(Gtk::Menu &menu);
440 void rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list);
442 void decrease_low_res_pixel_size();
443 void increase_low_res_pixel_size();
444 void toggle_low_res_pixel_flag();
445 void set_quality(int x);
446 void toggle_show_grid();
447 void toggle_snap_grid();
450 -- ** -- P U B L I C M E T H O D S -----------------------------------------
454 const synfig::TransformStack& get_curr_transform_stack()const { return curr_transform_stack; }
456 const synfig::Rect& get_bbox()const { return bbox; }
458 Glib::RefPtr<Glib::ObjectBase> get_ref_obj(const synfig::String& x);
459 Glib::RefPtr<const Glib::ObjectBase> get_ref_obj(const synfig::String& x)const;
460 void set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y);
462 Glib::RefPtr<Gtk::TreeModel> get_tree_model(const synfig::String& x);
463 Glib::RefPtr<const Gtk::TreeModel> get_tree_model(const synfig::String& x)const;
464 void set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y);
466 Gtk::Widget* get_ext_widget(const synfig::String& x);
467 void set_ext_widget(const synfig::String& x, Gtk::Widget* y);
469 //std::map<synfig::String,Gtk::Widget*>& tree_view_book() { return tree_view_book_; }
470 //std::map<synfig::String,Gtk::Widget*>& ext_widget_book() { return tree_view_book_; }
472 void popup_main_menu();
474 Smach& get_smach() { return smach_; }
476 const Smach& get_smach()const { return smach_; }
478 Smach::event_result process_event_key(EventKey x);
480 void popup_layer_menu(synfig::Layer::Handle layer);
482 virtual ~CanvasView();
484 void set_mode(Mode x) { canvas_interface()->set_mode(x); }
486 Mode get_mode()const { return canvas_interface()->get_mode(); }
488 Gtk::Adjustment &time_adjustment() { return time_adjustment_; }
490 const Gtk::Adjustment &time_adjustment()const { return time_adjustment_; }
492 studio::Adjust_Window &time_window_adjustment() { return time_window_adjustment_; }
494 const studio::Adjust_Window &time_window_adjustment()const { return time_window_adjustment_; }
496 etl::handle<synfigapp::UIInterface> get_ui_interface() { return ui_interface_;}
498 etl::handle<synfigapp::SelectionManager> get_selection_manager() { return selection_manager_; }
500 Glib::RefPtr<Gtk::TreeModel> layer_tree_store() { return get_tree_model("layers"); }
502 Glib::RefPtr<const Gtk::TreeModel> layer_tree_store()const { return get_tree_model("layers"); }
504 Glib::RefPtr<Gtk::TreeModel> children_tree_store() { return get_tree_model("children"); }
506 Glib::RefPtr<const Gtk::TreeModel> children_tree_store()const { return get_tree_model("children"); }
508 Glib::RefPtr<Gtk::TreeModel> keyframe_tree_store() { return get_tree_model("keyframes"); }
510 Glib::RefPtr<const Gtk::TreeModel> keyframe_tree_store()const { return get_tree_model("keyframes"); }
512 void set_time(synfig::Time t) { canvas_interface_->set_time(t); }
514 synfig::Time get_time() { return canvas_interface_->get_time(); }
516 etl::handle<synfig::Canvas> get_canvas()const { return canvas_interface_->get_canvas(); }
518 etl::handle<Instance> get_instance()const { return instance_; }
520 etl::handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
522 etl::handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
524 void add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList ¶m_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
526 //! Updates the title of the window
529 //! Closes this document
530 bool close_instance();
532 //! Closes this canvas view
535 //! Stops the currently executing action
536 /*! \see get_cancel_status(), reset_cancel_status(), IsWorking */
537 void stop() { cancel=true; }
539 //! Returns the cancel status
540 /*! \see stop(), reset_cancel_status(), IsWorking */
541 bool get_cancel_status()const { return cancel; }
543 //! Resets the cancel status
544 /*! \see stop(), get_cancel_status(), IsWorking */
545 void reset_cancel_status() { cancel=false; }
547 void new_child_canvas();
549 //! Rebuilds layer_tree_store_ from the Canvas. Maintains selected items.
550 void rebuild_tables();
552 //! Builds layer_tree_store_ from the Canvas. Does not maintain selected items.
555 //! Refreshes the data for the tables
556 void refresh_tables();
558 //void rebuild_layer_table();
559 //void build_layer_table();
560 //void refresh_layer_table();
562 // void rebuild_canvas_table();
563 // void build_canvas_table();
564 // void refresh_canvas_table();
566 // void rebuild_valuenode_table();
567 // void build_valuenode_table();
568 // void refresh_valuenode_table();
571 void rebuild_ducks();
573 //bool add_to_ducks(synfigapp::ValueDesc value_desc, synfig::ParamDesc *param_desc=NULL);
575 //! Starts "playing" the animation in real-time
578 //! Shows the tables (Layer/Children)
581 //! Hides the tables (Layer/Children)
584 //! Toggles the tables
585 void toggle_tables();
587 //! Gets the table status
588 bool tables_are_visible();
590 //! Shows the time bar
593 //! Hides the time bar
596 //t Enables or disables interaction with the timebar
597 void set_sensitive_timebar(bool sensitive);
600 void time_zoom_out();
602 void add_layer(synfig::String x);
604 void show_keyframe_dialog();
606 void play_audio(float t);
611 void on_waypoint_clicked_canvasview(synfigapp::ValueDesc,std::set<synfig::Waypoint,std::less<synfig::UniqueID> >, int button);
613 void preview_option() {on_preview_option();}
617 bool is_playing() { return is_playing_; }
619 void update_quality();
622 -- ** -- S I G N A L T E R M I N A L S -------------------------------------
627 void on_select_layers();
628 void on_unselect_layers();
630 void on_input_device_changed(GdkDevice*);
632 virtual void on_hide();
634 virtual bool on_focus_in_event(GdkEventFocus*);
635 virtual bool on_focus_out_event(GdkEventFocus*);
637 //bool on_children_tree_event(GdkEvent *event);
639 bool on_keyframe_tree_event(GdkEvent *event);
641 //void on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value);
643 void on_dirty_preview();
645 bool on_children_user_click(int, Gtk::TreeRow, ChildrenTree::ColumnID);
647 bool on_layer_user_click(int, Gtk::TreeRow, LayerTree::ColumnID);
649 // void on_layer_toggle(const Glib::ustring& path_string, Gtk::TreeModelColumn<bool> column);
651 void on_mode_changed(synfigapp::CanvasInterface::Mode mode);
653 // void on_layer_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
655 //void on_children_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
657 void on_waypoint_changed();
659 void on_waypoint_delete();
661 void on_refresh_pressed();
663 void on_id_changed();
665 void on_time_changed();
668 void on_layer_raise_pressed();
669 void on_layer_lower_pressed();
670 void on_layer_duplicate_pressed();
671 void on_layer_delete_pressed();
674 void on_keyframe_add_pressed();
676 void on_keyframe_duplicate_pressed();
678 void on_keyframe_remove_pressed();
680 void on_animate_button_pressed();
682 void on_keyframe_button_pressed();
684 void on_preview_option();
685 void on_preview_create(const PreviewInfo &);
687 void on_audio_option();
688 void on_audio_file_change(const std::string &f);
689 void on_audio_offset_change(const synfig::Time &t);
691 void on_audio_file_notify();
692 void on_audio_offset_notify();
694 bool on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc);
695 bool on_duck_angle_changed(const synfig::Angle &rotation,const synfigapp::ValueDesc& value_desc);
697 void on_layer_toggle(synfig::Layer::Handle);
699 void on_edited_value(synfigapp::ValueDesc,synfig::ValueBase);
701 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);
703 //void on_audio_play();
704 bool on_audio_scrub();
706 void on_play_stop_pressed();
709 bool close_instance_when_safe();
710 bool on_delete_event(GdkEventAny* event);
713 -- ** -- S T A T I C P U B L I C M E T H O D S ---------------------------
718 static etl::handle<studio::CanvasView> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
719 static std::list<int>& get_pixel_sizes();
721 }; // END of class CanvasView
723 }; // END of namespace studio
725 /* === E N D =============================================================== */