aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/lib/edje_calc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/edje/src/lib/edje_calc.c')
-rw-r--r--libraries/edje/src/lib/edje_calc.c2801
1 files changed, 2801 insertions, 0 deletions
diff --git a/libraries/edje/src/lib/edje_calc.c b/libraries/edje/src/lib/edje_calc.c
new file mode 100644
index 0000000..d9fd51d
--- /dev/null
+++ b/libraries/edje/src/lib/edje_calc.c
@@ -0,0 +1,2801 @@
1#include "edje_private.h"
2
3static void _edje_part_make_rtl(Edje_Part_Description_Common *desc);
4static Edje_Part_Description_Common *_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type);
5
6static void _edje_part_recalc_single(Edje *ed, Edje_Real_Part *ep,
7 Edje_Part_Description_Common *desc, Edje_Part_Description_Common *chosen_desc,
8 Edje_Real_Part *center, Edje_Real_Part *light, Edje_Real_Part *persp,
9 Edje_Real_Part *rel1_to_x, Edje_Real_Part *rel1_to_y,
10 Edje_Real_Part *rel2_to_x, Edje_Real_Part *rel2_to_y,
11 Edje_Real_Part *confine_to, Edje_Calc_Params *params);
12
13void
14_edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, FLOAT_T pos, FLOAT_T v1, FLOAT_T v2)
15{
16 FLOAT_T fp_pos;
17 FLOAT_T npos;
18
19 pos = CLAMP(pos, ZERO, FROM_INT(1));
20
21 fp_pos = pos;
22
23 npos = ZERO;
24#if 0 // old code - easy to enable for comparing float vs fixed point
25 /* take linear pos along timescale and use interpolation method */
26 switch (mode)
27 {
28 case EDJE_TWEEN_MODE_SINUSOIDAL:
29 /* npos = (1.0 - cos(pos * PI)) / 2.0; */
30 npos = DIV2(SUB(FROM_INT(1),
31 COS(MUL(fp_pos,
32 PI))));
33 break;
34 case EDJE_TWEEN_MODE_ACCELERATE:
35 /* npos = 1.0 - sin((PI / 2.0) + (pos * PI / 2.0)); */
36 npos = SUB(FROM_INT(1),
37 SIN(ADD(DIV2(PI),
38 MUL(fp_pos,
39 DIV2(PI)))));
40 break;
41 case EDJE_TWEEN_MODE_DECELERATE:
42 /* npos = sin(pos * PI / 2.0); */
43 npos = SIN(MUL(fp_pos,
44 DIV2(PI)));
45 break;
46 case EDJE_TWEEN_MODE_LINEAR:
47 npos = fp_pos;
48 break;
49 default:
50 npos = fp_pos;
51 break;
52 }
53#else
54 switch (mode & EDJE_TWEEN_MODE_MASK)
55 {
56 case EDJE_TWEEN_MODE_SINUSOIDAL:
57 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
58 ECORE_POS_MAP_SINUSOIDAL,
59 0.0, 0.0));
60 break;
61 case EDJE_TWEEN_MODE_ACCELERATE:
62 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
63 ECORE_POS_MAP_ACCELERATE,
64 0.0, 0.0));
65 break;
66 case EDJE_TWEEN_MODE_DECELERATE:
67 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
68 ECORE_POS_MAP_DECELERATE,
69 0.0, 0.0));
70 break;
71 case EDJE_TWEEN_MODE_LINEAR:
72 npos = fp_pos;
73/* npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
74 ECORE_POS_MAP_LINEAR,
75 0.0, 0.0));
76 */
77 break;
78 case EDJE_TWEEN_MODE_ACCELERATE_FACTOR:
79 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
80 ECORE_POS_MAP_ACCELERATE_FACTOR,
81 TO_DOUBLE(v1), 0.0));
82 break;
83 case EDJE_TWEEN_MODE_DECELERATE_FACTOR:
84 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
85 ECORE_POS_MAP_DECELERATE_FACTOR,
86 TO_DOUBLE(v1), 0.0));
87 break;
88 case EDJE_TWEEN_MODE_SINUSOIDAL_FACTOR:
89 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
90 ECORE_POS_MAP_SINUSOIDAL_FACTOR,
91 TO_DOUBLE(v1), 0.0));
92 break;
93 case EDJE_TWEEN_MODE_DIVISOR_INTERP:
94 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
95 ECORE_POS_MAP_DIVISOR_INTERP,
96 TO_DOUBLE(v1), TO_DOUBLE(v2)));
97 break;
98 case EDJE_TWEEN_MODE_BOUNCE:
99 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
100 ECORE_POS_MAP_BOUNCE,
101 TO_DOUBLE(v1), TO_DOUBLE(v2)));
102 break;
103 case EDJE_TWEEN_MODE_SPRING:
104 npos = FROM_DOUBLE(ecore_animator_pos_map(TO_DOUBLE(pos),
105 ECORE_POS_MAP_SPRING,
106 TO_DOUBLE(v1), TO_DOUBLE(v2)));
107 break;
108 default:
109 npos = fp_pos;
110 break;
111 }
112#endif
113 if (npos == ep->description_pos) return;
114
115 ep->description_pos = npos;
116
117 ed->dirty = 1;
118#ifdef EDJE_CALC_CACHE
119 ep->invalidate = 1;
120#endif
121}
122
123
124/**
125 * Returns part description
126 *
127 * @internal
128 *
129 * Converts part description to RTL-desc.
130 *
131 * @param desc Pointer to desc buffer.
132 *
133 **/
134static void
135_edje_part_make_rtl(Edje_Part_Description_Common *desc)
136{
137 double t;
138 int i;
139
140 if(!desc)
141 return;
142
143 /* This makes alignment right-oriented */
144 desc->align.x = 1.0 - desc->align.x;
145
146 /* same as above for relative components */
147 t = desc->rel1.relative_x;
148 desc->rel1.relative_x = 1.0 - desc->rel2.relative_x;
149 desc->rel2.relative_x = 1.0 - t;
150
151 /* +1 and +1 are because how edje works with right
152 * side borders - nothing is printed beyond that limit
153 *
154 * rel2 is now to the left of rel1, and Edje assumes
155 * the opposite so we switch corners on x-axis to define
156 * offset from right to left */
157 i = desc->rel1.offset_x;
158 desc->rel1.offset_x = -(desc->rel2.offset_x + 1);
159 desc->rel2.offset_x = -(i + 1);
160
161 i = desc->rel1.id_x;
162 desc->rel1.id_x = desc->rel2.id_x;
163 desc->rel2.id_x = i;
164}
165
166/**
167 * Returns part description
168 *
169 * @internal
170 *
171 * Returns part description according to object orientation.
172 * When object is in RTL-orientation (RTL flag is set)
173 * this returns the RTL-desc of it.
174 * RTL-desc would be allocated if was not created by a previous call.
175 * The dst pointer is updated in case of an allocation.
176 *
177 * @param ed Edje object.
178 * @param src The Left To Right (LTR), original desc.
179 * @param dst Pointer to Right To Left (RTL) desc-list.
180 * @param type name of dec type. Example: "default".
181 *
182 * @return Edje part description.
183 *
184 **/
185static Edje_Part_Description_Common *
186_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type)
187{
188 Edje_Part_Description_Common *desc_rtl = NULL;
189 Edje_Part_Collection_Directory_Entry *ce;
190 size_t memsize = 0;
191
192 /* RTL flag is not set, return original description */
193 if(!edje_object_mirrored_get(ed->obj))
194 return src;
195
196 if(*dst)
197 return *dst; /* Was allocated before and we should use it */
198
199#define EDIT_ALLOC_POOL_RTL(Short, Type, Name) \
200 case EDJE_PART_TYPE_##Short: \
201 { \
202 Edje_Part_Description_##Type *Name; \
203 Name = eina_mempool_malloc(ce->mp_rtl.Short, \
204 sizeof (Edje_Part_Description_##Type)); \
205 memset(Name, 0, sizeof(Edje_Part_Description_##Type)); \
206 desc_rtl = &Name->common; \
207 memsize = sizeof(Edje_Part_Description_##Type); \
208 break; \
209 }
210
211 ce = eina_hash_find(ed->file->collection, ed->group);
212
213 switch (type)
214 {
215 case EDJE_PART_TYPE_RECTANGLE:
216 desc_rtl = eina_mempool_malloc(ce->mp_rtl.RECTANGLE,
217 sizeof (Edje_Part_Description_Common));
218 ce->count.RECTANGLE++;
219 memsize = sizeof(Edje_Part_Description_Common);
220 break;
221 case EDJE_PART_TYPE_SWALLOW:
222 desc_rtl = eina_mempool_malloc(ce->mp_rtl.SWALLOW,
223 sizeof (Edje_Part_Description_Common));
224 ce->count.SWALLOW++;
225 memsize = sizeof(Edje_Part_Description_Common);
226 break;
227 case EDJE_PART_TYPE_GROUP:
228 desc_rtl = eina_mempool_malloc(ce->mp_rtl.GROUP,
229 sizeof (Edje_Part_Description_Common));
230 ce->count.GROUP++;
231 memsize = sizeof(Edje_Part_Description_Common);
232 break;
233 EDIT_ALLOC_POOL_RTL(TEXT, Text, text);
234 EDIT_ALLOC_POOL_RTL(TEXTBLOCK, Text, text);
235 EDIT_ALLOC_POOL_RTL(IMAGE, Image, image);
236 EDIT_ALLOC_POOL_RTL(PROXY, Proxy, proxy);
237 EDIT_ALLOC_POOL_RTL(BOX, Box, box);
238 EDIT_ALLOC_POOL_RTL(TABLE, Table, table);
239 EDIT_ALLOC_POOL_RTL(EXTERNAL, External, external_params);
240 }
241
242 if(desc_rtl)
243 memcpy(desc_rtl, src, memsize);
244
245 _edje_part_make_rtl(desc_rtl);
246
247 *dst = desc_rtl;
248 return desc_rtl;
249}
250
251Edje_Part_Description_Common *
252_edje_part_description_find(Edje *ed, Edje_Real_Part *rp, const char *name,
253 double val)
254{
255 Edje_Part *ep = rp->part;
256 Edje_Part_Description_Common *ret = NULL;
257 Edje_Part_Description_Common *d;
258
259 double min_dst = 99999.0;
260 unsigned int i;
261
262 /* RTL flag is set, return RTL description */
263 if(edje_object_mirrored_get(ed->obj))
264 if(!ep->other.desc_rtl)
265 ep->other.desc_rtl = (Edje_Part_Description_Common **)
266 calloc(ep->other.desc_count,
267 sizeof (Edje_Part_Description_Common *));
268
269 if (!strcmp(name, "default") && val == 0.0)
270 return _edje_get_description_by_orientation(ed,
271 ep->default_desc, &ep->default_desc_rtl, ep->type);
272
273 if (!strcmp(name, "custom"))
274 return rp->custom ?
275 _edje_get_description_by_orientation(ed, rp->custom->description,
276 &rp->custom->description_rtl, ep->type) : NULL;
277
278 if (!strcmp(name, "default"))
279 {
280 ret = _edje_get_description_by_orientation(ed, ep->default_desc,
281 &ep->default_desc_rtl, ep->type);
282
283 min_dst = ABS(ep->default_desc->state.value - val);
284 }
285
286 for (i = 0; i < ep->other.desc_count; ++i)
287 {
288 d = ep->other.desc[i];
289
290 if (d->state.name && (d->state.name == name || !strcmp(d->state.name, name)))
291 {
292 double dst;
293
294 dst = ABS(d->state.value - val);
295 if (dst < min_dst)
296 {
297 ret = _edje_get_description_by_orientation(ed, d,
298 &ep->other.desc_rtl[i], ep->type);
299 min_dst = dst;
300 }
301 }
302 }
303
304 return ret;
305}
306
307static void
308_edje_real_part_rel_to_apply(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_State *state)
309{
310 state->rel1_to_x = state->rel1_to_y = NULL;
311 state->rel2_to_x = state->rel2_to_y = NULL;
312
313 if (state->description)
314 {
315 if (state->description->rel1.id_x >= 0)
316 state->rel1_to_x = ed->table_parts[state->description->rel1.id_x % ed->table_parts_size];
317 if (state->description->rel1.id_y >= 0)
318 state->rel1_to_y = ed->table_parts[state->description->rel1.id_y % ed->table_parts_size];
319 if (state->description->rel2.id_x >= 0)
320 state->rel2_to_x = ed->table_parts[state->description->rel2.id_x % ed->table_parts_size];
321 if (state->description->rel2.id_y >= 0)
322 state->rel2_to_y = ed->table_parts[state->description->rel2.id_y % ed->table_parts_size];
323
324 if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
325 {
326 Edje_Part_Description_External *external;
327
328 external = (Edje_Part_Description_External*) state->description;
329
330 if (state->external_params)
331 _edje_external_parsed_params_free(ep->swallowed_object, state->external_params);
332 state->external_params = _edje_external_params_parse(ep->swallowed_object, external->external_params);
333 }
334 }
335}
336
337void
338_edje_part_description_apply(Edje *ed, Edje_Real_Part *ep, const char *d1, double v1, const char *d2, double v2)
339{
340 Edje_Part_Description_Common *epd1;
341 Edje_Part_Description_Common *epd2 = NULL;
342 Edje_Part_Description_Common *chosen_desc;
343
344 Edje_Part_Description_Image *epdi;
345
346 if (!d1) d1 = "default";
347
348 epd1 = _edje_part_description_find(ed, ep, d1, v1);
349 if (!epd1)
350 epd1 = ep->part->default_desc; /* never NULL */
351
352 if (d2)
353 epd2 = _edje_part_description_find(ed, ep, d2, v2);
354
355 epdi = (Edje_Part_Description_Image*) epd2;
356
357 /* There is an animation if both description are different or if description is an image with tweens */
358 if (epd2 && (epd1 != epd2 || (ep->part->type == EDJE_PART_TYPE_IMAGE && epdi->image.tweens_count)))
359 {
360 if (!ep->param2)
361 {
362 ep->param2 = eina_mempool_malloc(_edje_real_part_state_mp, sizeof (Edje_Real_Part_State));
363 memset(ep->param2, 0, sizeof (Edje_Real_Part_State));
364 }
365 else if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
366 _edje_external_parsed_params_free(ep->swallowed_object, ep->param2->external_params);
367 ep->param2->external_params = NULL;
368 }
369 else
370 if (ep->param2)
371 {
372 if (ep->part->type == EDJE_PART_TYPE_EXTERNAL)
373 _edje_external_parsed_params_free(ep->swallowed_object, ep->param2->external_params);
374 if (ep->param2)
375 free(ep->param2->set);
376 eina_mempool_free(_edje_real_part_state_mp, ep->param2);
377 ep->param2 = NULL;
378 }
379
380 chosen_desc = ep->chosen_description;
381 ep->param1.description = epd1;
382 ep->chosen_description = epd1;
383
384 _edje_real_part_rel_to_apply(ed, ep, &ep->param1);
385
386 if (ep->param2)
387 {
388 ep->param2->description = epd2;
389
390 _edje_real_part_rel_to_apply(ed, ep, ep->param2);
391
392 if (ep->description_pos != 0.0)
393 ep->chosen_description = epd2;
394 }
395
396 if (chosen_desc != ep->chosen_description &&
397 ep->part->type == EDJE_PART_TYPE_EXTERNAL)
398 _edje_external_recalc_apply(ed, ep, NULL, chosen_desc);
399
400 ed->dirty = 1;
401#ifdef EDJE_CALC_CACHE
402 ep->invalidate = 1;
403#endif
404}
405
406void
407_edje_recalc(Edje *ed)
408{
409 if ((ed->freeze > 0) || (_edje_freeze_val > 0))
410 {
411 ed->recalc = 1;
412 if (!ed->calc_only)
413 {
414 if (_edje_freeze_val > 0)
415 {
416 if (!ed->freeze_calc)
417 {
418 _edje_freeze_calc_count++;
419 _edje_freeze_calc_list = eina_list_append(_edje_freeze_calc_list, ed);
420 ed->freeze_calc = 1;
421 }
422 }
423 return;
424 }
425 }
426 if (ed->postponed) return;
427 evas_object_smart_changed(ed->obj);
428 ed->postponed = 1;
429}
430
431void
432_edje_recalc_do(Edje *ed)
433{
434 unsigned int i;
435
436 ed->postponed = 0;
437 evas_object_smart_need_recalculate_set(ed->obj, 0);
438 if (!ed->dirty) return;
439 ed->have_mapped_part = 0;
440 ed->dirty = 0;
441 ed->state++;
442 for (i = 0; i < ed->table_parts_size; i++)
443 {
444 Edje_Real_Part *ep;
445
446 ep = ed->table_parts[i];
447 ep->calculated = FLAG_NONE;
448 ep->calculating = FLAG_NONE;
449 }
450 for (i = 0; i < ed->table_parts_size; i++)
451 {
452 Edje_Real_Part *ep;
453
454 ep = ed->table_parts[i];
455 if (ep->calculated != FLAG_XY)
456 _edje_part_recalc(ed, ep, (~ep->calculated) & FLAG_XY, NULL);
457 }
458 if (!ed->calc_only) ed->recalc = 0;
459#ifdef EDJE_CALC_CACHE
460 ed->all_part_change = 0;
461 ed->text_part_change = 0;
462#endif
463}
464
465void
466_edje_part_recalc_1(Edje *ed, Edje_Real_Part *ep)
467{
468 _edje_part_recalc(ed, ep, FLAG_XY, NULL);
469}
470
471int
472_edje_part_dragable_calc(Edje *ed __UNUSED__, Edje_Real_Part *ep, FLOAT_T *x, FLOAT_T *y)
473{
474 if (ep->drag)
475 {
476 if (ep->drag->confine_to)
477 {
478 FLOAT_T dx, dy, dw, dh;
479 int ret = 0;
480
481 if ((ep->part->dragable.x != 0) &&
482 (ep->part->dragable.y != 0 )) ret = 3;
483 else if (ep->part->dragable.x != 0) ret = 1;
484 else if (ep->part->dragable.y != 0) ret = 2;
485
486 dx = FROM_INT(ep->x - ep->drag->confine_to->x);
487 dw = FROM_INT(ep->drag->confine_to->w - ep->w);
488 if (dw != ZERO) dx = DIV(dx, dw);
489 else dx = ZERO;
490
491 dy = FROM_INT(ep->y - ep->drag->confine_to->y);
492 dh = FROM_INT(ep->drag->confine_to->h - ep->h);
493 if (dh != ZERO) dy = DIV(dy, dh);
494 else dy = ZERO;
495
496 if (x) *x = dx;
497 if (y) *y = dy;
498
499 return ret;
500 }
501 else
502 {
503 if (x) *x = ADD(FROM_INT(ep->drag->tmp.x), ep->drag->x);
504 if (y) *y = ADD(FROM_INT(ep->drag->tmp.y), ep->drag->y);
505 return 0;
506 }
507 }
508 if (x) *x = ZERO;
509 if (y) *y = ZERO;
510 return 0;
511}
512
513void
514_edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
515{
516 /* check whether this part is dragable at all */
517 if (!ep->drag) return ;
518
519 /* instead of checking for equality, we really should check that
520 * the difference is greater than foo, but I have no idea what
521 * value we would set foo to, because it would depend on the
522 * size of the dragable...
523 */
524 if (ep->drag->x != x || ep->drag->tmp.x)
525 {
526 ep->drag->x = x;
527 ep->drag->tmp.x = 0;
528 ep->drag->need_reset = 0;
529 ed->dirty = 1;
530 }
531
532 if (ep->drag->y != y || ep->drag->tmp.y)
533 {
534 ep->drag->y = y;
535 ep->drag->tmp.y = 0;
536 ep->drag->need_reset = 0;
537 ed->dirty = 1;
538 }
539
540#ifdef EDJE_CALC_CACHE
541 ep->invalidate = 1;
542#endif
543 _edje_recalc(ed); /* won't do anything if dirty flag isn't set */
544}
545
546static void
547_edje_part_recalc_single_rel(Edje *ed,
548 Edje_Real_Part *ep __UNUSED__,
549 Edje_Part_Description_Common *desc,
550 Edje_Real_Part *rel1_to_x,
551 Edje_Real_Part *rel1_to_y,
552 Edje_Real_Part *rel2_to_x,
553 Edje_Real_Part *rel2_to_y,
554 Edje_Calc_Params *params)
555{
556 FLOAT_T x, w;
557 FLOAT_T y, h;
558
559 if (rel1_to_x)
560 x = ADD(FROM_INT(desc->rel1.offset_x + rel1_to_x->x),
561 SCALE(desc->rel1.relative_x, rel1_to_x->w));
562 else
563 x = ADD(FROM_INT(desc->rel1.offset_x),
564 SCALE(desc->rel1.relative_x, ed->w));
565 params->x = TO_INT(x);
566
567 if (rel2_to_x)
568 w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x + rel2_to_x->x),
569 SCALE(desc->rel2.relative_x, rel2_to_x->w)),
570 x),
571 FROM_INT(1));
572 else
573 w = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_x),
574 SCALE(desc->rel2.relative_x, ed->w)),
575 x),
576 FROM_INT(1));
577 params->w = TO_INT(w);
578
579 if (rel1_to_y)
580 y = ADD(FROM_INT(desc->rel1.offset_y + rel1_to_y->y),
581 SCALE(desc->rel1.relative_y, rel1_to_y->h));
582 else
583 y = ADD(FROM_INT(desc->rel1.offset_y),
584 SCALE(desc->rel1.relative_y, ed->h));
585 params->y = TO_INT(y);
586
587 if (rel2_to_y)
588 h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y + rel2_to_y->y),
589 SCALE(desc->rel2.relative_y, rel2_to_y->h)),
590 y),
591 FROM_INT(1));
592 else
593 h = ADD(SUB(ADD(FROM_INT(desc->rel2.offset_y),
594 SCALE(desc->rel2.relative_y, ed->h)),
595 y),
596 FROM_INT(1));
597 params->h = TO_INT(h);
598}
599
600static Edje_Internal_Aspect
601_edje_part_recalc_single_aspect(Edje_Real_Part *ep,
602 Edje_Part_Description_Common *desc,
603 Edje_Calc_Params *params,
604 int *minw, int *minh,
605 int *maxw, int *maxh)
606{
607 Edje_Internal_Aspect apref = EDJE_ASPECT_PREFER_NONE;
608 FLOAT_T aspect, amax, amin;
609 FLOAT_T new_w = ZERO, new_h = ZERO, want_x, want_y, want_w, want_h;
610
611 if (params->h <= ZERO) aspect = FROM_INT(999999);
612 else aspect = DIV(FROM_INT(params->w), FROM_INT(params->h));
613 amax = desc->aspect.max;
614 amin = desc->aspect.min;
615 if ((ep->swallow_params.aspect.w > 0) &&
616 (ep->swallow_params.aspect.h > 0))
617 amin = amax =
618 DIV(FROM_INT(ep->swallow_params.aspect.w),
619 FROM_INT(ep->swallow_params.aspect.h));
620 want_x = FROM_INT(params->x);
621 want_w = new_w = FROM_INT(params->w);
622
623 want_y = FROM_INT(params->y);
624 want_h = new_h = FROM_INT(params->h);
625
626 if ((amin > ZERO) && (amax > ZERO))
627 {
628 apref = desc->aspect.prefer;
629 if (ep->swallow_params.aspect.mode > EDJE_ASPECT_CONTROL_NONE)
630 {
631 switch (ep->swallow_params.aspect.mode)
632 {
633 case EDJE_ASPECT_CONTROL_NEITHER:
634 apref = EDJE_ASPECT_PREFER_NONE;
635 break;
636 case EDJE_ASPECT_CONTROL_HORIZONTAL:
637 apref = EDJE_ASPECT_PREFER_HORIZONTAL;
638 break;
639 case EDJE_ASPECT_CONTROL_VERTICAL:
640 apref = EDJE_ASPECT_PREFER_VERTICAL;
641 break;
642 case EDJE_ASPECT_CONTROL_BOTH:
643 apref = EDJE_ASPECT_PREFER_BOTH;
644 break;
645 default:
646 break;
647 }
648 }
649 switch (apref)
650 {
651 case EDJE_ASPECT_PREFER_NONE:
652 /* keep both dimensions in check */
653 /* adjust for min aspect (width / height) */
654 if ((amin > ZERO) && (aspect < amin))
655 {
656 new_h = DIV(FROM_INT(params->w), amin);
657 new_w = SCALE(amin, params->h);
658 }
659 /* adjust for max aspect (width / height) */
660 if ((amax > ZERO) && (aspect > amax))
661 {
662 new_h = DIV(FROM_INT(params->w), amax);
663 new_w = SCALE(amax, params->h);
664 }
665 if ((amax > ZERO) && (new_w < FROM_INT(params->w)))
666 {
667 new_w = FROM_INT(params->w);
668 new_h = DIV(FROM_INT(params->w), amax);
669 }
670 if ((amax > ZERO) && (new_h < FROM_INT(params->h)))
671 {
672 new_w = SCALE(amax, params->h);
673 new_h = FROM_INT(params->h);
674 }
675 break;
676 /* prefer vertical size as determiner */
677 case EDJE_ASPECT_PREFER_VERTICAL:
678 /* keep both dimensions in check */
679 /* adjust for max aspect (width / height) */
680 if ((amax > ZERO) && (aspect > amax))
681 new_w = SCALE(amax, params->h);
682 /* adjust for min aspect (width / height) */
683 if ((amin > ZERO) && (aspect < amin))
684 new_w = SCALE(amin, params->h);
685 break;
686 /* prefer horizontal size as determiner */
687 case EDJE_ASPECT_PREFER_HORIZONTAL:
688 /* keep both dimensions in check */
689 /* adjust for max aspect (width / height) */
690 if ((amax > ZERO) && (aspect > amax))
691 new_h = DIV(FROM_INT(params->w), amax);
692 /* adjust for min aspect (width / height) */
693 if ((amin > ZERO) && (aspect < amin))
694 new_h = DIV(FROM_INT(params->w), amin);
695 break;
696 case EDJE_ASPECT_PREFER_BOTH:
697 /* keep both dimensions in check */
698 /* adjust for max aspect (width / height) */
699 if ((amax > ZERO) && (aspect > amax))
700 {
701 new_w = SCALE(amax, params->h);
702 new_h = DIV(FROM_INT(params->w), amax);
703 }
704 /* adjust for min aspect (width / height) */
705 if ((amin > ZERO) && (aspect < amin))
706 {
707 new_w = SCALE(amin, params->h);
708 new_h = DIV(FROM_INT(params->w), amin);
709 }
710 break;
711 default:
712 break;
713 }
714
715 if (!((amin > ZERO) && (amax > ZERO) && (apref == EDJE_ASPECT_PREFER_NONE)))
716 {
717 if ((*maxw >= 0) && (new_w > FROM_INT(*maxw)))
718 new_w = FROM_INT(*maxw);
719 if (new_w < FROM_INT(*minw))
720 new_w = FROM_INT(*minw);
721
722 if ((FROM_INT(*maxh) >= 0) && (new_h > FROM_INT(*maxh)))
723 new_h = FROM_INT(*maxh);
724 if (new_h < FROM_INT(*minh))
725 new_h = FROM_INT(*minh);
726 }
727
728 /* do real adjustment */
729 if (apref == EDJE_ASPECT_PREFER_BOTH)
730 {
731 if (amin == ZERO) amin = amax;
732 if (amin != ZERO)
733 {
734 /* fix h and vary w */
735 if (new_w > FROM_INT(params->w))
736 {
737 // params->w = new_w;
738 // EXCEEDS BOUNDS in W
739 new_h = DIV(FROM_INT(params->w), amin);
740 new_w = FROM_INT(params->w);
741 if (new_h > FROM_INT(params->h))
742 {
743 new_h = FROM_INT(params->h);
744 new_w = SCALE(amin, params->h);
745 }
746 }
747 /* fix w and vary h */
748 else
749 {
750 // params->h = new_h;
751 // EXCEEDS BOUNDS in H
752 new_h = FROM_INT(params->h);
753 new_w = SCALE(amin, params->h);
754 if (new_w > FROM_INT(params->w))
755 {
756 new_h = DIV(FROM_INT(params->w), amin);
757 new_w = FROM_INT(params->w);
758 }
759 }
760 params->w = TO_INT(new_w);
761 params->h = TO_INT(new_h);
762 }
763 }
764 }
765 if (apref != EDJE_ASPECT_PREFER_BOTH)
766 {
767 if ((amin > 0.0) && (amax > ZERO) && (apref == EDJE_ASPECT_PREFER_NONE))
768 {
769 params->w = TO_INT(new_w);
770 params->h = TO_INT(new_h);
771 }
772 else if ((FROM_INT(params->h) - new_h) > (FROM_INT(params->w) - new_w))
773 {
774 if (params->h < TO_INT(new_h))
775 params->h = TO_INT(new_h);
776 else if (params->h > TO_INT(new_h))
777 params->h = TO_INT(new_h);
778 if (apref == EDJE_ASPECT_PREFER_VERTICAL)
779 params->w = TO_INT(new_w);
780 }
781 else
782 {
783 if (params->w < TO_INT(new_w))
784 params->w = TO_INT(new_w);
785 else if (params->w > TO_INT(new_w))
786 params->w = TO_INT(new_w);
787 if (apref == EDJE_ASPECT_PREFER_HORIZONTAL)
788 params->h = TO_INT(new_h);
789 }
790 }
791 params->x = TO_INT(ADD(want_x,
792 MUL(SUB(want_w, FROM_INT(params->w)),
793 desc->align.x)));
794 params->y = TO_INT(ADD(want_y,
795 MUL(SUB(want_h, FROM_INT(params->h)),
796 desc->align.y)));
797 return apref;
798}
799
800static void
801_edje_part_recalc_single_step(Edje_Part_Description_Common *desc,
802 Edje_Calc_Params *params)
803{
804 if (desc->step.x > 0)
805 {
806 int steps;
807 int new_w;
808
809 steps = params->w / desc->step.x;
810 new_w = desc->step.x * steps;
811 if (params->w > new_w)
812 {
813 params->x += TO_INT(SCALE(desc->align.x, (params->w - new_w)));
814 params->w = new_w;
815 }
816 }
817
818 if (desc->step.y > 0)
819 {
820 int steps;
821 int new_h;
822
823 steps = params->h / desc->step.y;
824 new_h = desc->step.y * steps;
825 if (params->h > new_h)
826 {
827 params->y += TO_INT(SCALE(desc->align.y, (params->h - new_h)));
828 params->h = new_h;
829 }
830 }
831}
832
833static void
834_edje_part_recalc_single_textblock(FLOAT_T sc,
835 Edje *ed,
836 Edje_Real_Part *ep,
837 Edje_Part_Description_Text *chosen_desc,
838 Edje_Calc_Params *params,
839 int *minw, int *minh,
840 int *maxw, int *maxh)
841{
842 if (chosen_desc)
843 {
844 Evas_Coord tw, th, ins_l, ins_r, ins_t, ins_b;
845 const char *text = "";
846 const char *style = "";
847 Edje_Style *stl = NULL;
848 const char *tmp;
849 Eina_List *l;
850
851 if (chosen_desc->text.id_source >= 0)
852 {
853 ep->text.source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
854
855 tmp = edje_string_get(&((Edje_Part_Description_Text *)ep->text.source->chosen_description)->text.style);
856 if (tmp) style = tmp;
857 }
858 else
859 {
860 ep->text.source = NULL;
861
862 tmp = edje_string_get(&chosen_desc->text.style);
863 if (tmp) style = tmp;
864 }
865
866 if (chosen_desc->text.id_text_source >= 0)
867 {
868 ep->text.text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
869 text = edje_string_get(&((Edje_Part_Description_Text*)ep->text.text_source->chosen_description)->text.text);
870
871 if (ep->text.text_source->text.text) text = ep->text.text_source->text.text;
872 }
873 else
874 {
875 ep->text.text_source = NULL;
876 text = edje_string_get(&chosen_desc->text.text);
877 if (ep->text.text) text = ep->text.text;
878 }
879
880 EINA_LIST_FOREACH(ed->file->styles, l, stl)
881 {
882 if ((stl->name) && (!strcmp(stl->name, style))) break;
883 stl = NULL;
884 }
885
886 if (ep->part->scale)
887 evas_object_scale_set(ep->object, TO_DOUBLE(sc));
888
889 if (stl)
890 {
891 const char *ptxt;
892
893 if (evas_object_textblock_style_get(ep->object) != stl->style)
894 evas_object_textblock_style_set(ep->object, stl->style);
895 // FIXME: need to account for editing
896 if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
897 {
898 // do nothing - should be done elsewhere
899 }
900 else
901 {
902 ptxt = evas_object_textblock_text_markup_get(ep->object);
903 if (((!ptxt) && (text)) ||
904 ((ptxt) && (text) && (strcmp(ptxt, text))) ||
905 ((ptxt) && (!text)))
906 evas_object_textblock_text_markup_set(ep->object, text);
907 }
908 if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y))
909 {
910 int mw = 0, mh = 0;
911
912 tw = th = 0;
913 if (!chosen_desc->text.min_x)
914 {
915 evas_object_resize(ep->object, params->w, params->h);
916 evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
917 }
918 else
919 evas_object_textblock_size_native_get(ep->object, &tw, &th);
920 evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r, &ins_t, &ins_b);
921 mw = ins_l + tw + ins_r;
922 mh = ins_t + th + ins_b;
923 if (chosen_desc->text.min_x)
924 {
925 if (mw > *minw) *minw = mw;
926 }
927 if (chosen_desc->text.min_y)
928 {
929 if (mh > *minh) *minh = mh;
930 }
931 }
932 }
933 if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y))
934 {
935 int mw = 0, mh = 0;
936
937 tw = th = 0;
938 if (!chosen_desc->text.max_x)
939 {
940 evas_object_resize(ep->object, params->w, params->h);
941 evas_object_textblock_size_formatted_get(ep->object, &tw, &th);
942 }
943 else
944 evas_object_textblock_size_native_get(ep->object, &tw, &th);
945 evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r, &ins_t, &ins_b);
946 mw = ins_l + tw + ins_r;
947 mh = ins_t + th + ins_b;
948 if (chosen_desc->text.max_x)
949 {
950 if (mw > *maxw) *maxw = mw;
951 if (*maxw < *minw) *maxw = *minw;
952 }
953 if (chosen_desc->text.max_y)
954 {
955 if (mh > *maxw) *maxh = mh;
956 if (*maxh < *minh) *maxh = *minh;
957 }
958 }
959 evas_object_textblock_valign_set(ep->object, chosen_desc->text.align.y);
960 }
961}
962
963static void
964_edje_part_recalc_single_text(FLOAT_T sc __UNUSED__,
965 Edje *ed,
966 Edje_Real_Part *ep,
967 Edje_Part_Description_Text *desc,
968 Edje_Part_Description_Text *chosen_desc,
969 Edje_Calc_Params *params,
970 int *minw, int *minh,
971 int *maxw, int *maxh)
972#define RECALC_SINGLE_TEXT_USING_APPLY 1
973#if RECALC_SINGLE_TEXT_USING_APPLY
974/*
975 * XXX TODO NOTE:
976 *
977 * Original _edje_part_recalc_single_text() was not working as
978 * expected since it was not doing size fit, range, ellipsis and so
979 * on.
980 *
981 * The purpose of this function compared with
982 * _edje_text_recalc_apply() is to be faster, not calling Evas update
983 * functions. However for text this is quite difficult given that to
984 * fit we need to set the font, size, style, etc. If it was done
985 * correctly, we'd save some calls to move and some color sets,
986 * however those shouldn't matter much in the overall picture.
987 *
988 * I've changed this to force applying the value, it should be more
989 * correct and not so slow. The previous code is kept below for
990 * reference but should be removed before next release!
991 *
992 * -- Gustavo Barbieri at 20-Aug-2011
993 */
994{
995 int tw, th, mw, mh, l, r, t, b, size;
996 char *sfont = NULL;
997
998 _edje_text_class_font_get(ed, desc, &size, &sfont);
999 free(sfont);
1000 params->type.text.size = size; /* XXX TODO used by further calcs, go inside recalc_apply? */
1001
1002 _edje_text_recalc_apply(ed, ep, params, chosen_desc);
1003
1004 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1005
1006 if ((!chosen_desc) ||
1007 ((!chosen_desc->text.min_x) && (!chosen_desc->text.min_y) &&
1008 (!chosen_desc->text.max_x) && (!chosen_desc->text.max_y)))
1009 return;
1010
1011 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1012 evas_object_text_style_pad_get(ep->object, &l, &r, &t, &b);
1013
1014 mw = tw + l + r;
1015 mh = th + t + b;
1016
1017 if (chosen_desc->text.max_x)
1018 {
1019 if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1020 }
1021 if (chosen_desc->text.max_y)
1022 {
1023 if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1024 }
1025 if (chosen_desc->text.min_x)
1026 {
1027 if (mw > *minw) *minw = mw;
1028 }
1029 if (chosen_desc->text.min_y)
1030 {
1031 if (mh > *minh) *minh = mh;
1032 }
1033}
1034#else
1035{
1036 char *sfont = NULL;
1037 int size;
1038
1039 if (chosen_desc)
1040 {
1041 const char *text;
1042 const char *font;
1043 Evas_Coord tw, th;
1044 int inlined_font = 0;
1045
1046 /* Update a object_text part */
1047
1048 if (chosen_desc->text.id_source >= 0)
1049 ep->text.source = ed->table_parts[chosen_desc->text.id_source % ed->table_parts_size];
1050 else
1051 ep->text.source = NULL;
1052
1053 if (chosen_desc->text.id_text_source >= 0)
1054 ep->text.text_source = ed->table_parts[chosen_desc->text.id_text_source % ed->table_parts_size];
1055 else
1056 ep->text.text_source = NULL;
1057
1058 if (ep->text.text_source)
1059 text = edje_string_get(&(((Edje_Part_Description_Text*)ep->text.text_source->chosen_description)->text.text));
1060 else
1061 text = edje_string_get(&chosen_desc->text.text);
1062
1063 if (ep->text.source)
1064 font = _edje_text_class_font_get(ed, ((Edje_Part_Description_Text*)ep->text.source->chosen_description), &size, &sfont);
1065 else
1066 font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
1067
1068 if (!font) font = "";
1069
1070 if (ep->text.text_source)
1071 {
1072 if (ep->text.text_source->text.text) text = ep->text.text_source->text.text;
1073 }
1074 else
1075 {
1076 if (ep->text.text) text = ep->text.text;
1077 }
1078
1079 if (ep->text.source)
1080 {
1081 if (ep->text.source->text.font) font = ep->text.source->text.font;
1082 if (ep->text.source->text.size > 0) size = ep->text.source->text.size;
1083 }
1084 else
1085 {
1086 if (ep->text.font) font = ep->text.font;
1087 if (ep->text.size > 0) size = ep->text.size;
1088 }
1089 if (!text) text = "";
1090
1091 /* check if the font is embedded in the .eet */
1092 if (ed->file->fonts)
1093 {
1094 Edje_Font_Directory_Entry *fnt;
1095
1096 fnt = eina_hash_find(ed->file->fonts, font);
1097
1098 if (fnt)
1099 {
1100 char *font2;
1101
1102 size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
1103 font2 = alloca(len);
1104 sprintf(font2, "edje/fonts/%s", font);
1105 font = font2;
1106 inlined_font = 1;
1107 }
1108 }
1109 if (ep->part->scale)
1110 evas_object_scale_set(ep->object, TO_DOUBLE(sc));
1111 if (inlined_font)
1112 {
1113 evas_object_text_font_source_set(ep->object, ed->path);
1114 }
1115 else evas_object_text_font_source_set(ep->object, NULL);
1116
1117 if ((_edje_fontset_append) && (font))
1118 {
1119 char *font2;
1120
1121 font2 = malloc(strlen(font) + 1 + strlen(_edje_fontset_append) + 1);
1122 if (font2)
1123 {
1124 strcpy(font2, font);
1125 strcat(font2, ",");
1126 strcat(font2, _edje_fontset_append);
1127 evas_object_text_font_set(ep->object, font2, size);
1128 free(font2);
1129 }
1130 }
1131 else
1132 evas_object_text_font_set(ep->object, font, size);
1133 if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y) ||
1134 (chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1135 {
1136 int mw, mh;
1137 Evas_Text_Style_Type
1138 style = EVAS_TEXT_STYLE_PLAIN,
1139 shadow = EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT;
1140 const Evas_Text_Style_Type styles[] = {
1141 EVAS_TEXT_STYLE_PLAIN,
1142 EVAS_TEXT_STYLE_PLAIN,
1143 EVAS_TEXT_STYLE_OUTLINE,
1144 EVAS_TEXT_STYLE_SOFT_OUTLINE,
1145 EVAS_TEXT_STYLE_SHADOW,
1146 EVAS_TEXT_STYLE_SOFT_SHADOW,
1147 EVAS_TEXT_STYLE_OUTLINE_SHADOW,
1148 EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW,
1149 EVAS_TEXT_STYLE_FAR_SHADOW,
1150 EVAS_TEXT_STYLE_FAR_SOFT_SHADOW,
1151 EVAS_TEXT_STYLE_GLOW
1152 };
1153 const Evas_Text_Style_Type shadows[] = {
1154 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_RIGHT,
1155 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM,
1156 EVAS_TEXT_STYLE_SHADOW_DIRECTION_BOTTOM_LEFT,
1157 EVAS_TEXT_STYLE_SHADOW_DIRECTION_LEFT,
1158 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_LEFT,
1159 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP,
1160 EVAS_TEXT_STYLE_SHADOW_DIRECTION_TOP_RIGHT,
1161 EVAS_TEXT_STYLE_SHADOW_DIRECTION_RIGHT
1162 };
1163
1164 if ((ep->part->effect & EVAS_TEXT_STYLE_MASK_BASIC)
1165 < EDJE_TEXT_EFFECT_LAST)
1166 style = styles[ep->part->effect];
1167 shadow = shadows
1168 [(ep->part->effect & EDJE_TEXT_EFFECT_MASK_SHADOW_DIRECTION) >> 4];
1169 EVAS_TEXT_STYLE_SHADOW_DIRECTION_SET(style, shadow);
1170
1171 evas_object_text_style_set(ep->object, style);
1172 evas_object_text_text_set(ep->object, text);
1173 evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th);
1174 if (chosen_desc->text.max_x)
1175 {
1176 int l, r;
1177 evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1178 mw = tw + l + r;
1179 if ((*maxw < 0) || (mw < *maxw)) *maxw = mw;
1180 }
1181 if (chosen_desc->text.max_y)
1182 {
1183 int t, b;
1184 evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1185 mh = th + t + b;
1186 if ((*maxh < 0) || (mh < *maxh)) *maxh = mh;
1187 }
1188 if (chosen_desc->text.min_x)
1189 {
1190 int l, r;
1191 evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);
1192 mw = tw + l + r;
1193 if (mw > *minw) *minw = mw;
1194 }
1195 if (chosen_desc->text.min_y)
1196 {
1197 int t, b;
1198 evas_object_text_style_pad_get(ep->object, NULL, NULL, &t, &b);
1199 mh = th + t + b;
1200 if (mh > *minh) *minh = mh;
1201 }
1202 }
1203 if (sfont) free(sfont);
1204 }
1205
1206 /* FIXME: Do we really need to call it twice if chosen_desc ? */
1207 sfont = NULL;
1208 _edje_text_class_font_get(ed, desc, &size, &sfont);
1209 free(sfont);
1210 params->type.text.size = size;
1211}
1212#endif
1213
1214static void
1215_edje_part_recalc_single_min_length(FLOAT_T align, int *start, int *length, int min)
1216{
1217 if (min >= 0)
1218 {
1219 if (*length < min)
1220 {
1221 *start += TO_INT(SCALE(align, (*length - min)));
1222 *length = min;
1223 }
1224 }
1225}
1226
1227static void
1228_edje_part_recalc_single_min(Edje_Part_Description_Common *desc,
1229 Edje_Calc_Params *params,
1230 int minw, int minh,
1231 Edje_Internal_Aspect aspect)
1232{
1233 int tmp;
1234 int w;
1235 int h;
1236
1237 w = params->w ? params->w : 99999;
1238 h = params->h ? params->h : 99999;
1239
1240 switch (aspect)
1241 {
1242 case EDJE_ASPECT_PREFER_NONE:
1243 break;
1244 case EDJE_ASPECT_PREFER_VERTICAL:
1245 tmp = minh * params->w / h;
1246 if (tmp >= minw)
1247 {
1248 minw = tmp;
1249 break;
1250 }
1251 case EDJE_ASPECT_PREFER_HORIZONTAL:
1252 tmp = minw * params->h / w;
1253 if (tmp >= minh)
1254 {
1255 minh = tmp;
1256 break;
1257 }
1258 case EDJE_ASPECT_PREFER_BOTH:
1259 tmp = minh * params->w / h;
1260 if (tmp >= minw)
1261 {
1262 minw = tmp;
1263 break;
1264 }
1265
1266 tmp = minw * params->h / w;
1267 if (tmp >= minh)
1268 {
1269 minh = tmp;
1270 break;
1271 }
1272
1273 break;
1274 }
1275
1276 _edje_part_recalc_single_min_length(desc->align.x, &params->x, &params->w, minw);
1277 _edje_part_recalc_single_min_length(desc->align.y, &params->y, &params->h, minh);
1278}
1279
1280static void
1281_edje_part_recalc_single_max_length(FLOAT_T align, int *start, int *length, int max)
1282{
1283 if (max >= 0)
1284 {
1285 if (*length > max)
1286 {
1287 *start += TO_INT(SCALE(align, (*length - max)));
1288 *length = max;
1289 }
1290 }
1291}
1292
1293static void
1294_edje_part_recalc_single_max(Edje_Part_Description_Common *desc,
1295 Edje_Calc_Params *params,
1296 int maxw, int maxh,
1297 Edje_Internal_Aspect aspect)
1298{
1299 int tmp;
1300 int w;
1301 int h;
1302
1303 w = params->w ? params->w : 99999;
1304 h = params->h ? params->h : 99999;
1305
1306 switch (aspect)
1307 {
1308 case EDJE_ASPECT_PREFER_NONE:
1309 break;
1310 case EDJE_ASPECT_PREFER_VERTICAL:
1311 tmp = maxh * params->w / h;
1312 if (tmp <= maxw)
1313 {
1314 maxw = tmp;
1315 break;
1316 }
1317 case EDJE_ASPECT_PREFER_HORIZONTAL:
1318 tmp = maxw * params->h / w;
1319 if (tmp <= maxh)
1320 {
1321 maxh = tmp;
1322 break;
1323 }
1324 case EDJE_ASPECT_PREFER_BOTH:
1325 tmp = maxh * params->w / h;
1326 if (tmp <= maxw)
1327 {
1328 maxw = tmp;
1329 break;
1330 }
1331
1332 tmp = maxw * params->h / w;
1333 if (tmp <= maxh)
1334 {
1335 maxh = tmp;
1336 break;
1337 }
1338
1339 break;
1340 }
1341
1342 _edje_part_recalc_single_max_length(desc->align.x, &params->x, &params->w, maxw);
1343 _edje_part_recalc_single_max_length(desc->align.y, &params->y, &params->h, maxh);
1344}
1345
1346static void
1347_edje_part_recalc_single_drag(Edje_Real_Part *ep,
1348 Edje_Real_Part *confine_to,
1349 Edje_Calc_Params *params,
1350 int minw, int minh,
1351 int maxw, int maxh)
1352{
1353 /* confine */
1354 if (confine_to)
1355 {
1356 int offset;
1357 int step;
1358 FLOAT_T v;
1359
1360 /* complex dragable params */
1361 v = SCALE(ep->drag->size.x, confine_to->w);
1362
1363 if ((minw > 0) && (TO_INT(v) < minw)) params->w = minw;
1364 else if ((maxw >= 0) && (TO_INT(v) > maxw)) params->w = maxw;
1365 else params->w = TO_INT(v);
1366
1367 offset = TO_INT(SCALE(ep->drag->x, (confine_to->w - params->w)))
1368 + ep->drag->tmp.x;
1369 if (ep->part->dragable.step_x > 0)
1370 {
1371 params->x = confine_to->x +
1372 ((offset / ep->part->dragable.step_x) * ep->part->dragable.step_x);
1373 }
1374 else if (ep->part->dragable.count_x > 0)
1375 {
1376 step = (confine_to->w - params->w) / ep->part->dragable.count_x;
1377 if (step < 1) step = 1;
1378 params->x = confine_to->x +
1379 ((offset / step) * step);
1380 }
1381 params->req_drag.x = params->x;
1382 params->req_drag.w = params->w;
1383
1384 v = SCALE(ep->drag->size.y, confine_to->h);
1385
1386 if ((minh > 0) && (TO_INT(v) < minh)) params->h = minh;
1387 else if ((maxh >= 0) && (TO_INT(v) > maxh)) params->h = maxh;
1388 else params->h = TO_INT(v);
1389
1390 offset = TO_INT(SCALE(ep->drag->y, (confine_to->h - params->h)))
1391 + ep->drag->tmp.y;
1392 if (ep->part->dragable.step_y > 0)
1393 {
1394 params->y = confine_to->y +
1395 ((offset / ep->part->dragable.step_y) * ep->part->dragable.step_y);
1396 }
1397 else if (ep->part->dragable.count_y > 0)
1398 {
1399 step = (confine_to->h - params->h) / ep->part->dragable.count_y;
1400 if (step < 1) step = 1;
1401 params->y = confine_to->y +
1402 ((offset / step) * step);
1403 }
1404 params->req_drag.y = params->y;
1405 params->req_drag.h = params->h;
1406
1407 /* limit to confine */
1408 if (params->x < confine_to->x)
1409 {
1410 params->x = confine_to->x;
1411 }
1412 if ((params->x + params->w) > (confine_to->x + confine_to->w))
1413 {
1414 params->x = confine_to->x + confine_to->w - params->w;
1415 }
1416 if (params->y < confine_to->y)
1417 {
1418 params->y = confine_to->y;
1419 }
1420 if ((params->y + params->h) > (confine_to->y + confine_to->h))
1421 {
1422 params->y = confine_to->y + confine_to->h - params->h;
1423 }
1424 }
1425 else
1426 {
1427 /* simple dragable params */
1428 params->x += TO_INT(ep->drag->x) + ep->drag->tmp.x;
1429 params->req_drag.x = params->x;
1430 params->req_drag.w = params->w;
1431
1432 params->y += TO_INT(ep->drag->y) + ep->drag->tmp.y;
1433 params->req_drag.y = params->y;
1434 params->req_drag.h = params->h;
1435 }
1436}
1437
1438static void
1439_edje_part_recalc_single_fill(Edje_Real_Part *ep,
1440 Edje_Part_Description_Spec_Fill *fill,
1441 Edje_Calc_Params *params)
1442{
1443 int fw;
1444 int fh;
1445
1446 params->smooth = fill->smooth;
1447
1448 if (fill->type == EDJE_FILL_TYPE_TILE)
1449 evas_object_image_size_get(ep->object, &fw, NULL);
1450 else
1451 fw = params->w;
1452
1453 params->type.common.fill.x = fill->pos_abs_x
1454 + TO_INT(SCALE(fill->pos_rel_x, fw));
1455 params->type.common.fill.w = fill->abs_x
1456 + TO_INT(SCALE(fill->rel_x, fw));
1457
1458 if (fill->type == EDJE_FILL_TYPE_TILE)
1459 evas_object_image_size_get(ep->object, NULL, &fh);
1460 else
1461 fh = params->h;
1462
1463 params->type.common.fill.y = fill->pos_abs_y
1464 + TO_INT(SCALE(fill->pos_rel_y, fh));
1465 params->type.common.fill.h = fill->abs_y
1466 + TO_INT(SCALE(fill->rel_y, fh));
1467
1468 params->type.common.fill.angle = fill->angle;
1469 params->type.common.fill.spread = fill->spread;
1470}
1471
1472static void
1473_edje_part_recalc_single_min_max(FLOAT_T sc,
1474 Edje_Real_Part *ep,
1475 Edje_Part_Description_Common *desc,
1476 int *minw, int *minh,
1477 int *maxw, int *maxh)
1478{
1479 *minw = desc->min.w;
1480 if (ep->part->scale) *minw = TO_INT(SCALE(sc, *minw));
1481 if (ep->swallow_params.min.w > desc->min.w)
1482 *minw = ep->swallow_params.min.w;
1483
1484 /* XXX TODO: remove need of EDJE_INF_MAX_W, see edje_util.c */
1485 if ((ep->swallow_params.max.w <= 0) ||
1486 (ep->swallow_params.max.w == EDJE_INF_MAX_W))
1487 {
1488 *maxw = desc->max.w;
1489 if (*maxw > 0)
1490 {
1491 if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1492 if (*maxw < 1) *maxw = 1;
1493 }
1494 }
1495 else
1496 {
1497 if (desc->max.w <= 0)
1498 *maxw = ep->swallow_params.max.w;
1499 else
1500 {
1501 *maxw = desc->max.w;
1502 if (*maxw > 0)
1503 {
1504 if (ep->part->scale) *maxw = TO_INT(SCALE(sc, *maxw));
1505 if (*maxw < 1) *maxw = 1;
1506 }
1507 if (ep->swallow_params.max.w < *maxw)
1508 *maxw = ep->swallow_params.max.w;
1509 }
1510 }
1511 if (*maxw >= 0)
1512 {
1513 if (*maxw < *minw) *maxw = *minw;
1514 }
1515
1516 *minh = desc->min.h;
1517 if (ep->part->scale) *minh = TO_INT(SCALE(sc, *minh));
1518 if (ep->swallow_params.min.h > desc->min.h)
1519 *minh = ep->swallow_params.min.h;
1520
1521 /* XXX TODO: remove need of EDJE_INF_MAX_H, see edje_util.c */
1522 if ((ep->swallow_params.max.h <= 0) ||
1523 (ep->swallow_params.max.h == EDJE_INF_MAX_H))
1524 {
1525 *maxh = desc->max.h;
1526 if (*maxh > 0)
1527 {
1528 if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1529 if (*maxh < 1) *maxh = 1;
1530 }
1531 }
1532 else
1533 {
1534 if (desc->max.h <= 0)
1535 *maxh = ep->swallow_params.max.h;
1536 else
1537 {
1538 *maxh = desc->max.h;
1539 if (*maxh > 0)
1540 {
1541 if (ep->part->scale) *maxh = TO_INT(SCALE(sc, *maxh));
1542 if (*maxh < 1) *maxh = 1;
1543 }
1544 if (ep->swallow_params.max.h < *maxh)
1545 *maxh = ep->swallow_params.max.h;
1546 }
1547 }
1548 if (*maxh >= 0)
1549 {
1550 if (*maxh < *minh) *maxh = *minh;
1551 }
1552}
1553
1554static void
1555_edje_part_recalc_single_map(Edje *ed,
1556 Edje_Real_Part *ep __UNUSED__,
1557 Edje_Real_Part *center,
1558 Edje_Real_Part *light,
1559 Edje_Real_Part *persp,
1560 Edje_Part_Description_Common *desc,
1561 Edje_Part_Description_Common *chosen_desc,
1562 Edje_Calc_Params *params)
1563{
1564 params->mapped = chosen_desc->map.on;
1565 params->lighted = params->mapped ? !!light : 0;
1566 params->persp_on = params->mapped ? !!persp : 0;
1567
1568 if (!params->mapped) return ;
1569
1570 if (center)
1571 {
1572 params->map.center.x = ed->x + center->x + (center->w / 2);
1573 params->map.center.y = ed->y + center->y + (center->h / 2);
1574 }
1575 else
1576 {
1577 params->map.center.x = ed->x + params->x + (params->w / 2);
1578 params->map.center.y = ed->y + params->y + (params->h / 2);
1579 }
1580 params->map.center.z = 0;
1581
1582 params->map.rotation.x = TO_DOUBLE(desc->map.rot.x);
1583 params->map.rotation.y = TO_DOUBLE(desc->map.rot.y);
1584 params->map.rotation.z = TO_DOUBLE(desc->map.rot.z);
1585
1586 if (light)
1587 {
1588 Edje_Part_Description_Common *light_desc2;
1589 FLOAT_T pos, pos2;
1590
1591 params->map.light.x = ed->x + light->x + (light->w / 2);
1592 params->map.light.y = ed->y + light->y + (light->h / 2);
1593
1594 pos = light->description_pos;
1595 pos2 = (pos < ZERO) ? ZERO : ((pos > FROM_INT(1)) ? FROM_INT(1) : pos);
1596
1597 light_desc2 = light->param2 ? light->param2->description : NULL;
1598
1599 /* take into account CURRENT state also */
1600 if (pos != ZERO && light_desc2)
1601 {
1602 params->map.light.z = light->param1.description->persp.zplane +
1603 TO_INT(SCALE(pos, light_desc2->persp.zplane - light->param1.description->persp.zplane));
1604 params->map.light.r = light->param1.description->color.r +
1605 TO_INT(SCALE(pos2, light_desc2->color.r - light->param1.description->color.r));
1606 params->map.light.g = light->param1.description->color.g +
1607 TO_INT(SCALE(pos2, light_desc2->color.g - light->param1.description->color.g));
1608 params->map.light.b = light->param1.description->color.b +
1609 TO_INT(SCALE(pos2, light_desc2->color.b - light->param1.description->color.b));
1610 params->map.light.ar = light->param1.description->color2.r +
1611 TO_INT(SCALE(pos2, light_desc2->color2.r - light->param1.description->color2.r));
1612 params->map.light.ag = light->param1.description->color2.g +
1613 TO_INT(SCALE(pos2, light_desc2->color2.g - light->param1.description->color2.g));
1614 params->map.light.ab = light->param1.description->color2.b +
1615 TO_INT(SCALE(pos2, light_desc2->color2.b - light->param1.description->color2.b));
1616 }
1617 else
1618 {
1619 params->map.light.z = light->param1.description->persp.zplane;
1620 params->map.light.r = light->param1.description->color.r;
1621 params->map.light.g = light->param1.description->color.g;
1622 params->map.light.b = light->param1.description->color.b;
1623 params->map.light.ar = light->param1.description->color2.r;
1624 params->map.light.ag = light->param1.description->color2.g;
1625 params->map.light.ab = light->param1.description->color2.b;
1626 }
1627 }
1628
1629 if (persp)
1630 {
1631 FLOAT_T pos;
1632
1633 params->map.persp.x = ed->x + persp->x + (persp->w / 2);
1634 params->map.persp.y = ed->y + persp->y + (persp->h / 2);
1635
1636 pos = persp->description_pos;
1637
1638 if (pos != 0 && persp->param2)
1639 {
1640 params->map.persp.z = persp->param1.description->persp.zplane +
1641 TO_INT(SCALE(pos, persp->param2->description->persp.zplane -
1642 persp->param1.description->persp.zplane));
1643 params->map.persp.focal = persp->param1.description->persp.focal +
1644 TO_INT(SCALE(pos, persp->param2->description->persp.focal -
1645 persp->param1.description->persp.focal));
1646 }
1647 else
1648 {
1649 params->map.persp.z = persp->param1.description->persp.zplane;
1650 params->map.persp.focal = persp->param1.description->persp.focal;
1651 }
1652 }
1653}
1654
1655static void
1656_edje_part_recalc_single(Edje *ed,
1657 Edje_Real_Part *ep,
1658 Edje_Part_Description_Common *desc,
1659 Edje_Part_Description_Common *chosen_desc,
1660 Edje_Real_Part *center,
1661 Edje_Real_Part *light,
1662 Edje_Real_Part *persp,
1663 Edje_Real_Part *rel1_to_x,
1664 Edje_Real_Part *rel1_to_y,
1665 Edje_Real_Part *rel2_to_x,
1666 Edje_Real_Part *rel2_to_y,
1667 Edje_Real_Part *confine_to,
1668 Edje_Calc_Params *params)
1669{
1670 Edje_Color_Class *cc = NULL;
1671 Edje_Internal_Aspect apref;
1672 int minw = 0, minh = 0, maxw = 0, maxh = 0;
1673 FLOAT_T sc;
1674
1675 sc = ed->scale;
1676 if (sc == ZERO) sc = _edje_scale;
1677 _edje_part_recalc_single_min_max(sc, ep, desc, &minw, &minh, &maxw, &maxh);
1678
1679 /* relative coords of top left & bottom right */
1680 _edje_part_recalc_single_rel(ed, ep, desc, rel1_to_x, rel1_to_y, rel2_to_x, rel2_to_y, params);
1681
1682 /* aspect */
1683 apref = _edje_part_recalc_single_aspect(ep, desc, params, &minw, &minh, &maxw, &maxh);
1684
1685 /* size step */
1686 _edje_part_recalc_single_step(desc, params);
1687
1688 /* if we have text that wants to make the min size the text size... */
1689 if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK)
1690 _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text*) chosen_desc, params, &minw, &minh, &maxw, &maxh);
1691 else if (ep->part->type == EDJE_PART_TYPE_TEXT)
1692 _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text*) desc, (Edje_Part_Description_Text*) chosen_desc, params, &minw, &minh, &maxw, &maxh);
1693
1694 if ((ep->part->type == EDJE_PART_TYPE_TABLE) &&
1695 (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) ||
1696 (((Edje_Part_Description_Table *)chosen_desc)->table.min.v))))
1697 {
1698 Evas_Coord lminw = 0, lminh = 0;
1699
1700 evas_object_smart_need_recalculate_set(ep->object, 1);
1701 evas_object_smart_calculate(ep->object);
1702 evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
1703 if (((Edje_Part_Description_Table *)chosen_desc)->table.min.h)
1704 {
1705 if (lminw > minw) minw = lminw;
1706 }
1707 if (((Edje_Part_Description_Table *)chosen_desc)->table.min.v)
1708 {
1709 if (lminh > minh) minh = lminh;
1710 }
1711 }
1712 else if ((ep->part->type == EDJE_PART_TYPE_BOX) &&
1713 ((((Edje_Part_Description_Box *)chosen_desc)->box.min.h) ||
1714 (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)))
1715 {
1716 Evas_Coord lminw = 0, lminh = 0;
1717
1718 evas_object_smart_need_recalculate_set(ep->object, 1);
1719 evas_object_smart_calculate(ep->object);
1720 evas_object_size_hint_min_get(ep->object, &lminw, &lminh);
1721 if (((Edje_Part_Description_Box *)chosen_desc)->box.min.h)
1722 {
1723 if (lminw > minw) minw = lminw;
1724 }
1725 if (((Edje_Part_Description_Box *)chosen_desc)->box.min.v)
1726 {
1727 if (lminh > minh) minh = lminh;
1728 }
1729 }
1730
1731 /* remember what our size is BEFORE we go limit it */
1732 params->req.x = params->x;
1733 params->req.y = params->y;
1734 params->req.w = params->w;
1735 params->req.h = params->h;
1736
1737 /* adjust for min size */
1738 _edje_part_recalc_single_min(desc, params, minw, minh, apref);
1739
1740 /* adjust for max size */
1741 _edje_part_recalc_single_max(desc, params, maxw, maxh, apref);
1742
1743 /* take care of dragable part */
1744 if (ep->drag)
1745 _edje_part_recalc_single_drag(ep, confine_to, params, minw, minh, maxw, maxh);
1746
1747 /* fill */
1748 if (ep->part->type == EDJE_PART_TYPE_IMAGE)
1749 _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Image *)desc)->image.fill, params);
1750 else if (ep->part->type == EDJE_PART_TYPE_PROXY)
1751 _edje_part_recalc_single_fill(ep, &((Edje_Part_Description_Proxy *)desc)->proxy.fill, params);
1752
1753 /* colors */
1754 if ((desc->color_class) && (*desc->color_class))
1755 cc = _edje_color_class_find(ed, desc->color_class);
1756
1757 if (cc)
1758 {
1759 params->color.r = (((int)cc->r + 1) * desc->color.r) >> 8;
1760 params->color.g = (((int)cc->g + 1) * desc->color.g) >> 8;
1761 params->color.b = (((int)cc->b + 1) * desc->color.b) >> 8;
1762 params->color.a = (((int)cc->a + 1) * desc->color.a) >> 8;
1763 }
1764 else
1765 {
1766 params->color.r = desc->color.r;
1767 params->color.g = desc->color.g;
1768 params->color.b = desc->color.b;
1769 params->color.a = desc->color.a;
1770 }
1771
1772 /* visible */
1773 params->visible = desc->visible;
1774
1775 switch (ep->part->type)
1776 {
1777 case EDJE_PART_TYPE_IMAGE:
1778 {
1779 Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image*) desc;
1780
1781 /* border */
1782 params->type.common.spec.image.l = img_desc->image.border.l;
1783 params->type.common.spec.image.r = img_desc->image.border.r;
1784
1785 params->type.common.spec.image.t = img_desc->image.border.t;
1786 params->type.common.spec.image.b = img_desc->image.border.b;
1787 break;
1788 }
1789 case EDJE_PART_TYPE_TEXT:
1790 case EDJE_PART_TYPE_TEXTBLOCK:
1791 {
1792 Edje_Part_Description_Text *text_desc = (Edje_Part_Description_Text*) desc;
1793
1794 /* text.align */
1795 params->type.text.align.x = text_desc->text.align.x;
1796 params->type.text.align.y = text_desc->text.align.y;
1797 params->type.text.elipsis = text_desc->text.elipsis;
1798
1799 /* text colors */
1800 if (cc)
1801 {
1802 params->type.text.color2.r = (((int)cc->r2 + 1) * text_desc->common.color2.r) >> 8;
1803 params->type.text.color2.g = (((int)cc->g2 + 1) * text_desc->common.color2.g) >> 8;
1804 params->type.text.color2.b = (((int)cc->b2 + 1) * text_desc->common.color2.b) >> 8;
1805 params->type.text.color2.a = (((int)cc->a2 + 1) * text_desc->common.color2.a) >> 8;
1806 params->type.text.color3.r = (((int)cc->r3 + 1) * text_desc->text.color3.r) >> 8;
1807 params->type.text.color3.g = (((int)cc->g3 + 1) * text_desc->text.color3.g) >> 8;
1808 params->type.text.color3.b = (((int)cc->b3 + 1) * text_desc->text.color3.b) >> 8;
1809 params->type.text.color3.a = (((int)cc->a3 + 1) * text_desc->text.color3.a) >> 8;
1810 }
1811 else
1812 {
1813 params->type.text.color2.r = text_desc->common.color2.r;
1814 params->type.text.color2.g = text_desc->common.color2.g;
1815 params->type.text.color2.b = text_desc->common.color2.b;
1816 params->type.text.color2.a = text_desc->common.color2.a;
1817 params->type.text.color3.r = text_desc->text.color3.r;
1818 params->type.text.color3.g = text_desc->text.color3.g;
1819 params->type.text.color3.b = text_desc->text.color3.b;
1820 params->type.text.color3.a = text_desc->text.color3.a;
1821 }
1822
1823 break;
1824 }
1825 case EDJE_PART_TYPE_RECTANGLE:
1826 case EDJE_PART_TYPE_BOX:
1827 case EDJE_PART_TYPE_TABLE:
1828 case EDJE_PART_TYPE_SWALLOW:
1829 case EDJE_PART_TYPE_GROUP:
1830 case EDJE_PART_TYPE_PROXY:
1831 break;
1832 case EDJE_PART_TYPE_GRADIENT:
1833 /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
1834 break;
1835 default:
1836 break;
1837 }
1838
1839 _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
1840}
1841
1842static void
1843_edje_table_recalc_apply(Edje *ed __UNUSED__,
1844 Edje_Real_Part *ep,
1845 Edje_Calc_Params *p3 __UNUSED__,
1846 Edje_Part_Description_Table *chosen_desc)
1847{
1848 evas_object_table_homogeneous_set(ep->object, chosen_desc->table.homogeneous);
1849 evas_object_table_align_set(ep->object, TO_DOUBLE(chosen_desc->table.align.x), TO_DOUBLE(chosen_desc->table.align.y));
1850 evas_object_table_padding_set(ep->object, chosen_desc->table.padding.x, chosen_desc->table.padding.y);
1851 if (evas_object_smart_need_recalculate_get(ep->object))
1852 {
1853 evas_object_smart_need_recalculate_set(ep->object, 0);
1854 evas_object_smart_calculate(ep->object);
1855 }
1856}
1857
1858static int
1859_edje_image_find(Evas_Object *obj, Edje *ed, Edje_Real_Part_Set **eps, Edje_Part_Description_Image *st, Edje_Part_Image_Id *imid)
1860{
1861 Edje_Image_Directory_Set_Entry *entry;
1862 Edje_Image_Directory_Set *set = NULL;
1863 Eina_List *l;
1864 int w = 0;
1865 int h = 0;
1866 int id;
1867
1868 if (!st && !imid)
1869 return -1;
1870
1871 if (st && !st->image.set)
1872 return st->image.id;
1873
1874 if (imid && !imid->set)
1875 return imid->id;
1876
1877 if (imid)
1878 id = imid->id;
1879 else
1880 id = st->image.id;
1881
1882 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1883
1884 if (eps && *eps)
1885 {
1886 if ((*eps)->id == id)
1887 set = (*eps)->set;
1888
1889 if (set)
1890 if ((*eps)->entry->size.min.w <= w && w <= (*eps)->entry->size.max.w)
1891 if ((*eps)->entry->size.min.h <= h && h <= (*eps)->entry->size.max.h)
1892 return (*eps)->entry->id;
1893 }
1894
1895 if (!set)
1896 set = ed->file->image_dir->sets + id;
1897
1898 EINA_LIST_FOREACH(set->entries, l, entry)
1899 {
1900 if (entry->size.min.w <= w && w <= entry->size.max.w)
1901 if (entry->size.min.h <= h && h <= entry->size.max.h)
1902 {
1903 if (eps)
1904 {
1905 if (!*eps)
1906 *eps = calloc(1, sizeof (Edje_Real_Part_Set));
1907
1908 if (*eps)
1909 {
1910 (*eps)->entry = entry;
1911 (*eps)->set = set;
1912 (*eps)->id = id;
1913 }
1914 }
1915 return entry->id;
1916 }
1917 }
1918
1919 return -1;
1920}
1921
1922static void
1923_edje_proxy_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Proxy *chosen_desc, FLOAT_T pos)
1924{
1925 Edje_Real_Part *pp;
1926 int part_id = -1;
1927
1928 if (pos >= 0.5)
1929 part_id = ((Edje_Part_Description_Proxy*) ep->param2->description)->proxy.id;
1930 else
1931 part_id = chosen_desc->proxy.id;
1932
1933 if ((p3->type.common.fill.w == 0) || (p3->type.common.fill.h == 0) ||
1934 (part_id < 0))
1935 {
1936 evas_object_image_source_set(ep->object, NULL);
1937 return;
1938 }
1939 pp = ed->table_parts[part_id % ed->table_parts_size];
1940
1941 switch (pp->part->type)
1942 {
1943 case EDJE_PART_TYPE_IMAGE:
1944 case EDJE_PART_TYPE_TEXT:
1945 case EDJE_PART_TYPE_TEXTBLOCK:
1946 case EDJE_PART_TYPE_RECTANGLE:
1947 case EDJE_PART_TYPE_BOX:
1948 case EDJE_PART_TYPE_TABLE:
1949 case EDJE_PART_TYPE_PROXY:
1950 evas_object_image_source_set(ep->object, pp->object);
1951 break;
1952 case EDJE_PART_TYPE_GRADIENT:
1953 /* FIXME: THIS ONE SHOULD NEVER BE TRIGGERED. */
1954 break;
1955 case EDJE_PART_TYPE_GROUP:
1956 case EDJE_PART_TYPE_SWALLOW:
1957 case EDJE_PART_TYPE_EXTERNAL:
1958 evas_object_image_source_set(ep->object, pp->swallowed_object);
1959 break;
1960 }
1961
1962 evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
1963 p3->type.common.fill.w, p3->type.common.fill.h);
1964 evas_object_image_smooth_scale_set(ep->object, p3->smooth);
1965}
1966
1967static void
1968_edje_image_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edje_Part_Description_Image *chosen_desc, FLOAT_T pos)
1969{
1970 int image_id;
1971 int image_count, image_num;
1972 FLOAT_T sc;
1973
1974 sc = ed->scale;
1975 if (sc == 0.0) sc = _edje_scale;
1976 evas_object_image_fill_set(ep->object, p3->type.common.fill.x, p3->type.common.fill.y,
1977 p3->type.common.fill.w, p3->type.common.fill.h);
1978 evas_object_image_smooth_scale_set(ep->object, p3->smooth);
1979 if (chosen_desc->image.border.scale)
1980 {
1981 if (chosen_desc->image.border.scale_by > FROM_DOUBLE(0.0))
1982 {
1983 FLOAT_T sc2 = MUL(sc, chosen_desc->image.border.scale_by);
1984 evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc2));
1985 }
1986 else
1987 evas_object_image_border_scale_set(ep->object, TO_DOUBLE(sc));
1988 }
1989 else
1990 {
1991 if (chosen_desc->image.border.scale_by > FROM_DOUBLE(0.0))
1992 evas_object_image_border_scale_set
1993 (ep->object, TO_DOUBLE(chosen_desc->image.border.scale_by));
1994 else
1995 evas_object_image_border_scale_set(ep->object, 1.0);
1996 }
1997 evas_object_image_border_set(ep->object, p3->type.common.spec.image.l, p3->type.common.spec.image.r,
1998 p3->type.common.spec.image.t, p3->type.common.spec.image.b);
1999 if (chosen_desc->image.border.no_fill == 0)
2000 evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_DEFAULT);
2001 else if (chosen_desc->image.border.no_fill == 1)
2002 evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_NONE);
2003 else if (chosen_desc->image.border.no_fill == 2)
2004 evas_object_image_border_center_fill_set(ep->object, EVAS_BORDER_FILL_SOLID);
2005
2006 image_id = _edje_image_find(ep->object, ed,
2007 &ep->param1.set,
2008 (Edje_Part_Description_Image*) ep->param1.description,
2009 NULL);
2010 if (image_id < 0)
2011 {
2012 Edje_Image_Directory_Entry *ie;
2013
2014 if (!ed->file->image_dir) ie = NULL;
2015 else ie = ed->file->image_dir->entries + (-image_id) - 1;
2016 if ((ie) &&
2017 (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) &&
2018 (ie->entry))
2019 {
2020 evas_object_image_file_set(ep->object, ie->entry, NULL);
2021 }
2022 }
2023 else
2024 {
2025 image_count = 2;
2026 if (ep->param2)
2027 image_count += ((Edje_Part_Description_Image*) ep->param2->description)->image.tweens_count;
2028 image_num = TO_INT(MUL(pos, SUB(FROM_INT(image_count),
2029 FROM_DOUBLE(0.5))));
2030 if (image_num > (image_count - 1))
2031 image_num = image_count - 1;
2032 if (image_num == 0)
2033 {
2034 image_id = _edje_image_find(ep->object, ed,
2035 &ep->param1.set,
2036 (Edje_Part_Description_Image*) ep->param1.description,
2037 NULL);
2038 }
2039 else
2040 if (ep->param2)
2041 {
2042 if (image_num == (image_count - 1))
2043 {
2044 image_id = _edje_image_find(ep->object, ed,
2045 &ep->param2->set,
2046 (Edje_Part_Description_Image*) ep->param2->description,
2047 NULL);
2048 }
2049 else
2050 {
2051 Edje_Part_Image_Id *imid;
2052
2053 imid = ((Edje_Part_Description_Image*) ep->param2->description)->image.tweens[image_num - 1];
2054 image_id = _edje_image_find(ep->object, ed, NULL, NULL, imid);
2055 }
2056 }
2057 if (image_id < 0)
2058 {
2059 ERR("¨Part \"%s\" has description, "
2060 "\"%s\" %3.3f with a missing image id!!!",
2061 ep->part->name,
2062 ep->param1.description->state.name,
2063 ep->param1.description->state.value);
2064 }
2065 else
2066 {
2067 char buf[1024];
2068
2069 /* Replace snprint("edje/images/%i") == memcpy + itoa */
2070#define IMAGES "edje/images/"
2071 memcpy(buf, IMAGES, strlen(IMAGES));
2072 eina_convert_itoa(image_id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characteres. */
2073
2074 evas_object_image_file_set(ep->object, ed->file->path, buf);
2075 if (evas_object_image_load_error_get(ep->object) != EVAS_LOAD_ERROR_NONE)
2076 {
2077 ERR("Error loading image collection \"%s\" from "
2078 "file \"%s\". Missing EET Evas loader module?",
2079 buf, ed->file->path);
2080 switch (evas_object_image_load_error_get(ep->object))
2081 {
2082 case EVAS_LOAD_ERROR_GENERIC:
2083 ERR("Error type: EVAS_LOAD_ERROR_GENERIC");
2084 break;
2085 case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
2086 ERR("Error type: EVAS_LOAD_ERROR_DOES_NOT_EXIST");
2087 break;
2088 case EVAS_LOAD_ERROR_PERMISSION_DENIED:
2089 ERR("Error type: EVAS_LOAD_ERROR_PERMISSION_DENIED");
2090 break;
2091 case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
2092 ERR("Error type: EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
2093 break;
2094 case EVAS_LOAD_ERROR_CORRUPT_FILE:
2095 ERR("Error type: EVAS_LOAD_ERROR_CORRUPT_FILE");
2096 break;
2097 case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
2098 ERR("Error type: EVAS_LOAD_ERROR_UNKNOWN_FORMAT");
2099 break;
2100 default:
2101 ERR("Error type: ???");
2102 break;
2103 }
2104 }
2105 }
2106 }
2107}
2108
2109static Edje_Real_Part *
2110_edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state)
2111{
2112 Edje_Real_Part *result = NULL;
2113
2114 if (id >= 0 && id != ep->part->id)
2115 {
2116 result = ed->table_parts[id % ed->table_parts_size];
2117 if (result)
2118 {
2119 if (!result->calculated) _edje_part_recalc(ed, result, flags, NULL);
2120#ifdef EDJE_CALC_CACHE
2121 if (state) *state = result->state;
2122#else
2123 (void) state;
2124#endif
2125 }
2126 }
2127 return result;
2128}
2129
2130void
2131_edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state)
2132{
2133#ifdef EDJE_CALC_CACHE
2134 Eina_Bool proxy_invalidate = EINA_FALSE;
2135 int state1 = -1;
2136 int state2 = -1;
2137 int statec = -1;
2138#else
2139 Edje_Calc_Params lp1, lp2;
2140#endif
2141 int statec1 = -1;
2142 int statec2 = -1;
2143 int statel1 = -1;
2144 int statel2 = -1;
2145 int statep1 = -1;
2146 int statep2 = -1;
2147 Edje_Real_Part *center[2] = { NULL, NULL };
2148 Edje_Real_Part *light[2] = { NULL, NULL };
2149 Edje_Real_Part *persp[2] = { NULL, NULL };
2150 Edje_Calc_Params *p1, *pf;
2151 Edje_Part_Description_Common *chosen_desc;
2152 Edje_Real_Part *confine_to = NULL;
2153 FLOAT_T pos = ZERO, pos2;
2154 Edje_Calc_Params lp3;
2155
2156 /* GRADIENT ARE GONE, WE MUST IGNORE IT FROM OLD FILE. */
2157 if (ep->part->type == EDJE_PART_TYPE_GRADIENT)
2158 {
2159 ERR("GRADIENT spotted during recalc ! That should never happen ! Send your edje file to devel ml.");
2160 return;
2161 }
2162
2163 if ((ep->calculated & FLAG_XY) == FLAG_XY && !state)
2164 {
2165 return;
2166 }
2167 if (ep->calculating & flags)
2168 {
2169#if 1
2170 const char *axes = "NONE", *faxes = "NONE";
2171
2172 if ((ep->calculating & FLAG_X) &&
2173 (ep->calculating & FLAG_Y))
2174 axes = "XY";
2175 else if ((ep->calculating & FLAG_X))
2176 axes = "X";
2177 else if ((ep->calculating & FLAG_Y))
2178 axes = "Y";
2179
2180 if ((flags & FLAG_X) &&
2181 (flags & FLAG_Y))
2182 faxes = "XY";
2183 else if ((flags & FLAG_X))
2184 faxes = "X";
2185 else if ((flags & FLAG_Y))
2186 faxes = "Y";
2187 ERR("Circular dependency when calculating part \"%s\". "
2188 "Already calculating %s [%02x] axes. "
2189 "Need to calculate %s [%02x] axes",
2190 ep->part->name,
2191 axes, ep->calculating,
2192 faxes, flags);
2193#endif
2194 return;
2195 }
2196#ifdef EDJE_CALC_CACHE
2197 if (ep->state == ed->state && !state)
2198 return ;
2199#endif
2200
2201 if (flags & FLAG_X)
2202 {
2203 ep->calculating |= flags & FLAG_X;
2204 if (ep->param1.rel1_to_x)
2205 {
2206 _edje_part_recalc(ed, ep->param1.rel1_to_x, FLAG_X, NULL);
2207#ifdef EDJE_CALC_CACHE
2208 state1 = ep->param1.rel1_to_x->state;
2209#endif
2210 }
2211 if (ep->param1.rel2_to_x)
2212 {
2213 _edje_part_recalc(ed, ep->param1.rel2_to_x, FLAG_X, NULL);
2214#ifdef EDJE_CALC_CACHE
2215 if (state1 < ep->param1.rel2_to_x->state)
2216 state1 = ep->param1.rel2_to_x->state;
2217#endif
2218 }
2219 if (ep->param2)
2220 {
2221 if (ep->param2->rel1_to_x)
2222 {
2223 _edje_part_recalc(ed, ep->param2->rel1_to_x, FLAG_X, NULL);
2224#ifdef EDJE_CALC_CACHE
2225 state2 = ep->param2->rel1_to_x->state;
2226#endif
2227 }
2228 if (ep->param2->rel2_to_x)
2229 {
2230 _edje_part_recalc(ed, ep->param2->rel2_to_x, FLAG_X, NULL);
2231#ifdef EDJE_CALC_CACHE
2232 if (state2 < ep->param2->rel2_to_x->state)
2233 state2 = ep->param2->rel2_to_x->state;
2234#endif
2235 }
2236 }
2237 }
2238 if (flags & FLAG_Y)
2239 {
2240 ep->calculating |= flags & FLAG_Y;
2241 if (ep->param1.rel1_to_y)
2242 {
2243 _edje_part_recalc(ed, ep->param1.rel1_to_y, FLAG_Y, NULL);
2244#ifdef EDJE_CALC_CACHE
2245 if (state1 < ep->param1.rel1_to_y->state)
2246 state1 = ep->param1.rel1_to_y->state;
2247#endif
2248 }
2249 if (ep->param1.rel2_to_y)
2250 {
2251 _edje_part_recalc(ed, ep->param1.rel2_to_y, FLAG_Y, NULL);
2252#ifdef EDJE_CALC_CACHE
2253 if (state1 < ep->param1.rel2_to_y->state)
2254 state1 = ep->param1.rel2_to_y->state;
2255#endif
2256 }
2257 if (ep->param2)
2258 {
2259 if (ep->param2->rel1_to_y)
2260 {
2261 _edje_part_recalc(ed, ep->param2->rel1_to_y, FLAG_Y, NULL);
2262#ifdef EDJE_CALC_CACHE
2263 if (state2 < ep->param2->rel1_to_y->state)
2264 state2 = ep->param2->rel1_to_y->state;
2265#endif
2266 }
2267 if (ep->param2->rel2_to_y)
2268 {
2269 _edje_part_recalc(ed, ep->param2->rel2_to_y, FLAG_Y, NULL);
2270#ifdef EDJE_CALC_CACHE
2271 if (state2 < ep->param2->rel2_to_y->state)
2272 state2 = ep->param2->rel2_to_y->state;
2273#endif
2274 }
2275 }
2276 }
2277 if (ep->drag && ep->drag->confine_to)
2278 {
2279 confine_to = ep->drag->confine_to;
2280 _edje_part_recalc(ed, confine_to, flags, NULL);
2281#ifdef EDJE_CALC_CACHE
2282 statec = confine_to->state;
2283#endif
2284 }
2285// if (ep->text.source) _edje_part_recalc(ed, ep->text.source, flags);
2286// if (ep->text.text_source) _edje_part_recalc(ed, ep->text.text_source, flags);
2287
2288 /* actually calculate now */
2289 chosen_desc = ep->chosen_description;
2290 if (!chosen_desc)
2291 {
2292 ep->calculating = FLAG_NONE;
2293 ep->calculated |= flags;
2294 return;
2295 }
2296
2297 if (ep->part->type == EDJE_PART_TYPE_PROXY)
2298 {
2299 Edje_Real_Part *pp;
2300 int part_id = -1;
2301
2302 if (pos >= 0.5)
2303 part_id = ((Edje_Part_Description_Proxy*) ep->param2->description)->proxy.id;
2304 else
2305 part_id = ((Edje_Part_Description_Proxy*) chosen_desc)->proxy.id;
2306
2307 pp = _edje_real_part_state_get(ed, ep, flags, part_id, NULL);
2308 if (pp && pp->invalidate) proxy_invalidate = EINA_TRUE;
2309 }
2310
2311 /* Recalc if needed the map center && light source */
2312 if (ep->param1.description->map.on)
2313 {
2314 center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.rot.id_center, &statec1);
2315 light[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_light, &statel1);
2316
2317 if (chosen_desc->map.persp_on)
2318 {
2319 persp[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_persp, &statep1);
2320 }
2321 }
2322
2323 if (ep->param2 && ep->param2->description->map.on)
2324 {
2325 center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.rot.id_center, &statec2);
2326 light[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_light, &statel2);
2327
2328 if (chosen_desc->map.persp_on)
2329 {
2330 persp[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_persp, &statep2);
2331 }
2332 }
2333
2334#ifndef EDJE_CALC_CACHE
2335 p1 = &lp1;
2336#else
2337 p1 = &ep->param1.p;
2338#endif
2339
2340 if (ep->param1.description)
2341 {
2342#ifdef EDJE_CALC_CACHE
2343 if (ed->all_part_change ||
2344 ep->invalidate ||
2345 state1 >= ep->param1.state ||
2346 statec >= ep->param1.state ||
2347 statec1 >= ep->param1.state ||
2348 statel1 >= ep->param1.state ||
2349 statep1 >= ep->param1.state ||
2350 proxy_invalidate ||
2351 state ||
2352 ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2353#endif
2354 {
2355 _edje_part_recalc_single(ed, ep, ep->param1.description, chosen_desc, center[0], light[0], persp[0],
2356 ep->param1.rel1_to_x, ep->param1.rel1_to_y, ep->param1.rel2_to_x, ep->param1.rel2_to_y,
2357 confine_to,
2358 p1);
2359
2360#ifdef EDJE_CALC_CACHE
2361 ep->param1.state = ed->state;
2362#endif
2363 }
2364 }
2365 if (ep->param2)
2366 {
2367 int beginning_pos, part_type;
2368 Edje_Calc_Params *p2, *p3;
2369
2370 if (ep->current)
2371 {
2372 /* FIXME: except for text, we don't need in that case to recalc p1 at all*/
2373 memcpy(p1, ep->current, sizeof (Edje_Calc_Params));
2374 p1->x += ed->x;
2375 p1->y += ed->y;
2376 p1->map.center.x += ed->x;
2377 p1->map.center.y += ed->y;
2378 p1->map.light.x += ed->x;
2379 p1->map.light.y += ed->y;
2380 p1->map.persp.x += ed->x;
2381 p1->map.persp.y += ed->y;
2382 }
2383
2384 p3 = &lp3;
2385
2386#ifndef EDJE_CALC_CACHE
2387 p2 = &lp2;
2388#else
2389 p2 = &ep->param2->p;
2390
2391 if (ed->all_part_change ||
2392 ep->invalidate ||
2393 state2 >= ep->param2->state ||
2394 statec >= ep->param2->state ||
2395 statec2 >= ep->param2->state ||
2396 statel2 >= ep->param2->state ||
2397 statep2 >= ep->param2->state ||
2398 proxy_invalidate ||
2399 state ||
2400 ((ep->part->type == EDJE_PART_TYPE_TEXT || ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) && ed->text_part_change))
2401#endif
2402 {
2403 _edje_part_recalc_single(ed, ep, ep->param2->description, chosen_desc, center[1], light[1], persp[1],
2404 ep->param2->rel1_to_x, ep->param2->rel1_to_y, ep->param2->rel2_to_x, ep->param2->rel2_to_y,
2405 confine_to,
2406 p2);
2407#ifdef EDJE_CALC_CACHE
2408 ep->param2->state = ed->state;
2409#endif
2410 }
2411
2412 pos = ep->description_pos;
2413 pos2 = pos;
2414 if (pos2 < ZERO) pos2 = ZERO;
2415 else if (pos2 > FROM_INT(1)) pos2 = FROM_INT(1);
2416 beginning_pos = (pos < FROM_DOUBLE(0.5));
2417 part_type = ep->part->type;
2418
2419 /* visible is special */
2420 if ((p1->visible) && (!p2->visible))
2421 p3->visible = (pos != FROM_INT(1));
2422 else if ((!p1->visible) && (p2->visible))
2423 p3->visible = (pos != ZERO);
2424 else
2425 p3->visible = p1->visible;
2426
2427 p3->smooth = (beginning_pos) ? p1->smooth : p2->smooth;
2428
2429 /* FIXME: do x and y separately base on flag */
2430#define FINTP(_x1, _x2, _p) \
2431 (((_x1) == (_x2)) \
2432 ? FROM_INT((_x1)) \
2433 : ADD(FROM_INT(_x1), \
2434 SCALE((_p), (_x2) - (_x1))))
2435
2436#define FFP(_x1, _x2, _p) \
2437 (((_x1) == (_x2)) \
2438 ? (_x1) \
2439 : ADD(_x1, MUL(_p, SUB(_x2, _x1))));
2440
2441#define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))
2442
2443 p3->x = INTP(p1->x, p2->x, pos);
2444 p3->y = INTP(p1->y, p2->y, pos);
2445 p3->w = INTP(p1->w, p2->w, pos);
2446 p3->h = INTP(p1->h, p2->h, pos);
2447
2448 p3->req.x = INTP(p1->req.x, p2->req.x, pos);
2449 p3->req.y = INTP(p1->req.y, p2->req.y, pos);
2450 p3->req.w = INTP(p1->req.w, p2->req.w, pos);
2451 p3->req.h = INTP(p1->req.h, p2->req.h, pos);
2452
2453 if (ep->part->dragable.x)
2454 {
2455 p3->req_drag.x = INTP(p1->req_drag.x, p2->req_drag.x, pos);
2456 p3->req_drag.w = INTP(p1->req_drag.w, p2->req_drag.w, pos);
2457 }
2458 if (ep->part->dragable.y)
2459 {
2460 p3->req_drag.y = INTP(p1->req_drag.y, p2->req_drag.y, pos);
2461 p3->req_drag.h = INTP(p1->req_drag.h, p2->req_drag.h, pos);
2462 }
2463
2464 p3->color.r = INTP(p1->color.r, p2->color.r, pos2);
2465 p3->color.g = INTP(p1->color.g, p2->color.g, pos2);
2466 p3->color.b = INTP(p1->color.b, p2->color.b, pos2);
2467 p3->color.a = INTP(p1->color.a, p2->color.a, pos2);
2468
2469 switch (part_type)
2470 {
2471 case EDJE_PART_TYPE_IMAGE:
2472 p3->type.common.spec.image.l = INTP(p1->type.common.spec.image.l, p2->type.common.spec.image.l, pos);
2473 p3->type.common.spec.image.r = INTP(p1->type.common.spec.image.r, p2->type.common.spec.image.r, pos);
2474 p3->type.common.spec.image.t = INTP(p1->type.common.spec.image.t, p2->type.common.spec.image.t, pos);
2475 p3->type.common.spec.image.b = INTP(p1->type.common.spec.image.b, p2->type.common.spec.image.b, pos);
2476 case EDJE_PART_TYPE_PROXY:
2477 p3->type.common.fill.x = INTP(p1->type.common.fill.x, p2->type.common.fill.x, pos);
2478 p3->type.common.fill.y = INTP(p1->type.common.fill.y, p2->type.common.fill.y, pos);
2479 p3->type.common.fill.w = INTP(p1->type.common.fill.w, p2->type.common.fill.w, pos);
2480 p3->type.common.fill.h = INTP(p1->type.common.fill.h, p2->type.common.fill.h, pos);
2481 break;
2482 case EDJE_PART_TYPE_TEXT:
2483 p3->type.text.size = INTP(p1->type.text.size, p2->type.text.size, pos);
2484 case EDJE_PART_TYPE_TEXTBLOCK:
2485 p3->type.text.color2.r = INTP(p1->type.text.color2.r, p2->type.text.color2.r, pos2);
2486 p3->type.text.color2.g = INTP(p1->type.text.color2.g, p2->type.text.color2.g, pos2);
2487 p3->type.text.color2.b = INTP(p1->type.text.color2.b, p2->type.text.color2.b, pos2);
2488 p3->type.text.color2.a = INTP(p1->type.text.color2.a, p2->type.text.color2.a, pos2);
2489
2490 p3->type.text.color3.r = INTP(p1->type.text.color3.r, p2->type.text.color3.r, pos2);
2491 p3->type.text.color3.g = INTP(p1->type.text.color3.g, p2->type.text.color3.g, pos2);
2492 p3->type.text.color3.b = INTP(p1->type.text.color3.b, p2->type.text.color3.b, pos2);
2493 p3->type.text.color3.a = INTP(p1->type.text.color3.a, p2->type.text.color3.a, pos2);
2494
2495 p3->type.text.align.x = FFP(p1->type.text.align.x, p2->type.text.align.x, pos);
2496 p3->type.text.align.y = FFP(p1->type.text.align.y, p2->type.text.align.y, pos);
2497 p3->type.text.elipsis = TO_DOUBLE(FINTP(p1->type.text.elipsis, p2->type.text.elipsis, pos2));
2498 break;
2499 }
2500
2501 p3->mapped = p1->mapped;
2502 p3->persp_on = p3->mapped ? p1->persp_on | p2->persp_on : 0;
2503 p3->lighted = p3->mapped ? p1->lighted | p2->lighted : 0;
2504 if (p1->mapped)
2505 {
2506 p3->map.center.x = INTP(p1->map.center.x, p2->map.center.x, pos);
2507 p3->map.center.y = INTP(p1->map.center.y, p2->map.center.y, pos);
2508 p3->map.center.z = INTP(p1->map.center.z, p2->map.center.z, pos);
2509 p3->map.rotation.x = FFP(p1->map.rotation.x, p2->map.rotation.x, pos);
2510 p3->map.rotation.y = FFP(p1->map.rotation.y, p2->map.rotation.y, pos);
2511 p3->map.rotation.z = FFP(p1->map.rotation.z, p2->map.rotation.z, pos);
2512
2513#define MIX(P1, P2, P3, pos, info) \
2514 P3->info = P1->info + TO_INT(SCALE(pos, P2->info - P1->info));
2515
2516 if (p1->lighted && p2->lighted)
2517 {
2518 MIX(p1, p2, p3, pos, map.light.x);
2519 MIX(p1, p2, p3, pos, map.light.y);
2520 MIX(p1, p2, p3, pos, map.light.z);
2521 MIX(p1, p2, p3, pos, map.light.r);
2522 MIX(p1, p2, p3, pos, map.light.g);
2523 MIX(p1, p2, p3, pos, map.light.b);
2524 MIX(p1, p2, p3, pos, map.light.ar);
2525 MIX(p1, p2, p3, pos, map.light.ag);
2526 MIX(p1, p2, p3, pos, map.light.ab);
2527 }
2528 else if (p1->lighted)
2529 {
2530 memcpy(&p3->map.light, &p1->map.light, sizeof (p1->map.light));
2531 }
2532 else if (p2->lighted)
2533 {
2534 memcpy(&p3->map.light, &p2->map.light, sizeof (p2->map.light));
2535 }
2536
2537 if (p1->persp_on && p2->persp_on)
2538 {
2539 MIX(p1, p2, p3, pos, map.persp.x);
2540 MIX(p1, p2, p3, pos, map.persp.y);
2541 MIX(p1, p2, p3, pos, map.persp.z);
2542 MIX(p1, p2, p3, pos, map.persp.focal);
2543 }
2544 else if (p1->persp_on)
2545 {
2546 memcpy(&p3->map.persp, &p1->map.persp, sizeof (p1->map.light));
2547 }
2548 else if (p2->persp_on)
2549 {
2550 memcpy(&p3->map.persp, &p2->map.persp, sizeof (p2->map.light));
2551 }
2552 }
2553
2554 pf = p3;
2555 }
2556 else
2557 {
2558 pf = p1;
2559 }
2560
2561 if (!pf->persp_on && chosen_desc->map.persp_on)
2562 {
2563 if (ed->persp)
2564 {
2565 pf->map.persp.x = ed->persp->px;
2566 pf->map.persp.y = ed->persp->py;
2567 pf->map.persp.z = ed->persp->z0;
2568 pf->map.persp.focal = ed->persp->foc;
2569 }
2570 else
2571 {
2572 const Edje_Perspective *ps;
2573
2574 // fixme: a tad inefficient as this is a has lookup
2575 ps = edje_object_perspective_get(ed->obj);
2576 if (!ps)
2577 ps = edje_evas_global_perspective_get(evas_object_evas_get(ed->obj));
2578 if (ps)
2579 {
2580 pf->map.persp.x = ps->px;
2581 pf->map.persp.y = ps->py;
2582 pf->map.persp.z = ps->z0;
2583 pf->map.persp.focal = ps->foc;
2584 }
2585 else
2586 {
2587 pf->map.persp.x = ed->x + (ed->w / 2);
2588 pf->map.persp.y = ed->y + (ed->h / 2);
2589 pf->map.persp.z = 0;
2590 pf->map.persp.focal = 1000;
2591 }
2592 }
2593 }
2594
2595 if (state)
2596 {
2597 memcpy(state, pf, sizeof (Edje_Calc_Params));
2598 }
2599
2600 ep->req = pf->req;
2601
2602 if (ep->drag && ep->drag->need_reset)
2603 {
2604 FLOAT_T dx, dy;
2605
2606 dx = ZERO;
2607 dy = ZERO;
2608 _edje_part_dragable_calc(ed, ep, &dx, &dy);
2609 ep->drag->x = dx;
2610 ep->drag->y = dy;
2611 ep->drag->tmp.x = 0;
2612 ep->drag->tmp.y = 0;
2613 ep->drag->need_reset = 0;
2614 }
2615 if (!ed->calc_only)
2616 {
2617 Evas_Object *mo;
2618
2619 /* Common move, resize and color_set for all part. */
2620 switch (ep->part->type)
2621 {
2622 case EDJE_PART_TYPE_IMAGE:
2623 {
2624 Edje_Part_Description_Image *img_desc = (Edje_Part_Description_Image*) chosen_desc;
2625
2626 evas_object_image_scale_hint_set(ep->object,
2627 img_desc->image.scale_hint);
2628 }
2629 case EDJE_PART_TYPE_PROXY:
2630 case EDJE_PART_TYPE_RECTANGLE:
2631 case EDJE_PART_TYPE_TEXTBLOCK:
2632 case EDJE_PART_TYPE_BOX:
2633 case EDJE_PART_TYPE_TABLE:
2634 evas_object_color_set(ep->object,
2635 (pf->color.r * pf->color.a) / 255,
2636 (pf->color.g * pf->color.a) / 255,
2637 (pf->color.b * pf->color.a) / 255,
2638 pf->color.a);
2639 if (!pf->visible)
2640 {
2641 evas_object_hide(ep->object);
2642 break;
2643 }
2644 evas_object_show(ep->object);
2645 /* move and resize are needed for all previous object => no break here. */
2646 case EDJE_PART_TYPE_SWALLOW:
2647 case EDJE_PART_TYPE_GROUP:
2648 case EDJE_PART_TYPE_EXTERNAL:
2649 /* visibility and color have no meaning on SWALLOW and GROUP part. */
2650 evas_object_move(ep->object, ed->x + pf->x, ed->y + pf->y);
2651 evas_object_resize(ep->object, pf->w, pf->h);
2652 if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
2653 _edje_entry_real_part_configure(ep);
2654 break;
2655 case EDJE_PART_TYPE_TEXT:
2656 /* This is correctly handle in _edje_text_recalc_apply at the moment. */
2657 break;
2658 case EDJE_PART_TYPE_GRADIENT:
2659 /* FIXME: definitivly remove this code when we switch to new format. */
2660 abort();
2661 break;
2662 }
2663
2664 /* Some object need special recalc. */
2665 switch (ep->part->type)
2666 {
2667 case EDJE_PART_TYPE_TEXT:
2668 _edje_text_recalc_apply(ed, ep, pf, (Edje_Part_Description_Text*) chosen_desc);
2669 break;
2670 case EDJE_PART_TYPE_PROXY:
2671 _edje_proxy_recalc_apply(ed, ep, pf, (Edje_Part_Description_Proxy*) chosen_desc, pos);
2672 break;
2673 case EDJE_PART_TYPE_IMAGE:
2674 _edje_image_recalc_apply(ed, ep, pf, (Edje_Part_Description_Image*) chosen_desc, pos);
2675 break;
2676 case EDJE_PART_TYPE_BOX:
2677 _edje_box_recalc_apply(ed, ep, pf, (Edje_Part_Description_Box*) chosen_desc);
2678 break;
2679 case EDJE_PART_TYPE_TABLE:
2680 _edje_table_recalc_apply(ed, ep, pf, (Edje_Part_Description_Table*) chosen_desc);
2681 break;
2682 case EDJE_PART_TYPE_EXTERNAL:
2683 case EDJE_PART_TYPE_RECTANGLE:
2684 case EDJE_PART_TYPE_SWALLOW:
2685 case EDJE_PART_TYPE_GROUP:
2686 case EDJE_PART_TYPE_TEXTBLOCK:
2687 /* Nothing special to do for this type of object. */
2688 break;
2689 case EDJE_PART_TYPE_GRADIENT:
2690 /* FIXME: definitivly remove this code when we switch to new format. */
2691 abort();
2692 break;
2693 }
2694
2695 if (ep->swallowed_object)
2696 {
2697//// the below really is wrong - swallow color shouldn't affect swallowed object
2698//// color - the edje color as a WHOLE should though - and that should be
2699//// done via the clipper anyway. this created bugs when objects had their
2700//// colro set and were swallowed - then had their color changed.
2701// evas_object_color_set(ep->swallowed_object,
2702// (pf->color.r * pf->color.a) / 255,
2703// (pf->color.g * pf->color.a) / 255,
2704// (pf->color.b * pf->color.a) / 255,
2705// pf->color.a);
2706 if (pf->visible)
2707 {
2708 evas_object_move(ep->swallowed_object, ed->x + pf->x, ed->y + pf->y);
2709 evas_object_resize(ep->swallowed_object, pf->w, pf->h);
2710 evas_object_show(ep->swallowed_object);
2711 }
2712 else evas_object_hide(ep->swallowed_object);
2713 mo = ep->swallowed_object;
2714 }
2715 else mo = ep->object;
2716 if (chosen_desc->map.on)
2717 {
2718 Evas_Map *map;
2719
2720 ed->have_mapped_part = 1;
2721 // create map and populate with part geometry
2722 map = evas_map_new(4);
2723 evas_map_util_points_populate_from_object(map, ep->object);
2724 if (ep->part->type == EDJE_PART_TYPE_IMAGE)
2725 {
2726 int iw = 1, ih = 1;
2727
2728 evas_object_image_size_get(mo, &iw, &ih);
2729 evas_map_point_image_uv_set(map, 0, 0.0, 0.0);
2730 evas_map_point_image_uv_set(map, 1, iw , 0.0);
2731 evas_map_point_image_uv_set(map, 2, iw , ih );
2732 evas_map_point_image_uv_set(map, 3, 0.0, ih );
2733 }
2734
2735 evas_map_util_3d_rotate(map,
2736 pf->map.rotation.x, pf->map.rotation.y, pf->map.rotation.z,
2737 pf->map.center.x, pf->map.center.y, pf->map.center.z);
2738
2739 // calculate light color & position etc. if there is one
2740 if (pf->lighted)
2741 {
2742 evas_map_util_3d_lighting(map,
2743 pf->map.light.x, pf->map.light.y, pf->map.light.z,
2744 pf->map.light.r, pf->map.light.g, pf->map.light.b,
2745 pf->map.light.ar, pf->map.light.ag, pf->map.light.ab);
2746 }
2747
2748 // calculate perspective point
2749 if (chosen_desc->map.persp_on)
2750 {
2751 evas_map_util_3d_perspective(map,
2752 pf->map.persp.x, pf->map.persp.y, pf->map.persp.z,
2753 pf->map.persp.focal);
2754 }
2755
2756 // handle backface culling (object is facing away from view
2757 if (chosen_desc->map.backcull)
2758 {
2759 if (pf->visible)
2760 {
2761 if (evas_map_util_clockwise_get(map))
2762 evas_object_show(mo);
2763 else evas_object_hide(mo);
2764 }
2765 }
2766
2767 // handle smooth
2768 if (chosen_desc->map.smooth) evas_map_smooth_set(map, 1);
2769 else evas_map_smooth_set(map, 0);
2770 // handle alpha
2771 if (chosen_desc->map.alpha) evas_map_alpha_set(map, 1);
2772 else evas_map_alpha_set(map, 0);
2773
2774 evas_object_map_set(mo, map);
2775 evas_object_map_enable_set(mo, 1);
2776 evas_map_free(map);
2777 }
2778 else
2779 {
2780 evas_object_map_enable_set(mo, 0);
2781 evas_object_map_set(mo, NULL);
2782 }
2783 }
2784
2785 ep->x = pf->x;
2786 ep->y = pf->y;
2787 ep->w = pf->w;
2788 ep->h = pf->h;
2789
2790 ep->calculated |= flags;
2791 ep->calculating = FLAG_NONE;
2792
2793#ifdef EDJE_CALC_CACHE
2794 if (ep->calculated == FLAG_XY)
2795 {
2796 ep->state = ed->state;
2797 ep->invalidate = 0;
2798 }
2799#endif
2800
2801}