efl

Форк
0
/
edje-codegen-example.c 
184 строки · 5.2 Кб
1
/**
2
 * @since 1.8.0
3
 * Simple Edje example illustrating the edje_codegen usage.
4
 *
5
 * edje_codegen is a tool that generates code to acessing the parts and programs
6
 * with the keyword "api" of a specified group. This tool make easier working
7
 * with edje avoiding common errors caused by typos when acessing the parts
8
 * and/or programs.
9
 *
10
 * To use the edje_codegen:
11
 * edje_codegen --prefix <myapp_myobj> <input.edj> <a_group> <source.c> <header.h>
12
 *
13
 * In case of this example:
14
 * edje_codegen --prefix=codegen_example codegen.edj group_example \
15
	codegen_example_generated.c codegen_example_generated.h
16
 *
17
 * @verbatim
18
 * edje_cc codegen.edc && edje_codegen --prefix=codegen_example codegen.edj \
19
 * example_group codegen_example_generated.c codegen_example_generated.h
20
 * gcc -c codegen_example_generated.c `pkg-config --libs --cflags ecore-evas edje`
21
 * gcc -o edje-codegen-example codegen_example_generated.o \
22
 * edje-codegen-example.c `pkg-config --libs --cflags ecore-evas edje`
23
 * @endverbatim
24
 */
25

26
#ifdef HAVE_CONFIG_H
27
# include "config.h"
28
#else
29
# define EINA_UNUSED
30
#endif
31

32
#ifndef PACKAGE_DATA_DIR
33
#define PACKAGE_DATA_DIR "."
34
#endif
35

36
#include "codegen_example_generated.h"
37

38
#include <Ecore.h>
39
#include <Ecore_Evas.h>
40
#include <Edje.h>
41

42
#define WIDTH  (800)
43
#define HEIGHT (800)
44

45
static void
46
_on_delete(Ecore_Evas *ee EINA_UNUSED)
47
{
48
   ecore_main_loop_quit();
49
}
50

51
static void
52
_columns_rows_print(Evas_Object *edje_obj)
53
{
54
   int cols, rows;
55

56
   if (codegen_example_part_four_col_row_size_get(edje_obj, &cols, &rows))
57
     printf("Number of columns: %d\nNumber of rows: %d\n", cols, rows);
58
   else
59
     fprintf(stderr, "Cannot get the number of columns and rows\n");
60
}
61

62
static void
63
_on_mouse_over(void *data EINA_UNUSED, Evas_Object *obj, const char *emission,
64
	       const char *source)
65
{
66
   Evas_Object *rect;
67
   static int i = 0;
68

69
   printf("Mouse over, source: %s - emission: %s\n",
70
	  source, emission);
71
   if (i == 2)
72
     {
73
	rect = codegen_example_part_three_remove_at(obj, 0);
74
	codegen_example_part_three_append(obj, rect);
75
     }
76
   if (i++ == 5)
77
     {
78
	rect = codegen_example_part_two_get(obj);
79
	evas_object_color_set(rect, 0, 255, 0, 255);
80
	codegen_example_part_below_over_callback_del_full(obj,_on_mouse_over,
81
							  NULL);
82
	codegen_example_part_four_clear(obj, EINA_TRUE);
83
	_columns_rows_print(obj);
84
	codegen_example_part_three_remove_all(obj, EINA_TRUE);
85
     }
86
}
87

88
static Evas_Object *
89
_rect_create(Evas *e, unsigned char r, unsigned char g, unsigned char b)
90
{
91
   Evas_Object *o;
92

93
   o = evas_object_rectangle_add(e);
94
   evas_object_color_set(o, r, g, b, 255);
95
   evas_object_size_hint_weight_set(o, 1.0, 1.0);
96
   evas_object_size_hint_min_set(o, 100, 100);
97
   evas_object_show(o);
98

99
   return o;
100
}
101

102
int
103
main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
104
{
105
   const char  *edje_file = PACKAGE_DATA_DIR"/codegen.edj";
106
   Ecore_Evas  *ee;
107
   Evas        *evas;
108
   Evas_Object *bg;
109
   Evas_Object *edje_obj;
110
   Evas_Object *red_rect, *yellow_rect, *blue_rect, *rects[4];
111

112
   if (!ecore_evas_init())
113
     return EXIT_FAILURE;
114

115
   if (!edje_init())
116
     goto shutdown_ecore_evas;
117

118
   /* this will give you a window with an Evas canvas under the first
119
    * engine available */
120
   ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
121
   if (!ee) goto shutdown_edje;
122

123
   ecore_evas_callback_delete_request_set(ee, _on_delete);
124
   ecore_evas_title_set(ee, "Edje Codegen Example");
125

126
   evas = ecore_evas_get(ee);
127

128
   bg = _rect_create(evas, 255, 255, 255);
129
   evas_object_move(bg, 0, 0); /* at canvas' origin */
130
   evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
131
   ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
132

133
   edje_obj = codegen_example_object_add(evas, edje_file);
134
   evas_object_resize(edje_obj, WIDTH, HEIGHT);
135
   evas_object_show(edje_obj);
136

137
   codegen_example_part_one_set(edje_obj, "CODEGEN_EXAMPLE");
138
   codegen_example_part_below_over_callback_add(edje_obj, _on_mouse_over, NULL);
139

140
   red_rect = _rect_create(evas, 255, 0, 0);
141
   codegen_example_part_two_set(edje_obj, red_rect);
142

143
   blue_rect = _rect_create(evas, 0, 0, 255);
144
   codegen_example_part_three_append(edje_obj, blue_rect);
145

146
   yellow_rect = _rect_create(evas, 255, 255, 0);
147
   codegen_example_part_three_prepend(edje_obj, yellow_rect);
148

149

150
   rects[0] = _rect_create(evas, 0, 0, 255);
151
   rects[1] = _rect_create(evas, 0, 255, 0);
152
   rects[2] = _rect_create(evas, 255, 0, 0);
153
   rects[3] = _rect_create(evas, 125, 140, 80);
154

155
   if (!codegen_example_part_four_pack(edje_obj, rects[0], 0, 0, 1, 2))
156
     fprintf(stderr, "Cannot add the rectangle 1 to table\n");
157

158
   if (!codegen_example_part_four_pack(edje_obj, rects[1], 0, 1, 1, 1))
159
     fprintf(stderr, "Cannot add the rectangle 2 to table\n");
160

161
   if (!codegen_example_part_four_pack(edje_obj, rects[2], 1, 0, 1, 1))
162
     fprintf(stderr, "Cannot add the rectangle 3 to table\n");
163

164
   if (!codegen_example_part_four_pack(edje_obj, rects[3], 1, 1, 1, 1))
165
     fprintf(stderr, "Cannot add the rectangle 4 to table\n");
166

167
   _columns_rows_print(edje_obj);
168
   ecore_evas_show(ee);
169

170
   ecore_main_loop_begin();
171

172
   ecore_evas_free(ee);
173
   ecore_evas_shutdown();
174
   edje_shutdown();
175

176
   return EXIT_SUCCESS;
177

178
 shutdown_edje:
179
   edje_shutdown();
180
 shutdown_ecore_evas:
181
   ecore_evas_shutdown();
182

183
   return EXIT_FAILURE;
184
}
185

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

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

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

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