From ae7ee5b32b8adf8970aa398bbe0d0318b10225d4 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 4 Jan 2012 21:30:40 +1000 Subject: Skeleton of the GUI test harness for the LuaSL script engine. --- LuaSL/build.sh | 70 ++++++++++++++ LuaSL/src/LuaSL.edc | 205 +++++++++++++++++++++++++++++++++++++++++ LuaSL/src/LuaSL.h | 64 +++++++++++++ LuaSL/src/LuaSL_main.c | 173 ++++++++++++++++++++++++++++++++++ LuaSL/src/LuaSL_utilities.c | 101 ++++++++++++++++++++ LuaSL/src/fonts/Vera.ttf | Bin 0 -> 65932 bytes LuaSL/src/images/bubble.png | Bin 0 -> 4737 bytes LuaSL/src/images/bubble_sh.png | Bin 0 -> 1600 bytes LuaSL/src/images/test.png | Bin 0 -> 22869 bytes 9 files changed, 613 insertions(+) create mode 100755 LuaSL/build.sh create mode 100644 LuaSL/src/LuaSL.edc create mode 100644 LuaSL/src/LuaSL.h create mode 100644 LuaSL/src/LuaSL_main.c create mode 100644 LuaSL/src/LuaSL_utilities.c create mode 100644 LuaSL/src/fonts/Vera.ttf create mode 100644 LuaSL/src/images/bubble.png create mode 100644 LuaSL/src/images/bubble_sh.png create mode 100644 LuaSL/src/images/test.png diff --git a/LuaSL/build.sh b/LuaSL/build.sh new file mode 100755 index 0000000..206f3c0 --- /dev/null +++ b/LuaSL/build.sh @@ -0,0 +1,70 @@ +#! /bin/bash + +cd src + +export LOCALDIR=`pwd` + +if [ -d "/opt/e17" ] +then + export E17DIR="/opt/e17" +else + export E17DIR="/usr" +fi + +# No need for a make file, or dependencies, the entire thing takes only a few seconds to build. + +CFLAGS="-g -Wall -I include -I $LOCALDIR" +CFLAGS="$CFLAGS -I $E17DIR/include/eina-1" +CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina" +CFLAGS="$CFLAGS -I $E17DIR/include/eet-1" +CFLAGS="$CFLAGS -I $E17DIR/include/edje-1" +CFLAGS="$CFLAGS -I $E17DIR/include/evas-1" +CFLAGS="$CFLAGS -I $E17DIR/include/ecore-1" +CFLAGS="$CFLAGS -I $E17DIR/include" +CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" + +LDFLAGS="-L lib -L /usr/lib -L /lib -L $E17DIR/lib" +libs="-lecore -levas -ledje -leet -leina" +# These need to be added to libs if linking staticaly, though some part of EFL don't like that. +#-lecore_evas \ +#-lecore_fb \ +#-lecore_file \ +#-lecore \ +#-ledje \ +#-levas \ +#-lembryo \ +#-leet \ +#-leina \ +#-llua \ +#-lm \ +#-ldl \ +#-lglib-2.0 \ +#-lpthread \ +#-lfontconfig \ +#-lfreetype \ +#-lexpat \ +#-lrt \ +#-lz + +names="LuaSL_main LuaSL_utilities" + +EDJE_FLAGS="-id images -fd fonts" + +rm -f LuaSL *.o *.edj +command="edje_cc $EDJE_FLAGS LuaSL.edc LuaSL.edj" +echo $command +$command + +objects="" +for i in $names +do + command="gcc $CFLAGS -c -o $i.o $i.c" + echo $command + $command + objects="$objects $i.o" +done + +command="gcc $CFLAGS -o LuaSL $objects $LDFLAGS $libs" +echo $command +$command + diff --git a/LuaSL/src/LuaSL.edc b/LuaSL/src/LuaSL.edc new file mode 100644 index 0000000..f74395b --- /dev/null +++ b/LuaSL/src/LuaSL.edc @@ -0,0 +1,205 @@ +color_classes { + color_class { name: "test_colour"; color: 255 255 255 255; } +} + +fonts { + font: "Vera.ttf" "default"; +} + +images { + image: "bubble.png" COMP; + image: "test.png" COMP; +} + +collections { + group { + name: "main"; + lua_script_only: 1; + lua_script { + --// stick object private/local vars here + local D; + local text_geom; + + --// init object here + D = {}; --// data is empty table to start + + --// send some random edje message + edje.messagesend(7, "none" ); + edje.messagesend(7, "sig", "signal", "source"); + edje.messagesend(7, "str", "hello world"); + edje.messagesend(7, "int", 987); + edje.messagesend(7, "float", 987.321); + edje.messagesend(7, "strset", {"hello", "there", "world"}); + edje.messagesend(7, "intset", {1, 2, 3}); + edje.messagesend(7, "floatset", {1.1, 2.2, 3.3}); + edje.messagesend(7, "strint", "hello world", 7); + edje.messagesend(7, "strfloat", "hello world", 7.654); + edje.messagesend(7, "strintset","hello world", {1, 2, 3}); + + D.edje = edje.edje(); + D.edje:file("plain/edje/group"); + D.edje:show(); + + D.text = edje.text(); + D.text:geom (50, 5, 150, 50); + D.text:color (255, 0, 0, 255); + D.text:font("Sans:style=Bold", 32); + D.text:text("Lua rocks!"); + text_geom = D.text:geom(); + print(D.text:text()); + D.text:show(); + + + --// shutdown func - generally empty or not there. everything garbage collected for you + function shutdown () + print("lua::shutdown"); + end + + function show () + print("lua::show"); + end + + function hide () + print("lua::hide"); + end + + function move (x, y) + print("lua::move x=" .. x .. " x=" .. y); + D.edje:move(0, 0); + end + + function resize (w, h) + print("lua::resize w=" .. w .. " h=" .. h); + D.text:move((w - text_geom.w) / 2, (h - text_geom.h) / 8); + D.edje:resize(w, h); + end + + function message (id, type, ...) + print("lua::message id=" .. id .. " type=" .. type); + --// handle your message type here. check id + type then use the + --// vararg appropriately. they are the same as the params passed + --// to edje:messagesend() (if any are passed at all). Any array + --// arguments are passed as a single table. + + if ("none" == type) then + print("lua::message no args"); + elseif ("strset" == type) then + strs = ... ; + print_table_start(strs, "", "lua::message strings"); + elseif ("intset" == type) then + ints = ... ; + print_table_start(ints, "", "lua::message ints"); + elseif ("floatset" == type) then + floats = ... ; + print_table_start(floats, "", "lua::message floats"); + elseif ("strintset" == type) then + str, ints = ... ; + print("lua::message " .. str); + print_table_start(ints, "", "lua::message ints"); + elseif ("strfloatset" == type) then + str, floats = ... ; + print("lua::message " .. str); + print_table_start(floats, "", "lua::message floats"); + else + print("lua::message " .. ... ); + end + end + + function signal (sig, src) + print("lua::signal sig= " .. sig .. " src= " .. src); + end + } + } + + // The group name NEEDS a / in it, + // or the part below that tries to swallow it won't work. + // Leaving just the lua part visible. + group { + name: "bubbles/lua"; + lua_script_only: 1; + lua_script { + local bubbles = { }; + local bubbleCols = 8; + local bubbleRows = 6; + + for i = 1, bubbleRows do + row = { }; + for j = 1, bubbleCols do + image = edje.image(); + image:image("bubble.png"); + image:show(); + table.insert(row, image); + end + table.insert(bubbles, row); + end + + function resize (w, h) + for i = 1, bubbleRows do + for j = 1, bubbleCols do + w1 = w / bubbleCols; + h1 = h / bubbleRows; + bubbles[i][j]:geom((j - 1) * w1, (i - 1) * h1, w1, h1); + if ((1 == i) or (1 == j) or (bubbleRows == i) or (bubbleCols == j)) then + bubbles[i][j]:color(0, 255, 0, 200); + else + bubbles[i][j]:color(math.random(200) + 55, 0, math.random(255) + 55, 200); + end + end + end + end + } + } + + group { + name: "plain/edje/group"; + parts { + part { + name: "background"; + type: RECT; + mouse_events: 0; + description { + state: "default" 0.0; + color: 0 0 0 255; + } + } + + // A lua group embedded in an edje group. + part { + name: "bubbles_lua"; + type: GROUP; + source: "bubbles/lua"; + mouse_events: 0; + description { state: "default" 0.0; } + } + + part { + name: "background_image"; + type: IMAGE; + mouse_events: 0; + description { + state: "default" 0.0; + aspect_preference: HORIZONTAL; + color_class: "test_colour"; + image { normal: "test.png"; } + } + } + + part { + name: "some_text"; + type: TEXT; + mouse_events: 0; + description { + state: "default" 0; + text + { + text: "This is test text."; + text_class: "test_text_class"; + } + } + } + + } + } + +} + diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h new file mode 100644 index 0000000..af87de5 --- /dev/null +++ b/LuaSL/src/LuaSL.h @@ -0,0 +1,64 @@ +//#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#else +#define PACKAGE_EXAMPLES_DIR "." +#define __UNUSED__ +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define WIDTH (1024) +#define HEIGHT (768) + +#define PC(...) EINA_LOG_DOM_CRIT(game->logDom, __VA_ARGS__) +#define PE(...) EINA_LOG_DOM_ERR(game->logDom, __VA_ARGS__) +#define PW(...) EINA_LOG_DOM_WARN(game->logDom, __VA_ARGS__) +#define PD(...) EINA_LOG_DOM_DBG(game->logDom, __VA_ARGS__) +#define PI(...) EINA_LOG_DOM_INFO(game->logDom, __VA_ARGS__) + +#define PCm(...) EINA_LOG_DOM_CRIT(game.logDom, __VA_ARGS__) +#define PEm(...) EINA_LOG_DOM_ERR(game.logDom, __VA_ARGS__) +#define PWm(...) EINA_LOG_DOM_WARN(game.logDom, __VA_ARGS__) +#define PDm(...) EINA_LOG_DOM_DBG(game.logDom, __VA_ARGS__) +#define PIm(...) EINA_LOG_DOM_INFO(game.logDom, __VA_ARGS__) + +#define D() PD("DEBUG") + +// "01:03:52 01-01-1973\n\0" +#define DATE_TIME_LEN 21 + +#define TABLE_WIDTH 7 +#define TABLE_HEIGHT 42 + +#ifndef FALSE +// NEVER change this +typedef enum +{ + FALSE = 0, + TRUE = 1 +} boolean; +#endif + +typedef struct +{ + Ecore_Evas *ee; // Our window. + Evas *canvas; // The canvas for drawing directly onto. + Evas_Object *bg; // Our background edje, also the game specific stuff. + Evas_Object *edje; // The edje of the background. + int logDom; +} gameGlobals; + +typedef void (*doSomething) (gameGlobals *game, unsigned char key); + +void loggingStartup(gameGlobals *game); +char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); +float timeDiff(struct timeval *now, struct timeval *then); + + 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 @@ +#include "LuaSL.h" + + +static const char *names[] = +{ + "bub1", "sh1", + "bub2", "sh2", + "bub3", "sh3", +}; + + +static void +_edje_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source) +{ +// gameGlobals *game = data; +} + +static +Eina_Bool anim(void *data) +{ + gameGlobals *game = data; + Evas_Object *bub, *sh; + Evas_Coord x, y, w, h, vw, vh; + double t, xx, yy, zz, r, fac; + double lx, ly; + unsigned int i; + + evas_output_viewport_get(game->canvas, 0, 0, &vw, &vh); + r = 48; + t = ecore_loop_time_get(); + fac = 2.0 / (double)((sizeof(names) / sizeof(char *) / 2)); + evas_pointer_canvas_xy_get(game->canvas, &x, &y); + lx = x; + ly = y; + + for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) + { + bub = evas_object_data_get(game->bg, names[i * 2]); + sh = evas_object_data_get(game->bg, names[(i * 2) + 1]); + zz = (((2 + sin(t * 6 + (M_PI * (i * fac)))) / 3) * 64) * 2; + xx = (cos(t * 4 + (M_PI * (i * fac))) * r) * 2; + yy = (sin(t * 6 + (M_PI * (i * fac))) * r) * 2; + + w = zz; + h = zz; + x = (vw / 2) + xx - (w / 2); + y = (vh / 2) + yy - (h / 2); + + evas_object_move(bub, x, y); + evas_object_resize(bub, w, h); + + x = x - ((lx - (x + (w / 2))) / 4); + y = y - ((ly - (y + (h / 2))) / 4); + + evas_object_move(sh, x, y); + evas_object_resize(sh, w, h); + evas_object_raise(sh); + evas_object_raise(bub); + } + return ECORE_CALLBACK_RENEW; +} + +static void +_on_delete(Ecore_Evas *ee __UNUSED__) +{ + ecore_main_loop_quit(); +} + +int +main(int argc, char **argv) +{ + /* put here any init specific to this app like parsing args etc. */ + gameGlobals game; + + if (!ecore_evas_init()) + return EXIT_FAILURE; + + if (!edje_init()) + { + ecore_evas_shutdown(); + return EXIT_FAILURE; + } + + memset(&game, 0, sizeof(gameGlobals)); + // Since we increment at the begining, we need to pre decrement this so it starts at 0. + + loggingStartup(&game); + +// else if ((game.config) && (game.data)) + { + char buf[PATH_MAX]; + char *group = "main"; + Evas_Object *bub, *sh; + Ecore_Animator *ani; + unsigned int i; + + /* this will give you a window with an Evas canvas under the first engine available */ + game.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); + if (!game.ee) + { + PEm("You got to have at least one evas engine built and linked up to ecore-evas for this example to run properly."); + edje_shutdown(); + ecore_evas_shutdown(); + return -1; + } + game.canvas = ecore_evas_get(game.ee); + ecore_evas_title_set(game.ee, "LuaoSL test harness"); + ecore_evas_show(game.ee); + + game.bg = evas_object_rectangle_add(game.canvas); + evas_object_color_set(game.bg, 255, 255, 255, 255); /* white bg */ + evas_object_move(game.bg, 0, 0); /* at canvas' origin */ + evas_object_size_hint_weight_set(game.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_resize(game.bg, WIDTH, HEIGHT); /* covers full canvas */ + evas_object_show(game.bg); + ecore_evas_object_associate(game.ee, game.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); + evas_object_focus_set(game.bg, EINA_TRUE); + + game.edje = edje_object_add(game.canvas); + snprintf(buf, sizeof(buf), "%s/%s.edj", PACKAGE_DATA_DIR, "LuaSL"); + if (!edje_object_file_set(game.edje, buf, group)) + { + int err = edje_object_load_error_get(game.edje); + const char *errmsg = edje_load_error_str(err); + PEm("Could not load '%s' from %s: %s\n", group, buf, errmsg); + + evas_object_del(game.edje); + ecore_evas_free(game.ee); + edje_shutdown(); + ecore_evas_shutdown(); + return -2; + } + evas_object_move(game.edje, 0, 0); + evas_object_resize(game.edje, WIDTH, HEIGHT); + evas_object_show(game.edje); + + snprintf(buf, sizeof(buf), "%s/images/bubble_sh.png", PACKAGE_DATA_DIR); + for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) + { + sh = evas_object_image_filled_add(game.canvas); + evas_object_image_file_set(sh, buf, NULL); + evas_object_resize(sh, 64, 64); + evas_object_show(sh); + evas_object_data_set(game.bg, names[(i * 2) + 1], sh); + } + + snprintf(buf, sizeof(buf), "%s/images/bubble.png", PACKAGE_DATA_DIR); + for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) + { + bub = evas_object_image_filled_add(game.canvas); + evas_object_image_file_set(bub, buf, NULL); + evas_object_resize(bub, 64, 64); + evas_object_show(bub); + evas_object_data_set(game.bg, names[(i * 2)], bub); + } + ani = ecore_animator_add(anim, &game); + evas_object_data_set(game.bg, "animator", ani); + + // Setup our callbacks. + ecore_evas_callback_delete_request_set(game.ee, _on_delete); + edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game); + + ecore_main_loop_begin(); + + ecore_animator_del(ani); + ecore_evas_free(game.ee); + edje_shutdown(); + ecore_evas_shutdown(); + } + + return 0; +} + diff --git a/LuaSL/src/LuaSL_utilities.c b/LuaSL/src/LuaSL_utilities.c new file mode 100644 index 0000000..1675a92 --- /dev/null +++ b/LuaSL/src/LuaSL_utilities.c @@ -0,0 +1,101 @@ +#include "LuaSL.h" + + +// "01:03:52 01-01-1973\n\0" +# define DATE_TIME_LEN 21 + + +char dateTime[DATE_TIME_LEN]; + + +static +void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args) +{ + FILE *f = data; + char dt[DATE_TIME_LEN + 1]; + char fileTab[256], funcTab[256]; + + getDateTime(NULL, dt, NULL); + dt[19] = '\0'; + if (12 > strlen(file)) + snprintf(fileTab, sizeof(fileTab), "%s\t\t", file); + else + snprintf(fileTab, sizeof(fileTab), "%s\t", file); + snprintf(funcTab, sizeof(funcTab), "\t%s", fnc); + fprintf(f, "%s ", dt); + if (f == stderr) + eina_log_print_cb_stderr(d, level, fileTab, funcTab, line, fmt, data, args); + else if (f == stdout) + eina_log_print_cb_stdout(d, level, fileTab, funcTab, line, fmt, data, args); + fflush(f); +} + +void loggingStartup(gameGlobals *game) +{ + game->logDom = eina_log_domain_register("LuaSL", NULL); + if (game->logDom < 0) + { + EINA_LOG_CRIT("could not register log domain 'LuaSL'"); + } + // TODO - should unregister this later. + eina_log_level_set(EINA_LOG_LEVEL_DBG); + eina_log_domain_level_set("LuaSL", EINA_LOG_LEVEL_DBG); +// TODO - use a different domain for those things we need to log for legal reasons. +// Setup a callback that calls both the usual stderr callback AND the file one, +// but sending ggg domain messages to one file, and legal ones to another. +// Don't bother sending the ggg ones to the file if we are not embedded, we can see them on the terminal. + eina_log_print_cb_set(_ggg_log_print_cb, stderr); +} + +char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) +{ + struct tm *newTime; + time_t szClock; + char *date = dateTime; + + // Get time in seconds + time(&szClock); + // Convert time to struct tm form + newTime = localtime(&szClock); + + if (nowOut) + *nowOut = newTime; + if (dateOut) + date = dateOut; + if (timeOut) + *timeOut = szClock; + + // format + strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); + return (dateTime); +} + +float timeDiff(struct timeval *now, struct timeval *then) +{ + if (0 == gettimeofday(now, 0)) + { + struct timeval thisTime = { 0, 0 }; + double result = 0.0; + +//fprintf(stderr, " %ld . %ld\n", now->tv_sec, now->tv_usec); +//fprintf(stderr, "minus %ld . %ld\n", then->tv_sec, then->tv_usec); + + thisTime.tv_sec = now->tv_sec; + thisTime.tv_usec = now->tv_usec; + if (thisTime.tv_usec < then->tv_usec) + { + thisTime.tv_sec--; + thisTime.tv_usec += 1000000; + } + thisTime.tv_usec -= then->tv_usec; + thisTime.tv_sec -= then->tv_sec; + result = ((double) thisTime.tv_usec) / ((double) 1000000.0); + result += thisTime.tv_sec; +//fprintf(stderr, "equals %lf\n", result); +//fflush(stderr); + return result; + } + else + return 0.0; +} + diff --git a/LuaSL/src/fonts/Vera.ttf b/LuaSL/src/fonts/Vera.ttf new file mode 100644 index 0000000..58cd6b5 Binary files /dev/null and b/LuaSL/src/fonts/Vera.ttf differ diff --git a/LuaSL/src/images/bubble.png b/LuaSL/src/images/bubble.png new file mode 100644 index 0000000..8fc50f9 Binary files /dev/null and b/LuaSL/src/images/bubble.png differ diff --git a/LuaSL/src/images/bubble_sh.png b/LuaSL/src/images/bubble_sh.png new file mode 100644 index 0000000..b66c1e6 Binary files /dev/null and b/LuaSL/src/images/bubble_sh.png differ diff --git a/LuaSL/src/images/test.png b/LuaSL/src/images/test.png new file mode 100644 index 0000000..fb620d7 Binary files /dev/null and b/LuaSL/src/images/test.png differ -- cgit v1.1