summaryrefslogtreecommitdiff
path: root/legacy/evas/src/lib/canvas/evas_clip.c
blob: 58da28c7c1202de0ee9022783e96edd3ce5375a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#include "evas_common.h"
#include "evas_private.h"

void
evas_object_clip_recalc(Evas_Object *obj)
{
   int cx, cy, cw, ch, cvis, cr, cg, cb, ca;
   int nx, ny, nw, nh, nvis, nr, ng, nb, na;

   if (obj->layer->evas->events_frozen > 0) return;
   evas_object_coords_recalc(obj);
   cx = obj->cur.cache.geometry.x; cy = obj->cur.cache.geometry.y;
   cw = obj->cur.cache.geometry.w; ch = obj->cur.cache.geometry.h;
   if (obj->cur.color.a == 0) cvis = 0;
   else cvis = obj->cur.visible;
   cr = obj->cur.color.r; cg = obj->cur.color.g;
   cb = obj->cur.color.b; ca = obj->cur.color.a;
   if (obj->cur.clipper)
     {
// this causes problems... hmmm
//	if (obj->cur.clipper->cur.cache.clip.dirty)
	  evas_object_clip_recalc(obj->cur.clipper);
	nx = obj->cur.clipper->cur.cache.clip.x;
	ny = obj->cur.clipper->cur.cache.clip.y;
	nw = obj->cur.clipper->cur.cache.clip.w;
	nh = obj->cur.clipper->cur.cache.clip.h;
	nvis = obj->cur.clipper->cur.cache.clip.visible;
	nr = obj->cur.clipper->cur.cache.clip.r;
	ng = obj->cur.clipper->cur.cache.clip.g;
	nb = obj->cur.clipper->cur.cache.clip.b;
	na = obj->cur.clipper->cur.cache.clip.a;
	RECTS_CLIP_TO_RECT(cx, cy, cw, ch, nx, ny, nw, nh);
	cvis = cvis * nvis;
	cr = (cr * (nr + 1)) >> 8;
	cg = (cg * (ng + 1)) >> 8;
	cb = (cb * (nb + 1)) >> 8;
	ca = (ca * (na + 1)) >> 8;
     }
   if ((ca == 0) || (cw <= 0) || (ch <= 0)) cvis = 0;
   obj->cur.cache.clip.x = cx;
   obj->cur.cache.clip.y = cy;
   obj->cur.cache.clip.w = cw;
   obj->cur.cache.clip.h = ch;
   obj->cur.cache.clip.visible = cvis;
   obj->cur.cache.clip.r = cr;
   obj->cur.cache.clip.g = cg;
   obj->cur.cache.clip.b = cb;
   obj->cur.cache.clip.a = ca;
   obj->cur.cache.clip.dirty = 0;
}

void
evas_object_clip_dirty(Evas_Object *obj)
{
   Evas_List *l;

   obj->cur.cache.clip.dirty = 1;
   for (l = obj->clip.clipees; l; l = l->next)
     evas_object_clip_dirty(l->data);
}

void
evas_object_recalc_clippees(Evas_Object *obj)
{
   Evas_List *l;

   if (obj->cur.cache.clip.dirty)
     {
	evas_object_clip_recalc(obj);
	for (l = obj->clip.clipees; l; l = l->next)
	  evas_object_recalc_clippees(l->data);
     }
}

int
evas_object_clippers_is_visible(Evas_Object *obj)
{
   if (obj->cur.visible)
     {
	if (obj->cur.clipper)
	  return evas_object_clippers_is_visible(obj->cur.clipper);
	return 1;
     }
   return 0;
}

int
evas_object_clippers_was_visible(Evas_Object *obj)
{
   if (obj->prev.visible)
     {
	if (obj->prev.clipper)
	  return evas_object_clippers_is_visible(obj->prev.clipper);
	return 1;
     }
   return 0;
}

/* public functions */

/**
 * @defgroup Evas_Clip_Group Clip Functions
 *
 * Functions that manage the clipping of objects by other objects.
 */

