synfig-studio  1.0.3
canvasinterface.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
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++/signal.h>
34 #include <sigc++/object.h>
35 #include <list>
36 #include "selectionmanager.h"
37 #include "uimanager.h"
38 #include "value_desc.h"
39 #include "editmode.h"
40 
41 /* === M A C R O S ========================================================= */
42 
43 /* === T Y P E D E F S ===================================================== */
44 
45 /* === C L A S S E S & S T R U C T S ======================================= */
46 
47 namespace synfig { class ValueNode_DynamicList; class Waypoint; class GUIDSet; class Canvas; };
48 
49 namespace synfigapp {
50 
51 namespace Action { class ParamList; class Param; class EditModeSet; };
52 
53 class Instance;
54 class ValueDesc;
55 
56 class CanvasInterface : public etl::shared_object, public sigc::trackable
57 {
58  friend class Instance;
59  friend class Action::EditModeSet;
60 
61 public:
62 
63  typedef EditMode Mode;
64 
65 private:
66  // Constructor is private to force the use of the "create()" constructor.
67  CanvasInterface(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
68 
69 private:
70  etl::loose_handle<Instance> instance_;
71  etl::handle<synfig::Canvas> canvas_;
72  etl::handle<SelectionManager> selection_manager_;
73  etl::handle<UIInterface> ui_interface_;
74  synfig::Time cur_time_;
75  Mode mode_;
76 
77  sigc::signal<void,synfig::Layer::Handle> signal_layer_raised_;
78  sigc::signal<void,synfig::Layer::Handle> signal_layer_lowered_;
79  sigc::signal<void,synfig::Layer::Handle,int> signal_layer_inserted_;
80  sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle> signal_layer_moved_;
81  sigc::signal<void,synfig::Layer::Handle> signal_layer_removed_;
82  sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_status_changed_;
83  sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_exclude_from_rendering_changed_;
84  sigc::signal<void,synfig::Layer::Handle,bool> signal_layer_z_range_changed_;
85  sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_new_description_;
86  sigc::signal<void,synfig::Canvas::Handle> signal_canvas_added_;
87  sigc::signal<void,synfig::Canvas::Handle> signal_canvas_removed_;
88 
89  sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_added_;
90  sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_deleted_;
91  sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle> signal_value_node_replaced_;
92 
93  sigc::signal<void,synfig::Keyframe> signal_keyframe_added_;
94  sigc::signal<void,synfig::Keyframe> signal_keyframe_removed_;
95  sigc::signal<void,synfig::Keyframe> signal_keyframe_changed_;
96  sigc::signal<void,synfig::Keyframe,void*> signal_keyframe_selected_;
97  sigc::signal<void> signal_keyframe_properties_;
98 
99  sigc::signal<void> signal_id_changed_;
100 
101  sigc::signal<void> signal_time_changed_;
102 
103  sigc::signal<void> signal_rend_desc_changed_;
104 
105  sigc::signal<void,Mode> signal_mode_changed_;
106 
107  //sigc::signal<void> signal_dirty_preview_;
108 
109  sigc::signal<void,synfig::Layer::Handle,synfig::String> signal_layer_param_changed_;
110 
111 public: // Signal Interface
112 
113  sigc::signal<void,synfig::Layer::Handle,int,synfig::Canvas::Handle>& signal_layer_moved() { return signal_layer_moved_; }
114 
115  sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_new_description() { return signal_layer_new_description_; }
116 
118  sigc::signal<void,synfig::Layer::Handle>& signal_layer_raised() { return signal_layer_raised_; }
119 
121  sigc::signal<void,synfig::Layer::Handle>& signal_layer_lowered() { return signal_layer_lowered_; }
122 
124  sigc::signal<void,synfig::Layer::Handle,int>& signal_layer_inserted() { return signal_layer_inserted_; }
125 
127  sigc::signal<void,synfig::Layer::Handle>& signal_layer_removed() { return signal_layer_removed_; }
128 
130  sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_status_changed() { return signal_layer_status_changed_; }
131 
133  sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_exclude_from_rendering_changed() { return signal_layer_exclude_from_rendering_changed_; }
134 
136  sigc::signal<void,synfig::Layer::Handle,bool>& signal_layer_z_range_changed() { return signal_layer_z_range_changed_; }
137 
139  sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_added() { return signal_canvas_added_; }
140 
142  sigc::signal<void,etl::handle<synfig::Canvas> >& signal_canvas_removed() { return signal_canvas_removed_; }
143 
145  sigc::signal<void,synfig::Layer::Handle,synfig::String>& signal_layer_param_changed() { return signal_layer_param_changed_; }
146 
148  //sigc::signal<void>& signal_dirty_preview() { return signal_dirty_preview_; }
149  sigc::signal<void>& signal_dirty_preview() { return get_canvas()->signal_dirty(); }
150 
151  sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
152  signal_value_node_child_added() { return get_canvas()->signal_value_node_child_added(); }
153  sigc::signal<void,etl::handle<synfig::ValueNode>,etl::handle<synfig::ValueNode> >&
154  signal_value_node_child_removed() { return get_canvas()->signal_value_node_child_removed(); }
155 
157  sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_added() { return signal_value_node_added_; }
158 
160  sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_deleted() { return signal_value_node_deleted_; }
161 
163  sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_changed() { return get_canvas()->signal_value_node_changed(); }
164 
166  sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_renamed() { return get_canvas()->signal_value_node_renamed(); }
167 
169  sigc::signal<void,Mode> signal_mode_changed() { return signal_mode_changed_; }
170 
172  sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
173 
175  sigc::signal<void> signal_time_changed() { return signal_time_changed_; }
176 
178 
179  sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle>& signal_value_node_replaced()
180  { return signal_value_node_replaced_; }
181 
183  sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
184 
186  sigc::signal<void,synfig::Keyframe>& signal_keyframe_added() { return signal_keyframe_added_; }
188  sigc::signal<void,synfig::Keyframe>& signal_keyframe_removed() { return signal_keyframe_removed_; }
190  sigc::signal<void,synfig::Keyframe>& signal_keyframe_changed() { return signal_keyframe_changed_; }
192 
193  sigc::signal<void,synfig::Keyframe,void*>& signal_keyframe_selected() { return signal_keyframe_selected_; }
195  sigc::signal<void>& signal_keyframe_properties() { return signal_keyframe_properties_; }
196 
197 public:
198 
199  void auto_export(const ValueDesc& value_desc);
200 
201  void auto_export(synfig::ValueNode::Handle value_node);
202 
203  void set_meta_data(const synfig::String& key,const synfig::String& data);
204 
205  void erase_meta_data(const synfig::String& key);
206 
208  void set_selection_manager(const etl::handle<SelectionManager> &sm) { selection_manager_=sm; }
209 
211  void unset_selection_manager() { selection_manager_=new NullSelectionManager(); }
212 
214  const etl::handle<SelectionManager> &get_selection_manager()const { return selection_manager_; }
215 
217  void set_ui_interface(const etl::handle<UIInterface> &uim) { ui_interface_=uim; }
218 
221 
223  const etl::handle<UIInterface> &get_ui_interface() { return ui_interface_; }
224 
226  etl::handle<synfig::Canvas> get_canvas()const { return canvas_; }
227 
229  etl::loose_handle<Instance> get_instance()const { return instance_; }
230 
232  void set_name(const synfig::String &x);
233 
235  void set_description(const synfig::String &x);
236 
238  void set_id(const synfig::String &x);
239 
241  synfig::String get_name()const { return get_canvas()->get_name(); }
242 
244  synfig::String get_description()const { return get_canvas()->get_description(); }
245 
247  synfig::String get_id()const { return get_canvas()->get_id(); }
248 
250  void set_time(synfig::Time x);
251 
253  synfig::Time get_time()const;
254 
256  void jump_to_next_keyframe();
257 
259  void jump_to_prev_keyframe();
260 
261  void seek_frame(int frames);
262 
263  void seek_time(synfig::Time time);
264 
266  void refresh_current_values();
267 
269 
270  void set_mode(Mode x);
271 
273 
274  Mode get_mode()const;
275 
277 
279 
281  // synfig::Layer::Handle add_layer(synfig::String id) { return add_layer_to(id,get_canvas()); }
282 
283  synfig::Layer::Handle add_layer_to(synfig::String id,synfig::Canvas::Handle canvas, int depth=0);
284 
285  bool convert(ValueDesc value_desc, synfig::String type);
287  bool add_value_node(synfig::ValueNode::Handle value_node, synfig::String name);
288 
289 
291 
292  Action::ParamList generate_param_list(const std::list<synfigapp::ValueDesc> &);
293 
294  void set_rend_desc(const synfig::RendDesc &rend_desc);
295 
296  bool import(const synfig::String &filename, synfig::String &errors, synfig::String &warnings, bool resize_image=false);
297 
298 
299  void waypoint_duplicate(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
300  void waypoint_duplicate(synfig::ValueNode::Handle value_node,synfig::Waypoint waypoint);
301 
302  void waypoint_remove(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
303  void waypoint_remove(synfig::ValueNode::Handle value_node,synfig::Waypoint waypoint);
304 
305  bool change_value(synfigapp::ValueDesc value_desc,synfig::ValueBase new_value,bool lock_animation = false);
306 
307 
308  int find_important_value_descs(std::vector<synfigapp::ValueDesc>& out);
309  static int find_important_value_descs(synfig::Canvas::Handle canvas,std::vector<synfigapp::ValueDesc>& out,synfig::GUIDSet& guid_set);
310 
312 
313  static etl::handle<CanvasInterface> create(etl::loose_handle<Instance> instance,etl::handle<synfig::Canvas> canvas);
314 }; // END of class CanvasInterface
315 
319 class PushMode
320 {
321  CanvasInterface* canvas_interface_;
322  CanvasInterface::Mode old_mode_;
323 public:
324  PushMode(etl::loose_handle<CanvasInterface> c, CanvasInterface::Mode mode):
325  canvas_interface_(c.get()), old_mode_(canvas_interface_->get_mode())
326  { canvas_interface_->set_mode(mode); }
327 
328  ~PushMode() { canvas_interface_->set_mode(old_mode_); }
329 }; // END of class PushMode
330 
331 }; // END of namespace synfigapp
332 
333 /* === E N D =============================================================== */
334 
335 #endif