efl
219 строк · 6.4 Кб
1#ifdef HAVE_CONFIG_H2# include "elementary_config.h"3#endif4
5#include <Elementary.h>6// FIXME: use smart cb
7#include "elm_notify_eo.h"8
9#define MAX_TRY 4010
11static int try_num = 0;12
13static void14_timer_del(void *data EINA_UNUSED,15Evas *e EINA_UNUSED,16Evas_Object *obj,17void *event_info EINA_UNUSED)18{
19Ecore_Timer *timer = evas_object_data_del(obj, "test-timer");20if (!timer) return;21ecore_timer_del(timer);22}
23
24static Eina_Bool25cb_plug_connect(void *data)26{
27Evas_Object *obj = data;28Ecore_Timer *timer;29
30if (!obj) return ECORE_CALLBACK_CANCEL;31
32try_num++;33if (try_num > MAX_TRY) return ECORE_CALLBACK_CANCEL;34
35timer= evas_object_data_get(obj, "test-timer");36if (!timer) return ECORE_CALLBACK_CANCEL;37
38if (elm_plug_connect(obj, "ello", 0, EINA_FALSE))39{40printf("plug connect to server[ello]\n");41evas_object_data_del(obj, "test-timer");42return ECORE_CALLBACK_CANCEL;43}44
45ecore_timer_interval_set(timer, 1);46return ECORE_CALLBACK_RENEW;47}
48
49static void50cb_plug_disconnected(void *data EINA_UNUSED,51Evas_Object *obj,52void *event_info EINA_UNUSED)53{
54Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");55if (timer)56{57ecore_timer_del(timer);58evas_object_data_del(obj, "test-timer");59}60
61timer = ecore_timer_add(1, cb_plug_connect, obj);62evas_object_data_set(obj, "test-timer", timer);63}
64
65static void66cb_plug_resized(void *data EINA_UNUSED,67Evas_Object *obj EINA_UNUSED,68void *event_info)69{
70Evas_Coord_Size *size = event_info;71printf("server image resized to %dx%d\n", size->w, size->h);72}
73
74static void75cb_mouse_down(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_info)76{
77Evas_Event_Mouse_Down *ev = event_info;78
79if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE);80}
81
82static void83cb_mouse_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_info)84{
85Evas_Event_Mouse_Move *ev = event_info;86Evas_Object *orig = data;87Evas_Coord x, y;88Evas_Map *p;89int i, w, h;90
91if (!ev->buttons) return;92evas_object_geometry_get(obj, &x, &y, NULL, NULL);93evas_object_move(obj,94x + (ev->cur.canvas.x - ev->prev.output.x),95y + (ev->cur.canvas.y - ev->prev.output.y));96evas_object_image_size_get(orig, &w, &h);97p = evas_map_new(4);98evas_object_map_enable_set(orig, EINA_TRUE);99evas_object_raise(orig);100for (i = 0; i < 4; i++)101{102Evas_Object *hand;103char key[32];104
105snprintf(key, sizeof(key), "h-%i\n", i);106hand = evas_object_data_get(orig, key);107evas_object_raise(hand);108evas_object_geometry_get(hand, &x, &y, NULL, NULL);109x += 15;110y += 15;111evas_map_point_coord_set(p, i, x, y, 0);112if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0);113else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0);114else if (i == 2) evas_map_point_image_uv_set(p, i, w, h);115else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h);116}117evas_object_map_set(orig, p);118evas_map_free(p);119}
120
121static void122create_handles(Evas_Object *obj)123{
124int i;125Evas_Coord x, y, w, h;126
127evas_object_geometry_get(obj, &x, &y, &w, &h);128for (i = 0; i < 4; i++)129{130Evas_Object *hand;131char buf[PATH_MAX];132char key[32];133
134hand = evas_object_image_filled_add(evas_object_evas_get(obj));135evas_object_resize(hand, 31, 31);136snprintf(buf, sizeof(buf), "%s/images/pt.png", elm_app_data_dir_get());137evas_object_image_file_set(hand, buf, NULL);138if (i == 0) evas_object_move(hand, x - 15, y - 15);139else if (i == 1) evas_object_move(hand, x + w - 15, y - 15);140else if (i == 2) evas_object_move(hand, x + w - 15, y + h - 15);141else if (i == 3) evas_object_move(hand, x - 15, y + h - 15);142evas_object_event_callback_add(hand, EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj);143evas_object_show(hand);144snprintf(key, sizeof(key), "h-%i\n", i);145evas_object_data_set(obj, key, hand);146}147}
148
149static void150_notify_end(void *data EINA_UNUSED, const Efl_Event *event)151{
152efl_del(event->object);153efl_event_callback_stop(event->object);154}
155
156static inline void157_notify_error(Evas_Object *parent, const char *msg)158{
159Evas_Object *notif, *txt;160
161printf("%s\n", msg);162
163notif = elm_notify_add(parent);164evas_object_size_hint_weight_set(notif, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);165elm_notify_align_set(notif, 0.5, 1.0);166elm_notify_timeout_set(notif, 3.0);167efl_event_callback_add(notif, ELM_NOTIFY_EVENT_DISMISSED, _notify_end, NULL);168
169txt = elm_label_add(notif);170elm_object_text_set(txt, msg);171elm_object_content_set(notif, txt);172
173evas_object_show(txt);174evas_object_show(notif);175}
176
177void
178test_win_plug(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)179{
180Evas_Object *win, *bg, *plug;181char buf[PATH_MAX];182
183win = elm_win_add(NULL, "window-plug", ELM_WIN_BASIC);184elm_win_title_set(win, "Window Plug");185elm_win_autodel_set(win, EINA_TRUE);186
187bg = elm_bg_add(win);188snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());189elm_bg_file_set(bg, buf, NULL);190evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);191elm_win_resize_object_add(win, bg);192evas_object_show(bg);193
194plug = elm_plug_add(win);195evas_object_event_callback_add(elm_plug_image_object_get(plug), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL);196evas_object_event_callback_add(plug, EVAS_CALLBACK_DEL, _timer_del, NULL);197if (!elm_plug_connect(plug, "ello", 0, EINA_FALSE))198{199if (data)200_notify_error(data, "Unable to connect to the Window Socket!");201else202fprintf(stderr, "Unable to connect to the Window Socket!\n");203evas_object_del(win);204return;205}206
207evas_object_smart_callback_add(plug, "image,deleted", cb_plug_disconnected, NULL);208evas_object_smart_callback_add(plug, "image,resized", cb_plug_resized, NULL);209
210evas_object_resize(plug, 380, 500);211evas_object_move(plug, 10, 10);212evas_object_show(plug);213
214create_handles(elm_plug_image_object_get(plug));215
216evas_object_resize(win, 400 * elm_config_scale_get(),217600 * elm_config_scale_get());218evas_object_show(win);219}
220