1 /* === S Y N F I G ========================================================= */
3 ** \brief Canvas Class Implementation
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_CANVAS_H
27 #define __SYNFIG_CANVAS_H
29 /* === H E A D E R S ======================================================= */
34 #include <sigc++/signal.h>
35 #include <sigc++/connection.h>
39 #include "canvasbase.h"
40 #include "valuenode.h"
46 /* === M A C R O S ========================================================= */
48 /* version change history:
50 * 0.1: the original version
52 * if a waypoint goes from -179 to 179 degrees, that is a 2
53 * degree change. there's no way to express a 720 degree
54 * rotation with a single pair of waypoints
58 * angles no longer wrap at -180 degrees back to 180 degrees; if
59 * a waypoint goes from -179 to 179 degrees, that is a rotation
60 * of 358 degrees. loading a version 0.1 canvas will modify
61 * constant angle waypoints to that they are within 180 degrees
62 * of the previous waypoint's value
64 * the 'straight' blend method didn't used to work properly. it
65 * didn't work at all on transparent pixels in layers other than
66 * the PasteCanvas layer. for example, the examples/japan.sifz
67 * file has a red circle (straight, amount=1.0) on top of a
68 * striped conical gradient. if 'straight' was working, the
69 * conical gradient would be entirely obscured by the circle
70 * layer (even by its transparent pixels)
74 * the 'straight' blend method was fixed. loading a version 0.2
75 * or older canvas will replace the 'straight' blend method in
76 * non-pastecanvas layers with 'composite', unless they're
77 * completely transparent, in which case it will replace them
78 * with an 'alpha over' blend instead. Images like
79 * examples/logo.sifz use transparent straight blends to do
80 * masking, which no longer works now that 'straight' blending is
83 * Tangent lengths calculated by the "Segment Tangent" and "BLine
84 * Tangent" ValueNodes were scaled by a factor of 0.5.
88 * Stop scaling tangents by 0.5.
91 #define CURRENT_CANVAS_VERSION "0.4"
93 /* === T Y P E D E F S ===================================================== */
95 /* === C L A S S E S & S T R U C T S ======================================= */
105 class Canvas : public CanvasBase, public Node
108 -- ** -- T Y P E S -----------------------------------------------------------
112 typedef etl::handle<Canvas> Handle;
113 typedef etl::loose_handle<Canvas> LooseHandle;
114 typedef etl::handle<const Canvas> ConstHandle;
116 typedef std::list<Handle> Children;
118 friend void synfig::optimize_layers(Time, Context, Canvas::Handle, bool seen_motion_blur);
121 -- ** -- D A T A -------------------------------------------------------------
126 //! Contains the ID string for the Canvas
127 /*! \see get_id(), set_id() */
130 //! Contains the name of the Canvas
131 /*! \see set_name(), get_name() */
134 //! Contains a description of the Canvas
135 /*! \see set_description(), get_description() */
138 //! Contains the canvas' version string
139 /*! \see set_version(), get_version() */
142 //! Contains the author's name
143 /*! \see set_author(), get_author() */
146 //! Contains the author's email address
147 /*! \todo This private parameter has no binding, so it's unusable at the moment */
150 //! File name of Canvas
151 /*! \see get_file_name(), set_file_name() */
154 //! Metadata map for Canvas.
155 /*! \see get_meta_data(), set_meta_data(), erase_meta_data() */
156 std::map<String, String> meta_data_;
158 //! Contains a list of ValueNodes that are in this Canvas
159 /*! \see value_node_list(), find_value_node() */
160 ValueNodeList value_node_list_;
163 KeyframeList keyframe_list_;
165 //! A handle to the parent canvas of this canvas.
166 /*! If canvas is a root canvas, then this handle is empty
171 //! List containing any child Canvases
172 /*! \see children() */
175 //! Render Description for Canvas
176 /*! \see rend_desc() */
179 //! Contains the value of the last call to set_time()
183 mutable std::map<String,Handle> externals_;
185 //! This flag is set if this canvas is "inline"
188 mutable bool is_dirty_;
192 //! Layer Group database
193 std::map<String,std::set<etl::handle<Layer> > > group_db_;
195 //! Layer Connection database
196 std::map<etl::loose_handle<Layer>,std::vector<sigc::connection> > connections_;
199 -- ** -- S I G N A L S -------------------------------------------------------
205 sigc::signal<void,String> signal_group_added_;
208 sigc::signal<void,String> signal_group_removed_;
211 sigc::signal<void,String> signal_group_changed_;
213 sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_added_;
214 sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_removed_;
217 sigc::signal<void,int*> signal_layers_reordered_;
220 sigc::signal<void> signal_rend_desc_changed_;
223 sigc::signal<void> signal_id_changed_;
226 //sigc::signal<void> signal_dirty_;
229 sigc::signal<void> signal_file_name_changed_;
232 sigc::signal<void, String> signal_meta_data_changed_;
234 //! Key-Specific meta data changed signals
235 std::map<String, sigc::signal<void> > signal_map_meta_data_changed_;
238 //! ValueBasenode Changed
239 sigc::signal<void, etl::handle<ValueNode> > signal_value_node_changed_;
241 sigc::signal<void, etl::handle<ValueNode> > signal_value_node_renamed_;
243 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_added_;
245 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_removed_;
248 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
253 sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_added() { return signal_group_pair_added_; }
254 sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_removed() { return signal_group_pair_removed_; }
257 sigc::signal<void,String>& signal_group_added() { return signal_group_added_; }
260 sigc::signal<void,String>& signal_group_removed() { return signal_group_removed_; }
263 sigc::signal<void,String>& signal_group_changed() { return signal_group_changed_; }
266 sigc::signal<void,int*>& signal_layers_reordered() { return signal_layers_reordered_; }
269 sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
272 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
274 //! File name Changed
275 sigc::signal<void>& signal_file_name_changed();
278 sigc::signal<void, String>& signal_meta_data_changed() { return signal_meta_data_changed_; }
281 sigc::signal<void>& signal_meta_data_changed(const String& key) { return signal_map_meta_data_changed_[key]; }
284 sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; }
286 sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_renamed() { return signal_value_node_renamed_; }
289 sigc::signal<void>& signal_dirty() { return signal_changed(); }
292 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_added() { return signal_value_node_child_added_; }
295 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_removed() { return signal_value_node_child_removed_; }
298 -- ** -- C O N S T R U C T O R S ---------------------------------------------
303 Canvas(const String &name);
310 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
315 //! Returns the set of layers in group
316 std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
318 //! Gets all the groups
319 std::set<String> get_groups()const;
321 //! Gets the number of groups in this canvas
322 int get_group_count()const;
324 //! Renames the given group
325 void rename_group(const String&old_name,const String&new_name);
328 bool is_inline()const { return is_inline_; }
330 //! Returns a handle to the RendDesc for this Canvas
331 RendDesc &rend_desc() { return desc_; }
333 //! Returns a handle to the RendDesc for this Canvas
334 const RendDesc &rend_desc()const { return desc_; }
336 //! Gets the name of the canvas
337 const String & get_name()const { return name_; }
339 //! Sets the name of the canvas
340 void set_name(const String &x);
342 //! Gets the version string of the canvas
343 const String get_version()const { return version_; }
345 //! Sets the version string of the canvas
346 void set_version(const String &x) { version_ = x; }
348 //! Gets the author of the canvas
349 const String & get_author()const { return author_; }
351 //! Sets the author of the canvas
352 void set_author(const String &x);
354 //! Gets the description of the canvas
355 const String & get_description()const { return description_; }
357 //! Sets the name of the canvas
358 void set_description(const String &x);
360 //! Gets the ID of the canvas
361 const String & get_id()const { return id_; }
363 //! Sets the ID of the canvas
364 void set_id(const String &x);
366 //! Returns the data string for the given meta data key
367 String get_meta_data(const String& key)const;
369 //! Returns a list of meta data keys
370 std::list<String> get_meta_data_keys()const;
372 //! Sets a meta data key to a specific string
373 void set_meta_data(const String& key, const String& data);
375 //! Removes a meta data key
376 void erase_meta_data(const String& key);
379 String get_relative_id(etl::loose_handle<const Canvas> x)const;
381 //! \internal \writeme
382 String _get_relative_id(etl::loose_handle<const Canvas> x)const;
384 //! Returns \c true if the Canvas is a root Canvas. \c false otherwise
385 bool is_root()const { return !parent_; }
387 //! Returns a handle to the parent Canvas.
388 /*! The returned handle will be empty if this is a root canvas */
389 LooseHandle parent()const { return parent_; }
391 LooseHandle get_root()const;
393 //! Returns a list of all child canvases in this canvas
394 std::list<Handle> &children() { return children_; }
396 //! Returns a list of all child canvases in this canvas
397 const std::list<Handle> &children()const { return children_; }
399 //! Gets the color at the specified point
400 //Color get_color(const Point &pos)const;
402 //! Sets the time for all the layers in the canvas
403 void set_time(Time t)const;
406 Time get_time()const { return cur_time_; }
408 //! Returns the number of layers in the canvas
411 //! Removes all the layers from the canvas
414 //! Returns true if the canvas has no layers
417 //! Returns a reference to the ValueNodeList for this Canvas
418 // ValueNodeList &value_node_list() { return value_node_list_; }
420 //! Returns a reference to the ValueNodeList for this Canvas
421 const ValueNodeList &value_node_list()const;
423 //! Returns a reference to the KeyframeList for this Canvas
424 KeyframeList &keyframe_list();
426 //! Returns a reference to the KeyframeList for this Canvas
427 const KeyframeList &keyframe_list()const;
429 //! Finds the ValueNode in the Canvas with the given \a id
430 /*! \return If found, returns a handle to the ValueNode.
431 ** Otherwise, returns an empty handle.
433 ValueNode::Handle find_value_node(const String &id);
435 //! \internal \writeme
436 ValueNode::Handle surefind_value_node(const String &id);
438 //! Finds the ValueNode in the Canvas with the given \a id
439 /*! \return If found, returns a handle to the ValueNode.
440 ** Otherwise, returns an empty handle.
442 ValueNode::ConstHandle find_value_node(const String &id)const;
445 void add_value_node(ValueNode::Handle x, const String &id);
448 //void rename_value_node(ValueNode::Handle x, const String &id);
451 void remove_value_node(ValueNode::Handle x);
454 void remove_value_node(const String &id) { remove_value_node(find_value_node(id)); }
456 //! Finds a child Canvas in the Canvas with the given \a name
457 /*! \return If found, returns a handle to the child Canvas.
458 ** If not found, it creates a new Canvas and returns it
459 ** If an error occurs, it returns an empty handle
461 Handle surefind_canvas(const String &id);
463 //! Finds a child Canvas in the Canvas with the given \a id
464 /*! \return If found, returns a handle to the child Canvas.
465 ** Otherwise, returns an empty handle.
467 Handle find_canvas(const String &id);
469 //! Finds a child Canvas in the Canvas with the given \a id
470 /*! \return If found, returns a handle to the child Canvas.
471 ** Otherwise, returns an empty handle.
473 ConstHandle find_canvas(const String &id)const;
475 //! Sets the file path for the Canvas
476 //void set_file_path(const String &);
478 //! Returns the file path from the file name
479 String get_file_path()const;
481 //! Sets the filename (with path)
482 void set_file_name(const String &);
484 //! Gets the filename (with path)
485 String get_file_name()const;
487 //! Creates a new child canvas, and returns its handle
488 Handle new_child_canvas();
490 //! Creates a new child canvas with an ID of \a id, and returns its handle
491 Handle new_child_canvas(const String &id);
493 //! Adds the given canvas as a child
494 Handle add_child_canvas(Handle child_canvas, const String &id);
496 void remove_child_canvas(Handle child_canvas);
498 etl::handle<Layer> find_layer(const Point &pos);
500 int get_depth(etl::handle<Layer>)const;
502 Context get_context()const;
506 const_iterator end()const;
508 reverse_iterator rbegin();
510 const_reverse_iterator rbegin()const;
512 etl::handle<Layer> &back();
514 void push_back(etl::handle<Layer> x);
516 void push_front(etl::handle<Layer> x);
518 void push_back_simple(etl::handle<Layer> x);
520 void insert(iterator iter,etl::handle<Layer> x);
521 void erase(iterator iter);
523 const etl::handle<Layer> &back()const;
525 void set_inline(LooseHandle parent);
527 static Handle create();
529 static Handle create_inline(Handle parent);
531 Handle clone(const GUID& deriv_guid=GUID())const;
534 void add_group_pair(String group, etl::handle<Layer> layer);
535 void remove_group_pair(String group, etl::handle<Layer> layer);
536 void add_connection(etl::loose_handle<Layer> layer, sigc::connection connection);
537 void disconnect_connections(etl::loose_handle<Layer> layer);
540 virtual void on_changed();
541 virtual void get_times_vfunc(Node::time_set &set) const;
542 }; // END of class Canvas
544 void optimize_layers(Time time, Context context, Canvas::Handle op_canvas, bool seen_motion_blur=false);
547 }; // END of namespace synfig
549 /* === E N D =============================================================== */