From 2a0069118b20d2e2158ab507169268eed7bb14cb Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 6 Nov 2011 14:59:44 +0000 Subject: [PATCH] Half of evas map API Added to lua. The rest is commented, so you can see what the API will look like. Needs more testing, and the other half. SVN revision: 64822 --- legacy/edje/ChangeLog | 4 + legacy/edje/src/examples/lua_script.edc | 36 ++++ legacy/edje/src/lib/edje_lua2.c | 215 +++++++++++++++++++++++- 3 files changed, 252 insertions(+), 3 deletions(-) diff --git a/legacy/edje/ChangeLog b/legacy/edje/ChangeLog index 59336d813a..33a4e2663f 100644 --- a/legacy/edje/ChangeLog +++ b/legacy/edje/ChangeLog @@ -201,3 +201,7 @@ Including some handling of size changes. * White space fixes, one of the editors I use cleans those up automatically. shrugs +2011-11-06 David Seikel (onefang) + + * Lua: Added half of the evas map API. + diff --git a/legacy/edje/src/examples/lua_script.edc b/legacy/edje/src/examples/lua_script.edc index bb4008f469..4df0ed40df 100644 --- a/legacy/edje/src/examples/lua_script.edc +++ b/legacy/edje/src/examples/lua_script.edc @@ -141,6 +141,42 @@ collections { print(D.text:text()); D.text:show(); + D.map = edje.map(4); + + D.map:coord(1, 100, 200, 300); + D.coord = D.map:coord(1); + + D.map:populate(100, 200, 23, 45, 0); + D.map:populate(D.rect2); + D.map:populate(D.rect2, 0); + + D.rect2:map(map); + D.rect2:map_enable(true); + if (D.rect2:map_enable()) then + print("lua::map enabled"); + end + + D.map:rotate(45.0, 10, 20); +--// D.map:zoom(10.0, 20.0, 100, 200); + +--// D.map:rotate3d(90.0, 180.0, 45.0, 100, 200, 300); +--// D.map:perspective(100, 200, 300, 400); + +--// D.map:color(1, r, g, b, a); // set just one point to this colour. +--// D.map:color(r, g, b, a); // set all points to this colour. + +--// D.map:lighting(100, 200, 300, r, g, b, r, g, b); + +--// D.map:uv(1, 123.0, 456.0); + +--// D.rect2:map_source(D.rect); + +--// D.map:clockwise(); +--// D.map:smooth(); +--// D.map:alpha(); +--// D.map:dup(); +--// D.map:size(); --// perhaps overide the # operator? For now it's only gonna return 4 anyway. + --// example of deleting something --// D.tim:del(); diff --git a/legacy/edje/src/lib/edje_lua2.c b/legacy/edje/src/lib/edje_lua2.c index 76aeb7ed0b..dbb8ad95bd 100644 --- a/legacy/edje/src/lib/edje_lua2.c +++ b/legacy/edje/src/lib/edje_lua2.c @@ -17,6 +17,7 @@ typedef struct _Edje_Lua_Timer Edje_Lua_Timer; typedef struct _Edje_Lua_Animator Edje_Lua_Animator; typedef struct _Edje_Lua_Transition Edje_Lua_Transition; typedef struct _Edje_Lua_Evas_Object Edje_Lua_Evas_Object; +typedef struct _Edje_Lua_Map Edje_Lua_Map; //--------------------------------------------------------------------------// struct _Edje_Lua_Alloc @@ -62,6 +63,12 @@ struct _Edje_Lua_Evas_Object int x, y; }; +struct _Edje_Lua_Map +{ + Edje_Lua_Obj obj; + Evas_Map *map; +}; + //--------------------------------------------------------------------------// static int _elua_obj_gc(lua_State *L); @@ -117,6 +124,10 @@ static int _elua_text(lua_State *L); static int _elua_edje(lua_State *L); static int _elua_line(lua_State *L); static int _elua_polygon(lua_State *L); +static int _elua_map(lua_State *L); + +static int _elua_obj_map(lua_State *L); +static int _elua_obj_map_enable(lua_State *L); static int _elua_text_text(lua_State *L); static int _elua_text_font(lua_State *L); @@ -129,6 +140,10 @@ static int _elua_line_xy(lua_State *L); static int _elua_polygon_point(lua_State *L); static int _elua_polygon_clear(lua_State *L); +static int _elua_map_coord(lua_State *L); +static int _elua_map_populate(lua_State *L); +static int _elua_map_rotate(lua_State *L); + #define ELO "|-ELO" @@ -205,6 +220,7 @@ static const struct luaL_reg _elua_edje_api [] = {"edje", _elua_edje}, {"line", _elua_line}, {"polygon", _elua_polygon}, + {"map", _elua_map}, // FIXME: add the new sound stuff. {NULL, NULL} // end @@ -272,7 +288,30 @@ static const struct luaL_reg _elua_edje_evas_obj [] = // FIXME: later - set render op, anti-alias, pointer mode (autograb, nograb) // FIXME: later - - // FIXME: map api here + // map api here + {"map", _elua_obj_map}, + {"map_enable", _elua_obj_map_enable}, +// {"map_source", _elua_obj_map_source}, + + {NULL, NULL} // end +}; + +static const struct luaL_reg _elua_evas_map_obj [] = +{ + {"coord", _elua_map_coord}, + {"populate", _elua_map_populate}, + {"rotate", _elua_map_rotate}, +// {"rotate3d", _elua_map_rotate3d}, +// {"perspective", _elua_map_perspective}, +// {"zoom", _elua_map_zoom}, +// {"lighting", _elua_map_lighting}, +// {"color", _elua_map_color}, +// {"uv", _elua_map_uv}, +// {"clockwise", _elua_map_clockwise}, +// {"smooth", _elua_map_smooth}, +// {"alpha", _elua_map_alpha}, +// {"dup", _elua_map_dup}, +// {"size", _elua_map_size}, {NULL, NULL} // end }; @@ -476,7 +515,7 @@ _elua_ref_get(lua_State *L, void *key) } static Edje_Lua_Obj * -_elua_obj_new(lua_State *L, Edje *ed, int size) +_elua_obj_new_common(lua_State *L, Edje *ed, int size, const char *metatable) { Edje_Lua_Obj *obj; @@ -484,7 +523,7 @@ _elua_obj_new(lua_State *L, Edje *ed, int size) memset(obj, 0, size); ed->lua_objs = eina_inlist_append(ed->lua_objs, EINA_INLIST_GET(obj)); - luaL_getmetatable(L, "edje_evas_obj"); + luaL_getmetatable(L, metatable); lua_setmetatable(L, -2); obj->ed = ed; @@ -492,6 +531,18 @@ _elua_obj_new(lua_State *L, Edje *ed, int size) return obj; } +static Edje_Lua_Obj * +_elua_obj_new(lua_State *L, Edje *ed, int size) +{ + _elua_obj_new_common(L, ed, size, "edje_evas_obj"); +} + +static Edje_Lua_Obj * +_elua_map_new(lua_State *L, Edje *ed, int size) +{ + _elua_obj_new_common(L, ed, size, "evas_map_obj"); +} + static void _elua_obj_free(lua_State *L __UNUSED__, Edje_Lua_Obj *obj) { @@ -1972,6 +2023,40 @@ _elua_precise(lua_State *L) return 1; } +static int +_elua_obj_map(lua_State *L) +{ + Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); + Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; + Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); + Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; + if (!obj) return 0; + if (!obj->is_evas_obj) return 0; + if (!obj2) return 0; + + evas_object_map_set(elo->evas_obj, elm->map); + + return 1; +} + +static int +_elua_obj_map_enable(lua_State *L) +{ + Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); + Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj; + int n; + if (!obj) return 0; + if (!obj->is_evas_obj) return 0; + + n = lua_gettop(L); + if (n == 2) + { + evas_object_map_enable_set(elo->evas_obj, lua_toboolean(L, 2)); + } + lua_pushboolean(L, evas_object_map_enable_get(elo->evas_obj)); + return 1; +} + static int _elua_text_font(lua_State *L) { @@ -2174,6 +2259,94 @@ static int _elua_polygon_clear(lua_State *L) return 1; } +static int +_elua_map_coord(lua_State *L) +{ + Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); + Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; + Evas_Coord x, y, z; + int n; + + if (!obj) return 0; + n = lua_gettop(L); + if (2 > n) return 0; + + if (_elua_4_int_get(L, 2, EINA_TRUE, "n", &n, "x", &x, "y", &y, "z", &z) > 0) + { + evas_map_point_coord_set(elm->map, n, x, y, z); + } + else + { + n = lua_tointeger(L, 2); + evas_map_point_coord_get(elm->map, n, &x, &y, &z); + } + _elua_int_ret(L, "x", x); + _elua_int_ret(L, "y", y); + _elua_int_ret(L, "z", z); + return 1; +} + +static int +_elua_map_populate(lua_State *L) +{ + Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); + Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; + int n; + + if (!obj) return 0; + n = lua_gettop(L); + + switch (n) + { + case 2 : + { + Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); + const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2; + + evas_map_util_points_populate_from_object(elm->map, source->evas_obj); + break; + } + + case 3 : + { + Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2); + const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2; + Evas_Coord z = lua_tointeger(L, 3); + + evas_map_util_points_populate_from_object_full(elm->map, source->evas_obj, z); + break; + } + + default : + { + // FIXME: unpack 5 integers and pass them to evas_map_util_points_populate_from_geometry() + break; + } + } + return 1; +} + +static int +_elua_map_rotate(lua_State *L) +{ + Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); + Edje_Lua_Map *elm = (Edje_Lua_Map *)obj; + double degrees; + Evas_Coord x, y; + int n; + + if (!obj) return 0; + n = lua_gettop(L); + if (4 != n) return 0; + + degrees = lua_tonumber(L, 2); + if (_elua_2_int_get(L, 3, EINA_TRUE, "x", &x, "y", &y) > 0) + { + evas_map_util_rotate(elm->map, degrees, x, y); + } + return 1; +} + //------------- static void _elua_evas_obj_free(void *obj) @@ -2314,6 +2487,34 @@ _elua_polygon(lua_State *L) return 1; } +static void +_elua_map_free(void *obj) +{ + Edje_Lua_Map *elm = obj; + lua_State *L; + if (!elm->obj.ed) return; + L = elm->obj.ed->L; + evas_map_free(elm->map); + elm->map = NULL; +} + +static int +_elua_map(lua_State *L) +{ + Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key); + Edje_Lua_Map *elm; + int count; + + count = luaL_checkinteger(L, 1); + + elm = (Edje_Lua_Map *)_elua_map_new(L, ed, sizeof(Edje_Lua_Map)); + elm->obj.free_func = _elua_map_free; + elm->map = evas_map_new(count); + lua_pushvalue(L, 2); + _elua_gc(L); + return 1; +} + //------------- //--------------- //------------------- @@ -2362,6 +2563,14 @@ _edje_lua2_script_init(Edje *ed) lua_rawset(L, -3); lua_pop(L, 2); + luaL_register(L, "evas_map_obj", _elua_evas_map_obj); + luaL_newmetatable(L, "evas_map_obj"); + luaL_register(L, 0, _elua_edje_meta); + + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + // weak table for our objects lua_pushlightuserdata(L, &_elua_objs); lua_newtable(L);