From: Minkyu Kang Date: Thu, 3 Sep 2015 10:19:43 +0000 (+0900) Subject: zoom: add mouse event X-Git-Tag: accepted/tizen/tv/20150904.063904^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F47453%2F1;p=profile%2Ftv%2Fapps%2Fnative%2Fair_mediahub.git zoom: add mouse event Change-Id: I91d6a83b63c87a0dfc301a0cdf3cde1140ddc3e6 Signed-off-by: Minkyu Kang --- diff --git a/src/view/zoom.c b/src/view/zoom.c index da4db9f..e3bd2c5 100644 --- a/src/view/zoom.c +++ b/src/view/zoom.c @@ -41,6 +41,8 @@ #define TOAST_MESSAGE "Press Back to Escape from Zoom mode" #define TOAST_TIMEOUT 3.0 +#define NAVI_RECT_NUM 5 + enum { DIR_UP = 0, DIR_DOWN, @@ -54,12 +56,15 @@ struct _priv { Evas_Object *base; Evas_Object *photo; Evas_Object *thumb; - Evas_Object *navi[DIR_NUM]; + Evas_Object *navi[NAVI_RECT_NUM]; Evas_Object *notify; app_media_info *mi; struct controller *ctl; double image_ratio; double zoom_ratio; + int navi_w; + int navi_h; + bool drag; }; struct _btn_info { @@ -182,6 +187,9 @@ static void _update_navi(struct _priv *priv) mw = pw * priv->image_ratio; mh = ph * priv->image_ratio; + priv->navi_w = mw; + priv->navi_h = mh; + /* up */ x[DIR_UP] = nx; y[DIR_UP] = ny; @@ -210,6 +218,47 @@ static void _update_navi(struct _priv *priv) evas_object_resize(priv->navi[i], w[i], h[i]); evas_object_move(priv->navi[i], x[i], y[i]); } + + evas_object_resize(priv->navi[i], mw, mh); + evas_object_move(priv->navi[i], mx, my); +} + +static void _move_navi(struct _priv *priv, Evas_Coord_Point coord) +{ + Evas_Object *obj; + int px, py, pw, ph; /* photo's geometry */ + int nx, ny, nw, nh; /* thumb's geometry */ + int mx, my, mw, mh; /* navi's geometry */ + int w, h; + + elm_photocam_image_size_get(priv->photo, &w, &h); + + elm_photocam_image_region_get(priv->photo, &px, &py, &pw, &ph); + + obj = elm_image_object_get(priv->thumb); + evas_object_geometry_get(obj, &nx, &ny, &nw, &nh); + + mw = priv->navi_w; + mh = priv->navi_h; + + mx = coord.x - (mw / 2); + my = coord.y - (mh / 2); + + if (mx < nx) + mx = 0; + else if (mx > nx + nw - mw) + mx = w - pw; + else + mx = (mx - nx) / priv->image_ratio; + + if (my < ny) + my = 0; + else if (my > ny + nh - mh) + my = h - ph; + else + my = (my - ny) / priv->image_ratio; + + elm_scroller_region_show(priv->photo, mx, my, pw, ph); } static Eina_Bool _zoom_set(void *data) @@ -335,7 +384,57 @@ static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, ctl->ops->signal(ctl->handle, dir, sig); } -static input_handler _handler = { +static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Move *ev) +{ + struct _priv *priv; + + if (!data || !ev) + return; + + priv = data; + + if (!priv->drag) + return; + + _move_navi(priv, ev->cur.canvas); +} + +static void _mouse_up(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Up *ev) +{ + struct _priv *priv; + + if (!data || !ev) + return; + + priv = data; + + priv->drag = false; +} + +static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Down *ev) +{ + struct _priv *priv; + + if (!data || !ev) + return; + + priv = data; + + priv->drag = true; + + _move_navi(priv, ev->canvas); +} + +static input_handler _navi_handler = { + .mouse_move = _mouse_move, + .mouse_down = _mouse_down, + .mouse_up = _mouse_up, +}; + +static input_handler _btn_handler = { .key_up = _key_up, .key_down = _key_down, }; @@ -391,7 +490,7 @@ static bool _draw_navi(struct _priv *priv) Evas_Object *obj; int i; - for (i = 0; i < DIR_NUM; i++) { + for (i = 0; i < NAVI_RECT_NUM; i++) { obj = evas_object_rectangle_add( evas_object_evas_get(priv->base)); if (!obj) { @@ -399,9 +498,15 @@ static bool _draw_navi(struct _priv *priv) return false; } - evas_object_color_set(obj, 0, 0, 0, 204); + if (i == NAVI_RECT_NUM - 1) + evas_object_color_set(obj, 0, 0, 0, 0); + else + evas_object_color_set(obj, 0, 0, 0, 204); + evas_object_show(obj); + inputmgr_add_callback(obj, 0, &_navi_handler, priv); + priv->navi[i] = obj; } @@ -442,7 +547,7 @@ static bool _ui_init(struct _priv *priv) obj = ctl->ops->get_object(ctl->handle, i); if (obj) - inputmgr_add_callback(obj, 0, &_handler, priv); + inputmgr_add_callback(obj, 0, &_btn_handler, priv); } priv->ctl = ctl; @@ -542,9 +647,11 @@ static void _hide(void *view_data) if (priv->thumb) evas_object_del(priv->thumb); - for (i = 0; i < DIR_NUM; i++) { - if (priv->navi[i]) + for (i = 0; i < NAVI_RECT_NUM; i++) { + if (priv->navi[i]) { + inputmgr_remove_callback(priv->navi[i], &_navi_handler); evas_object_del(priv->navi[i]); + } } _hide_toast(priv); @@ -602,7 +709,7 @@ static void _destroy(void *view_data) for (i = 0; i < ARRAY_SIZE(btn_arrow); i++) { obj = ctl->ops->get_object(ctl->handle, i); if (obj) - inputmgr_remove_callback(obj, &_handler); + inputmgr_remove_callback(obj, &_btn_handler); } evas_object_del(priv->base);