efl

Форк
0
/
test_win_plug.c 
219 строк · 6.4 Кб
1
#ifdef HAVE_CONFIG_H
2
# include "elementary_config.h"
3
#endif
4

5
#include <Elementary.h>
6
// FIXME: use smart cb
7
#include "elm_notify_eo.h"
8

9
#define MAX_TRY 40
10

11
static int try_num = 0;
12

13
static void
14
_timer_del(void *data       EINA_UNUSED,
15
           Evas *e          EINA_UNUSED,
16
           Evas_Object     *obj,
17
           void *event_info EINA_UNUSED)
18
{
19
   Ecore_Timer *timer = evas_object_data_del(obj, "test-timer");
20
   if (!timer) return;
21
   ecore_timer_del(timer);
22
}
23

24
static Eina_Bool
25
cb_plug_connect(void *data)
26
{
27
   Evas_Object *obj = data;
28
   Ecore_Timer *timer;
29

30
   if (!obj) return ECORE_CALLBACK_CANCEL;
31

32
   try_num++;
33
   if (try_num > MAX_TRY) return ECORE_CALLBACK_CANCEL;
34

35
   timer= evas_object_data_get(obj, "test-timer");
36
   if (!timer) return ECORE_CALLBACK_CANCEL;
37

38
   if (elm_plug_connect(obj, "ello", 0, EINA_FALSE))
39
     {
40
        printf("plug connect to server[ello]\n");
41
        evas_object_data_del(obj, "test-timer");
42
        return ECORE_CALLBACK_CANCEL;
43
     }
44

45
   ecore_timer_interval_set(timer, 1);
46
   return ECORE_CALLBACK_RENEW;
47
}
48

49
static void
50
cb_plug_disconnected(void *data EINA_UNUSED,
51
                    Evas_Object *obj,
52
                    void *event_info EINA_UNUSED)
53
{
54
   Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
55
   if (timer)
56
     {
57
        ecore_timer_del(timer);
58
        evas_object_data_del(obj, "test-timer");
59
     }
60

61
   timer = ecore_timer_add(1, cb_plug_connect, obj);
62
   evas_object_data_set(obj, "test-timer", timer);
63
}
64

65
static void
66
cb_plug_resized(void *data EINA_UNUSED,
67
                Evas_Object *obj EINA_UNUSED,
68
                void *event_info)
69
{
70
   Evas_Coord_Size *size = event_info;
71
   printf("server image resized to %dx%d\n", size->w, size->h);
72
}
73

74
static void
75
cb_mouse_down(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_info)
76
{
77
   Evas_Event_Mouse_Down *ev = event_info;
78

79
   if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE);
80
}
81

82
static void
83
cb_mouse_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event_info)
84
{
85
   Evas_Event_Mouse_Move *ev = event_info;
86
   Evas_Object *orig = data;
87
   Evas_Coord x, y;
88
   Evas_Map *p;
89
   int i, w, h;
90

91
   if (!ev->buttons) return;
92
   evas_object_geometry_get(obj, &x, &y, NULL, NULL);
93
   evas_object_move(obj,
94
                    x + (ev->cur.canvas.x - ev->prev.output.x),
95
                    y + (ev->cur.canvas.y - ev->prev.output.y));
96
   evas_object_image_size_get(orig, &w, &h);
97
   p = evas_map_new(4);
98
   evas_object_map_enable_set(orig, EINA_TRUE);
99
   evas_object_raise(orig);
100
   for (i = 0; i < 4; i++)
101
     {
102
        Evas_Object *hand;
103
        char key[32];
104

105
        snprintf(key, sizeof(key), "h-%i\n", i);
106
        hand = evas_object_data_get(orig, key);
107
        evas_object_raise(hand);
108
        evas_object_geometry_get(hand, &x, &y, NULL, NULL);
109
        x += 15;
110
        y += 15;
111
        evas_map_point_coord_set(p, i, x, y, 0);
112
        if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0);
113
        else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0);
114
        else if (i == 2) evas_map_point_image_uv_set(p, i, w, h);
115
        else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h);
116
     }
