diff options
author | Rafael Antognolli <antognolli@gmail.com> | 2011-09-15 18:51:33 +0000 |
---|---|---|
committer | Rafael Antognolli <antognolli@gmail.com> | 2011-09-15 18:51:33 +0000 |
commit | 0c4dd42a0aa82aabdca48c6efd377af3312a1382 (patch) | |
tree | ca5573bb39bd2216bc51e123bb8a5288bb9298b0 /legacy/emotion/src/lib/emotion_smart.c | |
parent | 5c3474beedf7618b927844b699b5e38ad62548b0 (diff) |
emotion/aspect: Add API to configure the aspect ratio policy.
The new function emotion_object_keep_aspect_set() allow to set a policy
that will automatically change the emotion object border property, based
on the video aspect ratio and object current aspect ratio.
Possible values are:
* EMOTION_ASPECT_KEEP_NONE
* EMOTION_ASPECT_KEEP_WIDTH
* EMOTION_ASPECT_KEEP_HEIGHT
* EMOTION_ASPECT_KEEP_BOTH
* EMOTION_ASPECT_CROP
* EMOTION_ASPECT_CUSTOM
SVN revision: 63416
Diffstat (limited to '')
-rw-r--r-- | legacy/emotion/src/lib/emotion_smart.c | 177 |
1 files changed, 149 insertions, 28 deletions
diff --git a/legacy/emotion/src/lib/emotion_smart.c b/legacy/emotion/src/lib/emotion_smart.c index f9882b096c..cde9351980 100644 --- a/legacy/emotion/src/lib/emotion_smart.c +++ b/legacy/emotion/src/lib/emotion_smart.c | |||
@@ -94,6 +94,7 @@ struct _Smart_Data | |||
94 | Emotion_Module_Options module_options; | 94 | Emotion_Module_Options module_options; |
95 | 95 | ||
96 | Emotion_Suspend state; | 96 | Emotion_Suspend state; |
97 | Emotion_Aspect aspect; | ||
97 | 98 | ||
98 | Eina_Bool open : 1; | 99 | Eina_Bool open : 1; |
99 | Eina_Bool play : 1; | 100 | Eina_Bool play : 1; |
@@ -289,16 +290,15 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module ** | |||
289 | } | 290 | } |
290 | 291 | ||
291 | static void | 292 | static void |
292 | _clipper_position_size_update(Evas_Object *obj, int vid_w, int vid_h) | 293 | _clipper_position_size_update(Evas_Object *obj, int w, int h, int vid_w, int vid_h) |
293 | { | 294 | { |
294 | Smart_Data *sd; | 295 | Smart_Data *sd; |
295 | double scale_w, scale_h; | 296 | double scale_w, scale_h; |
296 | int x, y; | 297 | int x, y; |
297 | int w, h; | ||
298 | 298 | ||
299 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | 299 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); |
300 | 300 | ||
301 | evas_object_geometry_get(obj, &x, &y, &w, &h); | 301 | evas_object_geometry_get(obj, &x, &y, NULL, NULL); |
302 | evas_object_move(sd->crop.clipper, x, y); | 302 | evas_object_move(sd->crop.clipper, x, y); |
303 | scale_w = (double)w / (double)(vid_w - sd->crop.l - sd->crop.r); | 303 | scale_w = (double)w / (double)(vid_w - sd->crop.l - sd->crop.r); |
304 | scale_h = (double)h / (double)(vid_h - sd->crop.t - sd->crop.b); | 304 | scale_h = (double)h / (double)(vid_h - sd->crop.t - sd->crop.b); |
@@ -450,30 +450,25 @@ emotion_object_file_get(const Evas_Object *obj) | |||
450 | return sd->file; | 450 | return sd->file; |
451 | } | 451 | } |
452 | 452 | ||
453 | EAPI void | 453 | static void |
454 | emotion_object_border_set(Evas_Object *obj, int l, int r, int t, int b) | 454 | _emotion_aspect_borders_apply(Evas_Object *obj, Smart_Data *sd, int w, int h, int iw, int ih) |
455 | { | 455 | { |
456 | Smart_Data *sd; | 456 | /* applying calculated borders */ |
457 | 457 | if (sd->crop.l == 0 && sd->crop.r == 0 && | |
458 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | 458 | sd->crop.t == 0 && sd->crop.b == 0) |
459 | sd->crop.l = -l; | ||
460 | sd->crop.r = -r; | ||
461 | sd->crop.t = -t; | ||
462 | sd->crop.b = -b; | ||
463 | if (l == 0 && r == 0 && t == 0 && b == 0) | ||
464 | { | 459 | { |
465 | Evas_Object *old_clipper; | 460 | Evas_Object *old_clipper; |
466 | if (!sd->crop.clipper) | 461 | if (sd->crop.clipper) |
467 | return; | 462 | { |
468 | old_clipper = evas_object_clip_get(sd->crop.clipper); | 463 | old_clipper = evas_object_clip_get(sd->crop.clipper); |
469 | evas_object_clip_unset(sd->obj); | 464 | evas_object_clip_unset(sd->obj); |
470 | evas_object_clip_set(sd->obj, old_clipper); | 465 | evas_object_clip_set(sd->obj, old_clipper); |
471 | evas_object_del(sd->crop.clipper); | 466 | evas_object_del(sd->crop.clipper); |
472 | sd->crop.clipper = NULL; | 467 | sd->crop.clipper = NULL; |
468 | } | ||
473 | } | 469 | } |
474 | else | 470 | else |
475 | { | 471 | { |
476 | int vid_w, vid_h; | ||
477 | if (!sd->crop.clipper) | 472 | if (!sd->crop.clipper) |
478 | { | 473 | { |
479 | Evas_Object *old_clipper; | 474 | Evas_Object *old_clipper; |
@@ -487,9 +482,108 @@ emotion_object_border_set(Evas_Object *obj, int l, int r, int t, int b) | |||
487 | if (evas_object_visible_get(sd->obj)) | 482 | if (evas_object_visible_get(sd->obj)) |
488 | evas_object_show(sd->crop.clipper); | 483 | evas_object_show(sd->crop.clipper); |
489 | } | 484 | } |
490 | sd->module->video_data_size_get(sd->video, &vid_w, &vid_h); | ||
491 | _clipper_position_size_update(obj, vid_w, vid_h); | ||
492 | } | 485 | } |
486 | _clipper_position_size_update(obj, w, h, iw, ih); | ||
487 | } | ||
488 | |||
489 | static void | ||
490 | _emotion_object_aspect_border_apply(Evas_Object *obj, Smart_Data *sd, int w, int h) | ||
491 | { | ||
492 | int iw, ih; | ||
493 | double ir; | ||
494 | double r; | ||
495 | |||
496 | int aspect_opt; | ||
497 | sd->module->video_data_size_get(sd->video, &iw, &ih); | ||
498 | |||
499 | ir = (double)iw / ih; | ||
500 | r = (double)w / h; | ||
501 | |||
502 | /* First check if we should fit the width or height of the video inside the | ||
503 | * width/height of the object. This check takes into account the original | ||
504 | * aspect ratio and the object aspect ratio, if we are keeping both sizes or | ||
505 | * cropping the exceding area. | ||
506 | */ | ||
507 | if (sd->aspect == EMOTION_ASPECT_KEEP_NONE) | ||
508 | { | ||
509 | sd->crop.l = 0; | ||
510 | sd->crop.r = 0; | ||
511 | sd->crop.t = 0; | ||
512 | sd->crop.b = 0; | ||
513 | aspect_opt = 0; // just ignore keep_aspect | ||
514 | } | ||
515 | else if (sd->aspect == EMOTION_ASPECT_KEEP_WIDTH) | ||
516 | { | ||
517 | aspect_opt = 1; | ||
518 | } | ||
519 | else if (sd->aspect == EMOTION_ASPECT_KEEP_HEIGHT) | ||
520 | { | ||
521 | aspect_opt = 2; | ||
522 | } | ||
523 | else if (sd->aspect == EMOTION_ASPECT_KEEP_BOTH) | ||
524 | { | ||
525 | if (ir > r) | ||
526 | aspect_opt = 1; | ||
527 | else | ||
528 | aspect_opt = 2; | ||
529 | } | ||
530 | else if (sd->aspect == EMOTION_ASPECT_CROP) | ||
531 | { | ||
532 | if (ir > r) | ||
533 | aspect_opt = 2; | ||
534 | else | ||
535 | aspect_opt = 1; | ||
536 | } | ||
537 | else if (sd->aspect == EMOTION_ASPECT_CUSTOM) | ||
538 | { | ||
539 | // nothing to do, just respect the border settings | ||
540 | aspect_opt = 0; | ||
541 | } | ||
542 | |||
543 | /* updating borders based on keep_aspect settings */ | ||
544 | if (aspect_opt == 1) // keep width | ||
545 | { | ||
546 | int th, dh; | ||
547 | double scale; | ||
548 | |||
549 | sd->crop.l = 0; | ||
550 | sd->crop.r = 0; | ||
551 | scale = (double)iw / w; | ||
552 | th = h * scale; | ||
553 | dh = ih - th; | ||
554 | sd->crop.t = sd->crop.b = dh / 2; | ||
555 | } | ||
556 | else if (aspect_opt == 2) // keep height | ||
557 | { | ||
558 | int tw, dw; | ||
559 | double scale; | ||
560 | |||
561 | sd->crop.t = 0; | ||
562 | sd->crop.b = 0; | ||
563 | scale = (double)ih / h; | ||
564 | tw = w * scale; | ||
565 | dw = iw - tw; | ||
566 | sd->crop.l = sd->crop.r = dw / 2; | ||
567 | } | ||
568 | |||
569 | _emotion_aspect_borders_apply(obj, sd, w, h, iw, ih); | ||
570 | } | ||
571 | |||
572 | EAPI void | ||
573 | emotion_object_border_set(Evas_Object *obj, int l, int r, int t, int b) | ||
574 | { | ||
575 | Smart_Data *sd; | ||
576 | int w, h; | ||
577 | |||
578 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | ||
579 | |||
580 | sd->aspect = EMOTION_ASPECT_CUSTOM; | ||
581 | sd->crop.l = -l; | ||
582 | sd->crop.r = -r; | ||
583 | sd->crop.t = -t; | ||
584 | sd->crop.b = -b; | ||
585 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); | ||
586 | _emotion_object_aspect_border_apply(obj, sd, w, h); | ||
493 | } | 587 | } |
494 | 588 | ||
495 | EAPI void | 589 | EAPI void |
@@ -532,6 +626,32 @@ emotion_object_bg_color_get(const Evas_Object *obj, int *r, int *g, int *b, int | |||
532 | } | 626 | } |
533 | 627 | ||
534 | EAPI void | 628 | EAPI void |
629 | emotion_object_keep_aspect_set(Evas_Object *obj, Emotion_Aspect a) | ||
630 | { | ||
631 | Smart_Data *sd; | ||
632 | int w, h; | ||
633 | |||
634 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | ||
635 | |||
636 | if (a == sd->aspect) | ||
637 | return; | ||
638 | |||
639 | sd->aspect = a; | ||
640 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); | ||
641 | _emotion_object_aspect_border_apply(obj, sd, w, h); | ||
642 | } | ||
643 | |||
644 | EAPI Emotion_Aspect | ||
645 | emotion_object_keep_aspect_get(const Evas_Object *obj) | ||
646 | { | ||
647 | Smart_Data *sd; | ||
648 | |||
649 | E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, EMOTION_ASPECT_KEEP_NONE); | ||
650 | |||
651 | return sd->aspect; | ||
652 | } | ||
653 | |||
654 | EAPI void | ||
535 | emotion_object_play_set(Evas_Object *obj, Eina_Bool play) | 655 | emotion_object_play_set(Evas_Object *obj, Eina_Bool play) |
536 | { | 656 | { |
537 | Smart_Data *sd; | 657 | Smart_Data *sd; |
@@ -653,8 +773,6 @@ emotion_object_size_get(const Evas_Object *obj, int *iw, int *ih) | |||
653 | if (ih) *ih = 0; | 773 | if (ih) *ih = 0; |
654 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | 774 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); |
655 | evas_object_image_size_get(sd->obj, iw, ih); | 775 | evas_object_image_size_get(sd->obj, iw, ih); |
656 | *iw -= (sd->crop.l + sd->crop.r); | ||
657 | *ih -= (sd->crop.t + sd->crop.b); | ||
658 | } | 776 | } |
659 | 777 | ||
660 | EAPI void | 778 | EAPI void |
@@ -1364,7 +1482,8 @@ _emotion_frame_resize(Evas_Object *obj, int w, int h, double ratio) | |||
1364 | { | 1482 | { |
1365 | evas_object_size_hint_request_set(obj, w, h); | 1483 | evas_object_size_hint_request_set(obj, w, h); |
1366 | evas_object_smart_callback_call(obj, SIG_FRAME_RESIZE, NULL); | 1484 | evas_object_smart_callback_call(obj, SIG_FRAME_RESIZE, NULL); |
1367 | _clipper_position_size_update(obj, w, h); | 1485 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); |
1486 | _emotion_object_aspect_border_apply(obj, sd, w, h); | ||
1368 | } | 1487 | } |
1369 | } | 1488 | } |
1370 | 1489 | ||
@@ -1750,7 +1869,8 @@ _smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y) | |||
1750 | 1869 | ||
1751 | int vid_w, vid_h, w, h; | 1870 | int vid_w, vid_h, w, h; |
1752 | sd->module->video_data_size_get(sd->video, &vid_w, &vid_h); | 1871 | sd->module->video_data_size_get(sd->video, &vid_w, &vid_h); |
1753 | _clipper_position_size_update(obj, vid_w, vid_h); | 1872 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); |
1873 | _clipper_position_size_update(obj, w, h, vid_w, vid_h); | ||
1754 | evas_object_move(sd->bg, x, y); | 1874 | evas_object_move(sd->bg, x, y); |
1755 | } | 1875 | } |
1756 | 1876 | ||
@@ -1765,7 +1885,8 @@ _smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h) | |||
1765 | int vid_w, vid_h; | 1885 | int vid_w, vid_h; |
1766 | 1886 | ||
1767 | sd->module->video_data_size_get(sd->video, &vid_w, &vid_h); | 1887 | sd->module->video_data_size_get(sd->video, &vid_w, &vid_h); |
1768 | _clipper_position_size_update(obj, vid_w, vid_h); | 1888 | fprintf(stderr, "smart resize: %dx%d\n", w, h); |
1889 | _emotion_object_aspect_border_apply(obj, sd, w, h); | ||
1769 | evas_object_resize(sd->bg, w, h); | 1890 | evas_object_resize(sd->bg, w, h); |
1770 | } | 1891 | } |
1771 | 1892 | ||