source: synfigstudio/trunk/fuentes/src/synfigapp/canvasinterface.h @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 13.6 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file canvasinterface.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, 2008 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_APP_CANVASINTERFACE_H
27#define __SYNFIG_APP_CANVASINTERFACE_H
28
29/* === H E A D E R S ======================================================= */
30
31//#include <synfig/canvas.h>
32#include <synfig/value.h>
33#include <sigc++/sigc++.h>
34#include <list>
35#include "selectionmanager.h"
36#include "uimanager.h"
37#include "value_desc.h"
38#include "editmode.h"
39
40/* === M A C R O S ========================================================= */
41
42/* === T Y P E D E F S ===================================================== */
43
44/* === C L A S S E S & S T R U C T S ======================================= */
45
46namespace synfig { class ValueNode_DynamicList; class Waypoint; class GUIDSet; class Canvas; };
47
48namespace synfigapp {
49
50namespace Action { class ParamList; class Param; class EditModeSet; };
51
52class Instance;
53class ValueDesc;
54
55class CanvasInterface : public etl::shared_object, public sigc::trackable
56{
57        friend class Instance;
58        friend class Action::EditModeSet;
59
60public:
61
62        typedef EditMode Mode;
63
64private:
65        // Constructor is private to force the use of the "create()" constructor.
66        CanvasInterface(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
67
68private:
69        etl::loose_handle<Instance> instance_;
70        etl::handle<synfig::Canvas> canvas_;
71        etl::handle<SelectionManager> selection_manager_;
72        etl::handle<UIInterface> ui_interface_;
73        synfig::Time cur_time_;
74        Mode mode_;
75
76        sigc::signal<void,synfig::Layer::Handle> signal_layer_raised_;
77        sigc::signal<void,synfig::Layer::Handle> signal_layer_lowered_;
78        sigc::signal<void,synfig::Layer::Handle,int> signal_layer_inserted_;
79        sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle> signal_layer_moved_;
80        sigc::signal<void,synfig::Layer::Handle> signal_layer_removed_;
81        sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_status_changed_;
82        sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_exclude_from_rendering_changed_;
83        sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_z_range_changed_;
84        sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_new_description_;
85        sigc::signal<void,synfig::Canvas::Handle> signal_canvas_added_;
86        sigc::signal<void,synfig::Canvas::Handle> signal_canvas_removed_;
87
88        sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_added_;
89        sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_deleted_;
90        sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle> signal_value_node_replaced_;
91
92        sigc::signal<void,synfig::Keyframe> signal_keyframe_added_;
93        sigc::signal<void,synfig::Keyframe> signal_keyframe_removed_;
94        sigc::signal<void,synfig::Keyframe> signal_keyframe_changed_;
95        sigc::signal<void,synfig::Keyframe,void*> signal_keyframe_selected_;
96        sigc::signal<void> signal_keyframe_properties_;
97
98        sigc::signal<void> signal_id_changed_;
99
100        sigc::signal<void> signal_time_changed_;
101
102        sigc::signal<void> signal_rend_desc_changed_;
103
104        sigc::signal<void,Mode> signal_mode_changed_;
105
106        //sigc::signal<void> signal_dirty_preview_;
107
108        sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_param_changed_;
109
110public: // Signal Interface
111
112        sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle>& signal_layer_moved() { return signal_layer_moved_; }
113
114        sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_new_description() { return signal_layer_new_description_; }
115
116        //! Signal called when layer is raised.
117        sigc::signal<void,synfig::Layer::Handle>& signal_layer_raised() { return signal_layer_raised_; }
118
119        //! Signal called when layer is lowered.
120        sigc::signal<void,synfig::Layer::Handle>& signal_layer_lowered() { return signal_layer_lowered_; }
121
122        //! Signal called when layer has been inserted at a given position.
123        sigc::signal<void,synfig::Layer::Handle,int>& signal_layer_inserted() { return signal_layer_inserted_; }
124
125        //! Signal called when a layer has been removed from the canvas.
126        sigc::signal<void,synfig::Layer::Handle>& signal_layer_removed() { return signal_layer_removed_; }
127
128        //! Signal called when the layer's active status has changed.
129        sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_status_changed() { return signal_layer_status_changed_; }
130
131        //! Signal called when the layer's "exclude from rendering" flag has changed.
132        sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_exclude_from_rendering_changed() { return signal_layer_exclude_from_rendering_changed_; }
133
134        //! Signal called when the layer's zdepth range has changed. This layer has to be Layer_PasteCanvas
135        sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_z_range_changed() { return signal_layer_z_range_changed_; }
136
137        //! Signal called when a canvas has been added.
138        sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_added() { return signal_canvas_added_; }
139
140        //! Signal called when a canvas has been removed.
141        sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_removed() { return signal_canvas_removed_; }
142
143        //! Signal called when a layer's parameter has been changed
144        sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_param_changed() { return signal_layer_param_changed_; }
145
146        //! Signal called when the canvas's preview needs to be updated
147        //sigc::signal<void>& signal_dirty_preview() { return signal_dirty_preview_; }
148        sigc::signal<void>& signal_dirty_preview() { return get_canvas()->signal_dirty(); }
149
150        sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
151                signal_value_node_child_added() { return get_canvas()->signal_value_node_child_added(); }
152        sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
153                signal_value_node_child_removed() { return get_canvas()->signal_value_node_child_removed(); }
154
155        //! Signal called when a ValueNode has changed
156        sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_added() { return signal_value_node_added_; }
157
158        //! Signal called when a ValueNode has been deleted
159        sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_deleted() { return signal_value_node_deleted_; }
160
161        //! Signal called when a ValueNode has been changed
162        sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_changed() { return get_canvas()->signal_value_node_changed(); }
163
164        //! Signal called when a ValueNode has been renamed
165        sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_renamed() { return get_canvas()->signal_value_node_renamed(); }
166
167        //! Signal called when the mode has changed
168        sigc::signal<void,Mode> signal_mode_changed() { return signal_mode_changed_; }
169
170        //! Signal called when a the ID has been changed
171        sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
172
173        //! Signal called whenever the time changes
174        sigc::signal<void> signal_time_changed() { return signal_time_changed_; }
175
176        //! Signal called whenever a data node has been replaced.
177        /*!     Second ValueNode replaces first */
178        sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle>& signal_value_node_replaced()
179                { return signal_value_node_replaced_; }
180
181        //! Signal called whenever the RendDesc changes
182        sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
183
184        //! Signal called when a keyframe is added
185        sigc::signal<void,synfig::Keyframe>& signal_keyframe_added() { return signal_keyframe_added_; }
186        //! Signal called when a keyframe is removed
187        sigc::signal<void,synfig::Keyframe>& signal_keyframe_removed() { return signal_keyframe_removed_; }
188        //! Signal called when a keyframe is changed
189        sigc::signal<void,synfig::Keyframe>& signal_keyframe_changed() { return signal_keyframe_changed_; }
190        //! Signal called when a keyframe is selected
191        /*!     Second parameter (void*) hold 'this*' of the signal emiter class (to prevent endless loop)*/
192        sigc::signal<void,synfig::Keyframe,void*>& signal_keyframe_selected() { return signal_keyframe_selected_; }
193        //! Signal called when the properties dialog of the selected keyframe must be shown
194        sigc::signal<void>& signal_keyframe_properties() { return signal_keyframe_properties_; }
195
196public:
197
198        void auto_export(const ValueDesc& value_desc);
199
200        void auto_export(synfig::ValueNode::Handle value_node);
201
202        void set_meta_data(const synfig::String& key,const synfig::String& data);
203
204        void erase_meta_data(const synfig::String& key);
205
206        //! Changes the current SelectionManager object
207        void set_selection_manager(const etl::handle<SelectionManager> &sm) { selection_manager_=sm; }
208
209        //! Disables the selection manager
210        void unset_selection_manager() { selection_manager_=new NullSelectionManager(); }
211
212        //! Returns a handle to the current SelectionManager
213        const etl::handle<SelectionManager> &get_selection_manager()const { return selection_manager_; }
214
215        //! Changes the current UIInterface object
216        void set_ui_interface(const etl::handle<UIInterface> &uim) { ui_interface_=uim; }
217
218        //! Disables the UIInterface
219        void unset_ui_interface() { ui_interface_=new DefaultUIInterface(); }
220
221        //! Returns a handle to the current UIInterface
222        const etl::handle<UIInterface> &get_ui_interface() { return ui_interface_; }
223
224        //! Returns the Canvas associated with this interface
225        etl::handle<synfig::Canvas> get_canvas()const { return canvas_; }
226
227        //! Returns the Instance associated with this interface
228        etl::loose_handle<Instance> get_instance()const { return instance_; }
229
230        //! Changes the name of the canvas. Undoable.
231        void set_name(const synfig::String &x);
232
233        //! Changes the description of the canvas. Undoable.
234        void set_description(const synfig::String &x);
235
236        //! Changes the ID of the canvas. Undoable.
237        void set_id(const synfig::String &x);
238
239        //! Convenience function to retrieve the name of the canvas
240        synfig::String get_name()const { return get_canvas()->get_name(); }
241
242        //! Convenience function to retrieve the description of the canvas
243        synfig::String get_description()const { return get_canvas()->get_description(); }
244
245        //! Convenience function to retrieve the ID of the canvas
246        synfig::String get_id()const { return get_canvas()->get_id(); }
247
248        //! Sets the current time
249        void set_time(synfig::Time x);
250
251        //! Retrieves the current time
252        synfig::Time get_time()const;
253
254        //! Changes the current time to the next keyframe
255        void jump_to_next_keyframe();
256
257        //! Changes the current time to the next keyframe
258        void jump_to_prev_keyframe();
259
260        void seek_frame(int frames);
261
262        void seek_time(synfig::Time time);
263
264        //! \writeme
265        void refresh_current_values();
266
267        //! Sets the current editing mode
268        /*! \see Mode */
269        void set_mode(Mode x);
270
271        //! Retrieves the current editing mode
272        /*! \see Mode */
273        Mode get_mode()const;
274
275        //! Applies initial param values for \c layer
276        /*! canvas property of layer should be set before call */
277        void apply_layer_param_defaults(synfig::Layer::Handle layer);
278
279        //! Creates a new layer, of type \c id at the top of the layer stack
280        // synfig::Layer::Handle add_layer(synfig::String id) { return add_layer_to(id,get_canvas()); }
281
282        synfig::Layer::Handle add_layer_to(synfig::String id,synfig::Canvas::Handle canvas, int depth=0);
283
284        bool convert(ValueDesc value_desc, synfig::String type);
285        //! Adds the given ValueNode to the canvas.
286        bool add_value_node(synfig::ValueNode::Handle value_node, synfig::String name);
287
288
289        Action::ParamList generate_param_list(const synfigapp::ValueDesc &);
290
291        Action::ParamList generate_param_list(const std::list<synfigapp::ValueDesc> &);
292
293        void set_rend_desc(const synfig::RendDesc &rend_desc);
294
295        bool import(const synfig::String &filename, synfig::String &errors, synfig::String &warnings, bool resize_image=false);
296
297
298        void waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
299        void waypoint_duplicate(synfig::ValueNode::Handle value_node,synfig::Waypoint waypoint);
300
301        void waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
302        void waypoint_remove(synfig::ValueNode::Handle value_node,synfig::Waypoint waypoint);
303
304        bool change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value,bool lock_animation = false);
305
306
307        int find_important_value_descs(std::vector<synfigapp::ValueDesc>& out);
308        static int find_important_value_descs(synfig::Canvas::Handle canvas,std::vector<synfigapp::ValueDesc>& out,synfig::GUIDSet& guid_set);
309
310        ~CanvasInterface();
311
312        static etl::handle<CanvasInterface> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
313}; // END of class CanvasInterface
314
315/*!     \class PushMode
316**      \brief Class that changes the mode of a CanvasInterface, and restores it on destruction.
317*/
318class PushMode
319{
320        CanvasInterface* canvas_interface_;
321        CanvasInterface::Mode old_mode_;
322public:
323        PushMode(etl::loose_handle<CanvasInterface> c, CanvasInterface::Mode mode):
324                canvas_interface_(c.get()), old_mode_(canvas_interface_->get_mode())
325        { canvas_interface_->set_mode(mode); }
326
327        ~PushMode() { canvas_interface_->set_mode(old_mode_); }
328}; // END of class PushMode
329
330}; // END of namespace synfigapp
331
332/* === E N D =============================================================== */
333
334#endif
Note: See TracBrowser for help on using the repository browser.