00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_LAYER_H
00026 #define __SYNFIG_LAYER_H
00027
00028
00029
00030 #include "string_decl.h"
00031 #include <map>
00032 #include <ETL/handle>
00033 #include "real.h"
00034 #include "string.h"
00035 #include <sigc++/signal.h>
00036 #include <sigc++/connection.h>
00037 #include "node.h"
00038 #include "time.h"
00039 #include "guid.h"
00040
00041
00042
00044 #define SYNFIG_LAYER_MODULE_EXT public: static const char name__[], version__[], cvs_id__[], local_name__[], category__[]; static Layer *create();
00045
00047 #define SYNFIG_LAYER_SET_NAME(class,x) const char class::name__[]=x
00048
00050 #define SYNFIG_LAYER_SET_LOCAL_NAME(class,x) const char class::local_name__[]=x;
00051
00053 #define SYNFIG_LAYER_SET_CATEGORY(class,x) const char class::category__[]=x
00054
00056 #define SYNFIG_LAYER_SET_VERSION(class,x) const char class::version__[]=x
00057
00059 #define SYNFIG_LAYER_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
00060
00062 #define SYNFIG_LAYER_INIT(class) synfig::Layer* class::create() { return new class(); }
00063
00065 #define IMPORT_PLUS(x,y) if(param==#x && value.same_as(x)) { value.put(&x);{y;}return true;}
00066
00068 #define IMPORT_AS(x,y) if(param==y && value.same_as(x)) { value.put(&x); return true;}
00069
00071 #define IMPORT(x) IMPORT_AS(x,#x)
00072
00074 #define EXPORT_AS(x,y) if(param==y) { return ValueBase(x); }
00075
00077 #define EXPORT(x) EXPORT_AS(x,#x)
00078
00080 #define EXPORT_NAME() if(param=="Name" || param=="name" || param=="name__") { return name__; } if(param=="local_name__") { return local_name__; }
00081
00083 #define EXPORT_VERSION() if(param=="Version" || param=="version" || param=="version__") { return version__; }
00084
00085
00086
00087
00088
00089 namespace synfig {
00090
00091 class Canvas;
00092 class Vector;
00093 typedef Vector Point;
00094 class Canvas;
00095 class ParamDesc;
00096 class ParamVocab;
00097 class ValueNode;
00098 class ValueBase;
00099 class Time;
00100 class Surface;
00101 class RendDesc;
00102 class ProgressCallback;
00103 class Context;
00104 class Color;
00105 class Transform;
00106 class Rect;
00107 class GUID;
00108
00109
00114 class Layer : public Node
00115 {
00116 friend class ValueNode;
00117 friend class Context;
00118
00119
00120
00121
00122
00123 public:
00124
00126 typedef Layer* (*Factory)();
00127
00128 struct BookEntry
00129 {
00130 Factory factory;
00131 String name;
00132 String local_name;
00133 String category;
00134 String cvs_id;
00135 String version;
00136 BookEntry() { }
00137 BookEntry(Factory factory, const String& name,const String& local_name,const String& category,const String& cvs_id,const String& version):
00138 factory(factory),name(name),local_name(local_name),category(category),cvs_id(cvs_id),version(version) { }
00139 };
00140
00141 typedef std::map<String,BookEntry> Book;
00142
00143 static void register_in_book(const BookEntry &);
00144
00145 static Book& book();
00146
00147 static bool subsys_init();
00148
00149 static bool subsys_stop();
00150
00151 typedef std::map<String,ValueBase> ParamList;
00152
00153 typedef etl::handle<Layer> Handle;
00154
00155 typedef etl::loose_handle<Layer> LooseHandle;
00156
00157 typedef etl::handle<const Layer> ConstHandle;
00158
00159 typedef std::map<String,etl::rhandle<ValueNode> > DynamicParamList;
00160
00162
00163 typedef ParamVocab Vocab;
00164
00165
00166
00167
00168
00169 private:
00170
00174 bool active_;
00175
00177 etl::loose_handle<Canvas> canvas_;
00178
00179 DynamicParamList dynamic_param_list_;
00180
00182 String description_;
00183
00185 float z_depth_;
00186
00188 mutable Time dirty_time_;
00189
00191 String group_;
00192
00194 sigc::connection parent_death_connect_;
00195
00196
00197
00198
00199
00200 private:
00201
00203 sigc::signal<void> signal_status_changed_;
00204
00206 sigc::signal<void,String> signal_param_changed_;
00207
00209 sigc::signal<void> signal_description_changed_;
00210
00212 sigc::signal<void, int, etl::handle<Canvas> > signal_moved_;
00213
00214 sigc::signal<void, String> signal_added_to_group_;
00215
00216 sigc::signal<void, String> signal_removed_from_group_;
00217
00218
00219
00220
00221
00222 public:
00223
00225 sigc::signal<void>& signal_status_changed() { return signal_status_changed_; }
00226
00228 sigc::signal<void,String>& signal_param_changed() { return signal_param_changed_; }
00229
00231 sigc::signal<void>& signal_description_changed() { return signal_description_changed_;}
00232
00234 sigc::signal<void, int, etl::handle<Canvas> >& signal_moved() { return signal_moved_; }
00235
00236 sigc::signal<void, String>& signal_added_to_group() { return signal_added_to_group_; }
00237
00238 sigc::signal<void, String>& signal_removed_from_group() { return signal_removed_from_group_; }
00239
00240
00241
00242
00243
00244 protected:
00245
00246 Layer();
00247
00248 public:
00249 virtual ~Layer();
00250
00251
00252
00253
00254
00255 public:
00256
00257 virtual void on_canvas_set();
00258
00260 void add_to_group(const String&);
00261
00263 void remove_from_group(const String&);
00264
00266 void remove_from_all_groups();
00267
00269 String get_group()const;
00270
00272
00273
00275 const DynamicParamList &dynamic_param_list()const { return dynamic_param_list_; }
00276
00277 bool connect_dynamic_param(const String& param, etl::loose_handle<ValueNode>);
00278 bool disconnect_dynamic_param(const String& param);
00279
00281 void enable() { set_active(true); }
00282
00284
00286 void disable() { set_active(false); }
00287
00289
00291 void set_active(bool x);
00292
00294 bool active()const { return active_; }
00295
00297
00298 int get_depth()const;
00299
00301 float get_z_depth()const { return z_depth_; }
00302
00304 float get_z_depth(const synfig::Time& t)const;
00305
00307 void set_z_depth(float x) { z_depth_=x; }
00308
00310 void set_canvas(etl::loose_handle<Canvas> canvas);
00311
00313 etl::loose_handle<Canvas> get_canvas()const;
00314
00316 const String& get_description()const { return description_; }
00317
00319 void set_description(const String& x);
00320
00321
00322
00323
00324
00325 public:
00326 virtual Rect get_bounding_rect()const;
00327
00328 virtual Rect get_full_bounding_rect(Context context)const;
00329
00331 virtual String get_name()const;
00332
00334 virtual String get_local_name()const;
00335
00337 virtual Vocab get_param_vocab()const;
00338
00340 virtual String get_version()const;
00341
00343 virtual etl::handle<Transform> get_transform()const;
00344
00346
00348 virtual bool set_version(const String &ver);
00349
00351
00353 virtual void reset_version();
00354
00356
00363 virtual bool set_param(const String ¶m, const ValueBase &value);
00364
00366 virtual bool set_param_list(const ParamList &);
00367
00369
00373 virtual ValueBase get_param(const String ¶m)const;
00374
00376 virtual ParamList get_param_list()const;
00377
00379
00383 virtual void set_time(Context context, Time time)const;
00384
00386
00391 virtual void set_time(Context context, Time time, const Point &point)const;
00392
00394
00399 virtual Color get_color(Context context, const Point &point)const;
00400
00402
00410 virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &rend_desc, ProgressCallback *callback)const;
00411
00413
00417 virtual Handle hit_check(Context context, const Point &point)const;
00418
00420 virtual Handle clone(const GUID& deriv_guid=GUID())const;
00421
00423 virtual Layer *simple_clone()const;
00424
00425 protected:
00426
00428 virtual void on_changed();
00429
00431 virtual void get_times_vfunc(Node::time_set &set) const;
00432
00433
00434
00435
00436
00437 public:
00438
00440
00445 static Layer::LooseHandle create(const String &type);
00446
00447 };
00448
00449 };
00450
00451
00452
00453
00454 #endif