/**
 * Clip one object to another.
 * @param obj The object to be clipped
 * @param clip The object to clip @p obj by
 *
 * This function will clip the object @p obj to the area occupied by the
 * object @p clipper. This means the object @p obj will only be visible within
 * the area occupied by the clipping object (@p clip). The color of the object
 * being clipped will be multiplied by the color of the clipping object, so
 * the resulting color for the clipped object is
 * RESULT = (OBJ * CLIP) / (255 * 255) per color element (red, green, blue and
 * alpha). Clipping is recursive, so clip objects may be clipped by other
 * objects, and their color will in tern be multiplied. You may NOT set up
 * circular clipping lists (i.e. object 1 clips object 2 which clips object 1).
 * The behavior of Evas is undefined in this case. Objects which do not clip
 * others are visible as normal, those that clip 1 or more objects become
 * invisible themselves, only affecting what they clip. If an object ceases to
 * have other objects being clipped by it, it will become visible again. The
 * visibility of an object affects the objects that are clipped by it, so if
 * the object clipping others is not shown, the objects clipped will not be
 * shown either. If the object was being clipped by another object when this
 * function is called, it is implicitly removed from the clipper it is being
 * clipped to, and now is made to clip its new clipper.
 *
 * At the moment the only objects that can validly be used to clip other
 * objects are rectangle objects. All other object types are invalid and the
 * result of using them is undefined.
 *
 * The clip object @p clip must be a valid object, but may also be NULL in
 * which case the effect of this function is the same as calling
 * evas_object_clip_unset() on the @p obj object.
 *
 * Example:
 * @code
 * extern Evas *evas;
 * extern Evas_Object *obj;
 * Evas_Object *clipper;
 *
 * clipper = evas_object_rectangle_add(evas);
 * evas_object_color_set(clipper, 255, 255, 255, 255);
 * evas_object_move(clipper, 10, 10);
 * evas_object_resize(clipper, 20, 50);
 * evas_object_clip_set(obj, clipper);
 * evas_object_show(clipper);
 * @endcode
 *
 * @ingroup Evas_Clip_Group
 */
