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