The 'polygon', 'draw', 'sketch', and 'width' tools are disabled by default. This...
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasview.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasview.h
3 **      \brief Template Header
4 **
5 **      $Id: canvasview.h,v 1.2 2005/01/13 18:37:30 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
26 #define __SYNFIG_STUDIO_GTKMM_CANVASVIEW_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <gtkmm/window.h>
31 #include <gtkmm/image.h>
32 #include <gtkmm/tooltips.h>
33 #include <gtkmm/table.h>
34 #include <gtkmm/statusbar.h>
35 #include <gtkmm/progressbar.h>
36 #include <gtkmm/button.h>
37 #include <gtkmm/menu.h>
38 #include <gtkmm/treeview.h>
39 #include <gtkmm/treestore.h>
40 #include <gtkmm/scrolledwindow.h>
41 #include <gtkmm/notebook.h>
42 #include <gdkmm/device.h>
43
44 #include <synfigapp/canvasinterface.h>
45 #include <synfigapp/selectionmanager.h>
46
47 #include <synfig/canvas.h>
48 #include <synfig/string.h>
49 #include <synfig/time.h>
50
51 #include "instance.h"
52 #include "canvasproperties.h"
53 #include "canvasoptions.h"
54 #include "render.h"
55 #include "cellrenderer_timetrack.h"
56 #include "app.h"
57
58 #include "layertreestore.h"
59 #include "layertree.h"
60 #include "childrentreestore.h"
61 #include "childrentree.h"
62 #include "keyframetreestore.h"
63 #include "keyframetree.h"
64
65 #include "dialog_waypoint.h"
66 #include "dialog_keyframe.h"
67
68 #include "duckmatic.h"
69 #include <gtkmm/scale.h>
70
71 #include <gtkmm/uimanager.h>
72
73 #include "smach.h"
74
75 #include <memory>
76 #include <set>
77 #include <map>
78 #include <gtkmm/toggleaction.h>
79 #include <gtkmm/radioaction.h>
80 #include <synfig/rect.h>
81
82 #include "adjust_window.h"
83
84 #include <synfig/transform.h>
85
86 /* === M A C R O S ========================================================= */
87
88 #ifndef DEBUGPOINT_CLASS
89 #if     _DEBUG
90 #define DEBUGPOINT_CLASS(x)             struct debugpointclass_ ## x { debugpointclass_ ## x () { DEBUGPOINT(); } ~debugpointclass_ ## x () { DEBUGPOINT(); } } badfthguae_ ## x ;
91 #else
92 #define DEBUGPOINT_CLASS(x)     
93 #endif
94 #endif
95
96 /* === T Y P E D E F S ===================================================== */
97
98 /* === C L A S S E S & S T R U C T S ======================================= */
99
100 namespace studio {
101
102 class CanvasViewUIInterface;
103 class CanvasViewSelectionManager;
104
105 class CellRenderer_TimeTrack;
106 class CellRenderer_ValueBase;
107 class UniversalScrubber;
108 class WorkArea;
109
110 class Duckmatic;
111
112 class Preview;
113 struct PreviewInfo;
114 class AudioContainer;
115         
116 class Widget_Sound;
117 class Widget_Timeslider;
118 class Widget_Time;
119         
120 class Dialog_SoundSelect;
121 class Dialog_Preview;
122
123 class synfig::TransformStack;
124 class Dock_Layers;
125 class Dock_Children;
126 class Dock_Keyframes;
127         
128 class CanvasView : public Gtk::Window, public etl::shared_object
129 {
130         friend class UniversalScrubber;
131         friend class Dock_Layers;
132         friend class Dock_Children;
133         friend class Dock_Keyframes;
134                 
135         friend class CanvasViewUIInterface;
136         friend class CanvasViewSelectionManager;
137
138         friend class Duckmatic;
139                 
140         /*
141  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
142         */
143         
144 public:
145
146         typedef etl::handle<CanvasView> Handle;
147         
148         typedef etl::handle<const CanvasView> ConstHandle;
149         
150         typedef etl::loose_handle<CanvasView> LooseHandle;
151
152         typedef LayerTreeStore::Model LayerTreeModel;
153
154         typedef ChildrenTreeStore::Model ChildrenTreeModel;
155
156         //! Create an instance of this class whenever doing a longer task.
157         /*! Make sure that you check the bool value of this class occasionaly
158         **      to make sure the action has not been canceled. */
159         class IsWorking
160         {
161                 CanvasView &canvas_view_;
162
163         public:
164                 IsWorking(CanvasView &canvas_view_);
165                 ~IsWorking();
166                 operator bool()const;
167         };
168         friend class IsWorking;
169
170         typedef synfigapp::CanvasInterface::Mode Mode;
171
172         /*
173  -- ** -- P R I V A T E   D A T A ---------------------------------------------
174         */
175
176 public:
177         std::auto_ptr<WorkArea> work_area;
178
179         WorkArea* get_work_area() { return work_area.get(); }
180 private:
181
182         synfig::TransformStack curr_transform_stack;
183         bool curr_transform_stack_set;
184
185         synfig::Rect bbox;
186
187         DEBUGPOINT_CLASS(1);
188
189         //! State Machine
190         Smach smach_;
191
192         DEBUGPOINT_CLASS(2);
193
194         etl::loose_handle<Instance> instance_;
195         etl::handle<synfigapp::CanvasInterface> canvas_interface_;
196
197         DEBUGPOINT_CLASS(3);
198
199         //! Sound and information to play it
200         etl::handle<AudioContainer>             audio;
201         studio::Widget_Sound                    *disp_audio; //should this be put into thing too?
202
203         SigC::Connection                                playcon;
204         SigC::Connection                                stopcon;
205         
206         std::auto_ptr<UniversalScrubber> universal_scrubber;
207         
208         //! Tooltip controler
209         Gtk::Tooltips tooltips;
210
211         DEBUGPOINT_CLASS(4);
212
213         //! TreeModel for the layers
214         LayerTreeModel layer_tree_model;
215
216         //! TreeModel for the the children
217         ChildrenTreeModel children_tree_model;
218
219         //Glib::RefPtr<LayerTreeStore> layer_tree_store_;
220
221         //Glib::RefPtr<ChildrenTreeStore> children_tree_store_;
222
223         //Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store_;
224
225         DEBUGPOINT_CLASS(5);
226         
227         //std::map<synfig::String,Glib::RefPtr<Gtk::TreeModel> > tree_model_book_;
228         std::map<synfig::String,Glib::RefPtr<Glib::ObjectBase> > ref_obj_book_;
229         std::map<synfig::String,Gtk::Widget*> ext_widget_book_;
230
231
232         //! The time adjustment's scope is defined by the time_window adjustment
233         Gtk::Adjustment time_adjustment_;
234         
235         //! The time_window adjustment governs the position of the time window on the whole time line
236         //Gtk::Adjustment time_window_adjustment_;
237         studio::Adjust_Window time_window_adjustment_;
238         
239                         
240         LayerTree *layer_tree;
241         
242         ChildrenTree *children_tree;
243
244         KeyframeTree *keyframe_tree;
245
246         Gtk::Widget *keyframe_tab_child;
247
248         Gtk::ProgressBar *progressbar;
249         Gtk::Statusbar *statusbar;
250         
251         Gtk::TreeRow children_canvas_row;
252         Gtk::TreeRow children_valuenode_row;
253         
254         Gtk::Button *stopbutton;
255         Gtk::Button *refreshbutton;
256         Gtk::Button *treetogglebutton;
257         Gtk::Notebook *notebook;
258         Gtk::Widget *timebar;
259
260         Widget_Time *current_time_widget;
261         void on_current_time_widget_changed();
262         
263         std::auto_ptr<Widget_Timeslider>                timeslider;
264
265         std::list<sigc::connection> duck_changed_connections;
266
267
268
269         Gtk::Button *animatebutton;
270         Gtk::Button *keyframebutton;
271         
272 /*      DEBUGPOINT_CLASS(8);
273
274         Gtk::Menu duckmaskmenu;
275         DEBUGPOINT_CLASS(77);
276         Gtk::Menu qualitymenu;
277         DEBUGPOINT_CLASS(6);
278
279         Gtk::Menu filemenu;
280         DEBUGPOINT_CLASS(777);
281         Gtk::Menu editmenu;
282         DEBUGPOINT_CLASS(71);
283         Gtk::Menu canvasmenu;
284         DEBUGPOINT_CLASS(73);
285 public:
286         Gtk::Menu layermenu;
287 private:
288         DEBUGPOINT_CLASS(74);
289         Gtk::Menu newlayermenu;
290         DEBUGPOINT_CLASS(76);
291         Gtk::Menu viewmenu;
292
293         DEBUGPOINT_CLASS(99);
294         Gtk::Menu keyframemenu;
295
296         Gtk::Menu parammenu;
297         DEBUGPOINT_CLASS(9);
298         Gtk::Menu trackmenu;
299         DEBUGPOINT_CLASS(7);
300
301         Gtk::CheckMenuItem* duck_mask_position;
302         Gtk::CheckMenuItem* duck_mask_vertex;
303         Gtk::CheckMenuItem* duck_mask_tangent;
304         Gtk::CheckMenuItem* duck_mask_radius;
305         Gtk::CheckMenuItem* duck_mask_width;
306         Gtk::CheckMenuItem* duck_mask_angle;
307 */
308         Gtk::Menu parammenu;
309
310
311         Glib::RefPtr<Gtk::ToggleAction> duck_mask_position;
312         Glib::RefPtr<Gtk::ToggleAction> duck_mask_vertex;
313         Glib::RefPtr<Gtk::ToggleAction> duck_mask_tangent;
314         Glib::RefPtr<Gtk::ToggleAction> duck_mask_radius;
315         Glib::RefPtr<Gtk::ToggleAction> duck_mask_width;
316         Glib::RefPtr<Gtk::ToggleAction> duck_mask_angle;
317
318         Gtk::RadioButtonGroup quality_group;
319         
320         Glib::RefPtr<Gtk::ActionGroup> action_group;
321
322
323         etl::handle<synfigapp::UIInterface> ui_interface_;
324         etl::handle<synfigapp::SelectionManager> selection_manager_;
325         
326         bool is_playing_;
327
328         sigc::signal<void> signal_deleted_;
329
330         bool rebuild_ducks_queued;
331         sigc::connection queue_rebuild_ducks_connection;
332
333         /*
334  -- ** -- P U B L I C   D A T A -----------------------------------------------
335         */
336
337 public:
338         void queue_rebuild_ducks();
339         sigc::signal<void>& signal_deleted() { return signal_deleted_; }
340
341         Gtk::Menu mainmenu;
342
343         bool duck_refresh_flag;
344         bool duck_refresh_needed;
345
346         //! This is for the IsWorking class.
347         int working_depth;
348
349         bool cancel;
350
351
352         /*
353  -- ** -- D I A L O G S -------------------------------------------------------
354         */
355
356 public:
357
358         CanvasProperties canvas_properties;
359         CanvasOptions canvas_options;
360         RenderSettings render_settings;
361         Dialog_Waypoint waypoint_dialog;
362         Dialog_Keyframe keyframe_dialog;
363
364         std::auto_ptr<Dialog_Preview>                   preview_dialog;
365         //std::auto_ptr<Dialog_PreviewOptions>  previewoption_dialog;
366         std::auto_ptr<Dialog_SoundSelect>               sound_dialog;
367
368         /*
369  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
370         */
371
372 private:
373         
374         // Constructor is private to force the use of the "create()" constructor
375         CanvasView(etl::loose_handle<Instance> instance,etl::handle<synfigapp::CanvasInterface> canvas_interface);
376
377         //! Constructor Helper
378         Gtk::Widget* create_layer_tree();
379
380         //! Constructor Helper
381         Gtk::Widget* create_children_tree();
382
383         //! Constructor Helper
384         Gtk::Widget* create_keyframe_tree();
385
386         //! Constructor Helper
387         Gtk::Widget* create_status_bar();
388
389         //! Constructor Helper - Initializes all of the menus
390         void init_menus();
391
392         bool duck_change_param(const synfig::Point &value,synfig::Layer::Handle layer, synfig::String param_name);
393
394         void refresh_time_window();
395
396         void time_was_changed();
397
398         void refresh_rend_desc();       
399         
400         void toggle_duck_mask(Duckmatic::Type type);
401
402         Gtk::Widget *create_work_area();
403
404         Gtk::Widget *create_time_bar();
405
406
407
408         void popup_param_menu_bezier(float location, synfigapp::ValueDesc value_desc)
409         { popup_param_menu(value_desc,location); }
410         
411         void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0);
412
413
414         void workarea_layer_selected(synfig::Layer::Handle layer);
415
416         void selected_layer_color_set(synfig::Color color);
417                 
418
419
420         void register_layer_type(synfig::Layer::Book::value_type &lyr,std::map<synfig::String,Gtk::Menu*>*);
421
422         //! Rebuilds the "new layer" menu
423         void build_new_layer_menu(Gtk::Menu &menu);
424
425         void rebuild_ducks_layer_(synfig::TransformStack& transform_stack, synfig::Canvas::Handle canvas, std::set<synfig::Layer::Handle>& selected_list);
426
427         /*
428  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
429         */
430
431 public:
432         const synfig::TransformStack& get_curr_transform_stack()const { return curr_transform_stack; }
433
434         const synfig::Rect& get_bbox()const { return bbox; }
435
436         Glib::RefPtr<Glib::ObjectBase> get_ref_obj(const synfig::String& x);
437         Glib::RefPtr<const Glib::ObjectBase> get_ref_obj(const synfig::String& x)const;
438         void set_ref_obj(const synfig::String& x, Glib::RefPtr<Glib::ObjectBase> y);
439
440         Glib::RefPtr<Gtk::TreeModel> get_tree_model(const synfig::String& x);
441         Glib::RefPtr<const Gtk::TreeModel> get_tree_model(const synfig::String& x)const;
442         void set_tree_model(const synfig::String& x, Glib::RefPtr<Gtk::TreeModel> y);
443
444         Gtk::Widget* get_ext_widget(const synfig::String& x);
445         void set_ext_widget(const synfig::String& x, Gtk::Widget* y);
446         
447         //std::map<synfig::String,Gtk::Widget*>& tree_view_book() { return tree_view_book_; }
448         //std::map<synfig::String,Gtk::Widget*>& ext_widget_book() { return tree_view_book_; }
449
450         void popup_main_menu();
451
452         Smach& get_smach() { return smach_; }
453
454         const Smach& get_smach()const { return smach_; }
455         
456         Smach::event_result process_event_key(EventKey x);
457         
458         void popup_layer_menu(synfig::Layer::Handle layer);
459
460         virtual ~CanvasView();
461
462         void set_mode(Mode x) { canvas_interface()->set_mode(x); }
463         
464         Mode get_mode()const { return canvas_interface()->get_mode(); }
465                                 
466         Gtk::Adjustment &time_adjustment() { return time_adjustment_; }
467         
468         const Gtk::Adjustment &time_adjustment()const { return time_adjustment_; }
469
470         studio::Adjust_Window &time_window_adjustment() { return time_window_adjustment_; }
471         
472         const studio::Adjust_Window &time_window_adjustment()const { return time_window_adjustment_; }
473
474         etl::handle<synfigapp::UIInterface> get_ui_interface() { return ui_interface_;}
475
476         etl::handle<synfigapp::SelectionManager> get_selection_manager() { return selection_manager_; }
477
478         Glib::RefPtr<Gtk::TreeModel> layer_tree_store() { return get_tree_model("layers"); }
479         
480         Glib::RefPtr<const Gtk::TreeModel> layer_tree_store()const { return get_tree_model("layers"); }
481
482         Glib::RefPtr<Gtk::TreeModel> children_tree_store() { return get_tree_model("children"); }
483         
484         Glib::RefPtr<const Gtk::TreeModel> children_tree_store()const { return get_tree_model("children"); }
485
486         Glib::RefPtr<Gtk::TreeModel> keyframe_tree_store() { return get_tree_model("keyframes"); }
487         
488         Glib::RefPtr<const Gtk::TreeModel> keyframe_tree_store()const { return get_tree_model("keyframes"); }
489
490         void set_time(synfig::Time t) { canvas_interface_->set_time(t); }
491         
492         synfig::Time get_time() { return canvas_interface_->get_time(); }
493
494         etl::handle<synfig::Canvas> get_canvas()const { return canvas_interface_->get_canvas(); }
495
496         etl::handle<Instance> get_instance()const { return instance_; }
497
498         etl::handle<synfigapp::CanvasInterface> canvas_interface() { return canvas_interface_; }
499
500         etl::handle<const synfigapp::CanvasInterface> canvas_interface()const { return canvas_interface_; }
501
502         void add_actions_to_menu(Gtk::Menu *menu,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
503
504         //! Updates the title of the window
505         void update_title();
506
507         //! Closes this canvas view
508         bool close();
509
510         //!     Stops the currently executing action
511         /*! \see get_cancel_status(), reset_cancel_status(), IsWorking */
512         void stop() { cancel=true; }
513
514         //! Returns the cancel status
515         /*! \see stop(), reset_cancel_status(), IsWorking */
516         bool get_cancel_status()const { return cancel; }
517
518         //! Resets the cancel status
519         /*! \see stop(), get_cancel_status(), IsWorking */
520         void reset_cancel_status() { cancel=false; }
521
522         void new_child_canvas();
523
524         //! Rebuilds layer_tree_store_ from the Canvas. Maintains selected items.
525         void rebuild_tables();
526
527         //! Builds layer_tree_store_ from the Canvas. Does not maintain selected items.
528         void build_tables();
529
530         //! Refreshes the data for the tables
531         void refresh_tables();
532
533         //void rebuild_layer_table();
534         //void build_layer_table();
535         //void refresh_layer_table();
536
537 //      void rebuild_canvas_table();
538 //      void build_canvas_table();
539 //      void refresh_canvas_table();
540
541 //      void rebuild_valuenode_table();
542 //      void build_valuenode_table();
543 //      void refresh_valuenode_table();
544
545         //! \writeme
546         void rebuild_ducks();
547         
548         //bool add_to_ducks(synfigapp::ValueDesc value_desc, synfig::ParamDesc *param_desc=NULL);
549                 
550         //! Starts "playing" the animation in real-time
551         void play();
552
553         //! Shows the tables (Layer/Children)
554         void show_tables();
555         
556         //! Hides the tables (Layer/Children)
557         void hide_tables();
558         
559         //! Toggles the tables
560         void toggle_tables();
561
562         //! Gets the table status
563         bool tables_are_visible();
564         
565         //! Shows the time bar
566         void show_timebar();
567
568         //! Hides the time bar
569         void hide_timebar();
570
571         void do_rotoscope_bline();
572
573         void do_rotoscope();
574
575         void do_rotoscope_poly();
576
577         void do_eyedrop();
578
579         void time_zoom_in();
580         void time_zoom_out();
581         
582         void add_layer(synfig::String x);
583         
584         void show_keyframe_dialog();
585         
586         void play_audio(float t);
587         void stop_audio();
588         
589         void image_import();
590
591         void on_waypoint_clicked(synfigapp::ValueDesc,synfig::Waypoint, int button);
592         
593         void preview_option() {on_preview_option();}
594         
595         void present();
596         
597         /*
598  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
599         */
600
601 private:
602         
603         void on_unselect_layers();
604
605         void on_input_device_changed(GdkDevice*);
606
607         virtual void on_hide();
608
609         virtual bool on_focus_in_event(GdkEventFocus*);
610         virtual bool on_focus_out_event(GdkEventFocus*);
611         
612         //bool on_children_tree_event(GdkEvent *event);
613
614         bool on_keyframe_tree_event(GdkEvent *event);
615
616         //void on_children_edited_value(const Glib::ustring&path_string,synfig::ValueBase value);
617
618         void on_dirty_preview();
619
620         bool on_children_user_click(int, Gtk::TreeRow, ChildrenTree::ColumnID);
621
622         bool on_layer_user_click(int, Gtk::TreeRow, LayerTree::ColumnID);
623
624 //      void on_layer_toggle(const Glib::ustring& path_string, Gtk::TreeModelColumn<bool> column);
625         
626         void on_mode_changed(synfigapp::CanvasInterface::Mode mode);
627
628 //      void on_layer_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
629         
630         //void on_children_waypoint_clicked(const Glib::ustring &, synfig::ValueNode_Animated::WaypointList::iterator);
631
632         void on_waypoint_changed();
633         
634         void on_waypoint_delete();
635
636         void on_refresh_pressed();
637
638         void on_id_changed();
639         
640         void on_time_changed();
641
642         /*
643         void on_layer_raise_pressed();
644         void on_layer_lower_pressed();
645         void on_layer_duplicate_pressed();
646         void on_layer_delete_pressed();
647         */
648         
649         void on_keyframe_add_pressed();
650
651         void on_keyframe_duplicate_pressed();
652
653         void on_keyframe_remove_pressed();
654
655         void on_animate_button_pressed();
656
657         void on_keyframe_button_pressed();
658         
659         void on_preview_option();
660         void on_preview_create(const PreviewInfo &);
661         
662         void on_audio_option();
663         void on_audio_file_change(const std::string &f);
664         void on_audio_offset_change(const synfig::Time &t);
665         
666         void on_audio_file_notify();
667         void on_audio_offset_notify();
668         
669         bool on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc);
670
671         void on_layer_toggle(synfig::Layer::Handle);
672
673         void on_edited_value(synfigapp::ValueDesc,synfig::ValueBase);
674
675         //void on_waypoint_clicked(synfigapp::ValueDesc,synfig::ValueNode_Animated::WaypointList::iterator, int button);
676
677         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);
678         
679         //void on_audio_play();
680         bool on_audio_scrub();
681
682 protected:
683         bool on_delete_event(GdkEventAny* event);
684         
685         /*
686  -- ** -- S T A T I C   P U B L I C   M E T H O D S ---------------------------
687         */
688
689 public:
690         
691         static etl::handle<studio::CanvasView> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
692 }; // END of class CanvasView
693
694 }; // END of namespace studio
695
696 /* === E N D =============================================================== */
697
698 #endif