aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GuiLua
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-27 20:37:46 +1000
committerDavid Walter Seikel2014-04-27 20:37:46 +1000
commitd2a6479b73af16d8265493d969abadf5b0984505 (patch)
tree4a8fa35dc66d1cba5efa07ff3f74c47393075580 /src/GuiLua
parentConvert GuiLua to EO. (diff)
downloadSledjHamr-d2a6479b73af16d8265493d969abadf5b0984505.zip
SledjHamr-d2a6479b73af16d8265493d969abadf5b0984505.tar.gz
SledjHamr-d2a6479b73af16d8265493d969abadf5b0984505.tar.bz2
SledjHamr-d2a6479b73af16d8265493d969abadf5b0984505.tar.xz
Convert the Evas 3D example stuff to EO, though it still doesn't work, but at least it compiles and runs with no error messages.
Diffstat (limited to 'src/GuiLua')
-rw-r--r--src/GuiLua/GuiLua.c221
-rw-r--r--src/GuiLua/test.skang2
2 files changed, 119 insertions, 104 deletions
diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c
index 06ad4d5..1cc8bf1 100644
--- a/src/GuiLua/GuiLua.c
+++ b/src/GuiLua/GuiLua.c
@@ -143,6 +143,10 @@ and ordinary elementary widgets. Proper introspection can come later.
143#include "GuiLua.h" 143#include "GuiLua.h"
144 144
145 145
146// TODO - This is missing, remove it when it's all sorted out.
147EAPI Evas_3D_Node *evas_3d_node_add(Evas *e, Evas_3D_Node_Type type);
148
149
146typedef struct _Scene_Data 150typedef struct _Scene_Data
147{ 151{
148 Evas_3D_Scene *scene; 152 Evas_3D_Scene *scene;
@@ -228,13 +232,14 @@ static Eina_Bool
228_animate_scene(void *data) 232_animate_scene(void *data)
229{ 233{
230 static float angle = 0.0f; 234 static float angle = 0.0f;
231/* 235
232 Scene_Data *scene = (Scene_Data *)data; 236 Scene_Data *scene = (Scene_Data *)data;
233 237
234 angle += 0.5; 238 angle += 0.5;
235 239
236 evas_3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0); 240 eo_do(scene->mesh_node,
237*/ 241 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0)
242 );
238 243
239 /* Rotate */ 244 /* Rotate */
240 if (angle > 360.0) 245 if (angle > 360.0)
@@ -243,109 +248,119 @@ _animate_scene(void *data)
243} 248}
244 249
245static void 250static void
246_camera_setup(Scene_Data *data) 251_camera_setup(globals *ourGlobals, Scene_Data *data)
247{ 252{
248/* 253 data->camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas);
249 data->camera = evas_3d_camera_add(evas); 254 eo_do(data->camera,
250 evas_3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0); 255 evas_3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0)
251 256 );
252 data->camera_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA); 257
253 evas_3d_node_camera_set(data->camera_node, data->camera); 258 data->camera_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA);
254 evas_3d_node_member_add(data->root_node, data->camera_node); 259 eo_do(data->camera_node,
255 evas_3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0); 260 evas_3d_node_camera_set(data->camera)
256 evas_3d_node_look_at_set(data->camera_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, 261 );
257 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); 262 eo_do(data->root_node,
258*/ 263 evas_3d_node_member_add(data->camera_node)
264 );
265 eo_do(data->camera_node,
266 evas_3d_node_position_set(0.0, 0.0, 10.0),
267 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0)
268 );
259} 269}
260 270
261static void 271static void
262_light_setup(Scene_Data *data) 272_light_setup(globals *ourGlobals, Scene_Data *data)
263{ 273{
264/* 274 data->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas);
265 data->light = evas_3d_light_add(evas); 275 eo_do(data->light,
266 evas_3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0); 276 evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
267 evas_3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0); 277 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
268 evas_3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0); 278 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0)
269 279 );
270 data->light_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_LIGHT); 280
271 evas_3d_node_light_set(data->light_node, data->light); 281 data->light_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_LIGHT);
272 evas_3d_node_member_add(data->root_node, data->light_node); 282 eo_do(data->light_node,
273 evas_3d_node_position_set(data->light_node, 0.0, 0.0, 10.0); 283 evas_3d_node_light_set(data->light)
274 evas_3d_node_look_at_set(data->light_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, 284 );
275 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); 285 eo_do(data->root_node,
276*/ 286 evas_3d_node_member_add(data->light_node)
287 );
288 eo_do(data->light_node,
289 evas_3d_node_position_set(0.0, 0.0, 10.0);
290 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0);
291 );
277} 292}
278 293
279static void 294static void
280_mesh_setup(Scene_Data *data) 295_mesh_setup(globals *ourGlobals, Scene_Data *data)
281{ 296{
282 /* Setup material. */ 297 /* Setup material. */
283/* 298 data->material = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
284 data->material = evas_3d_material_add(evas); 299 eo_do(data->material,
300 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
301 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
302 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
303
304 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
305 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
306 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
307 evas_3d_material_shininess_set(100.0)
308 );
285 309
286 evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE); 310 /* Setup mesh. */
287 evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE); 311 data->mesh = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
288 evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE); 312 eo_do(data->mesh,
313 evas_3d_mesh_vertex_count_set(24),
314 evas_3d_mesh_frame_add(0),
289 315
290 evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0); 316 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
291 evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0); 317 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
292 evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0); 318 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
293 evas_3d_material_shininess_set(data->material, 100.0); 319 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
294*/
295 320
296 /* Setup mesh. */ 321 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
297/* 322 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES);
298 data->mesh = evas_3d_mesh_add(evas); 323
299 evas_3d_mesh_vertex_count_set(data->mesh, 24); 324 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG),
300 evas_3d_mesh_frame_add(data->mesh, 0); 325
301 326 evas_3d_mesh_frame_material_set(0, data->material)
302 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_POSITION, 327
303 12 * sizeof(float), &cube_vertices[ 0]); 328 );
304 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_NORMAL, 329 data->mesh_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
305 12 * sizeof(float), &cube_vertices[ 3]); 330 eo_do(data->root_node,
306 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_COLOR, 331 evas_3d_node_member_add(data->mesh_node)
307 12 * sizeof(float), &cube_vertices[ 6]); 332 );
308 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_TEXCOORD, 333 eo_do(data->mesh_node,
309 12 * sizeof(float), &cube_vertices[10]); 334 evas_3d_node_mesh_add(data->mesh)
310 335 );
311 evas_3d_mesh_index_data_set(data->mesh, EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
312 36, &cube_indices[0]);
313 evas_3d_mesh_vertex_assembly_set(data->mesh, EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES);
314
315 evas_3d_mesh_shade_mode_set(data->mesh, EVAS_3D_SHADE_MODE_PHONG);
316
317 evas_3d_mesh_frame_material_set(data->mesh, 0, data->material);
318
319 data->mesh_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_MESH);
320 evas_3d_node_member_add(data->root_node, data->mesh_node);
321 evas_3d_node_mesh_add(data->mesh_node, data->mesh);
322*/
323} 336}
324 337
338
325static void 339static void
326_scene_setup(globals *ourGlobals, Scene_Data *data) 340_scene_setup(globals *ourGlobals, Scene_Data *data)
327{ 341{
328/* 342 data->scene = eo_add(EVAS_3D_SCENE_CLASS, ourGlobals->evas);
329 data->scene = evas_3d_scene_add(ourGlobals->evas); 343 eo_do(data->scene,
330 evas_3d_scene_size_set(data->scene, WIDTH, HEIGHT); 344 evas_3d_scene_size_set(WIDTH, HEIGHT),
331 evas_3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0); 345 evas_3d_scene_background_color_set(1.0, 0.0, 1.0, 0.5)
346 );
332 347
333 data->root_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_NODE); 348 // TODO - I have no idea how this should work.
334*/ 349// data->root_node = eo_add(EVAS_3D_NODE_CLASS, ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
350 data->root_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
335 351
336 _camera_setup(data); 352 _camera_setup(ourGlobals, data);
337 _light_setup(data); 353 _light_setup(ourGlobals, data);
338 _mesh_setup(data); 354 _mesh_setup(ourGlobals, data);
339 355
340/* 356 eo_do(data->scene,
341 evas_3d_scene_root_node_set(data->scene, data->root_node); 357 evas_3d_scene_root_node_set(data->root_node);
342 evas_3d_scene_camera_node_set(data->scene, data->camera_node); 358 evas_3d_scene_camera_node_set(data->camera_node);
343*/ 359 );
344} 360}
345 361
346 362
347 363
348
349// TODO - These functions should be able to deal with multiple windows. 364// TODO - These functions should be able to deal with multiple windows.
350// TODO - Should be able to open external and internal windows, and even switch between them on the fly. 365// TODO - Should be able to open external and internal windows, and even switch between them on the fly.
351static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 366static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
@@ -475,6 +490,8 @@ static int window(lua_State *L)
475 globals *ourGlobals; 490 globals *ourGlobals;
476 char *name = "GuiLua"; 491 char *name = "GuiLua";
477 char *title = "GuiLua test harness"; 492 char *title = "GuiLua test harness";
493 Evas_Object *background;
494 struct _Widget *wid;
478 int w = WIDTH, h = HEIGHT; 495 int w = WIDTH, h = HEIGHT;
479 496
480 lua_getfield(L, LUA_REGISTRYINDEX, globName); 497 lua_getfield(L, LUA_REGISTRYINDEX, globName);
@@ -482,7 +499,6 @@ static int window(lua_State *L)
482 lua_pop(L, 1); 499 lua_pop(L, 1);
483 500
484 pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name); 501 pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name);
485 PI("Setting window to %d %d %s", w, h, title);
486 502
487 if ((ourGlobals->win = elm_win_util_standard_add(name, title))) 503 if ((ourGlobals->win = elm_win_util_standard_add(name, title)))
488 { 504 {
@@ -494,29 +510,28 @@ static int window(lua_State *L)
494 510
495 // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas. 511 // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas.
496 ourGlobals->evas = evas_object_evas_get(ourGlobals->win); 512 ourGlobals->evas = evas_object_evas_get(ourGlobals->win);
497 // An Ecore_Evas holds an Evas.
498 // Get the Ecore_Evas that wraps an Evas.
499// ourGlobals->ecore_evas = ecore_evas_ecore_evas_get(ourGlobals->evas); // Only use this on Evas that was created with Ecore_Evas.
500
501 _scene_setup(ourGlobals, &data); 513 _scene_setup(ourGlobals, &data);
502 514
503 /* Add an image object for 3D scene rendering. */ 515 /* Add a background rectangle objects. */
504/* 516 background = evas_object_rectangle_add(ourGlobals->evas);
505 ourGlobals->image = elm_image_add(ourGlobals->win); 517 evas_object_color_set(background, 255, 0, 255, 255);
506 elm_image_no_scale_set(ourGlobals->image, EINA_TRUE); 518 evas_object_move(background, 0, 0);
507 elm_image_resizable_set(ourGlobals->image, EINA_FALSE, EINA_TRUE); 519 evas_object_resize(background, w, h);
508 elm_image_smooth_set(ourGlobals->image, EINA_FALSE); 520 evas_object_show(background);
509 elm_image_orient_set(ourGlobals->image, ELM_IMAGE_FLIP_HORIZONTAL); 521
510 elm_image_aspect_fixed_set(ourGlobals->image, EINA_TRUE); 522 // Add an image object for 3D scene rendering.
511 elm_image_fill_outside_set(ourGlobals->image, EINA_TRUE); 523 wid = calloc(1, sizeof(struct _Widget));
512 elm_image_editable_set(ourGlobals->image, EINA_TRUE); 524 strcpy(wid->magic, "Widget");
513 evas_object_size_hint_weight_set(ourGlobals->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 525 eina_clist_add_head(&ourGlobals->widgets, &wid->node);
514 elm_win_resize_object_add(ourGlobals->win, ourGlobals->image); 526
515 evas_object_show(ourGlobals->image); 527 wid->obj = eo_add(EVAS_OBJ_IMAGE_CLASS, ourGlobals->win);
516 528 eo_do(wid->obj,
517 // Set the image object as render target for 3D scene. 529 evas_obj_image_filled_set(EINA_TRUE),
518 evas_object_image_scene_set(ourGlobals->image, data.scene); 530 evas_obj_image_size_set(w, h),
519*/ 531 evas_obj_position_set(0, 0),
532 evas_obj_visibility_set(EINA_TRUE),
533 evas_obj_image_scene_set(data.scene)
534 );
520 535
521 // Add animation timer callback. 536 // Add animation timer callback.
522 ecore_timer_add(0.016, _animate_scene, &data); 537 ecore_timer_add(0.016, _animate_scene, &data);
diff --git a/src/GuiLua/test.skang b/src/GuiLua/test.skang
index 10382b5..897777f 100644
--- a/src/GuiLua/test.skang
+++ b/src/GuiLua/test.skang
@@ -4,7 +4,7 @@
4-- There's an implied local test = require 'test' 4-- There's an implied local test = require 'test'
5 5
6-- This is a bit more verbose than I wanted. lol 6-- This is a bit more verbose than I wanted. lol
7local win = skang.window(500, 500, "G'day planet.", 'testWindow') 7local win = skang.window(1024, 1024, "G'day planet.", 'testWindow')
8skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 30'} 8skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 30'}
9win.W.quitter.action = 'skang.quit()' -- TODO Should look it up in ThingSpace.commands, and translate 'quit' into the Lua 'skang.quit()'? 9win.W.quitter.action = 'skang.quit()' -- TODO Should look it up in ThingSpace.commands, and translate 'quit' into the Lua 'skang.quit()'?
10 10