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 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 /* === T Y P E D E F S ===================================================== */
50 /* === C L A S S E S & S T R U C T S ======================================= */
60 class Canvas : public CanvasBase, public Node
63 -- ** -- T Y P E S -----------------------------------------------------------
67 typedef etl::handle<Canvas> Handle;
68 typedef etl::loose_handle<Canvas> LooseHandle;
69 typedef etl::handle<const Canvas> ConstHandle;
71 typedef std::list<Handle> Children;
73 friend void synfig::optimize_layers(Context, Canvas::Handle, bool seen_motion_blur);
76 -- ** -- D A T A -------------------------------------------------------------
81 //! Contains the ID string for the Canvas
82 /*! \see get_id(), set_id() */
85 //! Contains the name of the Canvas
86 /*! \see set_name(), get_name() */
89 //! Contains a description of the Canvas
90 /*! \see set_description(), get_description() */
93 //! Contains the author's name
94 /*! \see set_author(), get_author() */
97 //! Contains the author's email address
98 /*! \todo This private parameter has no binding, so it's unusable at the moment */
101 //! File name of Canvas
102 /*! \see get_file_name(), set_file_name() */
105 //! Metadata map for Canvas.
106 /*! \see get_meta_data(), set_meta_data(), erase_meta_data() */
107 std::map<String, String> meta_data_;
109 //! Contains a list of ValueNodes that are in this Canvas
110 /*! \see value_node_list(), find_value_node() */
111 ValueNodeList value_node_list_;
114 KeyframeList keyframe_list_;
116 //! A handle to the parent canvas of this canvas.
117 /*! If canvas is a root canvas, then this handle is empty
122 //! List containing any child Canvases
123 /*! \see children() */
126 //! Render Description for Canvas
127 /*! \see rend_desc() */
130 //! Contains the value of the last call to set_time()
134 mutable std::map<String,Handle> externals_;
136 //! This flag is set if this canvas is "inline"
139 mutable bool is_dirty_;
143 //! Layer Group database
144 std::map<String,std::set<etl::handle<Layer> > > group_db_;
146 //! Layer Connection database
147 std::map<etl::loose_handle<Layer>,std::vector<sigc::connection> > connections_;
150 -- ** -- S I G N A L S -------------------------------------------------------
156 sigc::signal<void,String> signal_group_added_;
159 sigc::signal<void,String> signal_group_removed_;
162 sigc::signal<void,String> signal_group_changed_;
164 sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_added_;
165 sigc::signal<void,String,etl::handle<synfig::Layer> > signal_group_pair_removed_;
168 sigc::signal<void,int*> signal_layers_reordered_;
171 sigc::signal<void> signal_rend_desc_changed_;
174 sigc::signal<void> signal_id_changed_;
177 //sigc::signal<void> signal_dirty_;
180 sigc::signal<void> signal_file_name_changed_;
183 sigc::signal<void, String> signal_meta_data_changed_;
185 //! Key-Specific meta data changed signals
186 std::map<String, sigc::signal<void> > signal_map_meta_data_changed_;
189 //! ValueBasenode Changed
190 sigc::signal<void, etl::handle<ValueNode> > signal_value_node_changed_;
192 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_added_;
194 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> > signal_value_node_child_removed_;
197 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
202 sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_added() { return signal_group_pair_added_; }
203 sigc::signal<void,String,etl::handle<synfig::Layer> >& signal_group_pair_removed() { return signal_group_pair_removed_; }
206 sigc::signal<void,String>& signal_group_added() { return signal_group_added_; }
209 sigc::signal<void,String>& signal_group_removed() { return signal_group_removed_; }
212 sigc::signal<void,String>& signal_group_changed() { return signal_group_changed_; }
215 sigc::signal<void,int*>& signal_layers_reordered() { return signal_layers_reordered_; }
218 sigc::signal<void>& signal_rend_desc_changed() { return signal_rend_desc_changed_; }
221 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
223 //! File name Changed
224 sigc::signal<void>& signal_file_name_changed();
227 sigc::signal<void, String>& signal_meta_data_changed() { return signal_meta_data_changed_; }
230 sigc::signal<void>& signal_meta_data_changed(const String& key) { return signal_map_meta_data_changed_[key]; }
233 sigc::signal<void, etl::handle<ValueNode> >& signal_value_node_changed() { return signal_value_node_changed_; }
236 sigc::signal<void>& signal_dirty() { return signal_changed(); }
239 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_added() { return signal_value_node_child_added_; }
242 sigc::signal<void, etl::handle<ValueNode>, etl::handle<ValueNode> >& signal_value_node_child_removed() { return signal_value_node_child_removed_; }
245 -- ** -- C O N S T R U C T O R S ---------------------------------------------
250 Canvas(const String &name);
257 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
262 //! Returns the set of layers in group
263 std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
265 //! Gets all the groups
266 std::set<String> get_groups()const;
268 //! Gets the number of groups in this canvas
269 int get_group_count()const;
271 //! Renames the given group
272 void rename_group(const String&old_name,const String&new_name);
275 bool is_inline()const { return is_inline_; }
277 //! Returns a handle to the RendDesc for this Canvas
278 RendDesc &rend_desc() { return desc_; }
280 //! Returns a handle to the RendDesc for this Canvas
281 const RendDesc &rend_desc()const { return desc_; }
283 //! Gets the name of the canvas
284 const String & get_name()const { return name_; }
286 //! Sets the name of the canvas
287 void set_name(const String &x);
289 //! Gets the author of the canvas
290 const String & get_author()const { return author_; }
292 //! Sets the author of the canvas
293 void set_author(const String &x);
295 //! Gets the description of the canvas
296 const String & get_description()const { return description_; }
298 //! Sets the name of the canvas
299 void set_description(const String &x);
301 //! Gets the ID of the canvas
302 const String & get_id()const { return id_; }
304 //! Sets the ID of the canvas
305 void set_id(const String &x);
307 //! Returns the data string for the given meta data key
308 String get_meta_data(const String& key)const;
310 //! Returns a list of meta data keys
311 std::list<String> get_meta_data_keys()const;
313 //! Sets a meta data key to a specific string
314 void set_meta_data(const String& key, const String& data);
316 //! Removes a meta data key
317 void erase_meta_data(const String& key);
320 String get_relative_id(etl::loose_handle<const Canvas> x)const;
322 //! \internal \writeme
323 String _get_relative_id(etl::loose_handle<const Canvas> x)const;
325 //! Returns \c true if the Canvas is a root Canvas. \c false otherwise
326 bool is_root()const { return !parent_; }
328 //! Returns a handle to the parent Canvas.
329 /*! The returned handle will be empty if this is a root canvas */
330 LooseHandle parent()const { return parent_; }
332 LooseHandle get_root()const;
334 //! Returns a list of all child canvases in this canvas
335 std::list<Handle> &children() { return children_; }
337 //! Returns a list of all child canvases in this canvas
338 const std::list<Handle> &children()const { return children_; }
340 //! Gets the color at the specified point
341 //Color get_color(const Point &pos)const;
343 //! Sets the time for all the layers in the canvas
344 void set_time(Time t)const;
347 Time get_time()const { return cur_time_; }
349 //! Returns the number of layers in the canvas
352 //! Removes all the layers from the canvas
355 //! Returns true if the canvas has no layers
358 //! Returns a reference to the ValueNodeList for this Canvas
359 // ValueNodeList &value_node_list() { return value_node_list_; }
361 //! Returns a reference to the ValueNodeList for this Canvas
362 const ValueNodeList &value_node_list()const;
364 //! Returns a reference to the KeyframeList for this Canvas
365 KeyframeList &keyframe_list();
367 //! Returns a reference to the KeyframeList for this Canvas
368 const KeyframeList &keyframe_list()const;
370 //! Finds the ValueNode in the Canvas with the given \a id
371 /*! \return If found, returns a handle to the ValueNode.
372 ** Otherwise, returns an empty handle.
374 ValueNode::Handle find_value_node(const String &id);
376 //! \internal \writeme
377 ValueNode::Handle surefind_value_node(const String &id);
379 //! Finds the ValueNode in the Canvas with the given \a id
380 /*! \return If found, returns a handle to the ValueNode.
381 ** Otherwise, returns an empty handle.
383 ValueNode::ConstHandle find_value_node(const String &id)const;
386 void add_value_node(ValueNode::Handle x, const String &id);
389 //void rename_value_node(ValueNode::Handle x, const String &id);
392 void remove_value_node(ValueNode::Handle x);
395 void remove_value_node(const String &id) { remove_value_node(find_value_node(id)); }
397 //! Finds a child Canvas in the Canvas with the given \a name
398 /*! \return If found, returns a handle to the child Canvas.
399 ** If not found, it creates a new Canvas and returns it
400 ** If an error occurs, it returns an empty handle
402 Handle surefind_canvas(const String &id);
404 //! Finds a child Canvas in the Canvas with the given \a id
405 /*! \return If found, returns a handle to the child Canvas.
406 ** Otherwise, returns an empty handle.
408 Handle find_canvas(const String &id);
410 //! Finds a child Canvas in the Canvas with the given \a id
411 /*! \return If found, returns a handle to the child Canvas.
412 ** Otherwise, returns an empty handle.
414 ConstHandle find_canvas(const String &id)const;
416 //! Sets the file path for the Canvas
417 //void set_file_path(const String &);
419 //! Returns the file path from the file name
420 String get_file_path()const;
422 //! Sets the filename (with path)
423 void set_file_name(const String &);
425 //! Gets the filename (with path)
426 String get_file_name()const;
428 //! Creates a new child canvas, and returns its handle
429 Handle new_child_canvas();
431 //! Creates a new child canvas with an ID of \a id, and returns its handle
432 Handle new_child_canvas(const String &id);
434 //! Adds the given canvas as a child
435 Handle add_child_canvas(Handle child_canvas, const String &id);
437 void remove_child_canvas(Handle child_canvas);
439 etl::handle<Layer> find_layer(const Point &pos);
441 int get_depth(etl::handle<Layer>)const;
443 Context get_context()const;
447 const_iterator end()const;
449 reverse_iterator rbegin();
451 const_reverse_iterator rbegin()const;
453 etl::handle<Layer> &back();
455 void push_back(etl::handle<Layer> x);
457 void push_front(etl::handle<Layer> x);
459 void push_back_simple(etl::handle<Layer> x);
461 void insert(iterator iter,etl::handle<Layer> x);
462 void erase(iterator iter);
464 const etl::handle<Layer> &back()const;
466 void set_inline(LooseHandle parent);
468 static Handle create();
470 static Handle create_inline(Handle parent);
472 Handle clone(const GUID& deriv_guid=GUID())const;
475 void add_group_pair(String group, etl::handle<Layer> layer);
476 void remove_group_pair(String group, etl::handle<Layer> layer);
477 void add_connection(etl::loose_handle<Layer> layer, sigc::connection connection);
478 void disconnect_connections(etl::loose_handle<Layer> layer);
481 virtual void on_changed();
482 virtual void get_times_vfunc(Node::time_set &set) const;
483 }; // END of class Canvas
485 void optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_motion_blur=false);
488 }; // END of namespace synfig
490 /* === E N D =============================================================== */