synfig-core  1.0.3
canvas.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_CANVAS_H
27 #define __SYNFIG_CANVAS_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include <map>
32 #include <list>
33 #include <ETL/handle>
34 #include <sigc++/signal.h>
35 #include <sigc++/connection.h>
36 
37 #include "vector.h"
38 #include "string.h"
39 #include "canvasbase.h"
40 #include "valuenode.h"
41 #include "keyframe.h"
42 #include "renddesc.h"
43 #include "node.h"
44 #include "guid.h"
45 #include "filesystem.h"
46 
47 /* === M A C R O S ========================================================= */
48 
49 /* version change history:
50  *
51  * 0.1: the original version
52  *
53  * if a waypoint goes from -179 to 179 degrees, that is a 2
54  * degree change. there's no way to express a 720 degree
55  * rotation with a single pair of waypoints
56  *
57  * 0.2: svn r1227
58  *
59  * angles no longer wrap at -180 degrees back to 180 degrees; if
60  * a waypoint goes from -179 to 179 degrees, that is a rotation
61  * of 358 degrees. loading a version 0.1 canvas will modify
62  * constant angle waypoints to that they are within 180 degrees
63  * of the previous waypoint's value
64  *
65  * the 'straight' blend method didn't used to work properly. it
66  * didn't work at all on transparent pixels in layers other than
67  * the PasteCanvas layer. for example, the examples/japan.sifz
68  * file has a red circle (straight, amount=1.0) on top of a
69  * striped conical gradient. if 'straight' was working, the
70  * conical gradient would be entirely obscured by the circle
71  * layer (even by its transparent pixels)
72  *
73  * 0.3: svn r1422
74  *
75  * the 'straight' blend method was fixed. loading a version 0.2
76  * or older canvas will replace the 'straight' blend method in
77  * non-pastecanvas layers with 'composite', unless they're
78  * completely transparent, in which case it will replace them
79  * with an 'alpha over' blend instead. Images like
80  * examples/logo.sifz use transparent straight blends to do
81  * masking, which no longer works now that 'straight' blending is
82  * fixed.
83  *
84  * Tangent lengths calculated by the "Segment Tangent" and "BLine
85  * Tangent" ValueNodes were scaled by a factor of 0.5.
86  *
87  * 0.4: svn r1856
88  *
89  * Stop scaling tangents by 0.5.
90  *
91  * 0.5: svn r1863
92  *
93  * Added "offset", "scale", and "fixed_length" links to the
94  * "BLine Tangent" ValueNode.
95  *
96  * 0.6: svn r2067
97  *
98  * Added "scale" link to the "BLine Width" ValueNode in svn r1872.
99  *
100  * Added "loop" link to the "Gradient Color" ValueNode in svn r1901.
101  *
102  * 0.7: svn r2315
103  *
104  * Added "loop" link to the "Random" ValueNode in svn r2315.
105  *
106  * 0.8: git 82baee2702a65a9866f3dc4a28ef163dcf43795a
107  *
108  * Added "homogenous" link to "BLineCalcVertex", "BLineCalcTangent"
109  * and "BLineCalcWidth" valuenodes.
110  *
111  * 0.9: git 6922776b8129fdae6cb42953b2715decc810786c
112  *
113  * Added "split_radius" and "split_angle" to BLinePoint Composite
114  * Value Node
115  *
116  * 1.0 git
117  *
118  * Added a canvas component called
119  */
120 
121 #define CURRENT_CANVAS_VERSION "1.0"
122 
123 /* === T Y P E D E F S ===================================================== */
124 
125 /* === C L A S S E S & S T R U C T S ======================================= */
126 
127 namespace synfig {
128 
129 class IndependentContext;
130 class ContextParams;
131 class Context;
132 class GUID;
133 class Canvas;
135 
136 typedef etl::handle<Canvas> CanvasHandle;
137 
140 void optimize_layers(Time, Context, CanvasHandle, bool seen_motion_blur=false);
141 
150 class Canvas : public CanvasBase, public Node
151 {
152  /*
153  -- ** -- T Y P E S -----------------------------------------------------------
154  */
155 
156 public:
157  typedef etl::handle<Canvas> Handle;
158  typedef etl::loose_handle<Canvas> LooseHandle;
159  typedef etl::handle<const Canvas> ConstHandle;
160 
161  typedef std::list<Handle> Children;
162 
163  friend void synfig::optimize_layers(Time, Context, Canvas::Handle, bool seen_motion_blur);
164 
165  /*
166  -- ** -- D A T A -------------------------------------------------------------
167  */
168 
169 private:
170 
172 
173  String id_;
174 
176 
177  String name_;
178 
180 
181  String description_;
182 
184 
185  String version_;
186 
188 
189  String author_;
190 
192 
193  String email_;
194 
196 
197  String file_name_;
198 
200 
201  FileSystem::Identifier identifier_;
202 
204 
205  std::map<String, String> meta_data_;
206 
208 
209  ValueNodeList value_node_list_;
210 
212 
213  KeyframeList keyframe_list_;
214 
216 
219  LooseHandle parent_;
220 
222 
223  Children children_;
224 
226 
227  RendDesc desc_;
228 
230  Time cur_time_;
231 
233  mutable std::map<String,Handle> externals_;
234 
236  bool is_inline_;
237 
239  mutable bool is_dirty_;
240 
242  bool op_flag_;
243 
245  std::map<String,std::set<etl::handle<Layer> > > group_db_;
246 
248  std::map<etl::loose_handle<Layer>,std::vector<sigc::connection> > connections_;
249 
251 
252  Real grow_value;
253 
254 
255  /*
256  -- ** -- S I G N A L S -------------------------------------------------------
257  */
258 
259 private:
260 
262  sigc::signal<void,String> signal_group_added_;
263 
265  sigc::signal<void,String> signal_group_removed_;
266 
268  sigc::signal<void,String> signal_group_changed_;
269 
270  sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_added_;
271  sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_removed_;
272 
274  sigc::signal<void,int*> signal_layers_reordered_;
275 
277  sigc::signal<void> signal_rend_desc_changed_;
278 
280  sigc::signal<void> signal_id_changed_;
281 
283  //sigc::signal<void> signal_dirty_;
284 
286  sigc::signal<void> signal_file_name_changed_;
287 
289  sigc::signal<void, String> signal_meta_data_changed_;
290 
292  std::map<String, sigc::signal<void> > signal_map_meta_data_changed_;
293 
294 
296  sigc::signal<void, etl::handle<ValueNode> > signal_value_node_changed_;
298  sigc::signal<void, etl::handle<ValueNode> > signal_value_node_renamed_;
300  sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_added_;
302  sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_removed_;
303 
304  /*
305  -- ** -- S I G N A L I N T E R F A C E -------------------------------------
306  */
307 
308 public:
309 
310  sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_added() { return signal_group_pair_added_; }
311  sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_removed() { return signal_group_pair_removed_; }
312 
314  sigc::signal<void,String>& signal_group_added() { return signal_group_added_; }
315 
317  sigc::signal<void,String>& signal_group_removed() { return signal_group_removed_; }
318 
320  sigc::signal<void,String>& signal_group_changed() { return signal_group_changed_; }
321 
323  sigc::signal<void,int*>& signal_layers_reordered() { return signal_layers_reordered_; }
324 
326  sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
327 
329  sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
330 
332  sigc::signal<void>& signal_file_name_changed();
333 
335  sigc::signal<void, String>& signal_meta_data_changed() { return signal_meta_data_changed_; }
336 
338  sigc::signal<void>& signal_meta_data_changed(const String& key) { return signal_map_meta_data_changed_[key]; }
339 
341  sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; }
343  sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_renamed() { return signal_value_node_renamed_; }
344 
346  sigc::signal<void>& signal_dirty() { return signal_changed(); }
347 
349  sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_added() { return signal_value_node_child_added_; }
350 
352  sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_removed() { return signal_value_node_child_removed_; }
353 
354  void invoke_signal_value_node_child_removed(etl::handle<ValueNode>, etl::handle<ValueNode>);
355 
356  /*
357  -- ** -- C O N S T R U C T O R S ---------------------------------------------
358  */
359 
360 protected:
362  Canvas(const String &name);
363 
364 public:
365 
366  ~Canvas();
367 
368  /*
369  -- ** -- M E M B E R F U N C T I O N S -------------------------------------
370  */
371 
372 public:
373 
375  std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
376 
378  std::set<String> get_groups()const;
379 
381  int get_group_count()const;
382 
384  void rename_group(const String&old_name,const String&new_name);
385 
387  bool is_inline()const { return is_inline_; }
388 
390  RendDesc &rend_desc() { return desc_; }
391 
393  const RendDesc &rend_desc()const { return desc_; }
394 
396  const String & get_name()const { return name_; }
397 
399  void set_name(const String &x);
400 
402  const String get_version()const { return version_; }
403 
405  void set_version(const String &x) { version_ = x; }
406 
408  const String & get_author()const { return author_; }
409 
411  void set_author(const String &x);
412 
414  const String & get_description()const { return description_; }
415 
416  String get_string()const;
417 
419  void set_description(const String &x);
420 
422  const String & get_id()const { return id_; }
423 
425  void set_id(const String &x);
426 
428  String get_meta_data(const String& key)const;
429 
431  std::list<String> get_meta_data_keys()const;
432 
434  void set_meta_data(const String& key, const String& data);
435 
437  void erase_meta_data(const String& key);
438 
440  String get_relative_id(etl::loose_handle<const Canvas> x)const;
441 
443  String _get_relative_id(etl::loose_handle<const Canvas> x)const;
444 
446  bool is_root()const { return !parent_; }
447 
449 
450  LooseHandle parent()const { return parent_; }
451 
453  LooseHandle get_root()const;
454 
456 
458  std::list<Handle> &children() { return children_; }
459 
461  const std::list<Handle> &children()const { return children_; }
462 
464  //Color get_color(const Point &pos)const;
465 
467  void set_time(Time t)const;
468 
470  Time get_time()const { return cur_time_; }
471 
473  int size()const;
474 
476  void clear();
477 
479  bool empty()const;
480 
482  // ValueNodeList &value_node_list() { return value_node_list_; }
483 
485  const ValueNodeList &value_node_list()const;
486 
489 
491  const KeyframeList &keyframe_list()const;
492 
494 
497  ValueNode::Handle find_value_node(const String &id, bool might_fail);
498 
501 
503 
506  ValueNode::ConstHandle find_value_node(const String &id, bool might_fail)const;
507 
509 
511 
512  void add_value_node(ValueNode::Handle x, const String &id);
513 
515  //void rename_value_node(ValueNode::Handle x, const String &id);
516 
518  void remove_value_node(ValueNode::Handle x, bool might_fail);
519 
521  void remove_value_node(const String &id, bool might_fail) { remove_value_node(find_value_node(id, might_fail), might_fail); }
522 
524 
528  Handle surefind_canvas(const String &id,String &warnings);
529 
531 
534  Handle find_canvas(const String &id, String &warnings);
535 
537 
540  ConstHandle find_canvas(const String &id, String &warnings)const;
541 
543  //void set_file_path(const String &);
544 
546  String get_file_path()const;
547 
549  void set_file_name(const String &);
550 
552  String get_file_name()const;
553 
556 
559 
562 
564  Handle new_child_canvas(const String &id);
565 
567  Handle add_child_canvas(Handle child_canvas, const String &id);
568 
571  void remove_child_canvas(Handle child_canvas);
572 
575  etl::handle<Layer> find_layer(const ContextParams &context_params, const Point &pos);
576 
578  int get_depth(etl::handle<Layer>)const;
579 
582 
584  Context get_context(const ContextParams &params)const;
585 
587  Context get_context(const Context &parent_context)const;
588 
590 
592  iterator end();
594 
596  const_iterator end()const;
598 
600  reverse_iterator rbegin();
602 
604  const_reverse_iterator rbegin()const;
606  etl::handle<Layer> &back();
608  const etl::handle<Layer> &back()const;
611  void push_back(etl::handle<Layer> x);
613  void push_front(etl::handle<Layer> x);
617  void push_back_simple(etl::handle<Layer> x);
620  void insert(iterator iter,etl::handle<Layer> x);
624  void erase(iterator iter);
630  static Handle create();
633 
635  Handle clone(const GUID& deriv_guid=GUID(), bool for_export=false)const;
636 
638  void register_external_canvas(String file, Handle canvas);
640  Real get_grow_value()const;
641  void set_grow_value(Real x);
642 
643 #if 0
644  void show_canvas_ancestry(String file, int line, String note)const;
645  void show_canvas_ancestry()const;
646 #endif
647 
648 #ifdef _DEBUG
649  void show_externals(String file, int line, String text) const;
650  void show_structure(int i) const;
651 #endif // _DEBUG
652 
653 private:
656  void add_group_pair(String group, etl::handle<Layer> layer);
659  void remove_group_pair(String group, etl::handle<Layer> layer);
662  void add_connection(etl::loose_handle<Layer> layer, sigc::connection connection);
665  void disconnect_connections(etl::loose_handle<Layer> layer);
666 
667 protected:
669  virtual void on_changed();
673  virtual void get_times_vfunc(Node::time_set &set) const;
674 
675 public:
676  void fill_sound_processor(SoundProcessor &soundProcessor) const;
677 }; // END of class Canvas
678 
679 }; // END of namespace synfig
680 
681 /* === E N D =============================================================== */
682 
683 #endif