efl

Форк
0
/
signals2.c 
127 строк · 3.0 Кб
1
//Compile with:
2
// edje_cc signalsBubble.edc && gcc -o signals2 signals2.c `pkg-config --libs --cflags ecore ecore-evas edje`
3

4
#ifdef HAVE_CONFIG_H
5
#include "config.h"
6
#else
7
#define PACKAGE_EXAMPLES_DIR "."
8
#define EINA_UNUSED
9
#endif
10

11
#ifndef PACKAGE_DATA_DIR
12
#define PACKAGE_DATA_DIR "."
13
#endif
14

15
#include <Ecore.h>
16
#include <Ecore_Evas.h>
17
#include <Edje.h>
18
#include <stdio.h>
19

20
#define WIDTH     (700)
21
#define HEIGHT    (700)
22

23
static void
24
_on_delete(Ecore_Evas *ee EINA_UNUSED)
25
{
26
   ecore_main_loop_quit();
27
}
28

29
/* mouse over signals */
30
static void
31
_on_mouse_over(void *data, Evas_Object *edje_obj,
32
               const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
33
{
34
   Evas *evas;
35
   int x, y, mouseX, mouseY;
36

37
   evas = (Evas *) data;
38
   evas_object_geometry_get(edje_obj, &x, &y, NULL, NULL);
39

40
   evas_pointer_output_xy_get(evas, &mouseX, &mouseY);
41

42
   if ((rand() % 2) == 0)
43
     x += ((mouseX - x) + (x / 4 + mouseY / 2));
44
   else
45
     x -= ((mouseX - x) + (x / 4 + mouseY / 2));
46

47
   if ((rand() % 2) == 0)
48
     y += ((mouseY - y) + (y / 4 + mouseX / 2));
49
   else
50
     y -= ((mouseY - y) + (y / 4 + mouseX / 2));
51

52
   if (x > WIDTH)
53
     x = WIDTH;
54
   else if (x < 0) x = 0;
55

56
   if (y > HEIGHT)
57
     y = HEIGHT;
58
   else if (y < 0) y = 0;
59

60
   printf("Moving object to - (%d,%d)\n", x, y);
61

62
   evas_object_move(edje_obj, x, y);
63
}
64

65
int
66
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
67
{
68
   const char *edje_file = PACKAGE_DATA_DIR"/signalsBubble.edj";
69
   Ecore_Evas *ee;
70
   Evas *evas;
71
   Evas_Object *bg;
72
   Evas_Object *edje_obj;
73

74
   if (!ecore_evas_init()) return EXIT_FAILURE;
75

76
   if (!edje_init()) goto shutdown_ecore_evas;
77

78
   ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
79

80
   if (!ee) goto shutdown_edje;
81

82
   ecore_evas_callback_delete_request_set(ee, _on_delete);
83
   ecore_evas_title_set(ee, "Edje animations and signals");
84

85
   evas = ecore_evas_get(ee);
86

87
   bg = evas_object_rectangle_add(evas);
88
   evas_object_color_set(bg, 255, 255, 255, 255); //White
89
   evas_object_move(bg, 0, 0); //orign
90
   evas_object_resize(bg, WIDTH, HEIGHT); //cover the window
91
   evas_object_show(bg);
92

93
   ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
94
   evas_object_focus_set(bg, EINA_TRUE);
95

96
   edje_obj = edje_object_add(evas);
97

98
   if (!edje_object_file_set(edje_obj, edje_file, "image_group"))
99
     {
100
        int err = edje_object_load_error_get(edje_obj);
101
        const char *errmsg = edje_load_error_str(err);
102
        fprintf(stderr, "Could not load the edje file - reason:%s\n", errmsg);
103
        goto shutdown_edje;
104
     }
105

106
   edje_object_signal_callback_add(edje_obj, "mouse,move", "part_image",
107
                                   _on_mouse_over, evas);
108
   evas_object_resize(edje_obj, 63, 63);
109
   evas_object_move(edje_obj, 50, 50);
110
   evas_object_show(edje_obj);
111

112
   ecore_evas_show(ee);
113

114
   ecore_main_loop_begin();
115

116
   ecore_evas_free(ee);
117
   edje_shutdown();
118
   ecore_evas_shutdown();
119

120
   return EXIT_SUCCESS;
121

122
   shutdown_edje: edje_shutdown();
123

124
   shutdown_ecore_evas: ecore_evas_shutdown();
125

126
   return EXIT_FAILURE;
127
}
128

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

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

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

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