diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c new file mode 100644 index 0000000..29b04d6 --- /dev/null +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -0,0 +1,173 @@ | |||
1 | #include "LuaSL.h" | ||
2 | |||
3 | |||
4 | static const char *names[] = | ||
5 | { | ||
6 | "bub1", "sh1", | ||
7 | "bub2", "sh2", | ||
8 | "bub3", "sh3", | ||
9 | }; | ||
10 | |||
11 | |||
12 | static void | ||
13 | _edje_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source) | ||
14 | { | ||
15 | // gameGlobals *game = data; | ||
16 | } | ||
17 | |||
18 | static | ||
19 | Eina_Bool anim(void *data) | ||
20 | { | ||
21 | gameGlobals *game = data; | ||
22 | Evas_Object *bub, *sh; | ||
23 | Evas_Coord x, y, w, h, vw, vh; | ||
24 | double t, xx, yy, zz, r, fac; | ||
25 | double lx, ly; | ||
26 | unsigned int i; | ||
27 | |||
28 | evas_output_viewport_get(game->canvas, 0, 0, &vw, &vh); | ||
29 | r = 48; | ||
30 | t = ecore_loop_time_get(); | ||
31 | fac = 2.0 / (double)((sizeof(names) / sizeof(char *) / 2)); | ||
32 | evas_pointer_canvas_xy_get(game->canvas, &x, &y); | ||
33 | lx = x; | ||
34 | ly = y; | ||
35 | |||
36 | for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) | ||
37 | { | ||
38 | bub = evas_object_data_get(game->bg, names[i * 2]); | ||
39 | sh = evas_object_data_get(game->bg, names[(i * 2) + 1]); | ||
40 | zz = (((2 + sin(t * 6 + (M_PI * (i * fac)))) / 3) * 64) * 2; | ||
41 | xx = (cos(t * 4 + (M_PI * (i * fac))) * r) * 2; | ||
42 | yy = (sin(t * 6 + (M_PI * (i * fac))) * r) * 2; | ||
43 | |||
44 | w = zz; | ||
45 | h = zz; | ||
46 | x = (vw / 2) + xx - (w / 2); | ||
47 | y = (vh / 2) + yy - (h / 2); | ||
48 | |||
49 | evas_object_move(bub, x, y); | ||
50 | evas_object_resize(bub, w, h); | ||
51 | |||
52 | x = x - ((lx - (x + (w / 2))) / 4); | ||
53 | y = y - ((ly - (y + (h / 2))) / 4); | ||
54 | |||
55 | evas_object_move(sh, x, y); | ||
56 | evas_object_resize(sh, w, h); | ||
57 | evas_object_raise(sh); | ||
58 | evas_object_raise(bub); | ||
59 | } | ||
60 | return ECORE_CALLBACK_RENEW; | ||
61 | } | ||
62 | |||
63 | static void | ||
64 | _on_delete(Ecore_Evas *ee __UNUSED__) | ||
65 | { | ||
66 | ecore_main_loop_quit(); | ||
67 | } | ||
68 | |||
69 | int | ||
70 | main(int argc, char **argv) | ||
71 | { | ||
72 | /* put here any init specific to this app like parsing args etc. */ | ||
73 | gameGlobals game; | ||
74 | |||
75 | if (!ecore_evas_init()) | ||
76 | return EXIT_FAILURE; | ||
77 | |||
78 | if (!edje_init()) | ||
79 | { | ||
80 | ecore_evas_shutdown(); | ||
81 | return EXIT_FAILURE; | ||
82 | } | ||
83 | |||
84 | memset(&game, 0, sizeof(gameGlobals)); | ||
85 | // Since we increment at the begining, we need to pre decrement this so it starts at 0. | ||
86 | |||
87 | loggingStartup(&game); | ||
88 | |||
89 | // else if ((game.config) && (game.data)) | ||
90 | { | ||
91 | char buf[PATH_MAX]; | ||
92 | char *group = "main"; | ||
93 | Evas_Object *bub, *sh; | ||
94 | Ecore_Animator *ani; | ||
95 | unsigned int i; | ||
96 | |||
97 | /* this will give you a window with an Evas canvas under the first engine available */ | ||
98 | game.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
99 | if (!game.ee) | ||
100 | { | ||
101 | PEm("You got to have at least one evas engine built and linked up to ecore-evas for this example to run properly."); | ||
102 | edje_shutdown(); | ||
103 | ecore_evas_shutdown(); | ||
104 | return -1; | ||
105 | } | ||
106 | game.canvas = ecore_evas_get(game.ee); | ||
107 | ecore_evas_title_set(game.ee, "LuaoSL test harness"); | ||
108 | ecore_evas_show(game.ee); | ||
109 | |||
110 | game.bg = evas_object_rectangle_add(game.canvas); | ||
111 | evas_object_color_set(game.bg, 255, 255, 255, 255); /* white bg */ | ||
112 | evas_object_move(game.bg, 0, 0); /* at canvas' origin */ | ||
113 | evas_object_size_hint_weight_set(game.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
114 | evas_object_resize(game.bg, WIDTH, HEIGHT); /* covers full canvas */ | ||
115 | evas_object_show(game.bg); | ||
116 | ecore_evas_object_associate(game.ee, game.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | ||
117 | evas_object_focus_set(game.bg, EINA_TRUE); | ||
118 | |||
119 | game.edje = edje_object_add(game.canvas); | ||
120 | snprintf(buf, sizeof(buf), "%s/%s.edj", PACKAGE_DATA_DIR, "LuaSL"); | ||
121 | if (!edje_object_file_set(game.edje, buf, group)) | ||
122 | { | ||
123 | int err = edje_object_load_error_get(game.edje); | ||
124 | const char *errmsg = edje_load_error_str(err); | ||
125 | PEm("Could not load '%s' from %s: %s\n", group, buf, errmsg); | ||
126 | |||
127 | evas_object_del(game.edje); | ||
128 | ecore_evas_free(game.ee); | ||
129 | edje_shutdown(); | ||
130 | ecore_evas_shutdown(); | ||
131 | return -2; | ||
132 | } | ||
133 | evas_object_move(game.edje, 0, 0); | ||
134 | evas_object_resize(game.edje, WIDTH, HEIGHT); | ||
135 | evas_object_show(game.edje); | ||
136 | |||
137 | snprintf(buf, sizeof(buf), "%s/images/bubble_sh.png", PACKAGE_DATA_DIR); | ||
138 | for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) | ||
139 | { | ||
140 | sh = evas_object_image_filled_add(game.canvas); | ||
141 | evas_object_image_file_set(sh, buf, NULL); | ||
142 | evas_object_resize(sh, 64, 64); | ||
143 | evas_object_show(sh); | ||
144 | evas_object_data_set(game.bg, names[(i * 2) + 1], sh); | ||
145 | } | ||
146 | |||
147 | snprintf(buf, sizeof(buf), "%s/images/bubble.png", PACKAGE_DATA_DIR); | ||
148 | for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) | ||
149 | { | ||
150 | bub = evas_object_image_filled_add(game.canvas); | ||
151 | evas_object_image_file_set(bub, buf, NULL); | ||
152 | evas_object_resize(bub, 64, 64); | ||
153 | evas_object_show(bub); | ||
154 | evas_object_data_set(game.bg, names[(i * 2)], bub); | ||
155 | } | ||
156 | ani = ecore_animator_add(anim, &game); | ||
157 | evas_object_data_set(game.bg, "animator", ani); | ||
158 | |||
159 | // Setup our callbacks. | ||
160 | ecore_evas_callback_delete_request_set(game.ee, _on_delete); | ||
161 | edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game); | ||
162 | |||
163 | ecore_main_loop_begin(); | ||
164 | |||
165 | ecore_animator_del(ani); | ||
166 | ecore_evas_free(game.ee); | ||
167 | edje_shutdown(); | ||
168 | ecore_evas_shutdown(); | ||
169 | } | ||
170 | |||
171 | return 0; | ||
172 | } | ||
173 | |||