EAPI void
evas_object_clip_set(Evas_Object *obj, Evas_Object *clip)
{
   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   if (!clip)
     {
	evas_object_clip_unset(obj);
	return;
     }
   MAGIC_CHECK(clip, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   if (obj->cur.clipper == clip) return;
   if (obj->smart.smart)
     {
       if (obj->smart.smart->smart_class->clip_set)
	  obj->smart.smart->smart_class->clip_set(obj, clip);
     }
   if (obj->cur.clipper)
     {
	/* unclip */
	obj->cur.clipper->clip.clipees = evas_list_remove(obj->cur.clipper->clip.clipees, obj);
	if (!obj->cur.clipper->clip.clipees) obj->cur.clipper->cur.have_clipees = 0;
	evas_object_change(obj->cur.clipper);
	evas_object_change(obj);
	obj->cur.clipper = NULL;
     }
   /* clip me */
   if ((clip->clip.clipees == NULL) && (clip->cur.visible))
     {
	/* Basically it just went invisible */
	clip->changed = 1;
	clip->layer->evas->changed = 1;
	evas_damage_rectangle_add(clip->layer->evas,
				  clip->cur.geometry.x, clip->cur.geometry.y,
				  clip->cur.geometry.w, clip->cur.geometry.h);
     }
   obj->cur.clipper = clip;
   clip->clip.clipees = evas_list_append(clip->clip.clipees, obj);
   if (clip->clip.clipees) clip->cur.have_clipees = 1;
   evas_object_change(clip);
   evas_object_change(obj);
   evas_object_clip_dirty(obj);
   evas_object_recalc_clippees(obj);
   if (!obj->smart.smart)
     {
	if (evas_object_is_in_output_rect(obj,
					  obj->layer->evas->pointer.x,
					  obj->layer->evas->pointer.y, 1, 1))
	  evas_event_feed_mouse_move(obj->layer->evas,
				     obj->layer->evas->pointer.x,
				     obj->layer->evas->pointer.y,
				     obj->layer->evas->last_timestamp,
				     NULL);
     }
}

/**
 * Get the object clipping this one (if any).
 * @param obj The object to get the clipper from
 *
 * This function returns the the object clipping @p obj. If @p obj not being
 * clipped, NULL is returned. The object @p obj must be a valid object.
 *
 * See also evas_object_clip_set(), evas_object_clip_unset() and
 * evas_object_clipees_get().
 *
 * Example:
 * @code
 * extern Evas_Object *obj;
 * Evas_Object *clipper;
 *
 * clipper = evas_object_clip_get(obj);
 * if (clipper) evas_object_show(clipper);
 * @endcode
 *
 * @ingroup Evas_Clip_Group
 */
EAPI Evas_Object *
evas_object_clip_get(Evas_Object *obj)
{
   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return NULL;
   MAGIC_CHECK_END();
   return obj->cur.clipper;
}

/**
 * Disable clipping for an object.
 *
 * @param obj The object to cease clipping on
 *
 * This function disables clipping for the object @p obj, if it was already
 * clipped. If it wasn't, this has no effect. The object @p obj must be a
 * valid object.
 *
 * See also evas_object_clip_set(), evas_object_clipees_get() and
 * evas_object_clip_get().
 *
 * Example:
 * @code
 * extern Evas_Object *obj;
 * Evas_Object *clipper;
 *
 * clipper = evas_object_clip_get(obj);
 * if (clipper)
 *   {
 *     evas_object_clip_unset(obj);
 *     evas_object_hide(obj);
 *   }
 * @endcode
 *
 * @ingroup Evas_Clip_Group
 */
EAPI void
evas_object_clip_unset(Evas_Object *obj)
{
   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return;
   MAGIC_CHECK_END();
   if (!obj->cur.clipper) return;
   /* unclip */
   if (obj->smart.smart)
     {
       if (obj->smart.smart->smart_class->clip_unset)
	  obj->smart.smart->smart_class->clip_unset(obj);
     }
   if (obj->cur.clipper) 
     {
        obj->cur.clipper->clip.clipees = evas_list_remove(obj->cur.clipper->clip.clipees, obj);
	if (!obj->cur.clipper->clip.clipees) 
	  obj->cur.clipper->cur.have_clipees = 0;
	evas_object_change(obj->cur.clipper);
     }
   obj->cur.clipper = NULL;
   evas_object_change(obj);
   evas_object_clip_dirty(obj);
   evas_object_recalc_clippees(obj);
   if (!obj->smart.smart)
     {
	if (evas_object_is_in_output_rect(obj,
					  obj->layer->evas->pointer.x,
					  obj->layer->evas->pointer.y, 1, 1))
	  evas_event_feed_mouse_move(obj->layer->evas,
				     obj->layer->evas->pointer.x,
				     obj->layer->evas->pointer.y,
                                     obj->layer->evas->last_timestamp,
				     NULL);
     }
}

/**
 * Return a list of objects currently clipped by a specific object.
 *
 * @param obj The object to get a list of clippees from
 *
 * This returns the inernal list handle that contains all objects clipped by
 * the object @p obj. If none are clipped, it returns NULL. This list is only
 * valid until the clip list is changed and should be fetched again with another
 * call to evas_object_clipees_get() if any objects being clipped by this object
 * are unclipped, clipped by a new object, are deleted or the clipper is
 * deleted.  These operations will invalidate the list returned so it should
 * not be used anymore after that point. Any use of the list after this may have
 * undefined results, not limited just to strange behavior but possible
 * segfaults and other strange memory errors. The object @p obj must be a valid
 * object.
 *
 * See also evas_object_clip_set(), evas_object_clip_unset() and
 * evas_object_clip_get().
 *
 * Example:
 * @code
 * extern Evas_Object *obj;
 * Evas_Object *clipper;
 *
 * clipper = evas_object_clip_get(obj);
 * if (clipper)
 *   {
 *     Evas_List *clippees, *l;
 *
 *     clippees = evas_object_clipees_get(clipper);
 *     printf("Clipper clips %i objects\n", evas_list_count(clippees));
 *     for (l = clippees; l; l = l->next)
 *       {
 *         Evas_Object *obj_tmp;
 *
 *         obj_tmp = l->data;
 *         evas_object_show(obj_tmp);
 *       }
 *   }
 * @endcode
 * @ingroup Evas_Clip_Group
 */
EAPI const Evas_List *
evas_object_clipees_get(Evas_Object *obj)
{
   MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
   return NULL;
   MAGIC_CHECK_END();
   return obj->clip.clipees;
}