c08ee9af953277b98372a2ba84cc76cde9135008
[framework/uifw/evas.git] / src / lib / include / evas_inline.x
1 #ifndef EVAS_INLINE_H
2 #define EVAS_INLINE_H
3
4 static inline void
5 _evas_object_event_new(void)
6 {
7    _evas_event_counter++;
8 }
9
10 static inline int
11 evas_object_was_visible(Evas_Object *obj)
12 {
13    if ((obj->prev.visible) &&
14        ((obj->prev.cache.clip.visible) || (obj->smart.smart)) &&
15        (obj->prev.cache.clip.a > 0))
16      {
17         if (obj->func->was_visible)
18           return obj->func->was_visible(obj);
19         return 1;
20      }
21    return 0;
22 }
23
24 static inline void
25 evas_add_rect(Eina_Array *rects, int x, int y, int w, int h)
26 {
27    Eina_Rectangle *r;
28
29    NEW_RECT(r, x, y, w, h);
30    if (r) eina_array_push(rects, r);
31 }
32
33 static inline Cutout_Rect*
34 evas_common_draw_context_cutouts_add(Cutout_Rects* rects,
35                                      int x, int y, int w, int h)
36 {
37    Cutout_Rect* rect;
38
39    if (rects->max < (rects->active + 1))
40      {
41         rects->max += 32;
42         rects->rects = (Cutout_Rect *)realloc(rects->rects, sizeof(Cutout_Rect) * rects->max);
43      }
44
45    rect = rects->rects + rects->active;
46    rect->x = x;
47    rect->y = y;
48    rect->w = w;
49    rect->h = h;
50    rects->active++;
51
52    return rect;
53 }
54
55 static inline int
56 evas_object_is_opaque(Evas_Object *obj)
57 {
58    if (obj->smart.smart) return 0;
59    if (obj->cur.cache.clip.a == 255)
60      {
61         if (obj->func->is_opaque)
62           return obj->func->is_opaque(obj);
63         return 1;
64      }
65    return 0;
66 }
67
68 static inline int
69 evas_event_passes_through(Evas_Object *obj)
70 {
71    if (obj->layer->evas->events_frozen > 0) return 1;
72    if (obj->pass_events) return 1;
73    if (obj->parent_cache_valid) return obj->parent_pass_events;
74    if (obj->smart.parent)
75      {
76         int par_pass;
77
78         par_pass = evas_event_passes_through(obj->smart.parent);
79         obj->parent_cache_valid = 1;
80         obj->parent_pass_events = par_pass;
81         return par_pass;
82      }
83    return 0;
84 }
85
86 static inline int
87 evas_object_is_visible(Evas_Object *obj)
88 {
89    if ((obj->cur.visible) &&
90        ((obj->cur.cache.clip.visible) || (obj->smart.smart)) &&
91        (obj->cur.cache.clip.a > 0))
92      {
93         if (obj->func->is_visible)
94           return obj->func->is_visible(obj);
95         return 1;
96      }
97    return 0;
98 }
99
100 static inline int
101 evas_object_clippers_is_visible(Evas_Object *obj)
102 {
103    if (obj->cur.visible)
104      {
105         if (obj->cur.clipper)
106           return evas_object_clippers_is_visible(obj->cur.clipper);
107         return 1;
108      }
109    return 0;
110 }
111
112 static inline int
113 evas_object_is_in_output_rect(Evas_Object *obj, int x, int y, int w, int h)
114 {
115    /* assumes coords have been recalced */
116    if ((RECTS_INTERSECT(x, y, w, h,
117                         obj->cur.cache.clip.x,
118                         obj->cur.cache.clip.y,
119                         obj->cur.cache.clip.w,
120                         obj->cur.cache.clip.h)))
121      return 1;
122    return 0;
123 }
124
125 static inline int
126 evas_object_is_active(Evas_Object *obj)
127 {
128    if (evas_object_is_visible(obj) || evas_object_was_visible(obj))
129      {
130         if (obj->smart.smart)
131           {
132              int mapsmt = 0;
133              if (obj->smart.smart && (obj->cur.map && obj->cur.usemap)) mapsmt = 1;
134              if (!mapsmt) return 1;
135              if (evas_object_is_in_output_rect(obj, 0, 0, obj->layer->evas->output.w,
136                                                obj->layer->evas->output.h) ||
137                  evas_object_was_in_output_rect(obj, 0, 0, obj->layer->evas->output.w,
138                                                 obj->layer->evas->output.h))
139                return 1;
140           }
141         else
142           {
143              if (evas_object_is_in_output_rect(obj, 0, 0, obj->layer->evas->output.w,
144                                                obj->layer->evas->output.h) ||
145                  evas_object_was_in_output_rect(obj, 0, 0, obj->layer->evas->output.w,
146                                                 obj->layer->evas->output.h))
147                return 1;
148           }
149      }
150    return 0;
151 }
152
153 static inline void
154 evas_object_coords_recalc(Evas_Object *obj)
155 {
156 ////   if (obj->cur.cache.geometry.validity == obj->layer->evas->output_validity)
157 ////     return;
158 ////   obj->cur.cache.geometry.x =
159 ////     evas_coord_world_x_to_screen(obj->layer->evas, obj->cur.geometry.x);
160 ////   obj->cur.cache.geometry.y =
161 ////     evas_coord_world_y_to_screen(obj->layer->evas, obj->cur.geometry.y);
162 ////   obj->cur.cache.geometry.w =
163 ////     evas_coord_world_x_to_screen(obj->layer->evas, obj->cur.geometry.w) -
164 ////     evas_coord_world_x_to_screen(obj->layer->evas, 0);
165 ////   obj->cur.cache.geometry.h =
166 ////     evas_coord_world_y_to_screen(obj->layer->evas, obj->cur.geometry.h) -
167 ////     evas_coord_world_y_to_screen(obj->layer->evas, 0);
168    if (obj->func->coords_recalc) obj->func->coords_recalc(obj);
169 ////   obj->cur.cache.geometry.validity = obj->layer->evas->output_validity;
170 }
171
172 static inline void
173 evas_object_clip_recalc(Evas_Object *obj)
174 {
175    int cx, cy, cw, ch, cvis, cr, cg, cb, ca;
176    int nx, ny, nw, nh, nvis, nr, ng, nb, na;
177
178    if (!obj->cur.cache.clip.dirty &&
179        !(obj->cur.clipper == NULL || obj->cur.clipper->cur.cache.clip.dirty))
180      return;
181    if (obj->layer->evas->events_frozen > 0) return;
182    evas_object_coords_recalc(obj);
183    if ((obj->cur.map) && (obj->cur.usemap))
184      {
185         cx = obj->cur.map->normal_geometry.x;
186         cy = obj->cur.map->normal_geometry.y;
187         cw = obj->cur.map->normal_geometry.w;
188         ch = obj->cur.map->normal_geometry.h;
189      }
190    else
191      {
192         cx = obj->cur.geometry.x;
193         cy = obj->cur.geometry.y;
194         cw = obj->cur.geometry.w;
195         ch = obj->cur.geometry.h;
196      }
197 ////   cx = obj->cur.cache.geometry.x; cy = obj->cur.cache.geometry.y;
198 ////   cw = obj->cur.cache.geometry.w; ch = obj->cur.cache.geometry.h;
199    if (obj->cur.color.a == 0) cvis = 0;
200    else cvis = obj->cur.visible;
201    cr = obj->cur.color.r; cg = obj->cur.color.g;
202    cb = obj->cur.color.b; ca = obj->cur.color.a;
203    if (obj->cur.clipper)
204      {
205 // this causes problems... hmmm
206         if (obj->cur.clipper->cur.cache.clip.dirty)
207           evas_object_clip_recalc(obj->cur.clipper);
208         nx = obj->cur.clipper->cur.cache.clip.x;
209         ny = obj->cur.clipper->cur.cache.clip.y;
210         nw = obj->cur.clipper->cur.cache.clip.w;
211         nh = obj->cur.clipper->cur.cache.clip.h;
212         RECTS_CLIP_TO_RECT(cx, cy, cw, ch, nx, ny, nw, nh);
213
214         nvis = obj->cur.clipper->cur.cache.clip.visible;
215         nr = obj->cur.clipper->cur.cache.clip.r;
216         ng = obj->cur.clipper->cur.cache.clip.g;
217         nb = obj->cur.clipper->cur.cache.clip.b;
218         na = obj->cur.clipper->cur.cache.clip.a;
219         cvis = cvis * nvis;
220         cr = (cr * (nr + 1)) >> 8;
221         cg = (cg * (ng + 1)) >> 8;
222         cb = (cb * (nb + 1)) >> 8;
223         ca = (ca * (na + 1)) >> 8;
224      }
225    if ((ca == 0) || (cw <= 0) || (ch <= 0)) cvis = 0;
226    obj->cur.cache.clip.x = cx;
227    obj->cur.cache.clip.y = cy;
228    obj->cur.cache.clip.w = cw;
229    obj->cur.cache.clip.h = ch;
230    obj->cur.cache.clip.visible = cvis;
231    obj->cur.cache.clip.r = cr;
232    obj->cur.cache.clip.g = cg;
233    obj->cur.cache.clip.b = cb;
234    obj->cur.cache.clip.a = ca;
235    obj->cur.cache.clip.dirty = 0;
236 }
237
238 #endif