diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/edje/src/examples/edje-table.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/edje/src/examples/edje-table.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-table.c b/libraries/edje/src/examples/edje-table.c new file mode 100644 index 0000000..3866d22 --- /dev/null +++ b/libraries/edje/src/examples/edje-table.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating table functions. | ||
3 | * | ||
4 | * You'll need at least one Evas engine built for it (excluding the | ||
5 | * buffer one). See stdout/stderr for output. | ||
6 | * | ||
7 | * @verbatim | ||
8 | * edje_cc table.edc && gcc -o edje-table edje-table.c `pkg-config --libs --cflags evas ecore ecore-evas edje` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #ifdef HAVE_CONFIG_H | ||
13 | #include "config.h" | ||
14 | #else | ||
15 | #define PACKAGE_EXAMPLES_DIR "." | ||
16 | #define __UNUSED__ | ||
17 | #endif | ||
18 | |||
19 | #include <Ecore.h> | ||
20 | #include <Ecore_Evas.h> | ||
21 | #include <Edje.h> | ||
22 | |||
23 | #define WIDTH (400) | ||
24 | #define HEIGHT (400) | ||
25 | |||
26 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/table.edj"; | ||
27 | |||
28 | static Ecore_Evas *ee; | ||
29 | static Evas *evas; | ||
30 | static Evas_Object *bg, *edje_obj, *rects[4]; | ||
31 | |||
32 | static void | ||
33 | _on_delete(Ecore_Evas *ee __UNUSED__) | ||
34 | { | ||
35 | ecore_main_loop_quit(); | ||
36 | } | ||
37 | |||
38 | /* Try to get the number of columns and rows of the table | ||
39 | * and print them. */ | ||
40 | static void | ||
41 | _columns_rows_print(void) | ||
42 | { | ||
43 | int cols, rows; | ||
44 | |||
45 | if (edje_object_part_table_col_row_size_get(edje_obj, "table_part", &cols, | ||
46 | &rows)) | ||
47 | fprintf(stdout, "Number of columns: %d\nNumber of rows: %d\n", cols, rows); | ||
48 | else | ||
49 | fprintf(stderr, "Cannot get the number of columns and rows\n"); | ||
50 | } | ||
51 | |||
52 | /* here just to keep our example's window size and table items | ||
53 | * size in synchrony. */ | ||
54 | static void | ||
55 | _canvas_resize_cb(Ecore_Evas *ee) | ||
56 | { | ||
57 | int i, w, h; | ||
58 | |||
59 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
60 | |||
61 | evas_object_resize(bg, w, h); | ||
62 | evas_object_resize(edje_obj, w, h); | ||
63 | |||
64 | for (i = 0; i < 4; i++) | ||
65 | evas_object_size_hint_min_set(rects[i], w/2, h/2); | ||
66 | } | ||
67 | |||
68 | /* Mouse button 1 = remove the clicked item | ||
69 | * any other button = remove all items. */ | ||
70 | static void | ||
71 | _on_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
72 | { | ||
73 | Evas_Event_Mouse_Down *ev = event_info; | ||
74 | |||
75 | if (ev->button != 1) | ||
76 | edje_object_part_table_clear(edje_obj, "table_part", EINA_TRUE); | ||
77 | else if (!edje_object_part_table_unpack(edje_obj, "table_part", obj)) | ||
78 | fprintf(stderr, "Cannot remove the selected rectangle\n"); | ||
79 | |||
80 | evas_object_del(obj); | ||
81 | _columns_rows_print(); | ||
82 | } | ||
83 | |||
84 | static void | ||
85 | _rects_create(void) | ||
86 | { | ||
87 | int i; | ||
88 | |||
89 | for (i = 0; i < 4; i++) | ||
90 | { | ||
91 | rects[i] = evas_object_rectangle_add(evas); | ||
92 | evas_object_size_hint_min_set(rects[i], 200, 200); | ||
93 | evas_object_size_hint_weight_set(rects[i], 1.0, 1.0); | ||
94 | evas_object_show(rects[i]); | ||
95 | evas_object_event_callback_add(rects[i], EVAS_CALLBACK_MOUSE_DOWN, | ||
96 | _on_mouse_down, NULL); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | int | ||
101 | main(void) | ||
102 | { | ||
103 | int i; | ||
104 | |||
105 | ecore_evas_init(); | ||
106 | edje_init(); | ||
107 | |||
108 | /* this will give you a window with an Evas canvas under the first | ||
109 | * engine available */ | ||
110 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
111 | |||
112 | ecore_evas_callback_delete_request_set(ee, _on_delete); | ||
113 | ecore_evas_callback_resize_set(ee, _canvas_resize_cb); | ||
114 | ecore_evas_title_set(ee, "Edje Table Example"); | ||
115 | ecore_evas_show(ee); | ||
116 | |||
117 | evas = ecore_evas_get(ee); | ||
118 | |||
119 | bg = evas_object_rectangle_add(evas); | ||
120 | evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */ | ||
121 | evas_object_move(bg, 0, 0); /* at canvas' origin */ | ||
122 | evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */ | ||
123 | evas_object_show(bg); | ||
124 | |||
125 | edje_obj = edje_object_add(evas); | ||
126 | |||
127 | edje_object_file_set(edje_obj, edje_file_path, "example_table"); | ||
128 | evas_object_move(edje_obj, 0, 0); /* at canvas' origin */ | ||
129 | evas_object_resize(edje_obj, WIDTH, HEIGHT); | ||
130 | evas_object_show(edje_obj); | ||
131 | |||
132 | _rects_create(); | ||
133 | |||
134 | /* Colouring the rectangles */ | ||
135 | evas_object_color_set(rects[0], 255, 0, 0, 255); | ||
136 | evas_object_color_set(rects[1], 0, 255, 0, 255); | ||
137 | evas_object_color_set(rects[2], 0, 0, 255, 255); | ||
138 | evas_object_color_set(rects[3], 128, 128, 128, 255); | ||
139 | |||
140 | /* Packing the rectangles into the table */ | ||
141 | if (!edje_object_part_table_pack(edje_obj, "table_part", rects[0], | ||
142 | 0, 0, 1, 2)) | ||
143 | fprintf(stderr, "Cannot add the rectangle 1 to table\n"); | ||
144 | |||
145 | if (!edje_object_part_table_pack(edje_obj, "table_part", rects[1], | ||
146 | 0, 1, 1, 1)) | ||
147 | fprintf(stderr, "Cannot add the rectangle 2 to table\n"); | ||
148 | |||
149 | if (!edje_object_part_table_pack(edje_obj, "table_part", rects[2], | ||
150 | 1, 0, 1, 1)) | ||
151 | fprintf(stderr, "Cannot add the rectangle 3 to table\n"); | ||
152 | |||
153 | if (!edje_object_part_table_pack(edje_obj, "table_part", rects[3], | ||
154 | 1, 1, 1, 1)) | ||
155 | fprintf(stderr, "Cannot add the rectangle 4 to table\n"); | ||
156 | |||
157 | _columns_rows_print(); | ||
158 | |||
159 | ecore_main_loop_begin(); | ||
160 | |||
161 | ecore_evas_free(ee); | ||
162 | ecore_evas_shutdown(); | ||
163 | edje_shutdown(); | ||
164 | return 0; | ||
165 | } | ||