流星悟语 发表于 2015-8-13 13:34:10

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

Tizen去顶级图像的图像堆栈窗口小部件 (基本框)代码
#include "welcomeexample.h"

typedef struct appdata {
        Evas_Object *win;
        Evas_Object *conform;
        Evas_Object *imgstack;
        Ecore_Animator *ea;
        int distance;
        Evas_Object *top;
        Evas_Object *second;
} appdata_s;

static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
        ui_app_exit();
}

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

typedef struct _flick_info {
} flick_info;

static Eina_Bool flick_anim_cb(void *user_data)
{
        appdata_s *ad = user_data;

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

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

        return 1;
}

static Eina_Bool flick_back_anim_cb(void *user_data)
{
        appdata_s *ad = user_data;

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

        if (x != px) evas_object_move(ad->top, x + 30, y);
        else {
                evas_object_hide(ad->second);
                ad->ea = NULL;
                return 0;
        }

        return 1;
}

Evas_Event_Flags flick_start_cb(void *data, void *event_info)
{
        LOGI("flick start");
        appdata_s *ad = data;

        Eina_List *list = evas_object_box_children_get(ad->imgstack);
        unsigned int count = eina_list_count(list);
        Evas_Object *first = eina_list_nth(list, count-1);
        Evas_Object *second = eina_list_nth(list, count-2);
        evas_object_show(second);
        ad->top = first;
        ad->second = second;
        if (ad->ea == NULL)        {
                ad->ea = ecore_animator_add(flick_anim_cb, ad);
        }

        return EVAS_EVENT_FLAG_ON_HOLD;
}
Evas_Event_Flags flick_end_cb(void *data, void *event_info)
{
        LOGI("flick end");
        appdata_s *ad = data;
        if (ad->ea){
                ecore_animator_del(ad->ea);
                ad->ea = NULL;
        }

        evas_object_box_remove(ad->imgstack, ad->top);
        evas_object_hide(ad->top);
        evas_object_box_prepend(ad->imgstack, ad->top);
        ad->top = NULL;

        return EVAS_EVENT_FLAG_NONE;
}
Evas_Event_Flags flick_abort_cb(void *data, void *event_info)
{
        LOGI("flick abort");
        appdata_s *ad = data;
        if (ad->ea)
                ecore_animator_del(ad->ea);

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

        return EVAS_EVENT_FLAG_NONE;
}

static void create_base_gui(appdata_s *ad)
{
        /* Window */
        ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
        elm_win_autodel_set(ad->win, EINA_TRUE);

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

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

        /* Conformant */
        ad->conform = elm_conformant_add(ad->win);
        elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
        elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
        evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        elm_win_resize_object_add(ad->win, ad->conform);
        evas_object_show(ad->conform);

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

        elm_object_content_set(ad->conform, ad->imgstack);
        evas_object_show(ad->imgstack);

        Evas_Object *img;
        int i;
        char *res = app_get_resource_path();
        char path;
        for(i=1; i<=7; i++) {
                sprintf(path, "%s/img%d.%s", res, i, "png");
                img = elm_bg_add(ad->imgstack);
                elm_bg_file_set(img, path, NULL);
                elm_bg_option_set(img, ELM_BG_OPTION_STRETCH);
                evas_object_size_hint_align_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
                evas_object_box_append(ad->imgstack, img);
        }
        evas_object_show(img);

        Evas_Object *gesture = elm_gesture_layer_add(ad->conform);
        elm_gesture_layer_flick_time_limit_ms_set(gesture, 500);
        elm_gesture_layer_attach(gesture, ad->imgstack);
        elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_START, flick_start_cb, ad);
        elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_END, flick_end_cb, ad);
        elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_ABORT, flick_abort_cb, ad);

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

        LOGI("initialized");
}

static bool app_create(void *data)
{
        appdata_s *ad = data;

        create_base_gui(ad);

        return true;
}

int main(int argc, char *argv[])
{
        appdata_s ad = {0,};
        ui_app_lifecycle_callback_s event_callback = {0,};
        event_callback.create = app_create;
        return ui_app_main(argc, argv, &event_callback, &ad);
}


页: [1]
查看完整版本: Tizen去顶级图像的图像堆栈窗口小部件 (基本框)代码