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 const char *o_rect_type = o_type;
9 /* private struct for rectangle object internal data */
10 typedef struct _Evas_Object_Rectangle Evas_Object_Rectangle;
12 struct _Evas_Object_Rectangle
18 /* private methods for rectangle objects */
19 static void evas_object_rectangle_init(Evas_Object *obj);
20 static void *evas_object_rectangle_new(void);
21 static void evas_object_rectangle_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
22 static void evas_object_rectangle_free(Evas_Object *obj);
23 static void evas_object_rectangle_render_pre(Evas_Object *obj);
24 static void evas_object_rectangle_render_post(Evas_Object *obj);
26 static unsigned int evas_object_rectangle_id_get(Evas_Object *obj);
27 static unsigned int evas_object_rectangle_visual_id_get(Evas_Object *obj);
28 static void *evas_object_rectangle_engine_data_get(Evas_Object *obj);
30 static int evas_object_rectangle_is_opaque(Evas_Object *obj);
31 static int evas_object_rectangle_was_opaque(Evas_Object *obj);
33 #if 0 /* usless calls for a rect object. much more useful for images etc. */
34 static void evas_object_rectangle_store(Evas_Object *obj);
35 static void evas_object_rectangle_unstore(Evas_Object *obj);
36 static int evas_object_rectangle_is_visible(Evas_Object *obj);
37 static int evas_object_rectangle_was_visible(Evas_Object *obj);
38 static int evas_object_rectangle_is_inside(Evas_Object *obj, double x, double y);
39 static int evas_object_rectangle_was_inside(Evas_Object *obj, double x, double y);
42 static const Evas_Object_Func object_func =
44 /* methods (compulsory) */
45 evas_object_rectangle_free,
46 evas_object_rectangle_render,
47 evas_object_rectangle_render_pre,
48 evas_object_rectangle_render_post,
49 evas_object_rectangle_id_get,
50 evas_object_rectangle_visual_id_get,
51 evas_object_rectangle_engine_data_get,
52 /* these are optional. NULL = nothing */
57 evas_object_rectangle_is_opaque,
58 evas_object_rectangle_was_opaque,
68 /* the actual api call to add a rect */
69 /* it has no other api calls as all properties are standard */
71 EVAS_MEMPOOL(_mp_obj);
74 evas_object_rectangle_add(Evas *e)
78 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
81 obj = evas_object_new(e);
82 evas_object_rectangle_init(obj);
83 evas_object_inject(obj, e);
87 /* all nice and private */
89 evas_object_rectangle_init(Evas_Object *obj)
91 /* alloc image ob, setup methods and default values */
92 obj->object_data = evas_object_rectangle_new();
93 /* set up default settings for this kind of object */
94 obj->cur.color.r = 255;
95 obj->cur.color.g = 255;
96 obj->cur.color.b = 255;
97 obj->cur.color.a = 255;
98 obj->cur.geometry.x = 0;
99 obj->cur.geometry.y = 0;
100 obj->cur.geometry.w = 0;
101 obj->cur.geometry.h = 0;
103 obj->cur.render_op = EVAS_RENDER_BLEND;
104 /* set up object-specific settings */
105 obj->prev = obj->cur;
106 /* set up methods (compulsory) */
107 obj->func = &object_func;
112 evas_object_rectangle_new(void)
114 Evas_Object_Rectangle *o;
116 /* alloc obj private data */
117 EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_rectangle", Evas_Object_Rectangle, 256, NULL);
118 o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Rectangle);
120 EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Rectangle);
121 o->magic = MAGIC_OBJ_RECTANGLE;
126 evas_object_rectangle_free(Evas_Object *obj)
128 Evas_Object_Rectangle *o;
130 /* frees private object data. very simple here */
131 o = (Evas_Object_Rectangle *)(obj->object_data);
132 MAGIC_CHECK(o, Evas_Object_Rectangle, MAGIC_OBJ_RECTANGLE);
137 EVAS_MEMPOOL_FREE(_mp_obj, o);
141 evas_object_rectangle_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
143 /* render object to surface with context, and offxet by x,y */
144 obj->layer->evas->engine.func->context_color_set(output,
146 obj->cur.cache.clip.r,
147 obj->cur.cache.clip.g,
148 obj->cur.cache.clip.b,
149 obj->cur.cache.clip.a);
150 obj->layer->evas->engine.func->context_multiplier_unset(output,
152 obj->layer->evas->engine.func->context_render_op_set(output, context,
154 obj->layer->evas->engine.func->rectangle_draw(output,
157 obj->cur.geometry.x + x,
158 obj->cur.geometry.y + y,
160 obj->cur.geometry.h);
161 //// obj->cur.cache.geometry.x + x,
162 //// obj->cur.cache.geometry.y + y,
163 //// obj->cur.cache.geometry.w,
164 //// obj->cur.cache.geometry.h);
168 evas_object_rectangle_render_pre(Evas_Object *obj)
172 /* dont pre-render the obj twice! */
173 if (obj->pre_render_done) return;
174 obj->pre_render_done = 1;
175 /* pre-render phase. this does anything an object needs to do just before */
176 /* rendering. this could mean loading the image data, retrieving it from */
177 /* elsewhere, decoding video etc. */
178 /* then when this is done the object needs to figure if it changed and */
179 /* if so what and where and add the appropriate redraw rectangles */
180 /* if someone is clipping this obj - go calculate the clipper */
181 if (obj->cur.clipper)
183 if (obj->cur.cache.clip.dirty)
184 evas_object_clip_recalc(obj->cur.clipper);
185 obj->cur.clipper->func->render_pre(obj->cur.clipper);
187 /* now figure what changed and add draw rects */
188 /* if it just became visible or invisible */
189 is_v = evas_object_is_visible(obj);
190 was_v = evas_object_was_visible(obj);
191 if (!(is_v | was_v)) goto done;
194 evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes, obj, is_v, was_v);
197 if (obj->changed_map)
199 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes,
203 /* it's not visible - we accounted for it appearing or not so just abort */
204 if (!is_v) goto done;
205 /* clipper changed this is in addition to anything else for obj */
206 evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, obj);
207 /* if we restacked (layer or just within a layer) and don't clip anyone */
208 if ((obj->restack) && (!obj->clip.clipees))
210 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
213 /* if it changed render op */
214 if (obj->cur.render_op != obj->prev.render_op)
216 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
219 /* if it changed color */
220 if ((obj->cur.color.r != obj->prev.color.r) ||
221 (obj->cur.color.g != obj->prev.color.g) ||
222 (obj->cur.color.b != obj->prev.color.b) ||
223 (obj->cur.color.a != obj->prev.color.a))
225 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
228 /* if it changed geometry - and obviously not visibility or color */
229 /* calculate differences since we have a constant color fill */
230 /* we really only need to update the differences */
231 if ((obj->cur.geometry.x != obj->prev.geometry.x) ||
232 (obj->cur.geometry.y != obj->prev.geometry.y) ||
233 (obj->cur.geometry.w != obj->prev.geometry.w) ||
234 (obj->cur.geometry.h != obj->prev.geometry.h))
236 evas_rects_return_difference_rects(&obj->layer->evas->clip_changes,
241 obj->prev.geometry.x,
242 obj->prev.geometry.y,
243 obj->prev.geometry.w,
244 obj->prev.geometry.h);
245 //// rl = evas_rects_return_difference_rects(obj->cur.cache.geometry.x,
246 //// obj->cur.cache.geometry.y,
247 //// obj->cur.cache.geometry.w,
248 //// obj->cur.cache.geometry.h,
249 //// obj->prev.cache.geometry.x,
250 //// obj->prev.cache.geometry.y,
251 //// obj->prev.cache.geometry.w,
252 //// obj->prev.cache.geometry.h);
255 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
256 /* area so if there were updates for it they get wiped. don't do it if we */
257 /* arent fully opaque and we are visible */
259 if (evas_object_is_visible(obj) &&
260 evas_object_is_opaque(obj) &&
261 (!obj->clip.clipees))
262 obj->layer->evas->engine.func->output_redraws_rect_del(obj->layer->evas->engine.data.output,
263 obj->cur.cache.clip.x,
264 obj->cur.cache.clip.y,
265 obj->cur.cache.clip.w,
266 obj->cur.cache.clip.h);
269 evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes, obj, is_v, was_v);
273 evas_object_rectangle_render_post(Evas_Object *obj)
276 /* this moves the current data to the previous state parts of the object */
277 /* in whatever way is safest for the object. also if we don't need object */
278 /* data anymore we can free it if the object deems this is a good idea */
279 /* remove those pesky changes */
280 evas_object_clip_changes_clean(obj);
281 /* move cur to prev safely for object data */
282 obj->prev = obj->cur;
286 evas_object_rectangle_is_opaque(Evas_Object *obj)
288 /* this returns 1 if the internal object data implies that the object is */
289 /* currently fully opaque over the entire rectangle it occupies */
290 if ((obj->cur.map) && (obj->cur.usemap)) return 0;
291 if (obj->cur.render_op == EVAS_RENDER_COPY)
293 if (obj->cur.render_op != EVAS_RENDER_BLEND)
299 evas_object_rectangle_was_opaque(Evas_Object *obj)
301 /* this returns 1 if the internal object data implies that the object was */
302 /* previously fully opaque over the entire rectangle it occupies */
303 if (obj->prev.render_op == EVAS_RENDER_COPY)
305 if (obj->prev.render_op != EVAS_RENDER_BLEND)
310 static unsigned int evas_object_rectangle_id_get(Evas_Object *obj)
312 Evas_Object_Rectangle *o;
314 o = (Evas_Object_Rectangle *)(obj->object_data);
316 return MAGIC_OBJ_RECTANGLE;
319 static unsigned int evas_object_rectangle_visual_id_get(Evas_Object *obj)
321 Evas_Object_Rectangle *o;
323 o = (Evas_Object_Rectangle *)(obj->object_data);
325 return MAGIC_OBJ_SHAPE;
328 static void *evas_object_rectangle_engine_data_get(Evas_Object *obj)
330 Evas_Object_Rectangle *o;
332 o = (Evas_Object_Rectangle *)(obj->object_data);
334 return o->engine_data;
338 #if 0 /* usless calls for a rect object. much more useful for images etc. */
340 evas_object_rectangle_store(Evas_Object *obj)
342 /* store... nothing for rectangle objects... it's a bit silly */
343 /* but for others that may have expensive caluclations to do to */
344 /* generate the object data, hint that they might want to be pre-calced */
345 /* once and stored */
349 evas_object_rectangle_unstore(Evas_Object *obj)
351 /* store... nothing for rectangle objects... it's a bit silly */
355 evas_object_rectangle_is_visible(Evas_Object *obj)
357 /* this returns 1 if the internal object data would imply that it is */
358 /* visible (ie drawing it draws something. this is not to do with events */
363 evas_object_rectangle_was_visible(Evas_Object *obj)
365 /* this returns 1 if the internal object data would imply that it was */
366 /* visible (ie drawing it draws something. this is not to do with events */
371 evas_object_rectangle_is_inside(Evas_Object *obj, double x, double y)
373 /* this returns 1 if the canvas co-ordinates are inside the object based */
374 /* on object private data. not much use for rects, but for polys, images */
375 /* and other complex objects it might be */
380 evas_object_rectangle_was_inside(Evas_Object *obj, double x, double y)
382 /* this returns 1 if the canvas co-ordinates were inside the object based */
383 /* on object private data. not much use for rects, but for polys, images */
384 /* and other complex objects it might be */