找回密码
 立即注册
查看: 2602|回复: 0

Tizen去顶级图像的图像堆栈窗口小部件 (基本框)代码

[复制链接]
发表于 2015-8-13 13:34:10 | 显示全部楼层 |阅读模式
Tizen去顶级图像的图像堆栈窗口小部件 (基本框)代码
  1. #include "welcomeexample.h"

  2. typedef struct appdata {
  3.         Evas_Object *win;
  4.         Evas_Object *conform;
  5.         Evas_Object *imgstack;
  6.         Ecore_Animator *ea;
  7.         int distance;
  8.         Evas_Object *top;
  9.         Evas_Object *second;
  10. } appdata_s;

  11. static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
  12. {
  13.         ui_app_exit();
  14. }

  15. static void win_back_cb(void *data, Evas_Object *obj, void *event_info)
  16. {
  17.         appdata_s *ad = data;
  18.         /* Let window go to hide state. */
  19.         elm_win_lower(ad->win);
  20. }

  21. typedef struct _flick_info {
  22. } flick_info;

  23. static Eina_Bool flick_anim_cb(void *user_data)
  24. {
  25.         appdata_s *ad = user_data;

  26.         int x, y, w;
  27.         evas_object_geometry_get(ad->top, &x, &y, &w, NULL);

  28.         if (x > -w) evas_object_move(ad->top, x - 30, y);
  29.         else return 0;

  30.         return 1;
  31. }

  32. static Eina_Bool flick_back_anim_cb(void *user_data)
  33. {
  34.         appdata_s *ad = user_data;

  35.         int px, py, x, y;
  36.         evas_object_geometry_get(ad->imgstack, &px, &py, NULL, NULL);
  37.         evas_object_geometry_get(ad->top, &x, &y, NULL, NULL);

  38.         if (x != px) evas_object_move(ad->top, x + 30, y);
  39.         else {
  40.                 evas_object_hide(ad->second);
  41.                 ad->ea = NULL;
  42.                 return 0;
  43.         }

  44.         return 1;
  45. }

  46. Evas_Event_Flags flick_start_cb(void *data, void *event_info)
  47. {
  48.         LOGI("flick start");
  49.         appdata_s *ad = data;

  50.         Eina_List *list = evas_object_box_children_get(ad->imgstack);
  51.         unsigned int count = eina_list_count(list);
  52.         Evas_Object *first = eina_list_nth(list, count-1);
  53.         Evas_Object *second = eina_list_nth(list, count-2);
  54.         evas_object_show(second);
  55.         ad->top = first;
  56.         ad->second = second;
  57.         if (ad->ea == NULL)        {
  58.                 ad->ea = ecore_animator_add(flick_anim_cb, ad);
  59.         }

  60.         return EVAS_EVENT_FLAG_ON_HOLD;
  61. }
  62. Evas_Event_Flags flick_end_cb(void *data, void *event_info)
  63. {
  64.         LOGI("flick end");
  65.         appdata_s *ad = data;
  66.         if (ad->ea){
  67.                 ecore_animator_del(ad->ea);
  68.                 ad->ea = NULL;
  69.         }

  70.         evas_object_box_remove(ad->imgstack, ad->top);
  71.         evas_object_hide(ad->top);
  72.         evas_object_box_prepend(ad->imgstack, ad->top);
  73.         ad->top = NULL;

  74.         return EVAS_EVENT_FLAG_NONE;
  75. }
  76. Evas_Event_Flags flick_abort_cb(void *data, void *event_info)
  77. {
  78.         LOGI("flick abort");
  79.         appdata_s *ad = data;
  80.         if (ad->ea)
  81.                 ecore_animator_del(ad->ea);

  82.         ad->ea = ecore_animator_add(flick_back_anim_cb, ad);

  83.         return EVAS_EVENT_FLAG_NONE;
  84. }

  85. static void create_base_gui(appdata_s *ad)
  86. {
  87.         /* Window */
  88.         ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
  89.         elm_win_autodel_set(ad->win, EINA_TRUE);

  90.         if (elm_win_wm_rotation_supported_get(ad->win)) {
  91.                 int rots[4] = { 0, 90, 180, 270 };
  92.                 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
  93.         }

  94.         evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
  95.         eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);

  96.         /* Conformant */
  97.         ad->conform = elm_conformant_add(ad->win);
  98.         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
  99.         elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
  100.         evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  101.         elm_win_resize_object_add(ad->win, ad->conform);
  102.         evas_object_show(ad->conform);

  103.         /* image stack */
  104.         ad->imgstack = evas_object_box_add(evas_object_evas_get(ad->conform));
  105.         evas_object_box_layout_set(ad->imgstack, evas_object_box_layout_stack, NULL, NULL);

  106.         elm_object_content_set(ad->conform, ad->imgstack);
  107.         evas_object_show(ad->imgstack);

  108.         Evas_Object *img;
  109.         int i;
  110.         char *res = app_get_resource_path();
  111.         char path[256];
  112.         for(i=1; i<=7; i++) {
  113.                 sprintf(path, "%s/img%d.%s", res, i, "png");
  114.                 img = elm_bg_add(ad->imgstack);
  115.                 elm_bg_file_set(img, path, NULL);
  116.                 elm_bg_option_set(img, ELM_BG_OPTION_STRETCH);
  117.                 evas_object_size_hint_align_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
  118.                 evas_object_box_append(ad->imgstack, img);
  119.         }
  120.         evas_object_show(img);

  121.         Evas_Object *gesture = elm_gesture_layer_add(ad->conform);
  122.         elm_gesture_layer_flick_time_limit_ms_set(gesture, 500);
  123.         elm_gesture_layer_attach(gesture, ad->imgstack);
  124.         elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_START, flick_start_cb, ad);
  125.         elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_END, flick_end_cb, ad);
  126.         elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_ABORT, flick_abort_cb, ad);

  127.         /* Show window after base gui is set up */
  128.         evas_object_show(ad->win);

  129.         LOGI("initialized");
  130. }

  131. static bool app_create(void *data)
  132. {
  133.         appdata_s *ad = data;

  134.         create_base_gui(ad);

  135.         return true;
  136. }

  137. int main(int argc, char *argv[])
  138. {
  139.         appdata_s ad = {0,};
  140.         ui_app_lifecycle_callback_s event_callback = {0,};
  141.         event_callback.create = app_create;
  142.         return ui_app_main(argc, argv, &event_callback, &ad);
  143. }
复制代码


欢迎来到泰泽网:http://www.tizennet.com/ 泰泽论坛:http://bbs.tizennet.com/ 好没有内涵哦,快到设置中更改这个无聊的签名吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|泰泽应用|泰泽论坛|泰泽网|小黑屋|Archiver|手机版|泰泽邮箱|泰泽网 ( 蜀ICP备13024062号-1 )

GMT+8, 2024-11-24 18:30 , Processed in 0.046416 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表