From 980652cd0c3096ce73c0dbfe312ad30cedd669cb Mon Sep 17 00:00:00 2001 From: Minkyu Kang Date: Thu, 3 Sep 2015 15:33:08 +0900 Subject: add zoom view Change-Id: I9ac6f1e9c89064bd8b25bb083be21c1f17a12c6e Signed-off-by: Minkyu Kang --- CMakeLists.txt | 1 + include/define.h | 2 + include/view.h | 3 + include/view/zoom.h | 50 +++ res/edc/images/ic_zoom_indicator_down_foc.png | Bin 0 -> 2807 bytes res/edc/images/ic_zoom_indicator_down_nor.png | Bin 0 -> 2728 bytes res/edc/images/ic_zoom_indicator_left_foc.png | Bin 0 -> 2786 bytes res/edc/images/ic_zoom_indicator_left_nor.png | Bin 0 -> 2764 bytes res/edc/images/ic_zoom_indicator_right_foc.png | Bin 0 -> 2777 bytes res/edc/images/ic_zoom_indicator_right_nor.png | Bin 0 -> 2759 bytes res/edc/images/ic_zoom_indicator_up_foc.png | Bin 0 -> 2803 bytes res/edc/images/ic_zoom_indicator_up_nor.png | Bin 0 -> 2667 bytes res/edc/mediahub.edc | 1 + res/edc/view/zoom.edc | 230 ++++++++++ res/edc/widgets/button.edc | 166 +++++++ src/main.c | 1 + src/view/viewer.c | 19 +- src/view/zoom.c | 598 +++++++++++++++++++++++++ 18 files changed, 1068 insertions(+), 3 deletions(-) create mode 100644 include/view/zoom.h create mode 100644 res/edc/images/ic_zoom_indicator_down_foc.png create mode 100644 res/edc/images/ic_zoom_indicator_down_nor.png create mode 100644 res/edc/images/ic_zoom_indicator_left_foc.png create mode 100644 res/edc/images/ic_zoom_indicator_left_nor.png create mode 100644 res/edc/images/ic_zoom_indicator_right_foc.png create mode 100644 res/edc/images/ic_zoom_indicator_right_nor.png create mode 100644 res/edc/images/ic_zoom_indicator_up_foc.png create mode 100644 res/edc/images/ic_zoom_indicator_up_nor.png create mode 100644 res/edc/view/zoom.edc create mode 100644 src/view/zoom.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5045400..9baba92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ src/view/base.c src/view/viewer.c src/view/mplayer.c src/view/action_menu.c +src/view/zoom.c src/layout/movie.c src/layout/gallery.c src/layout/music.c diff --git a/include/define.h b/include/define.h index 1e702ad..a169928 100644 --- a/include/define.h +++ b/include/define.h @@ -22,6 +22,7 @@ #include "view/viewer.h" #include "view/mplayer.h" #include "view/action_menu.h" +#include "view/zoom.h" /* layouts */ #include "layout/movie.h" @@ -90,6 +91,7 @@ #define SIG_HIDE_VIEW "hide,view" #define SIG_DISMISSED "dismissed" #define SIG_TIMEOUT "timeout" +#define SIG_SCROLL "scroll" /* transition */ #define TRANSITION_FOCUS DECELERATE 0.20 diff --git a/include/view.h b/include/view.h index 755c6e8..19dca1e 100644 --- a/include/view.h +++ b/include/view.h @@ -29,6 +29,9 @@ view_class *view_mplayer_get_vclass(void); /* action menu */ view_class *view_action_menu_get_vclass(void); +/* zoom */ +view_class *view_zoom_get_vclass(void); + /* view data */ struct view_update_data { Eina_List *list; diff --git a/include/view/zoom.h b/include/view/zoom.h new file mode 100644 index 0000000..f5d7257 --- /dev/null +++ b/include/view/zoom.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __AIR_MEDIAHUB_VIEW_ZOOM_H__ +#define __AIR_MEDIAHUB_VIEW_ZOOM_H__ + +/* view */ +#define VIEW_ZOOM "VIEW_ZOOM" + +/* group */ +#define GRP_ZOOM_VIEW "group.zoom_view" + +/* part */ +#define PART_ZOOM_CONTENT "part.zoom_content" +#define PART_ZOOM_NAVI "part.zoom_navi" + +/* source */ +#define SRC_BTN_UP "up" +#define SRC_BTN_DOWN "down" +#define SRC_BTN_LEFT "left" +#define SRC_BTN_RIGHT "right" + +/* signal */ +#define SIG_SET_FOCUS "set,focus" +#define SIG_SET_UNFOCUS "set,unfocus" + +/* image */ +#define IMAGE_ZOOM_UP_NORMAL "ic_zoom_indicator_up_nor.png" +#define IMAGE_ZOOM_UP_FOC "ic_zoom_indicator_up_foc.png" +#define IMAGE_ZOOM_DOWN_NORMAL "ic_zoom_indicator_down_nor.png" +#define IMAGE_ZOOM_DOWN_FOC "ic_zoom_indicator_down_foc.png" +#define IMAGE_ZOOM_LEFT_NORMAL "ic_zoom_indicator_left_nor.png" +#define IMAGE_ZOOM_LEFT_FOC "ic_zoom_indicator_left_foc.png" +#define IMAGE_ZOOM_RIGHT_NORMAL "ic_zoom_indicator_right_nor.png" +#define IMAGE_ZOOM_RIGHT_FOC "ic_zoom_indicator_right_foc.png" + +#endif diff --git a/res/edc/images/ic_zoom_indicator_down_foc.png b/res/edc/images/ic_zoom_indicator_down_foc.png new file mode 100644 index 0000000..797738c Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_down_foc.png differ diff --git a/res/edc/images/ic_zoom_indicator_down_nor.png b/res/edc/images/ic_zoom_indicator_down_nor.png new file mode 100644 index 0000000..1ec7c1a Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_down_nor.png differ diff --git a/res/edc/images/ic_zoom_indicator_left_foc.png b/res/edc/images/ic_zoom_indicator_left_foc.png new file mode 100644 index 0000000..d224bb1 Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_left_foc.png differ diff --git a/res/edc/images/ic_zoom_indicator_left_nor.png b/res/edc/images/ic_zoom_indicator_left_nor.png new file mode 100644 index 0000000..bdc35fe Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_left_nor.png differ diff --git a/res/edc/images/ic_zoom_indicator_right_foc.png b/res/edc/images/ic_zoom_indicator_right_foc.png new file mode 100644 index 0000000..2509aa1 Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_right_foc.png differ diff --git a/res/edc/images/ic_zoom_indicator_right_nor.png b/res/edc/images/ic_zoom_indicator_right_nor.png new file mode 100644 index 0000000..0825b13 Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_right_nor.png differ diff --git a/res/edc/images/ic_zoom_indicator_up_foc.png b/res/edc/images/ic_zoom_indicator_up_foc.png new file mode 100644 index 0000000..ee95dee Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_up_foc.png differ diff --git a/res/edc/images/ic_zoom_indicator_up_nor.png b/res/edc/images/ic_zoom_indicator_up_nor.png new file mode 100644 index 0000000..ecd4be4 Binary files /dev/null and b/res/edc/images/ic_zoom_indicator_up_nor.png differ diff --git a/res/edc/mediahub.edc b/res/edc/mediahub.edc index c73dcd1..3c2d3be 100644 --- a/res/edc/mediahub.edc +++ b/res/edc/mediahub.edc @@ -21,6 +21,7 @@ collections { #include "view/viewer.edc" #include "view/mplayer.edc" #include "view/action_menu.edc" + #include "view/zoom.edc" #include "layout/movie.edc" #include "layout/gallery.edc" #include "layout/music.edc" diff --git a/res/edc/view/zoom.edc b/res/edc/view/zoom.edc new file mode 100644 index 0000000..6beb985 --- /dev/null +++ b/res/edc/view/zoom.edc @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +group { + name: GRP_ZOOM_VIEW; + parts { + part { + name: "bg"; + type: RECT; + scale: 1; + description { + state: "default" 0.0; + color: 0 0 0 255; + } + } + part { + name: PART_ZOOM_CONTENT; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + rel1.to: "bg"; + rel2.to: "bg"; + } + } + part { + name: "padding_top"; + type: SPACER; + scale: 1; + description { + state: "default" 0.0; + min: 0 40; + rel1 { + to: "bg"; + relative: 0.0 0.0; + } + rel2 { + to: "bg"; + relative: 1.0 0.0; + } + align: 0.0 0.0; + fixed: 0 1; + } + } + part { + name: "padding_bottom"; + type: SPACER; + scale: 1; + description { + state: "default" 0.0; + min: 0 40; + rel1 { + to: "bg"; + relative: 0.0 1.0; + } + rel2 { + to: "bg"; + relative: 1.0 1.0; + } + align: 0.0 1.0; + fixed: 0 1; + } + } + part { + name: "padding_left"; + type: SPACER; + scale: 1; + description { + state: "default" 0.0; + min: 40 0; + rel1 { + to: "bg"; + relative: 0.0 0.0; + } + rel2 { + to: "bg"; + relative: 0.0 1.0; + } + align: 0.0 0.0; + fixed: 1 0; + } + } + part { + name: "padding_right"; + type: SPACER; + scale: 1; + description { + state: "default" 0.0; + min: 40 0; + rel1 { + to: "bg"; + relative: 1.0 0.0; + } + rel2 { + to: "bg"; + relative: 1.0 1.0; + } + align: 1.0 0.0; + fixed: 1 0; + } + } + part { + name: "arrow_btn0"; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + min: 90 90; + rel1 { + to: "padding_top"; + relative: 0.5 1.0; + } + rel2 { + to: "padding_top"; + relative: 0.5 1.0; + } + fixed: 1 1; + align: 0.5 0.0; + } + } + part { + name: "arrow_btn1"; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + min: 90 90; + rel1 { + to: "padding_bottom"; + relative: 0.5 0.0; + } + rel2 { + to: "padding_bottom"; + relative: 0.5 0.0; + } + fixed: 1 1; + align: 0.5 1.0; + } + } + part { + name: "arrow_btn2"; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + min: 90 90; + rel1 { + to: "padding_left"; + relative: 1.0 0.5; + } + rel2 { + to: "padding_left"; + relative: 1.0 0.5; + } + fixed: 1 1; + align: 0.0 0.5; + } + } + part { + name: "arrow_btn3"; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + min: 90 90; + rel1 { + to: "padding_right"; + relative: 0.0 0.5; + } + rel2 { + to: "padding_right"; + relative: 0.0 0.5; + } + fixed: 1 1; + align: 1.0 0.5; + } + } + part { + name: "padding_navi"; + type: SPACER; + scale: 1; + description { + state: "default" 0.0; + min: 40 40; + rel1 { + to: "bg"; + relative: 1.0 1.0; + } + rel2 { + to: "bg"; + relative: 1.0 1.0; + } + align: 1.0 1.0; + fixed: 1 1; + } + } + part { + name: PART_ZOOM_NAVI; + type: SWALLOW; + scale: 1; + description { + state: "default" 0.0; + min: 536 300; + rel1 { + to: "padding_navi"; + relative: 0.0 0.0; + } + rel2 { + to: "padding_navi"; + relative: 0.0 0.0; + } + align: 1.0 1.0; + fixed: 1 1; + } + } + } +} diff --git a/res/edc/widgets/button.edc b/res/edc/widgets/button.edc index c796b32..b29bd5d 100644 --- a/res/edc/widgets/button.edc +++ b/res/edc/widgets/button.edc @@ -4408,3 +4408,169 @@ group { } } } + +group { + name: "elm/button/base/zoom_btn_up"; + data.item, "focus_highlight" "on"; + images { + image: IMAGE_ZOOM_UP_NORMAL COMP; + image: IMAGE_ZOOM_UP_FOC COMP; + } + parts { + part { + name: "bg"; + scale: 1; + description { + state: "default" 0.0; + min: 90 90; + image { + normal: IMAGE_ZOOM_UP_NORMAL; + } + } + description { + state: "selected" 0.0; + inherit: "default" 0.0; + image { + normal: IMAGE_ZOOM_UP_FOC; + } + } + } + } + programs { + program { + name: "button_clicked"; + signal: "mouse,clicked,1"; + source: "bg"; + action: SIGNAL_EMIT "elm,action,click" ""; + } + program { + name: SIG_BTN_CLICKED; + signal: SIG_BTN_CLICKED; + source: ""; + after: "emit,signal"; + } + program { + name: "emit,signal"; + action: SIGNAL_EMIT SIG_BTN_CALLBACK SRC_BTN_UP; + } + program { + name: SIG_SET_FOCUS; + signal: SIG_SET_FOCUS; + source: ""; + action: STATE_SET "selected" 0.0; + target: "bg"; + } + program { + name: SIG_SET_UNFOCUS; + signal: SIG_SET_UNFOCUS; + source: ""; + action: STATE_SET "default" 0.0; + target: "bg"; + } + } +} + +group { + name: "elm/button/base/zoom_btn_down"; + inherit: "elm/button/base/zoom_btn_up"; + data.item, "focus_highlight" "on"; + images { + image: IMAGE_ZOOM_DOWN_NORMAL COMP; + image: IMAGE_ZOOM_DOWN_FOC COMP; + } + parts { + part { + name: "bg"; + scale: 1; + description { + state: "default" 0.0; + image { + normal: IMAGE_ZOOM_DOWN_NORMAL; + } + } + description { + state: "selected" 0.0; + inherit: "default" 0.0; + image { + normal: IMAGE_ZOOM_DOWN_FOC; + } + } + } + } + programs { + program { + name: "emit,signal"; + action: SIGNAL_EMIT SIG_BTN_CALLBACK SRC_BTN_DOWN; + } + } +} + +group { + name: "elm/button/base/zoom_btn_left"; + inherit: "elm/button/base/zoom_btn_up"; + data.item, "focus_highlight" "on"; + images { + image: IMAGE_ZOOM_LEFT_NORMAL COMP; + image: IMAGE_ZOOM_LEFT_FOC COMP; + } + parts { + part { + name: "bg"; + scale: 1; + description { + state: "default" 0.0; + image { + normal: IMAGE_ZOOM_LEFT_NORMAL; + } + } + description { + state: "selected" 0.0; + inherit: "default" 0.0; + image { + normal: IMAGE_ZOOM_LEFT_FOC; + } + } + } + } + programs { + program { + name: "emit,signal"; + action: SIGNAL_EMIT SIG_BTN_CALLBACK SRC_BTN_LEFT; + } + } +} + +group { + name: "elm/button/base/zoom_btn_right"; + inherit: "elm/button/base/zoom_btn_up"; + data.item, "focus_highlight" "on"; + images { + image: IMAGE_ZOOM_RIGHT_NORMAL COMP; + image: IMAGE_ZOOM_RIGHT_FOC COMP; + } + parts { + part { + name: "bg"; + scale: 1; + description { + state: "default" 0.0; + image { + normal: IMAGE_ZOOM_RIGHT_NORMAL; + } + } + description { + state: "selected" 0.0; + inherit: "default" 0.0; + image { + normal: IMAGE_ZOOM_RIGHT_FOC; + } + } + } + } + programs { + program { + name: "emit,signal"; + action: SIGNAL_EMIT SIG_BTN_CALLBACK SRC_BTN_RIGHT; + } + } +} diff --git a/src/main.c b/src/main.c index e18e1dd..ff0b293 100644 --- a/src/main.c +++ b/src/main.c @@ -89,6 +89,7 @@ static bool _create(void *data) viewmgr_add_view(view_viewer_get_vclass(), NULL); viewmgr_add_view(view_mplayer_get_vclass(), NULL); viewmgr_add_view(view_action_menu_get_vclass(), NULL); + viewmgr_add_view(view_zoom_get_vclass(), NULL); elm_win_focus_highlight_enabled_set(win, EINA_TRUE); elm_win_focus_highlight_style_set(win, STYLE_INVISIBLE); diff --git a/src/view/viewer.c b/src/view/viewer.c index ca82aad..738bc55 100644 --- a/src/view/viewer.c +++ b/src/view/viewer.c @@ -485,6 +485,17 @@ static void _set_image_orientation(struct _priv *priv) app_media_update(am); } +static void _set_image_zoom(struct _priv *priv) +{ + struct view_update_data vdata; + + vdata.list = priv->playlist.list; + vdata.index = priv->playlist.cur; + + viewmgr_update_view(VIEW_ZOOM, UPDATE_CONTENT, &vdata); + viewmgr_push_view(VIEW_ZOOM); +} + static void _update_to_player(struct _priv *priv) { viewmgr_update_view(VIEW_MPLAYER, UPDATE_PLAYER, NULL); @@ -886,15 +897,17 @@ static void _callback_photo(void *data, const char *ev) priv = data; - if (!strcmp(ev, SRC_BTN_GALLERY_PREV)) + if (!strcmp(ev, SRC_BTN_GALLERY_PREV)) { _viewer_prev(priv); - else if (!strcmp(ev, SRC_BTN_GALLERY_NEXT)) + } else if (!strcmp(ev, SRC_BTN_GALLERY_NEXT)) { _viewer_next(priv); - else if (!strcmp(ev, SRC_BTN_ROTATE)) { + } else if (!strcmp(ev, SRC_BTN_ROTATE)) { _set_image_orientation(priv); priv->viewer.foc = BTN_LOC_ROTATE; _viewer_show(priv); + } else if (!strcmp(ev, SRC_BTN_ZOOM)) { + _set_image_zoom(priv); } } diff --git a/src/view/zoom.c b/src/view/zoom.c new file mode 100644 index 0000000..afcc0fc --- /dev/null +++ b/src/view/zoom.c @@ -0,0 +1,598 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "define.h" +#include "view.h" +#include "util/controller.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define STYLE_ARROW_BTN "zoom_btn" +#define PART_ARROW_BTN "arrow_btn" + +#define ZOOM_INTERVAL 0.3 +#define ZOOM_RATIO_X2 0.5 +#define ZOOM_RATIO_X4 0.25 +#define MOVE_SIZE 10 + +enum { + DIR_UP = 0, + DIR_DOWN, + DIR_LEFT, + DIR_RIGHT, + DIR_NUM +}; + +struct _priv { + Evas_Object *win; + Evas_Object *base; + Evas_Object *photo; + Evas_Object *thumb; + Evas_Object *navi[DIR_NUM]; + app_media_info *mi; + struct controller *ctl; + double image_ratio; + double zoom_ratio; +}; + +struct _btn_info { + const char *name; + int loc; +}; + +static struct _btn_info btn_arrow[DIR_NUM] = { + { + .name = SRC_BTN_UP, + .loc = DIR_UP, + }, + { + .name = SRC_BTN_DOWN, + .loc = DIR_DOWN, + }, + { + .name = SRC_BTN_LEFT, + .loc = DIR_LEFT, + }, + { + .name = SRC_BTN_RIGHT, + .loc = DIR_RIGHT, + }, +}; + + +static app_media_info *_get_media_info(Eina_List *list, int cur) +{ + app_media *am; + app_media_info *mi; + + am = eina_list_nth(list, cur); + if (!am) { + _ERR("failed to get app_media"); + return NULL; + } + + mi = app_media_get_info(am); + if (!mi) { + _ERR("failed to getting media info"); + return NULL; + } + + return mi; +} + +static void _get_image_ratio(struct _priv *priv) +{ + Evas_Object *obj; + int w, w2; + + elm_photocam_image_size_get(priv->photo, &w, NULL); + + obj = elm_image_object_get(priv->thumb); + evas_object_geometry_get(obj, NULL, NULL, &w2, NULL); + + priv->image_ratio = w2 / (double)w; +} + +static void _get_zoom_ratio(struct _priv *priv) +{ + app_image_info *image; + int win, img; + int w, h; + double ratio; + + elm_win_screen_size_get(priv->win, NULL, NULL, &w, &h); + + image = priv->mi->image; + + if (image->width > image->height) { + img = image->width; + win = w; + ratio = ZOOM_RATIO_X2; + } else { + img = image->height; + win = h; + ratio = ZOOM_RATIO_X4; + } + + priv->zoom_ratio = ratio * img / (double)win; +} + +static void _update_navi(struct _priv *priv) +{ + 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 x[DIR_NUM], y[DIR_NUM], w[DIR_NUM], h[DIR_NUM]; + int i; + + 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); + + mx = nx + px * priv->image_ratio; + my = ny + py * priv->image_ratio; + mw = pw * priv->image_ratio; + mh = ph * priv->image_ratio; + + /* up */ + x[DIR_UP] = nx; + y[DIR_UP] = ny; + w[DIR_UP] = nw; + h[DIR_UP] = my - ny; + + /* down */ + x[DIR_DOWN] = nx; + y[DIR_DOWN] = my + mh; + w[DIR_DOWN] = nw; + h[DIR_DOWN] = nh - mh - h[DIR_UP]; + + /* left */ + x[DIR_LEFT] = nx; + y[DIR_LEFT] = my; + w[DIR_LEFT] = mx - nx; + h[DIR_LEFT] = mh; + + /* right */ + x[DIR_RIGHT] = mx + mw; + y[DIR_RIGHT] = my; + w[DIR_RIGHT] = nw - mw - w[DIR_LEFT]; + h[DIR_RIGHT] = mh; + + for (i = 0; i < DIR_NUM; i++) { + evas_object_resize(priv->navi[i], w[i], h[i]); + evas_object_move(priv->navi[i], x[i], y[i]); + } +} + +static Eina_Bool _zoom_set(void *data) +{ + struct _priv *priv; + + if (!data) + return ECORE_CALLBACK_CANCEL; + + priv = data; + + _get_zoom_ratio(priv); + + elm_photocam_zoom_mode_set(priv->photo, ELM_PHOTOCAM_ZOOM_MODE_MANUAL); + elm_photocam_zoom_set(priv->photo, priv->zoom_ratio); + + _get_image_ratio(priv); + _update_navi(priv); + + return ECORE_CALLBACK_CANCEL; +} + +static void _scrolled(void *data, Evas_Object *obj, void *ev) +{ + struct _priv *priv; + + if (!data) + return; + + priv = data; + + _update_navi(priv); +} + +static bool _move_image(struct _priv *priv, int dir) +{ + int x, y, w, h; + int px, py; + + elm_scroller_region_get(priv->photo, &x, &y, &w, &h); + + switch (dir) { + case DIR_UP: + y -= MOVE_SIZE; + break; + case DIR_DOWN: + y += MOVE_SIZE; + break; + case DIR_LEFT: + x -= MOVE_SIZE; + break; + case DIR_RIGHT: + x += MOVE_SIZE; + break; + default: + return false; + } + + elm_scroller_region_show(priv->photo, x, y, w, h); + + elm_scroller_region_get(priv->photo, &px, &py, NULL, NULL); + if (x != px || y != py) + return false; + + return true; +} + +static void _key_up(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Up *ev) +{ + struct _priv *priv; + struct controller *ctl; + + if (!data || !ev) + return; + + priv = data; + ctl = priv->ctl; + + if (!strcmp(ev->keyname, KEY_BACK) || + !strcmp(ev->keyname, KEY_BACK_REMOTE)) + viewmgr_pop_view(); + else if (!strcmp(ev->keyname, KEY_UP)) + ctl->ops->signal(ctl->handle, DIR_UP, SIG_SET_UNFOCUS); + else if (!strcmp(ev->keyname, KEY_DOWN)) + ctl->ops->signal(ctl->handle, DIR_DOWN, SIG_SET_UNFOCUS); + else if (!strcmp(ev->keyname, KEY_LEFT)) + ctl->ops->signal(ctl->handle, DIR_LEFT, SIG_SET_UNFOCUS); + else if (!strcmp(ev->keyname, KEY_RIGHT)) + ctl->ops->signal(ctl->handle, DIR_RIGHT, SIG_SET_UNFOCUS); +} + +static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev) +{ + struct _priv *priv; + struct controller *ctl; + const char *sig; + int dir; + + if (!data || !ev) + return; + + priv = data; + ctl = priv->ctl; + + if (!strcmp(ev->keyname, KEY_UP)) + dir = DIR_UP; + else if (!strcmp(ev->keyname, KEY_DOWN)) + dir = DIR_DOWN; + else if (!strcmp(ev->keyname, KEY_LEFT)) + dir = DIR_LEFT; + else if (!strcmp(ev->keyname, KEY_RIGHT)) + dir = DIR_RIGHT; + else + return; + + if (_move_image(priv, dir)) + sig = SIG_SET_FOCUS; + else + sig = SIG_SET_UNFOCUS; + + ctl->ops->signal(ctl->handle, dir, sig); +} + +static input_handler _handler = { + .key_up = _key_up, + .key_down = _key_down, +}; + +static bool _draw_image(struct _priv *priv) +{ + Evas_Object *obj; + + obj = elm_photocam_add(priv->base); + if (!obj) { + _ERR("failed to adding photocam"); + return false; + } + + priv->photo = obj; + + elm_object_focus_allow_set(obj, EINA_FALSE); + elm_scroller_policy_set(obj, + ELM_SCROLLER_POLICY_OFF, + ELM_SCROLLER_POLICY_OFF); + elm_photocam_file_set(obj, priv->mi->file_path); + elm_photocam_paused_set(obj, EINA_TRUE); + + elm_object_part_content_set(priv->base, PART_ZOOM_CONTENT, obj); + + evas_object_smart_callback_add(obj, SIG_SCROLL, _scrolled, priv); + + return true; +} + +static bool _draw_thumbnail(struct _priv *priv) +{ + Evas_Object *obj; + + obj = elm_image_add(priv->base); + if (!obj) { + _ERR("failed to adding photocam"); + return false; + } + + priv->thumb = obj; + + evas_object_size_hint_align_set(obj, 1.0, 1.0); + elm_image_file_set(obj, priv->mi->thumbnail_path, NULL); + + elm_object_part_content_set(priv->base, PART_ZOOM_NAVI, obj); + + return true; +} + +static bool _draw_navi(struct _priv *priv) +{ + Evas_Object *obj; + int i; + + for (i = 0; i < DIR_NUM; i++) { + obj = evas_object_rectangle_add( + evas_object_evas_get(priv->base)); + if (!obj) { + _ERR("failed to add rect"); + return false; + } + + evas_object_color_set(obj, 0, 0, 0, 204); + evas_object_show(obj); + + priv->navi[i] = obj; + } + + return true; +} + +static void _draw_contents(struct _priv *priv) +{ + if (!_draw_image(priv)) + return; + + if (!_draw_thumbnail(priv)) + return; + + if (!_draw_navi(priv)) + return; + + /* zoom should set after showing photocam object */ + ecore_timer_add(ZOOM_INTERVAL, _zoom_set, priv); +} + +static bool _ui_init(struct _priv *priv) +{ + Evas_Object *obj; + struct controller *ctl; + int i; + + ctl = controller_create(priv->base); + if (!ctl) { + _ERR("failed to create controller"); + return false; + } + + for (i = 0; i < DIR_NUM; i++) { + ctl->ops->add_control(ctl->handle, + btn_arrow[i].name, btn_arrow[i].loc, + STYLE_ARROW_BTN, PART_ARROW_BTN); + + obj = ctl->ops->get_object(ctl->handle, i); + if (obj) + inputmgr_add_callback(obj, 0, &_handler, priv); + } + + priv->ctl = ctl; + + return true; +} + +static Evas_Object *_create(Evas_Object *win, void *data) +{ + struct _priv *priv; + Evas_Object *base; + bool r; + + if (!win) { + _ERR("failed to get win object"); + return NULL; + } + + priv = calloc(1, sizeof(*priv)); + if (!priv) { + _ERR("failed to allocate priv"); + return NULL; + } + + base = elm_layout_add(win); + if (!base) { + _ERR("failed to create base object"); + goto err; + } + + elm_layout_file_set(base, EDJEFILE, GRP_ZOOM_VIEW); + + evas_object_size_hint_weight_set(base, + EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, base); + + priv->win = win; + priv->base = base; + + r = _ui_init(priv); + if (!r) { + _ERR("failed to init UI"); + evas_object_del(base); + goto err; + } + + viewmgr_set_view_data(VIEW_ZOOM, priv); + + return base; + +err: + free(priv); + return NULL; +} + +static void _show(void *view_data) +{ + struct _priv *priv; + struct controller *ctl; + + if (!view_data) { + _ERR("failed to get view data"); + return; + } + + priv = view_data; + + evas_object_show(priv->base); + + _draw_contents(priv); + + ctl = priv->ctl; + ctl->ops->show(ctl->handle); + ctl->ops->focus(ctl->handle, DIR_UP, true); +} + +static void _hide(void *view_data) +{ + struct _priv *priv; + struct controller *ctl; + int i; + + if (!view_data) { + _ERR("failed to get view data"); + return; + } + + priv = view_data; + + evas_object_hide(priv->base); + + if (priv->photo) + evas_object_del(priv->photo); + + if (priv->thumb) + evas_object_del(priv->thumb); + + for (i = 0; i < DIR_NUM; i++) { + if (priv->navi[i]) + evas_object_del(priv->navi[i]); + } + + ctl = priv->ctl; + ctl->ops->hide(ctl->handle); +} + +static void _update(void *view_data, int update_type, void *data) +{ + struct _priv *priv; + struct view_update_data *vdata; + + if (!view_data) { + _ERR("failed to get view data"); + return; + } + + priv = view_data; + vdata = data; + + switch (update_type) { + case UPDATE_CONTENT: + if (!vdata) + break; + + priv->mi = _get_media_info(vdata->list, vdata->index); + break; + default: + break; + } +} + +static void _pause(void *view_data) +{ + viewmgr_pop_view(); +} + +static void _destroy(void *view_data) +{ + struct _priv *priv; + struct controller *ctl; + Evas_Object *obj; + int i; + + if (!view_data) { + _ERR("failed to get view data"); + return; + } + + priv = view_data; + + ctl = priv->ctl; + + for (i = 0; i < ARRAY_SIZE(btn_arrow); i++) { + obj = ctl->ops->get_object(ctl->handle, i); + if (obj) + inputmgr_remove_callback(obj, &_handler); + } + + evas_object_del(priv->base); + + free(priv); +} + +static view_class _vclass = { + .view_id = VIEW_ZOOM, + .create = _create, + .show = _show, + .hide = _hide, + .update = _update, + .pause = _pause, + .destroy = _destroy, +}; + +view_class *view_zoom_get_vclass(void) +{ + return &_vclass; +} -- cgit v1.2.3