move around - flatter.
[profile/ivi/evas.git] / src / lib / canvas / evas_object_rectangle.c
1 #include "evas_common.h"
2 #include "evas_private.h"
3
4 /* private magic number for rectangle objects */
5 static const char o_type[] = "rectangle";
6
7 /* private struct for rectangle object internal data */
8 typedef struct _Evas_Object_Rectangle      Evas_Object_Rectangle;
9
10 struct _Evas_Object_Rectangle
11 {
12    DATA32            magic;
13    void             *engine_data;
14 };
15
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);
25
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);
33 #endif
34
35 static const Evas_Object_Func object_func =
36 {
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 */
43      NULL,
44      NULL,
45      NULL,
46      NULL,
47      evas_object_rectangle_is_opaque,
48      evas_object_rectangle_was_opaque,
49      NULL,
50      NULL,
51      NULL
52 };
53
54 /* the actual api call to add a rect */
55 /* it has no other api calls as all properties are standard */
56
57 /**
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.
62  */
63 EAPI Evas_Object *
64 evas_object_rectangle_add(Evas *e)
65 {
66    Evas_Object *obj;
67
68    MAGIC_CHECK(e, Evas, MAGIC_EVAS);
69    return NULL;
70    MAGIC_CHECK_END();
71    obj = evas_object_new();
72    evas_object_rectangle_init(obj);
73    evas_object_inject(obj, e);
74    return obj;
75 }
76
77
78
79
80
81
82 /* all nice and private */
83 static void
84 evas_object_rectangle_init(Evas_Object *obj)
85 {
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;
97    obj->cur.layer = 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;
103    obj->type = o_type;
104 }
105
106 static void *
107 evas_object_rectangle_new(void)
108 {
109    Evas_Object_Rectangle *o;
110
111    /* alloc obj private data */
112    o = calloc(1, sizeof(Evas_Object_Rectangle));
113    o->magic = MAGIC_OBJ_RECTANGLE;
114    return o;
115 }
116
117 static void
118 evas_object_rectangle_free(Evas_Object *obj)
119 {
120    Evas_Object_Rectangle *o;
121
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);
125    return;
126    MAGIC_CHECK_END();
127    /* free obj */
128    o->magic = 0;
129    free(o);
130 }
131
132 static void
133 evas_object_rectangle_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
134 {
135    Evas_Object_Rectangle *o;
136
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,
140                                                     context,
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,
146                                                            context);
147    obj->layer->evas->engine.func->context_render_op_set(output, context,
148                                                         obj->cur.render_op);
149    obj->layer->evas->engine.func->rectangle_draw(output,
150                                                  context,
151                                                  surface,
152                                                  obj->cur.geometry.x + x,
153                                                  obj->cur.geometry.y + y,
154                                                  obj->cur.geometry.w,
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);
160 }
161
162 static void
163 evas_object_rectangle_render_pre(Evas_Object *obj)
164 {
165    Evas_Rectangles rects = { 0, 0, NULL };
166    Evas_Object_Rectangle *o;
167    int is_v, was_v;
168
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)
180      {
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);
184      }
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);
189    if (is_v != was_v)
190      {
191         evas_object_render_pre_visible_change(&rects, obj, is_v, was_v);
192         goto done;
193      }
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))
200      {
201         evas_object_render_pre_prev_cur_add(&rects, obj);
202         goto done;
203      }
204    /* if it changed render op */
205    if (obj->cur.render_op != obj->prev.render_op)
206      {
207         evas_object_render_pre_prev_cur_add(&rects, obj);
208         goto done;
209      }
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))
215      {
216         evas_object_render_pre_prev_cur_add(&rects, obj);
217         goto done;
218      }
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))
226      {
227         evas_rects_return_difference_rects(&rects,
228                                            obj->cur.geometry.x,
229                                            obj->cur.geometry.y,
230                                            obj->cur.geometry.w,
231                                            obj->cur.geometry.h,
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);
244         goto done;
245      }
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 */
249  /*   
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);
258   */
259    done:
260    evas_object_render_pre_effect_updates(&rects, obj, is_v, was_v);
261 }
262
263 static void
264 evas_object_rectangle_render_post(Evas_Object *obj)
265 {
266    Evas_Object_Rectangle *o;
267
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)
274      {
275         Evas_Rectangle *r;
276
277         r = (Evas_Rectangle *)obj->clip.changes->data;
278         obj->clip.changes = evas_list_remove(obj->clip.changes, r);
279         free(r);
280      }
281    /* move cur to prev safely for object data */
282    obj->prev = obj->cur;
283 }
284
285 static int
286 evas_object_rectangle_is_opaque(Evas_Object *obj)
287 {
288    Evas_Object_Rectangle *o;
289
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)
294         return 1;
295    if (obj->cur.render_op != EVAS_RENDER_BLEND)
296         return 0;
297    return 1;
298 }
299
300 static int
301 evas_object_rectangle_was_opaque(Evas_Object *obj)
302 {
303    Evas_Object_Rectangle *o;
304
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)
309         return 1;
310    if (obj->prev.render_op != EVAS_RENDER_BLEND)
311         return 0;
312    return 1;
313 }
314
315 #if 0 /* usless calls for a rect object. much more useful for images etc. */
316 static void
317 evas_object_rectangle_store(Evas_Object *obj)
318 {
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 */
323 }
324
325 static void
326 evas_object_rectangle_unstore(Evas_Object *obj)
327 {
328    /* store... nothing for rectangle objects... it's a bit silly */
329 }
330
331 static int
332 evas_object_rectangle_is_visible(Evas_Object *obj)
333 {
334    Evas_Object_Rectangle *o;
335
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);
339    return 1;
340 }
341
342 static int
343 evas_object_rectangle_was_visible(Evas_Object *obj)
344 {
345    Evas_Object_Rectangle *o;
346
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);
350    return 1;
351 }
352
353 static int
354 evas_object_rectangle_is_inside(Evas_Object *obj, double x, double y)
355 {
356    Evas_Object_Rectangle *o;
357
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);
362    return 1;
363 }
364
365 static int
366 evas_object_rectangle_was_inside(Evas_Object *obj, double x, double y)
367 {
368    Evas_Object_Rectangle *o;
369
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);
374    return 1;
375 }
376 #endif