1 /* === S Y N F I G ========================================================= */
3 ** \brief Layer Class Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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_LAYER_H
27 #define __SYNFIG_LAYER_H
29 /* === H E A D E R S ======================================================= */
31 #include "string_decl.h"
36 #include <sigc++/signal.h>
37 #include <sigc++/connection.h>
42 /* === M A C R O S ========================================================= */
45 #define SYNFIG_LAYER_MODULE_EXT \
47 static const char name__[], version__[], cvs_id__[], local_name__[], category__[]; \
48 static Layer *create();
50 //! Sets the name of the layer
51 #define SYNFIG_LAYER_SET_NAME(class,x) \
52 const char class::name__[]=x
54 //! Sets the local name of the layer
55 #define SYNFIG_LAYER_SET_LOCAL_NAME(class,x) \
56 const char class::local_name__[]=x;
58 //! Sets the category of the layer
59 #define SYNFIG_LAYER_SET_CATEGORY(class,x) \
60 const char class::category__[]=x
62 //! Sets the version string for the layer
63 #define SYNFIG_LAYER_SET_VERSION(class,x) \
64 const char class::version__[]=x
66 //! Sets the CVS ID string for the layer
67 #define SYNFIG_LAYER_SET_CVS_ID(class,x) \
68 const char class::cvs_id__[]=x
71 #define SYNFIG_LAYER_INIT(class) \
72 synfig::Layer* class::create() \
78 #define IMPORT_PLUS(x,y) \
79 if (param==#x && value.same_type_as(x)) \
89 #define IMPORT_AS(x,y) \
90 if (param==y && value.same_type_as(x)) \
101 #define EXPORT_AS(x,y) \
110 #define EXPORT_NAME() \
111 if (param=="Name" || param=="name" || param=="name__") \
113 else if (param=="local_name__") \
114 return dgettext("synfig",local_name__);
117 #define EXPORT_VERSION() \
118 if (param=="Version" || param=="version" || param=="version__") \
121 //! This is used as the category for layer book entries which represent aliases of layers.
122 //! It prevents these layers showing up in the menu.
123 #define CATEGORY_DO_NOT_USE "Do Not Use"
125 /* === T Y P E D E F S ===================================================== */
127 /* === C L A S S E S & S T R U C T S ======================================= */
133 typedef Vector Point;
142 class ProgressCallback;
154 class Layer : public Node
156 friend class ValueNode;
157 friend class Context;
160 -- ** -- T Y P E S -----------------------------------------------------------
165 //! Type that represents a pointer to a layer's constructor
166 typedef Layer* (*Factory)();
177 BookEntry(Factory factory, const String& name,const String& local_name,const String& category,const String& cvs_id,const String& version):
178 factory(factory),name(name),local_name(local_name),category(category),cvs_id(cvs_id),version(version) { }
181 typedef std::map<String,BookEntry> Book;
183 static void register_in_book(const BookEntry &);
187 static bool subsys_init();
189 static bool subsys_stop();
191 typedef std::map<String,ValueBase> ParamList;
193 typedef etl::handle<Layer> Handle;
195 typedef etl::loose_handle<Layer> LooseHandle;
197 typedef etl::handle<const Layer> ConstHandle;
199 typedef std::map<String,etl::rhandle<ValueNode> > DynamicParamList;
201 //! A list type which describes all the parameters that a layer has.
202 /*! \see get_param_vocab() */
203 typedef ParamVocab Vocab;
206 -- ** -- D A T A -------------------------------------------------------------
211 /*! \c true if the layer is visible, \c false if it is to be skipped
212 ** \see set_active(), enable(), disable, active()
216 //! Handle to the canvas to which this layer belongs
217 etl::loose_handle<Canvas> canvas_;
219 DynamicParamList dynamic_param_list_;
221 //! A description of what this layer does
228 mutable Time dirty_time_;
230 //! Contains the name of the group that this layer belongs to
234 sigc::connection parent_death_connect_;
237 -- ** -- S I G N A L S -------------------------------------------------------
243 sigc::signal<void> signal_status_changed_;
245 //! Parameter changed
246 sigc::signal<void,String> signal_param_changed_;
248 //! Description Changed
249 sigc::signal<void> signal_description_changed_;
252 sigc::signal<void, int, etl::handle<Canvas> > signal_moved_;
254 sigc::signal<void, String> signal_added_to_group_;
256 sigc::signal<void, String> signal_removed_from_group_;
259 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
265 sigc::signal<void>& signal_status_changed() { return signal_status_changed_; }
267 //! Parameter changed
268 sigc::signal<void,String>& signal_param_changed() { return signal_param_changed_; }
270 //! Description Changed
271 sigc::signal<void>& signal_description_changed() { return signal_description_changed_;}
274 sigc::signal<void, int, etl::handle<Canvas> >& signal_moved() { return signal_moved_; }
276 sigc::signal<void, String>& signal_added_to_group() { return signal_added_to_group_; }
278 sigc::signal<void, String>& signal_removed_from_group() { return signal_removed_from_group_; }
281 -- ** -- C O N S T R U C T O R S ---------------------------------------------
292 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
297 virtual void on_canvas_set();
299 //! Adds this layer to the given layer group
300 void add_to_group(const String&);
302 //! Removes this layer from the given layer group
303 void remove_from_group(const String&);
305 //! Removes this layer from all layer groups
306 void remove_from_all_groups();
308 //! Gets the name of the group that this layer belongs to
309 String get_group()const;
312 //DynamicParamList &dynamic_param_list() { return dynamic_param_list_; }
315 const DynamicParamList &dynamic_param_list()const { return dynamic_param_list_; }
317 bool connect_dynamic_param(const String& param, etl::loose_handle<ValueNode>);
318 bool disconnect_dynamic_param(const String& param);
320 //! Enables the layer for rendering (Making it \em active)
321 void enable() { set_active(true); }
323 //! Disables the layer for rendering. (Making it \em inactive)
324 /*! When a layer is disabled, it will be skipped when the
325 ** canvas is rendered. */
326 void disable() { set_active(false); }
328 //! Sets the 'active' flag for the Layer to the state described by \a x
329 /*! When a layer is disabled, it will be skipped when the
330 ** canvas is rendered. */
331 void set_active(bool x);
333 //! Returns that status of the 'active' flag
334 bool active()const { return active_; }
336 //! Returns the position of the layer in the canvas.
337 /*! Returns negative on error */
338 int get_depth()const;
341 float get_z_depth()const { return z_depth_; }
344 float get_z_depth(const synfig::Time& t)const;
347 void set_z_depth(float x) { z_depth_=x; }
349 //! Sets the Canvas that this Layer is a part of
350 void set_canvas(etl::loose_handle<Canvas> canvas);
352 //! Returns a handle to the Canvas to which this Layer belongs
353 etl::loose_handle<Canvas> get_canvas()const;
356 const String& get_description()const { return description_; }
359 void set_description(const String& x);
361 //! Returns the layer's description if it's not empty, else its local name
362 const String get_non_empty_description()const { return get_description().empty() ? get_local_name() : get_description(); }
364 //! Returns the localised version of the given layer parameter
365 const String get_param_local_name(const String ¶m_name)const;
368 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
372 virtual Rect get_bounding_rect()const;
374 virtual Rect get_full_bounding_rect(Context context)const;
376 //! Returns a string containing the name of the Layer
377 virtual String get_name()const;
379 //! Returns a string containing the localized name of the Layer
380 virtual String get_local_name()const;
382 //! Gets the parameter vocabulary
383 virtual Vocab get_param_vocab()const;
385 //! Gets the version string for this layer
386 virtual String get_version()const;
389 virtual etl::handle<Transform> get_transform()const;
391 //! Sets the virtual version to use for backwards-compatibility
393 ** \see reset_version() */
394 virtual bool set_version(const String &ver);
396 //! Resets the virtual version
398 ** \see set_version() */
399 virtual void reset_version();
401 //! Sets the parameter described by \a param to \a value.
402 /*! \param param The name of the parameter to set
403 ** \param value What the parameter is to be set to.
404 ** \return \c true on success, \c false upon rejection or failure.
405 ** If it returns \c false, then the Layer is assumed to remain unchanged.
407 ** \todo \a param should be of the type <tt>const String \¶m</tt>
409 virtual bool set_param(const String ¶m, const ValueBase &value);
411 //! Sets a list of parameters
412 virtual bool set_param_list(const ParamList &);
414 //! Get the value of the specified parameter.
415 /*! \return The requested parameter value, or (upon failure) a NIL ValueBase.
417 ** \todo \a param should be of the type <tt>const String \&</tt>
419 virtual ValueBase get_param(const String ¶m)const;
421 //! Get a list of all of the parameters and their values
422 virtual ParamList get_param_list()const;
424 //! Sets the \a time for the selected Layer and those under it
425 /*! \param context Context iterator referring to next Layer.
426 ** \param time writeme
427 ** \see Handle::set_time()
429 virtual void set_time(Context context, Time time)const;
431 //! Sets the \a time for the selected Layer and those under it for a specific \a point
432 /*! \param context Context iterator referring to next Layer.
433 ** \param time writeme
434 ** \param point writeme
435 ** \see Handle::set_time()
436 ** \todo \a point should be of the type <tt>const Point \&</tt> */
437 virtual void set_time(Context context, Time time, const Point &point)const;
439 //! Gets the color of the Canvas at \a pos
440 /*! \param context Context iterator referring to next Layer.
441 ** \param pos Point which indicates where the Color should come from
442 ** \see Handle::get_color()
444 virtual Color get_color(Context context, const Point &pos)const;
446 //! Renders the Canvas to the given Surface in an accelerated manner
447 /*! \param context Context iterator referring to next Layer.
448 ** \param surface Pointer to Surface to render to.
449 ** \param quality The requested quality-level to render at.
450 ** \param renddesc The associated RendDesc.
451 ** \param cb Pointer to callback object. May be NULL if there is no callback.
452 ** \return \c true on success, \c false on failure
453 ** \see Handle::accelerated_render()
455 virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
457 //! Checks to see if a part of the layer is directly under \a point
458 /*! \param context Context iterator referring to next Layer.
459 ** \param point The point to check
460 ** \return The handle of the layer under \a point. If there is not
461 ** a layer under \a point, then returns an empty handle. */
462 virtual Handle hit_check(Context context, const Point &point)const;
464 //! Duplicates the Layer
465 virtual Handle clone(const GUID& deriv_guid=GUID())const;
467 //! Returns true if the layer needs to be able to examine its context.
468 /*! context to render itself, other than for simple blending. For
469 ** example, the blur layer will return true - it can't do its job
470 ** if it can't see its context, and the circle layer will return
471 ** false - rendering a circle doesn't depend on the underlying
472 ** context until the final blend operation. */
473 virtual bool reads_context()const;
475 #ifdef THIS_CODE_IS_NOT_USED
476 //! Duplicates the Layer without duplicating the value nodes
477 virtual Layer *simple_clone()const;
478 #endif /* THIS_CODE_IS_NOT_USED */
482 //! This is called whenever a parameter is changed
483 virtual void on_changed();
485 //! Called to figure out the animation time information
486 virtual void get_times_vfunc(Node::time_set &set) const;
489 -- ** -- S T A T I C F U N C T I O N S --------------------------------------
494 //! Creates a Layer of type \a type
495 /*! If the Layer type is unknown, then a Mime layer is created in its place.
496 ** \param type A string describing the name of the layer to construct.
497 ** \return Always returns a handle to a new Layer.
500 static Layer::LooseHandle create(const String &type);
502 }; // END of class Layer
504 }; // END of namespace synfig
507 /* === E N D =============================================================== */