synfig-core  1.0.3
context.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
22 /* ========================================================================= */
23 
24 /* === S T A R T =========================================================== */
25 
26 #ifndef __SYNFIG_CONTEXT_H
27 #define __SYNFIG_CONTEXT_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include "canvasbase.h"
32 #include "rect.h"
33 #include "renddesc.h"
34 #include "surface.h"
36 #include "general.h"
37 
38 /* === M A C R O S ========================================================= */
39 
40 /* === T Y P E D E F S ===================================================== */
41 
42 /* === C L A S S E S & S T R U C T S ======================================= */
43 
44 namespace synfig {
45 
46 class Vector;
47 typedef Vector Point;
48 class Color;
49 class Surface;
50 class CairoSurface;
51 class RendDesc;
52 class ProgressCallback;
53 class Layer;
54 class Time;
55 class Rect;
56 
61 class IndependentContext: public CanvasBase::const_iterator
62 {
63 public:
65 
67  IndependentContext(const CanvasBase::const_iterator &x):CanvasBase::const_iterator(x) { }
68 
70  IndependentContext operator=(const CanvasBase::const_iterator &x)
72 
74  void set_time(Time time)const;
75 
77  void set_time(Time time,const Vector &pos)const;
78 
80  void set_dirty_outlines();
81 };
82 
83 
88 public:
92  bool z_range;
99 
100  explicit ContextParams(bool render_excluded_contexts = false):
102  z_range(false),
103  z_range_position(0.0),
104  z_range_depth(0.0),
105  z_range_blur(0.0){ }
106 };
107 
113 {
114 private:
116  ContextParams params;
117 
118 public:
119 
120  Context() { }
121 
123  Context(const IndependentContext &x, const ContextParams &params):
124  IndependentContext(x), params(params) { }
125 
127  Context(const IndependentContext &x, const Context &context):
128  IndependentContext(x), params(context.params) { }
129 
131  Context(const CanvasBase::const_iterator &x, const ContextParams &params):
132  IndependentContext(x), params(params) { }
133 
134  Context(const CanvasBase::const_iterator &x, const Context &context):
135  IndependentContext(x), params(context.params) { }
136 
138  Context get_next()const { return Context(*this+1, params); }
139 
141  Context get_previous()const { return Context(*this-1, params); }
142 
144  const ContextParams& get_params()const { return params; }
145 
148  Color get_color(const Point &pos)const;
149  CairoColor get_cairocolor(const Point &pos)const;
150 
153  bool accelerated_render(Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb) const;
154  bool accelerated_cairorender(cairo_t *cr,int quality, const RendDesc &renddesc, ProgressCallback *cb) const;
155 
159 
161  etl::handle<Layer> hit_check(const Point &point)const;
162 
163  // Set Render Method. Passes the information of the render method to use to the layers
165 
167  static inline bool active(const ContextParams &context_params, const Layer &layer) {
168  return layer.active()
169  && (context_params.render_excluded_contexts
170  || !layer.get_exclude_from_rendering());
171  }
172 
174  static inline float z_depth_visibility(const ContextParams &cp, const Layer &layer) {
175  if(!cp.z_range)
176  return 1.0;
177  float z=layer.get_true_z_depth();
178  float p=cp.z_range_position;
179  float d=cp.z_range_depth;
180  float t=cp.z_range_blur;
181  // Out of range
182  if(z>p+d+t || z<p-t)
183  return 0.0;
184  else
185  // Inside right range
186  if(z>p+d)
187  return t>0.0?(p+d+t-z)/t:0.0;
188  else
189  // Inside left range
190  if(z<p)
191  return t>0.0?(z-p+t)/t:0.0;
192  else
193  // Full visible
194  return 1.0;
195  }
196 
198  inline bool active(const Layer &layer) {
199  return active(params, layer);
200  }
201 
203  inline float z_depth_visibility(const Layer &layer) {
204  return z_depth_visibility(params, layer);
205  }
206 
208  inline bool active()const {
209  return !(operator*()).empty()
210  && active(params, *(operator*()));
211  }
212 
214  inline bool in_z_range()const {
215  return !(operator*()).empty()
216  && z_depth_visibility(params, *(operator*()));
217  }
218 
219 }; // END of class Context
220 
221 }; // END of namespace synfig
222 
223 /* === E N D =============================================================== */
224 
225 #endif