1 #include "evas_common.h"
2 #include "evas_private.h"
4 /* private magic number for rectangle objects */
5 static const char o_type[] = "rectangle";
7 /* private struct for rectangle object internal data */
8 typedef struct _Evas_Object_Rectangle Evas_Object_Rectangle;
10 struct _Evas_Object_Rectangle
16 /* private methods for rectangle objects */
17 static void evas_object_rectangle_init(Evas_Object *obj);
18 static void *evas_object_rectangle_new(void);
19 static void evas_object_rectangle_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
20 static void evas_object_rectangle_free(Evas_Object *obj);
21 static void evas_object_rectangle_render_pre(Evas_Object *obj);
22 static void evas_object_rectangle_render_post(Evas_Object *obj);
23 static int evas_object_rectangle_is_opaque(Evas_Object *obj);
24 static int evas_object_rectangle_was_opaque(Evas_Object *obj);
26 #if 0 /* usless calls for a rect object. much more useful for images etc. */
27 static void evas_object_rectangle_store(Evas_Object *obj);
28 static void evas_object_rectangle_unstore(Evas_Object *obj);
29 static int evas_object_rectangle_is_visible(Evas_Object *obj);
30 static int evas_object_rectangle_was_visible(Evas_Object *obj);
31 static int evas_object_rectangle_is_inside(Evas_Object *obj, double x, double y);
32 static int evas_object_rectangle_was_inside(Evas_Object *obj, double x, double y);
35 static const Evas_Object_Func object_func =
37 /* methods (compulsory) */
38 evas_object_rectangle_free,
39 evas_object_rectangle_render,
40 evas_object_rectangle_render_pre,
41 evas_object_rectangle_render_post,
42 /* these are optional. NULL = nothing */
47 evas_object_rectangle_is_opaque,
48 evas_object_rectangle_was_opaque,
54 /* the actual api call to add a rect */
55 /* it has no other api calls as all properties are standard */
58 * Adds a rectangle to the given evas.
59 * @param e The given evas.
60 * @return The new rectangle object.
61 * @todo Find a documentation group to put this under.
64 evas_object_rectangle_add(Evas *e)
68 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
71 obj = evas_object_new();
72 evas_object_rectangle_init(obj);
73 evas_object_inject(obj, e);
82 /* all nice and private */
84 evas_object_rectangle_init(Evas_Object *obj)
86 /* alloc image ob, setup methods and default values */
87 obj->object_data = evas_object_rectangle_new();
88 /* set up default settings for this kind of object */
89 obj->cur.color.r = 255;
90 obj->cur.color.g = 255;
91 obj->cur.color.b = 255;
92 obj->cur.color.a = 255;
93 obj->cur.geometry.x = 0;
94 obj->cur.geometry.y = 0;
95 obj->cur.geometry.w = 0;
96 obj->cur.geometry.h = 0;
98 obj->cur.render_op = EVAS_RENDER_BLEND;
99 /* set up object-specific settings */
100 obj->prev = obj->cur;
101 /* set up methods (compulsory) */
102 obj->func = &object_func;
107 evas_object_rectangle_new(void)
109 Evas_Object_Rectangle *o;
111 /* alloc obj private data */
112 o = calloc(1, sizeof(Evas_Object_Rectangle));
113 o->magic = MAGIC_OBJ_RECTANGLE;
118 evas_object_rectangle_free(Evas_Object *obj)
120 Evas_Object_Rectangle *o;
122 /* frees private object data. very simple here */
123 o = (Evas_Object_Rectangle *)(obj->object_data);
124 MAGIC_CHECK(o, Evas_Object_Rectangle, MAGIC_OBJ_RECTANGLE);
133 evas_object_rectangle_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
135 Evas_Object_Rectangle *o;
137 /* render object to surface with context, and offxet by x,y */
138 o = (Evas_Object_Rectangle *)(obj->object_data);
139 obj->layer->evas->engine.func->context_color_set(output,
141 obj->cur.cache.clip.r,
142 obj->cur.cache.clip.g,
143 obj->cur.cache.clip.b,
144 obj->cur.cache.clip.a);
145 obj->layer->evas->engine.func->context_multiplier_unset(output,
147 obj->layer->evas->engine.func->context_render_op_set(output, context,
149 obj->layer->evas->engine.func->rectangle_draw(output,
152 obj->cur.geometry.x + x,
153 obj->cur.geometry.y + y,
155 obj->cur.geometry.h);
156 //// obj->cur.cache.geometry.x + x,
157 //// obj->cur.cache.geometry.y + y,
158 //// obj->cur.cache.geometry.w,
159 //// obj->cur.cache.geometry.h);
163 evas_object_rectangle_render_pre(Evas_Object *obj)
165 Evas_Rectangles rects = { 0, 0, NULL };
166 Evas_Object_Rectangle *o;
169 /* dont pre-render the obj twice! */
170 if (obj->pre_render_done) return;
171 obj->pre_render_done = 1;
172 /* pre-render phase. this does anything an object needs to do just before */
173 /* rendering. this could mean loading the image data, retrieving it from */
174 /* elsewhere, decoding video etc. */
175 /* then when this is done the object needs to figure if it changed and */
176 /* if so what and where and add the appropriate redraw rectangles */
177 o = (Evas_Object_Rectangle *)(obj->object_data);
178 /* if someone is clipping this obj - go calculate the clipper */
179 if (obj->cur.clipper)
181 if (obj->cur.cache.clip.dirty)
182 evas_object_clip_recalc(obj->cur.clipper);
183 obj->cur.clipper->func->render_pre(obj->cur.clipper);
185 /* now figure what changed and add draw rects */
186 /* if it just became visible or invisible */
187 is_v = evas_object_is_visible(obj);
188 was_v = evas_object_was_visible(obj);
191 evas_object_render_pre_visible_change(&rects, obj, is_v, was_v);
194 /* it's not visible - we accounted for it appearing or not so just abort */
195 if (!is_v) goto done;
196 /* clipper changed this is in addition to anything else for obj */
197 evas_object_render_pre_clipper_change(&rects, obj);
198 /* if we restacked (layer or just within a layer) and don't clip anyone */
199 if ((obj->restack) && (!obj->clip.clipees))
201 evas_object_render_pre_prev_cur_add(&rects, obj);
204 /* if it changed render op */
205 if (obj->cur.render_op != obj->prev.render_op)
207 evas_object_render_pre_prev_cur_add(&rects, obj);
210 /* if it changed color */
211 if ((obj->cur.color.r != obj->prev.color.r) ||
212 (obj->cur.color.g != obj->prev.color.g) ||
213 (obj->cur.color.b != obj->prev.color.b) ||
214 (obj->cur.color.a != obj->prev.color.a))
216 evas_object_render_pre_prev_cur_add(&rects, obj);
219 /* if it changed geometry - and obviously not visibility or color */
220 /* caluclate differences since we have a constant color fill */
221 /* we really only need to update the differences */
222 if ((obj->cur.geometry.x != obj->prev.geometry.x) ||
223 (obj->cur.geometry.y != obj->prev.geometry.y) ||
224 (obj->cur.geometry.w != obj->prev.geometry.w) ||
225 (obj->cur.geometry.h != obj->prev.geometry.h))
227 evas_rects_return_difference_rects(&rects,
232 obj->prev.geometry.x,
233 obj->prev.geometry.y,
234 obj->prev.geometry.w,
235 obj->prev.geometry.h);
236 //// rl = evas_rects_return_difference_rects(obj->cur.cache.geometry.x,
237 //// obj->cur.cache.geometry.y,
238 //// obj->cur.cache.geometry.w,
239 //// obj->cur.cache.geometry.h,
240 //// obj->prev.cache.geometry.x,
241 //// obj->prev.cache.geometry.y,
242 //// obj->prev.cache.geometry.w,
243 //// obj->prev.cache.geometry.h);
246 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
247 /* area so if there were updates for it they get wiped. don't do it if we */
248 /* arent fully opaque and we are visible */
250 if (evas_object_is_visible(obj) &&
251 evas_object_is_opaque(obj) &&
252 (!obj->clip.clipees))
253 obj->layer->evas->engine.func->output_redraws_rect_del(obj->layer->evas->engine.data.output,
254 obj->cur.cache.clip.x,
255 obj->cur.cache.clip.y,
256 obj->cur.cache.clip.w,
257 obj->cur.cache.clip.h);
260 evas_object_render_pre_effect_updates(&rects, obj, is_v, was_v);
264 evas_object_rectangle_render_post(Evas_Object *obj)
266 Evas_Object_Rectangle *o;
268 /* this moves the current data to the previous state parts of the object */
269 /* in whatever way is safest for the object. also if we don't need object */
270 /* data anymore we can free it if the object deems this is a good idea */
271 o = (Evas_Object_Rectangle *)(obj->object_data);
272 /* remove those pesky changes */
273 while (obj->clip.changes)
277 r = (Evas_Rectangle *)obj->clip.changes->data;
278 obj->clip.changes = evas_list_remove(obj->clip.changes, r);
281 /* move cur to prev safely for object data */
282 obj->prev = obj->cur;
286 evas_object_rectangle_is_opaque(Evas_Object *obj)
288 Evas_Object_Rectangle *o;
290 /* this returns 1 if the internal object data implies that the object is */
291 /* currently fully opaque over the entire rectangle it occupies */
292 o = (Evas_Object_Rectangle *)(obj->object_data);
293 if (obj->cur.render_op == EVAS_RENDER_COPY)
295 if (obj->cur.render_op != EVAS_RENDER_BLEND)
301 evas_object_rectangle_was_opaque(Evas_Object *obj)
303 Evas_Object_Rectangle *o;
305 /* this returns 1 if the internal object data implies that the object was */
306 /* previously fully opaque over the entire rectangle it occupies */
307 o = (Evas_Object_Rectangle *)(obj->object_data);
308 if (obj->prev.render_op == EVAS_RENDER_COPY)
310 if (obj->prev.render_op != EVAS_RENDER_BLEND)
315 #if 0 /* usless calls for a rect object. much more useful for images etc. */
317 evas_object_rectangle_store(Evas_Object *obj)
319 /* store... nothing for rectangle objects... it's a bit silly */
320 /* but for others that may have expensive caluclations to do to */
321 /* generate the object data, hint that they might want to be pre-calced */
322 /* once and stored */
326 evas_object_rectangle_unstore(Evas_Object *obj)
328 /* store... nothing for rectangle objects... it's a bit silly */
332 evas_object_rectangle_is_visible(Evas_Object *obj)
334 Evas_Object_Rectangle *o;
336 /* this returns 1 if the internal object data would imply that it is */
337 /* visible (ie drawing it draws something. this is not to do with events */
338 o = (Evas_Object_Rectangle *)(obj->object_data);
343 evas_object_rectangle_was_visible(Evas_Object *obj)
345 Evas_Object_Rectangle *o;
347 /* this returns 1 if the internal object data would imply that it was */
348 /* visible (ie drawing it draws something. this is not to do with events */
349 o = (Evas_Object_Rectangle *)(obj->object_data);
354 evas_object_rectangle_is_inside(Evas_Object *obj, double x, double y)
356 Evas_Object_Rectangle *o;
358 /* this returns 1 if the canvas co-ordinates are inside the object based */
359 /* on object private data. not much use for rects, but for polys, images */
360 /* and other complex objects it might be */
361 o = (Evas_Object_Rectangle *)(obj->object_data);
366 evas_object_rectangle_was_inside(Evas_Object *obj, double x, double y)
368 Evas_Object_Rectangle *o;
370 /* this returns 1 if the canvas co-ordinates were inside the object based */
371 /* on object private data. not much use for rects, but for polys, images */
372 /* and other complex objects it might be */
373 o = (Evas_Object_Rectangle *)(obj->object_data);