summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-02-03 23:22:17 +0100
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-02-03 23:22:17 +0100
commit775ccf17a6af5a0a48cf6280a22caca8a5023da7 (patch)
tree87d746ef650e3277cb274405a572b7043611b7f9
init commit!
-rw-r--r--CMakeLists.txt30
-rw-r--r--src/main.c239
2 files changed, 269 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..4b54b8b
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,30 @@
1cmake_minimum_required (VERSION 2.6)
2project (Edje-theme-spec)
3
4include(GNUInstallDirs)
5enable_testing()
6
7add_definitions("-Wall -O0 -g")
8
9find_package(Eina REQUIRED)
10find_package(Evas REQUIRED)
11find_package(Edje REQUIRED)
12
13set(SOURCE
14 src/main.c
15)
16
17include_directories(
18 ${EINA_INCLUDE_DIRS}
19 ${EDJE_INCLUDE_DIRS}
20 ${EVAS_INCLUDE_DIRS}
21)
22
23
24add_executable(edje-theme-spec ${SOURCE})
25
26target_link_libraries(edje-theme-spec
27 ${EINA_LIBRARIES}
28 ${EDJE_LIBRARIES}
29 ${EVAS_LIBRARIES}
30)
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..db918e1
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,239 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <Evas.h>
4#include <Evas_Engine_Buffer.h>
5#include <regex.h>
6
7#define EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT
8#include <Edje_Edit.h>
9
10typedef struct {
11 const char *file;
12 Eina_List *groups;
13} Theme;
14
15typedef struct {
16 const char *name;
17 Eina_List *parts[EDJE_PART_TYPE_LAST];
18 Eina_List *signals;
19} Theme_Group;
20
21static Evas *evas;
22
23static Evas*
24create_canvas(int width, int height)
25{
26 Evas *canvas;
27 Evas_Engine_Info_Buffer *einfo;
28 int method;
29 void *pixels;
30 method = evas_render_method_lookup("buffer");
31 if (method <= 0)
32 {
33 fputs("ERROR: evas was not compiled with 'buffer' engine!\n", stderr);
34 return NULL;
35 }
36 canvas = evas_new();
37 if (!canvas)
38 {
39 fputs("ERROR: could not instantiate new evas canvas.\n", stderr);
40 return NULL;
41 }
42 evas_output_method_set(canvas, method);
43 evas_output_size_set(canvas, width, height);
44 evas_output_viewport_set(canvas, 0, 0, width, height);
45 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
46 if (!einfo)
47 {
48 fputs("ERROR: could not get evas engine info!\n", stderr);
49 evas_free(canvas);
50 return NULL;
51 }
52 // ARGB32 is sizeof(int), that is 4 bytes, per pixel
53 pixels = malloc(width * height * sizeof(int));
54 if (!pixels)
55 {
56 fputs("ERROR: could not allocate canvas pixels!\n", stderr);
57 evas_free(canvas);
58 return NULL;
59 }
60 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
61 einfo->info.dest_buffer = pixels;
62 einfo->info.dest_buffer_row_bytes = width * sizeof(int);
63 einfo->info.use_color_key = 0;
64 einfo->info.alpha_threshold = 0;
65 einfo->info.func.new_update_region = NULL;
66 einfo->info.func.free_update_region = NULL;
67 evas_engine_info_set(canvas, (Evas_Engine_Info *)einfo);
68 return canvas;
69}
70
71void
72add_parts(Theme *theme, Theme_Group *group)
73{
74 Eina_List *parts, *programs, *node;
75 Evas_Object *o;
76 const char *part, *program;
77
78 o = edje_edit_object_add(evas);
79
80 edje_object_file_set(o, theme->file, group->name);
81 parts = edje_edit_parts_list_get(o);
82
83 EINA_LIST_FOREACH(parts, node, part)
84 {
85 Edje_Part_Type type;
86
87 type = edje_edit_part_type_get(o, part);
88
89 group->parts[type] = eina_list_append(group->parts[type], part);
90 }
91
92 programs = edje_edit_programs_list_get(o);
93
94 EINA_LIST_FOREACH(programs, node, program)
95 {
96 const char *_signal;
97
98 _signal = edje_edit_program_signal_get(o, program);
99 if (!_signal) continue;
100
101 group->signals = eina_list_append(group->signals, _signal);
102 }
103}
104
105Theme*
106parse_theme(const char *file)
107{
108 Theme *theme;
109 Eina_List *groups, *node;
110 const char *group_name;
111
112 theme = calloc(1, sizeof(Theme));
113
114 theme->file = file;
115
116 groups = edje_file_collection_list(file);
117
118 EINA_LIST_FOREACH(groups, node, group_name)
119 {
120 Theme_Group *theme_group = calloc(1, sizeof(Theme_Group));
121 theme_group->name = eina_stringshare_add(group_name);
122
123 add_parts(theme, theme_group);
124
125 theme->groups = eina_list_append(theme->groups, theme_group);
126 }
127
128 edje_file_collection_list_free(groups);
129
130 return theme;
131}
132
133static char *type_string[] =
134{
135 "None",//EDJE_PART_TYPE_NONE
136 "Rectangle", //EDJE_PART_TYPE_RECTANGLE
137 "Text", //EDJE_PART_TYPE_TEXT
138 "Image", //EDJE_PART_TYPE_IMAGE
139 "Swallow", //EDJE_PART_TYPE_SWALLOW
140 "Textblock", //EDJE_PART_TYPE_TEXTBLOCK
141 "Gradient", //EDJE_PART_TYPE_GRADIENT
142 "Group", //EDJE_PART_TYPE_GROUP
143 "Box", //EDJE_PART_TYPE_BOX
144 "Table", //EDJE_PART_TYPE_TABLE
145 "External", //EDJE_PART_TYPE_EXTERNAL
146 "Proxy", //EDJE_PART_TYPE_PROXY
147 "Spacer", //EDJE_PART_TYPE_SPACER
148 "Mesh_Node", //EDJE_PART_TYPE_MESH_NODE
149 "Light", //EDJE_PART_TYPE_LIGHT
150 "Camera", //EDJE_PART_TYPE_CAMERA
151 "Snapshot", //EDJE_PART_TYPE_SNAPSHOT
152 "Last" //EDJE_PART_TYPE_LAST
153};
154
155static void
156output_theme(Theme *theme, regex_t *group, regex_t *part, regex_t *signal)
157{
158 Eina_List *node;
159 Theme_Group *theme_group;
160
161 EINA_LIST_FOREACH(theme->groups, node, theme_group)
162 {
163 const char *signals, *parts;
164 Eina_List *node;
165 if (!!regexec(group, theme_group->name, 0, NULL, 0))
166 continue;
167 printf("Group: %s\n", theme_group->name);
168
169 for(int type = EDJE_PART_TYPE_NONE; type < EDJE_PART_TYPE_LAST; type++){
170 EINA_LIST_FOREACH(theme_group->parts[type], node, parts)
171 {
172 if (!!regexec(part, parts, 0, NULL, 0)) continue;
173
174 printf("\t %s: %s\n", type_string[type], parts);
175 }
176 }
177
178 EINA_LIST_FOREACH(theme_group->signals, node, signals)
179 {
180 if (!!regexec(signal, signals, 0, NULL, 0)) continue;
181
182 printf("\t Signal: %s\n", signals);
183 }
184 }
185}
186
187int main(int argc, char const *argv[])
188{
189 struct stat st;
190 eina_init();
191 evas_init();
192 edje_init();
193 regex_t group, part, signal;
194
195
196 Theme *theme;
197
198 if (argc != 2) {
199 printf("Pass one file which is a edje theme!\n");
200 exit(-1);
201 }
202
203 const char *file = argv[1];
204
205 if (stat(file, &st) == -1) {
206 printf("File %s does not exist\n", file);
207 exit(-1);
208 }
209
210 evas = create_canvas(20, 20);
211
212 theme = parse_theme(file);
213
214 if (regcomp(&group, "^(e|elm)\\/[a-zA-Z\\_\\/]*", REG_EXTENDED))
215 {
216 printf("Failed to compile regex for group");
217 return -1;
218 }
219
220 if (regcomp(&part, "^(e|elm)\\.[a-zA-Z\\_\\.]*", REG_EXTENDED))
221 {
222 printf("Failed to compile regex for part");
223 return -1;
224 }
225
226 if (regcomp(&signal, "^(e|elm),[a-zA-Z\\_,]*", REG_EXTENDED))
227 {
228 printf("Failed to compile regex for signal");
229 return -1;
230 }
231
232 printf("Start output!\n");
233 output_theme(theme,&group, &part, &signal);
234
235 edje_shutdown();
236 evas_shutdown();
237 eina_shutdown();
238 return 0;
239} \ No newline at end of file