fixed plugin image size problem
[framework/uifw/elementary.git] / src / bin / test_win_plug.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7
8 static void
9 cb_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
10 {
11    Evas_Event_Mouse_Move *ev = event_info;
12    Evas_Object *orig = data;
13    Evas_Coord x, y;
14    Evas_Map *p;
15    int i, w, h;
16
17    if (!ev->buttons) return;
18    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
19    evas_object_move(obj,
20                     x + (ev->cur.canvas.x - ev->prev.output.x),
21                     y + (ev->cur.canvas.y - ev->prev.output.y));
22    evas_object_image_size_get(orig, &w, &h);
23    p = evas_map_new(4);
24    evas_object_map_enable_set(orig, EINA_TRUE);
25    evas_object_raise(orig);
26    for (i = 0; i < 4; i++)
27      {
28         Evas_Object *hand;
29         char key[32];
30
31         snprintf(key, sizeof(key), "h-%i\n", i);
32         hand = evas_object_data_get(orig, key);
33         evas_object_raise(hand);
34         evas_object_geometry_get(hand, &x, &y, NULL, NULL);
35         x += 15;
36         y += 15;
37         evas_map_point_coord_set(p, i, x, y, 0);
38         if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0);
39         else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0);
40         else if (i == 2) evas_map_point_image_uv_set(p, i, w, h);
41         else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h);
42      }
43    evas_object_map_set(orig, p);
44    evas_map_free(p);
45 }
46
47 static void
48 create_handles(Evas_Object *obj)
49 {
50    int i;
51    Evas_Coord x, y, w, h;
52
53    evas_object_geometry_get(obj, &x, &y, &w, &h);
54    for (i = 0; i < 4; i++)
55      {
56         Evas_Object *hand;
57         char buf[PATH_MAX];
58         char key[32];
59
60         hand = evas_object_image_filled_add(evas_object_evas_get(obj));
61         evas_object_resize(hand, 31, 31);
62         snprintf(buf, sizeof(buf), "%s/images/pt.png", elm_app_data_dir_get());
63         evas_object_image_file_set(hand, buf, NULL);
64         if (i == 0)      evas_object_move(hand, x     - 15, y     - 15);
65         else if (i == 1) evas_object_move(hand, x + w - 15, y     - 15);
66         else if (i == 2) evas_object_move(hand, x + w - 15, y + h - 15);
67         else if (i == 3) evas_object_move(hand, x     - 15, y + h - 15);
68         evas_object_event_callback_add(hand, EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj);
69         evas_object_show(hand);
70         snprintf(key, sizeof(key), "h-%i\n", i);
71         evas_object_data_set(obj, key, hand);
72      }
73 }
74
75 void
76 test_win_plug(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
77 {
78    Evas_Object *win, *bg, *plug;
79    char buf[PATH_MAX];
80
81    win = elm_win_add(NULL, "window-inline", ELM_WIN_BASIC);
82    elm_win_title_set(win, "Window Inline");
83    elm_win_autodel_set(win, EINA_TRUE);
84
85    bg = elm_bg_add(win);
86    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
87    elm_bg_file_set(bg, buf, NULL);
88    elm_win_resize_object_add(win, bg);
89    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
90    evas_object_show(bg);
91
92    plug = elm_plug_add(win);
93    if (!elm_plug_connect(plug, "ello", 0, EINA_FALSE))
94      {
95         printf("Cannot connect plug\n");
96         return;
97      }
98
99    evas_object_resize(plug, 380, 500);
100    evas_object_move(plug, 10, 10);
101    evas_object_show(plug);
102
103    create_handles(elm_plug_image_object_get(plug));
104
105    evas_object_resize(win, 400, 600);
106    evas_object_show(win);
107 }
108 #endif