1 /* === S I N F G =========================================================== */
3 ** \brief Layer Class Header
5 ** $Id: layer.h,v 1.2 2005/01/24 03:08:18 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_LAYER_H
25 #define __SINFG_LAYER_H
27 /* === H E A D E R S ======================================================= */
29 #include "string_decl.h"
34 #include <sigc++/signal.h>
35 #include <sigc++/connection.h>
40 /* === M A C R O S ========================================================= */
43 #define SINFG_LAYER_MODULE_EXT public: static const char name__[], version__[], cvs_id__[], local_name__[], category__[]; static Layer *create();
45 //! Sets the name of the layer
46 #define SINFG_LAYER_SET_NAME(class,x) const char class::name__[]=x
48 //! Sets the local name of the layer
49 #define SINFG_LAYER_SET_LOCAL_NAME(class,x) const char class::local_name__[]=x;
51 //! Sets the categpru of the layer
52 #define SINFG_LAYER_SET_CATEGORY(class,x) const char class::category__[]=x
54 //! Sets the version string for the layer
55 #define SINFG_LAYER_SET_VERSION(class,x) const char class::version__[]=x
57 //! Sets the CVS ID string for the layer
58 #define SINFG_LAYER_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
61 #define SINFG_LAYER_INIT(class) sinfg::Layer* class::create() { return new class(); }
64 #define IMPORT_PLUS(x,y) if(param==#x && value.same_as(x)) { value.put(&x);{y;}return true;}
67 #define IMPORT_AS(x,y) if(param==y && value.same_as(x)) { value.put(&x); return true;}
70 #define IMPORT(x) IMPORT_AS(x,#x)
73 #define EXPORT_AS(x,y) if(param==y) { return ValueBase(x); }
76 #define EXPORT(x) EXPORT_AS(x,#x)
79 #define EXPORT_NAME() if(param=="Name" || param=="name" || param=="name__") { return name__; } if(param=="local_name__") { return local_name__; }
82 #define EXPORT_VERSION() if(param=="Version" || param=="version" || param=="version__") { return version__; }
84 /* === T Y P E D E F S ===================================================== */
86 /* === C L A S S E S & S T R U C T S ======================================= */
101 class ProgressCallback;
113 class Layer : public Node
115 friend class ValueNode;
116 friend class Context;
119 -- ** -- T Y P E S -----------------------------------------------------------
124 //! Type that represents a pointer to a layer's constructor
125 typedef Layer* (*Factory)();
136 BookEntry(Factory factory, const String& name,const String& local_name,const String& category,const String& cvs_id,const String& version):
137 factory(factory),name(name),local_name(local_name),category(category),cvs_id(cvs_id),version(version) { }
140 typedef std::map<String,BookEntry> Book;
142 static void register_in_book(const BookEntry &);
146 static bool subsys_init();
148 static bool subsys_stop();
150 typedef std::map<String,ValueBase> ParamList;
152 typedef etl::handle<Layer> Handle;
154 typedef etl::loose_handle<Layer> LooseHandle;
156 typedef etl::handle<const Layer> ConstHandle;
158 typedef std::map<String,etl::rhandle<ValueNode> > DynamicParamList;
160 //! A list type which describes all the parameters that a layer has.
161 /*! \see get_param_vocab() */
162 typedef ParamVocab Vocab;
165 -- ** -- D A T A -------------------------------------------------------------
170 /*! \c true if the layer is visible, \c is it is to be skipped
171 ** \see set_active(), enable(), disable, active()
175 //! Handle to the canvas to which this layer belongs
176 etl::loose_handle<Canvas> canvas_;
178 DynamicParamList dynamic_param_list_;
180 //! A description of what this layer does
187 mutable Time dirty_time_;
189 //! Contains the name of the group that this layer belongs to
193 sigc::connection parent_death_connect_;
196 -- ** -- S I G N A L S -------------------------------------------------------
202 sigc::signal<void> signal_status_changed_;
204 //! Parameter changed
205 sigc::signal<void,String> signal_param_changed_;
207 //! Description Changed
208 sigc::signal<void> signal_description_changed_;
211 sigc::signal<void, int, etl::handle<Canvas> > signal_moved_;
213 sigc::signal<void, String> signal_added_to_group_;
215 sigc::signal<void, String> signal_removed_from_group_;
218 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
224 sigc::signal<void>& signal_status_changed() { return signal_status_changed_; }
226 //! Parameter changed
227 sigc::signal<void,String>& signal_param_changed() { return signal_param_changed_; }
229 //! Description Changed
230 sigc::signal<void>& signal_description_changed() { return signal_description_changed_;}
233 sigc::signal<void, int, etl::handle<Canvas> >& signal_moved() { return signal_moved_; }
235 sigc::signal<void, String>& signal_added_to_group() { return signal_added_to_group_; }
237 sigc::signal<void, String>& signal_removed_from_group() { return signal_removed_from_group_; }
240 -- ** -- C O N S T R U C T O R S ---------------------------------------------
251 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
256 virtual void on_canvas_set();
258 //! Adds this layer to the given layer group
259 void add_to_group(const String&);
261 //! Removes this layer from the given layer group
262 void remove_from_group(const String&);
264 //! Removes this layer from all layer groups
265 void remove_from_all_groups();
267 //! Gets the name of the group that this layer belongs to
268 String get_group()const;
271 //DynamicParamList &dynamic_param_list() { return dynamic_param_list_; }
274 const DynamicParamList &dynamic_param_list()const { return dynamic_param_list_; }
276 bool connect_dynamic_param(const String& param, etl::loose_handle<ValueNode>);
277 bool disconnect_dynamic_param(const String& param);
279 //! Enables the layer for rendering (Making it \em active)
280 void enable() { set_active(true); }
282 //! Disables the layer for rendering. (Making it \em inactive)
283 /*! When a layer is disabled, it will be skipped when the
284 ** canvas is rendered. */
285 void disable() { set_active(false); }
287 //! Sets the 'active' flag for the Layer to the state described by \a x
288 /*! When a layer is disabled, it will be skipped when the
289 ** canvas is rendered. */
290 void set_active(bool x);
292 //! Returns that status of the 'active' flag
293 bool active()const { return active_; }
295 //! Returns the position of the layer in the canvas.
296 /*! Returns negative on error */
297 int get_depth()const;
300 float get_z_depth()const { return z_depth_; }
303 float get_z_depth(const sinfg::Time& t)const;
306 void set_z_depth(float x) { z_depth_=x; }
308 //! Sets the Canvas that this Layer is a part of
309 void set_canvas(etl::loose_handle<Canvas> canvas);
311 //! Returns a handle to the Canvas to which this Layer belongs
312 etl::loose_handle<Canvas> get_canvas()const;
315 const String& get_description()const { return description_; }
318 void set_description(const String& x);
321 -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
325 virtual Rect get_bounding_rect()const;
327 virtual Rect get_full_bounding_rect(Context context)const;
329 //! Returns a string containing the name of the Layer
330 virtual String get_name()const;
332 //! Returns a string containing the localized name of the Layer
333 virtual String get_local_name()const;
335 //! Gets the paramater vocabulary
336 virtual Vocab get_param_vocab()const;
338 //! Gets the version string for this layer
339 virtual String get_version()const;
342 virtual etl::handle<Transform> get_transform()const;
344 //! Sets the virtual version to use for backwards-compatibility
346 ** \see reset_version() */
347 virtual bool set_version(const String &ver);
349 //! Resets the virtual version
351 ** \see set_version() */
352 virtual void reset_version();
354 //! Sets the parameter described by \a param to \a value.
355 /*! \param param The name of the parameter to set
356 ** \param value What the parameter is to be set to.
357 ** \return \c true on success, \c false upon rejection or failure.
358 ** If it returns \c false, then the Layer is assumed to remain unchanged.
360 ** \todo \a param should be of the type <tt>const String \¶m</tt>
362 virtual bool set_param(const String ¶m, const ValueBase &value);
364 //! Sets a list of parameters
365 virtual bool set_param_list(const ParamList &);
367 //! Get the value of the specified parameter.
368 /*! \return The requested parameter value, or (upon failure) a NIL ValueBase.
370 ** \todo \a param should be of the type <tt>const String \&</tt>
372 virtual ValueBase get_param(const String ¶m)const;
374 //! Get a list of all of the parameters and their values
375 virtual ParamList get_param_list()const;
377 //! Sets the \a time for the selected Layer and those under it
378 /*! \param context Context iterator refering to next Layer.
379 ** \param time writeme
380 ** \see Handle::set_time()
382 virtual void set_time(Context context, Time time)const;
384 //! Sets the \a time for the selected Layer and those under it for a specific \a point
385 /*! \param context Context iterator refering to next Layer.
386 ** \param time writeme
387 ** \param point writeme
388 ** \see Handle::set_time()
389 ** \todo \a point should be of the type <tt>const Point \&</tt> */
390 virtual void set_time(Context context, Time time, const Point &point)const;
392 //! Gets the color of the Canvas at \a point
393 /*! \param context Context iterator refering to next Layer.
394 ** \param point Point which indicates where the desired Color should come from
395 ** \todo \a point should be of the type <tt>const Point \&</tt>
396 ** \see Handle::get_color()
398 virtual Color get_color(Context context, const Point &point)const;
400 //! Renders the Canvas to the given Surface in an accelerated manner
401 /*! \param context Context iterator refering to next Layer.
402 ** \param surface Pointer to Surface to render to.
403 ** \param quality The requested quality-level to render at.
404 ** \param rend_desc The associated RendDesc.
405 ** \param callback Pointer to callback object. May be NULL if there is no callback.
406 ** \return \c true on success, \c false on failure
407 ** \see Handle::accelerated_render()
409 virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &rend_desc, ProgressCallback *callback)const;
411 //! Checks to see if a part of the layer is directly under \a point
412 /*! \param context Context iterator refering to next Layer.
413 ** \param point The point to check
414 ** \return The handle of the layer under \a point. If there is not
415 ** a layer under \a point, then returns an empty handle. */
416 virtual Handle hit_check(Context context, const Point &point)const;
418 //! Duplicates the Layer
419 virtual Handle clone(const GUID& deriv_guid=GUID())const;
421 //! Duplicates the Layer without duplicating the value nodes
422 virtual Layer *simple_clone()const;
426 //! This is called whenever a parameter is changed
427 virtual void on_changed();
429 //! Called to figure out the animation time information
430 virtual void get_times_vfunc(Node::time_set &set) const;
433 -- ** -- S T A T I C F U N C T I O N S --------------------------------------
438 //! Creates a Layer of type \a type
439 /*! If the Layer type is unknown, then a Mime layer is created in its place.
440 ** \param type A string describing the name of the layer to construct.
441 ** \return Always returns a handle to a new Layer.
444 static Layer::LooseHandle create(const String &type);
446 }; // END of class Layer
448 }; // END of namespace sinfg
451 /* === E N D =============================================================== */