117
   evas_object_map_set(orig, p);
118
   evas_map_free(p);
119
}
120

121
static void
122
create_handles(Evas_Object *obj)
123
{
124
   int i;
125
   Evas_Coord x, y, w, h;
126

127
   evas_object_geometry_get(obj, &x, &y, &w, &h);
128
   for (i = 0; i < 4; i++)
129
     {
130
        Evas_Object *hand;
131
        char buf[PATH_MAX];
132
        char key[32];
133

134
        hand = evas_object_image_filled_add(evas_object_evas_get(obj));
135
        evas_object_resize(hand, 31, 31);
136
        snprintf(buf, sizeof(buf), "%s/images/pt.png", elm_app_data_dir_get());
137
        evas_object_image_file_set(hand, buf, NULL);
138
        if (i == 0)      evas_object_move(hand, x     - 15, y     - 15);
139
        else if (i == 1) evas_object_move(hand, x + w - 15, y     - 15);
140
        else if (i == 2) evas_object_move(hand, x + w - 15, y + h - 15);
141
        else if (i == 3) evas_object_move(hand, x     - 15, y + h - 15);
142
        evas_object_event_callback_add(hand, EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj);
143
        evas_object_show(hand);
144
        snprintf(key, sizeof(key), "h-%i\n", i);
145
        evas_object_data_set(obj, key, hand);
146
     }
147
}
148

149
static void
150
_notify_end(void *data EINA_UNUSED, const Efl_Event *event)
151
{
152
   efl_del(event->object);
153
   efl_event_callback_stop(event->object);
154
}
155

156
static inline void
157
_notify_error(Evas_Object *parent, const char *msg)
158
{
159
   Evas_Object *notif, *txt;
160

161
   printf("%s\n", msg);
162

163
   notif = elm_notify_add(parent);
164
   evas_object_size_hint_weight_set(notif, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
165
   elm_notify_align_set(notif, 0.5, 1.0);
166
   elm_notify_timeout_set(notif, 3.0);
167
   efl_event_callback_add(notif, ELM_NOTIFY_EVENT_DISMISSED, _notify_end, NULL);
168

169
   txt = elm_label_add(notif);
170
   elm_object_text_set(txt, msg);
171
   elm_object_content_set(notif, txt);
172

173
   evas_object_show(txt);
174
   evas_object_show(notif);
175
}
176

177
void
178
test_win_plug(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
179
{
180
   Evas_Object *win, *bg, *plug;
181
   char buf[PATH_MAX];
182

183
   win = elm_win_add(NULL, "window-plug", ELM_WIN_BASIC);
184
   elm_win_title_set(win, "Window Plug");
185
   elm_win_autodel_set(win, EINA_TRUE);
186

187
   bg = elm_bg_add(win);
188
   snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
189
   elm_bg_file_set(bg, buf, NULL);
190
   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
191
   elm_win_resize_object_add(win, bg);
192
   evas_object_show(bg);
193

194
   plug = elm_plug_add(win);
195
   evas_object_event_callback_add(elm_plug_image_object_get(plug), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL);
196
   evas_object_event_callback_add(plug, EVAS_CALLBACK_DEL, _timer_del, NULL);
197
   if (!elm_plug_connect(plug, "ello", 0, EINA_FALSE))
198
     {
199
        if (data)
200
          _notify_error(data, "Unable to connect to the Window Socket!");
201
        else
202
          fprintf(stderr, "Unable to connect to the Window Socket!\n");
203
        evas_object_del(win);
204
        return;
205
     }
206

207
   evas_object_smart_callback_add(plug, "image,deleted", cb_plug_disconnected, NULL);
208
   evas_object_smart_callback_add(plug, "image,resized", cb_plug_resized, NULL);
209

210
   evas_object_resize(plug, 380, 500);
211
   evas_object_move(plug, 10, 10);
212
   evas_object_show(plug);
213

214
   create_handles(elm_plug_image_object_get(plug));
215

216
   evas_object_resize(win, 400 * elm_config_scale_get(),
217
                           600 * elm_config_scale_get());
218
   evas_object_show(win);
219
}
220

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.