summaryrefslogtreecommitdiff
path: root/legacy/emotion/src/lib/emotion_smart.c
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2011-09-15 18:51:23 +0000
committerRafael Antognolli <antognolli@gmail.com>2011-09-15 18:51:23 +0000
commit77f43424a6c0fa2d467ae9fd622012d5719c6d7a (patch)
treeb9932baf2a962dc219c77aabf7f59d009a0f88e9 /legacy/emotion/src/lib/emotion_smart.c
parent64f3a6da0f21ae57f003046a99ae7e9ba306eed9 (diff)
emotion/border: Add border/crop support for emotion objects.
The emotion_object_border_set/get APIs were added, allowing one to specify a positive (border) or negative (crop) value for each of the edjes of the video being played. This allows easier setup on an Emotion object to keep the aspect ratio, either by adding black areas on it, or by cropping the exceding area of the video. NOTE: The specified border/crop is based on the original size of the video. If it is scaled (emotion object size is different from the video size), the borders will be scaled as well. Patch based on an original patch sent by Hugo Camboulive <hugo.camboulive@gmail.com>. SVN revision: 63414
Diffstat (limited to '')
-rw-r--r--legacy/emotion/src/lib/emotion_smart.c114
1 files changed, 108 insertions, 6 deletions
diff --git a/legacy/emotion/src/lib/emotion_smart.c b/legacy/emotion/src/lib/emotion_smart.c
index 3fbcbea5f5..59ffb2a0a4 100644
--- a/legacy/emotion/src/lib/emotion_smart.c
+++ b/legacy/emotion/src/lib/emotion_smart.c
@@ -76,6 +76,13 @@ struct _Smart_Data
76 int button_num; 76 int button_num;
77 int button; 77 int button;
78 } spu; 78 } spu;
79 struct {
80 int l; /* left */
81 int r; /* right */
82 int t; /* top */
83 int b; /* bottom */
84 Evas_Object *clipper;
85 } crop;
79 86
80 double ratio; 87 double ratio;
81 double pos; 88 double pos;
@@ -200,6 +207,7 @@ _smart_data_free(Smart_Data *sd)
200 if (sd->video) sd->module->file_close(sd->video); 207 if (sd->video) sd->module->file_close(sd->video);
201 _emotion_module_close(sd->module, sd->video); 208 _emotion_module_close(sd->module, sd->video);
202 evas_object_del(sd->obj); 209 evas_object_del(sd->obj);
210 evas_object_del(sd->crop.clipper);
203 eina_stringshare_del(sd->file); 211 eina_stringshare_del(sd->file);
204 free(sd->module_name); 212 free(sd->module_name);
205 if (sd->job) ecore_job_del(sd->job); 213 if (sd->job) ecore_job_del(sd->job);
@@ -279,6 +287,27 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module **
279 return NULL; 287 return NULL;
280} 288}
281 289
290static void
291_clipper_position_size_update(Evas_Object *obj, int vid_w, int vid_h)
292{
293 Smart_Data *sd;
294 double scale_w, scale_h;
295 int x, y;
296 int w, h;
297
298 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
299
300 evas_object_geometry_get(obj, &x, &y, &w, &h);
301 evas_object_move(sd->crop.clipper, x, y);
302 scale_w = (double)w / (double)(vid_w - sd->crop.l - sd->crop.r);
303 scale_h = (double)h / (double)(vid_h - sd->crop.t - sd->crop.b);
304
305 evas_object_image_fill_set(sd->obj, 0, 0, vid_w * scale_w, vid_h * scale_h);
306 evas_object_resize(sd->obj, vid_w * scale_w, vid_h * scale_h);
307 evas_object_move(sd->obj, x - sd->crop.l * scale_w, y - sd->crop.t * scale_h);
308 evas_object_resize(sd->crop.clipper, w, h);
309}
310
282/*******************************/ 311/*******************************/
283/* Externally accessible calls */ 312/* Externally accessible calls */
284/*******************************/ 313/*******************************/
@@ -421,6 +450,60 @@ emotion_object_file_get(const Evas_Object *obj)
421} 450}
422 451
423EAPI void 452EAPI void
453emotion_object_border_set(Evas_Object *obj, int l, int r, int t, int b)
454{
455 Smart_Data *sd;
456
457 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
458 sd->crop.l = -l;
459 sd->crop.r = -r;
460 sd->crop.t = -t;
461 sd->crop.b = -b;
462 if (l == 0 && r == 0 && t == 0 && b == 0)
463 {
464 Evas_Object *old_clipper;
465 if (!sd->crop.clipper)
466 return;
467 old_clipper = evas_object_clip_get(sd->crop.clipper);
468 evas_object_clip_unset(sd->obj);
469 evas_object_clip_set(sd->obj, old_clipper);
470 evas_object_del(sd->crop.clipper);
471 sd->crop.clipper = NULL;
472 }
473 else
474 {
475 int vid_w, vid_h;
476 if (!sd->crop.clipper)
477 {
478 Evas_Object *old_clipper;
479 sd->crop.clipper = evas_object_rectangle_add(
480 evas_object_evas_get(obj));
481 evas_object_color_set(sd->crop.clipper, 255, 255, 255, 255);
482 evas_object_smart_member_add(sd->crop.clipper, obj);
483 old_clipper = evas_object_clip_get(sd->obj);
484 evas_object_clip_set(sd->obj, sd->crop.clipper);
485 evas_object_clip_set(sd->crop.clipper, old_clipper);
486 if (evas_object_visible_get(sd->obj))
487 evas_object_show(sd->crop.clipper);
488 }
489 sd->module->video_data_size_get(sd->video, &vid_w, &vid_h);
490 _clipper_position_size_update(obj, vid_w, vid_h);
491 }
492}
493
494EAPI void
495emotion_object_border_get(Evas_Object *obj, int *l, int *r, int *t, int *b)
496{
497 Smart_Data *sd;
498
499 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
500 *l = -sd->crop.l;
501 *r = -sd->crop.r;
502 *t = -sd->crop.t;
503 *b = -sd->crop.b;
504}
505
506EAPI void
424emotion_object_play_set(Evas_Object *obj, Eina_Bool play) 507emotion_object_play_set(Evas_Object *obj, Eina_Bool play)
425{ 508{
426 Smart_Data *sd; 509 Smart_Data *sd;
@@ -542,6 +625,8 @@ emotion_object_size_get(const Evas_Object *obj, int *iw, int *ih)
542 if (ih) *ih = 0; 625 if (ih) *ih = 0;
543 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); 626 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
544 evas_object_image_size_get(sd->obj, iw, ih); 627 evas_object_image_size_get(sd->obj, iw, ih);
628 *iw -= (sd->crop.l + sd->crop.r);
629 *ih -= (sd->crop.t + sd->crop.b);
545} 630}
546 631
547EAPI void 632EAPI void
@@ -1251,6 +1336,7 @@ _emotion_frame_resize(Evas_Object *obj, int w, int h, double ratio)
1251 { 1336 {
1252 evas_object_size_hint_request_set(obj, w, h); 1337 evas_object_size_hint_request_set(obj, w, h);
1253 evas_object_smart_callback_call(obj, SIG_FRAME_RESIZE, NULL); 1338 evas_object_smart_callback_call(obj, SIG_FRAME_RESIZE, NULL);
1339 _clipper_position_size_update(obj, w, h);
1254 } 1340 }
1255} 1341}
1256 1342
@@ -1629,7 +1715,10 @@ _smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y)
1629 1715
1630 sd = evas_object_smart_data_get(obj); 1716 sd = evas_object_smart_data_get(obj);
1631 if (!sd) return; 1717 if (!sd) return;
1632 evas_object_move(sd->obj, x, y); 1718
1719 int vid_w, vid_h, w, h;
1720 sd->module->video_data_size_get(sd->video, &vid_w, &vid_h);
1721 _clipper_position_size_update(obj, vid_w, vid_h);
1633} 1722}
1634 1723
1635static void 1724static void
@@ -1639,8 +1728,11 @@ _smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h)
1639 1728
1640 sd = evas_object_smart_data_get(obj); 1729 sd = evas_object_smart_data_get(obj);
1641 if (!sd) return; 1730 if (!sd) return;
1642 evas_object_image_fill_set(sd->obj, 0, 0, w, h); 1731
1643 evas_object_resize(sd->obj, w, h); 1732 int vid_w, vid_h;
1733
1734 sd->module->video_data_size_get(sd->video, &vid_w, &vid_h);
1735 _clipper_position_size_update(obj, vid_w, vid_h);
1644} 1736}
1645 1737
1646static void 1738static void
@@ -1651,7 +1743,8 @@ _smart_show(Evas_Object * obj)
1651 sd = evas_object_smart_data_get(obj); 1743 sd = evas_object_smart_data_get(obj);
1652 if (!sd) return; 1744 if (!sd) return;
1653 evas_object_show(sd->obj); 1745 evas_object_show(sd->obj);
1654 1746 if (sd->crop.clipper)
1747 evas_object_show(sd->crop.clipper);
1655} 1748}
1656 1749
1657static void 1750static void
@@ -1662,6 +1755,8 @@ _smart_hide(Evas_Object * obj)
1662 sd = evas_object_smart_data_get(obj); 1755 sd = evas_object_smart_data_get(obj);
1663 if (!sd) return; 1756 if (!sd) return;
1664 evas_object_hide(sd->obj); 1757 evas_object_hide(sd->obj);
1758 if (sd->crop.clipper)
1759 evas_object_hide(sd->crop.clipper);
1665} 1760}
1666 1761
1667static void 1762static void
@@ -1672,6 +1767,7 @@ _smart_color_set(Evas_Object * obj, int r, int g, int b, int a)
1672 sd = evas_object_smart_data_get(obj); 1767 sd = evas_object_smart_data_get(obj);
1673 if (!sd) return; 1768 if (!sd) return;
1674 evas_object_color_set(sd->obj, r, g, b, a); 1769 evas_object_color_set(sd->obj, r, g, b, a);
1770 evas_object_color_set(sd->crop.clipper, r, g, b, a);
1675} 1771}
1676 1772
1677static void 1773static void
@@ -1681,7 +1777,10 @@ _smart_clip_set(Evas_Object * obj, Evas_Object * clip)
1681 1777
1682 sd = evas_object_smart_data_get(obj); 1778 sd = evas_object_smart_data_get(obj);
1683 if (!sd) return; 1779 if (!sd) return;
1684 evas_object_clip_set(sd->obj, clip); 1780 if (sd->crop.clipper)
1781 evas_object_clip_set(sd->crop.clipper, clip);
1782 else
1783 evas_object_clip_set(sd->obj, clip);
1685} 1784}
1686 1785
1687static void 1786static void
@@ -1691,6 +1790,9 @@ _smart_clip_unset(Evas_Object * obj)
1691 1790
1692 sd = evas_object_smart_data_get(obj); 1791 sd = evas_object_smart_data_get(obj);
1693 if (!sd) return; 1792 if (!sd) return;
1694 evas_object_clip_unset(sd->obj); 1793 if (sd->crop.clipper)
1794 evas_object_clip_unset(sd->crop.clipper);
1795 else
1796 evas_object_clip_unset(sd->obj);
1695} 1797}
1696 1798