synfig-core  1.0.3
layer.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_LAYER_H
28 #define __SYNFIG_LAYER_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include <map>
33 #include <ETL/handle>
34 #include "real.h"
35 #include "string.h"
36 #include <sigc++/signal.h>
37 #include <sigc++/connection.h>
38 #include "node.h"
39 #include "time.h"
40 #include "guid.h"
41 #include "interpolation.h"
42 #include "target.h" // for RenderMethod. TODO: put RenderMethod apart
43 
44 #include "cairo.h"
45 #include "rendermethod.h"
46 
47 /* === M A C R O S ========================================================= */
48 
49 // This macros should be removed when rendering optimization complete
50 #define RENDER_TRANSFORMED_IF_NEED(file, line) \
51  if (!renddesc.get_transformation_matrix().is_identity()) \
52  return render_transformed(this, context, surface, quality, renddesc, cb, file, line);
53 
54 
57 #define SYNFIG_LAYER_MODULE_EXT \
58  public: \
59  static const char name__[], version__[], cvs_id__[], local_name__[], category__[]; \
60  static Layer *create();
61 
63 #define SYNFIG_LAYER_SET_NAME(class,x) \
64  const char class::name__[]=x
65 
67 #define SYNFIG_LAYER_SET_LOCAL_NAME(class,x) \
68  const char class::local_name__[]=x;
69 
71 #define SYNFIG_LAYER_SET_CATEGORY(class,x) \
72  const char class::category__[]=x
73 
75 #define SYNFIG_LAYER_SET_VERSION(class,x) \
76  const char class::version__[]=x
77 
79 #define SYNFIG_LAYER_SET_CVS_ID(class,x) \
80  const char class::cvs_id__[]=x
81 
83 #define SYNFIG_LAYER_INIT(class) \
84  synfig::Layer* class::create() \
85  { \
86  return new class(); \
87  }
88 
90 #define IMPORT_VALUE(x) \
91  if (#x=="param_"+param && x.get_type()==value.get_type()) \
92  { \
93  x=value; \
94  return true; \
95  }
96 
99 #define IMPORT_VALUE_PLUS_BEGIN(x) \
100  if (#x=="param_"+param && x.get_type()==value.get_type()) \
101  { \
102  x=value; \
103  {
104 #define IMPORT_VALUE_PLUS_END \
105  } \
106  return true; \
107  }
108 #define IMPORT_VALUE_PLUS(x,y) \
109  IMPORT_VALUE_PLUS_BEGIN(x) \
110  y; \
111  IMPORT_VALUE_PLUS_END
112 
114 #define EXPORT_VALUE(x) \
115  if (#x=="param_"+param) \
116  { \
117  synfig::ValueBase ret; \
118  ret.copy(x); \
119  return ret; \
120  }
121 
123 #define EXPORT_NAME() \
124  if (param=="Name" || param=="name" || param=="name__") \
125  return name__; \
126  else if (param=="local_name__") \
127  return dgettext("synfig",local_name__);
128 
130 #define EXPORT_VERSION() \
131  if (param=="Version" || param=="version" || param=="version__") \
132  return version__;
133 
136 #define CATEGORY_DO_NOT_USE "Do Not Use"
137 
139 #define SET_INTERPOLATION_DEFAULTS() \
140 { \
141  Vocab vocab(get_param_vocab()); \
142  Vocab::const_iterator viter; \
143  for(viter=vocab.begin();viter!=vocab.end();viter++) \
144  { \
145  ValueBase v=get_param(viter->get_name()); \
146  v.set_interpolation(viter->get_interpolation()); \
147  set_param(viter->get_name(), v); \
148  } \
149 } \
150 
151 
152 #define SET_STATIC_DEFAULTS() \
153 { \
154  Vocab vocab(get_param_vocab()); \
155  Vocab::const_iterator viter; \
156  for(viter=vocab.begin();viter!=vocab.end();viter++) \
157  { \
158  ValueBase v=get_param(viter->get_name()); \
159  v.set_static(viter->get_static()); \
160  set_param(viter->get_name(), v); \
161  } \
162 } \
163 
164 /* === T Y P E D E F S ===================================================== */
165 
166 /* === C L A S S E S & S T R U C T S ======================================= */
167 
168 namespace synfig {
169 
170 class Canvas;
171 class Vector;
172 typedef Vector Point;
173 class Canvas;
174 class ParamDesc;
175 class ParamVocab;
176 class ValueNode;
177 class ValueBase;
178 class Time;
179 class Surface;
180 class CairoSurface;
181 class RendDesc;
182 class ProgressCallback;
183 class IndependentContext;
184 class Context;
185 class Color;
186 class CairoColor;
187 class Transform;
188 class Rect;
189 class GUID;
190 
191 
196 class Layer : public Node
197 {
198  friend class ValueNode;
199  friend class IndependentContext;
200  friend class Context;
201 
202  /*
203  -- ** -- T Y P E S -----------------------------------------------------------
204  */
205 
206 public:
207 
209 
211  typedef Layer* (*Factory)();
212 
213  struct BookEntry
214  {
223  const String &name,
224  const String &local_name,
225  const String &category,
226  const String &cvs_id,
227  const String &version):
228  factory(factory),
229  name(name),
230  local_name(local_name),
231  category(category),
232  cvs_id(cvs_id),
233  version(version) { }
234  };
235 
237 
243  typedef std::map<String,BookEntry> Book;
244 
245  static void register_in_book(const BookEntry &);
246 
247  static Book& book();
248 
251 
253  static bool subsys_init();
254 
256  static bool subsys_stop();
257 
259  typedef std::map<String,ValueBase> ParamList;
260 
261  typedef etl::handle<Layer> Handle;
262 
263  typedef etl::loose_handle<Layer> LooseHandle;
264 
265  typedef etl::handle<const Layer> ConstHandle;
266 
268  typedef std::map<String,etl::rhandle<ValueNode> > DynamicParamList;
269 
271 
272  typedef ParamVocab Vocab;
273 
274  /*
275  -- ** -- D A T A -------------------------------------------------------------
276  */
277 
278 private:
279 
283  bool active_;
284 
286  bool optimized_;
287 
292  bool exclude_from_rendering_;
293 
295  etl::loose_handle<Canvas> canvas_;
296 
298  DynamicParamList dynamic_param_list_;
299 
301  String description_;
302 
304  ValueBase param_z_depth;
305 
307  mutable Time dirty_time_;
308 
310  String group_;
311 
316  sigc::connection parent_death_connect_;
317 
318  /*
319  -- ** -- S I G N A L S -------------------------------------------------------
320  */
321 
322 private:
323 
325  sigc::signal<void> signal_status_changed_;
326 
328  sigc::signal<void,String> signal_param_changed_;
329 
331  sigc::signal<void> signal_description_changed_;
332 
334  sigc::signal<void, int, etl::handle<Canvas> > signal_moved_;
335 
336  sigc::signal<void, String> signal_added_to_group_;
337 
338  sigc::signal<void, String> signal_removed_from_group_;
339 
340  /*
341  -- ** -- S I G N A L I N T E R F A C E -------------------------------------
342  */
343 
344 public:
345 
347  sigc::signal<void>& signal_status_changed() { return signal_status_changed_; }
348 
350  sigc::signal<void,String>& signal_param_changed() { return signal_param_changed_; }
351 
353  sigc::signal<void>& signal_description_changed() { return signal_description_changed_;}
354 
356  sigc::signal<void, int, etl::handle<Canvas> >& signal_moved() { return signal_moved_; }
357 
358  sigc::signal<void, String>& signal_added_to_group() { return signal_added_to_group_; }
359 
360  sigc::signal<void, String>& signal_removed_from_group() { return signal_removed_from_group_; }
361 
362  /*
363  -- ** -- C O N S T R U C T O R S ---------------------------------------------
364  */
365 
366 protected:
367 
368  Layer();
369 
370 public:
371  virtual ~Layer();
372 
373  /*
374  -- ** -- M E M B E R F U N C T I O N S -------------------------------------
375  */
376 
377 public:
378 
379  virtual void on_canvas_set();
380 
382  void add_to_group(const String&);
383 
385  void remove_from_group(const String&);
386 
388  void remove_from_all_groups();
389 
391  String get_group()const;
392 
395  const DynamicParamList &dynamic_param_list()const { return dynamic_param_list_; }
396 
398  void enable() { set_active(true); }
399 
401 
403  void disable() { set_active(false); }
404 
406 
408  void set_active(bool x);
409 
411  bool active()const { return active_; }
412 
414  bool optimized()const { return optimized_; }
415 
417  void set_optimized(bool x) { optimized_ = x; }
418 
420 
422  void set_exclude_from_rendering(bool x);
423 
425  bool get_exclude_from_rendering()const { return exclude_from_rendering_; }
426 
428 
429  int get_depth()const;
430 
432  float get_z_depth()const { return param_z_depth.get(Real()); }
433 
435  float get_z_depth(const synfig::Time& t)const;
436 
438  float get_true_z_depth(const synfig::Time& t=Time(0))const;
439 
441  void set_z_depth(float x) { param_z_depth=ValueBase(Real(x)); }
442 
444  void set_canvas(etl::loose_handle<Canvas> canvas);
445 
447  etl::loose_handle<Canvas> get_canvas()const;
448 
450  const String& get_description()const { return description_; }
451 
452 
453  String get_string()const;
454 
456  void set_description(const String& x);
457 
460 
462  const String get_param_local_name(const String &param_name)const;
463 
465 
468 
469  /*
470  -- ** -- V I R T U A L F U N C T I O N S -----------------------------------
471  */
472 
473 public:
476  virtual Rect get_bounding_rect()const;
477 
480  virtual Rect get_full_bounding_rect(Context context)const;
481 
483  virtual String get_name()const;
484 
486  virtual String get_local_name()const;
487 
489  virtual Vocab get_param_vocab()const;
490 
492  virtual String get_version()const;
493 
496  virtual etl::handle<Transform> get_transform()const;
497 
499 
501  virtual bool set_version(const String &ver);
502 
504 
506  virtual void reset_version();
507 
509 
516  virtual bool set_param(const String &param, const ValueBase &value);
517 
519  virtual bool set_param_list(const ParamList &);
520 
522 
526  virtual ValueBase get_param(const String &param)const;
527 
529  virtual ParamList get_param_list()const;
530 
532 
536  virtual void set_time(IndependentContext context, Time time)const;
537 
539 
544  virtual void set_time(IndependentContext context, Time time, const Point &point)const;
545 
547 
551  virtual Color get_color(Context context, const Point &pos)const;
552  virtual CairoColor get_cairocolor(Context context, const Point &pos)const;
553 
555  virtual void set_render_method(Context context, RenderMethod x);
556 
557  // Temporary function to render transformed layer for leyers which yet not suppurt transformed rendering
558  static bool render_transformed(const Layer *layer, Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb, const char *file, int line);
559 
561 
569  virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
570  virtual bool accelerated_cairorender(Context context, cairo_t* cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const;
571 
573 
579  virtual Handle hit_check(Context context, const Point &point)const;
580 
582  virtual Handle clone(etl::loose_handle<Canvas> canvas, const GUID& deriv_guid=GUID())const;
583 
585 
590  virtual bool reads_context()const;
591 
593  virtual Handle simple_clone()const;
594 
596  virtual bool connect_dynamic_param(const String& param, etl::loose_handle<ValueNode>);
597 
599  virtual bool disconnect_dynamic_param(const String& param);
600 
603 
604  virtual void fill_sound_processor(SoundProcessor &soundProcessor) const;
605 
606 protected:
607 
609  virtual void on_changed();
610 
612  virtual void get_times_vfunc(Node::time_set &set) const;
613 
614  /*
615  -- ** -- S T A T I C F U N C T I O N S --------------------------------------
616  */
617 
618 public:
619 
621 
626  static Layer::LooseHandle create(const String &type);
627 
628 }; // END of class Layer
629 
630 }; // END of namespace synfig
631 
632 
633 /* === E N D =============================================================== */
634 
635 #endif