On Tue, 1 Nov 2011 00:14:08 +1000 David Seikel <[email protected]> wrote:
> On Mon, 31 Oct 2011 15:09:33 +1000 David Seikel <[email protected]> > wrote: > > > So try this one instead. It works. B-) > > Now here is a patch for text_class, it includes the last one. Spent so much time writing that, I forgot to actually attach the patch. lol -- A big old stinking pile of genius that no one wants coz there are too many silver coated monkeys in the world.
Index: ChangeLog
===================================================================
--- ChangeLog (revision 64519)
+++ ChangeLog (working copy)
@@ -175,3 +175,12 @@
2011-10-03 Tom Hacohen (TAsn)
* Entry: Added change information to entry,changed,user
+
+2011-10-30 David Seikel (onefang)
+
+ * Lua: Added color_class function.
+
+2011-10-31 David Seikel (onefang)
+
+ * Lua: Added text_class function.
+
Index: src/lib/edje_lua2.c
===================================================================
--- src/lib/edje_lua2.c (revision 64519)
+++ src/lib/edje_lua2.c (working copy)
@@ -84,6 +84,9 @@
static int _elua_objsize(lua_State *L);
static int _elua_objgeom(lua_State *L);
+static int _elua_color_class(lua_State *L);
+static int _elua_text_class(lua_State *L);
+
static int _elua_show(lua_State *L);
static int _elua_hide(lua_State *L);
static int _elua_visible(lua_State *L);
@@ -172,8 +175,9 @@
{"size", _elua_objsize}, // get while edje object pos in canvas
{"geom", _elua_objgeom}, // get while edje object geometry in canvas
- // FIXME: query color classes
- // FIXME: query text classes
+ // set and query color / text class
+ {"color_class", _elua_color_class},
+ {"text_class", _elua_text_class},
{"rect", _elua_rect}, // new rect
// FIXME: need image(filled, normal), text, textblock, edje
@@ -1213,6 +1217,63 @@
return n;
}
+// FIXME: Should have separate functions for each lua type, instead of these multi argument style ones.
+static int
+_elua_str_int_get(lua_State *L, int i, Eina_Bool tr,
+ const char *n1, char **v1,
+ const char *n2, int *v2
+ )
+{
+ int n = 0;
+
+ if (lua_istable(L, i))
+ {
+ lua_getfield(L, i, n1);
+ if (lua_isnil(L, -1))
+ {
+ lua_pop(L, 1);
+ lua_rawgeti(L, i, 1);
+ lua_rawgeti(L, i, 2);
+ }
+ else
+ lua_getfield(L, i, n2);
+ if ((!lua_isnil(L, -1)) && (!lua_isnil(L, -2)))
+ {
+ size_t len;
+ const char *temp = lua_tolstring(L, -2, &len);
+
+ len++; // Cater for the null at the end.
+ *v1 = malloc(len);
+ if (*v1)
+ {
+ memcpy(*v1, temp, len);
+ *v2 = lua_tointeger(L, -1);
+ n = 1;
+ }
+ }
+ if (tr) lua_settop(L, i);
+ }
+ else
+ {
+ if ((lua_isstring(L, i + 0)) && (lua_isnumber(L, i + 1)))
+ {
+ size_t len;
+ const char *temp = lua_tolstring(L, i + 0, &len);
+
+ len++; // Cater for the null at the end.
+ *v1 = malloc(len);
+ if (*v1)
+ {
+ memcpy(*v1, temp, len);
+ *v2 = lua_tointeger(L, i + 1);
+ n = 2;
+ }
+ }
+ if (tr) lua_newtable(L);
+ }
+ return n;
+}
+
/* XXX: not used
static int
_elua_3_int_get(lua_State *L, int i, Eina_Bool tr,
@@ -1327,6 +1388,14 @@
}
static void
+_elua_str_ret(lua_State *L, const char *n, const char *v)
+{
+ lua_pushstring(L, n);
+ lua_pushstring(L, v);
+ lua_settable(L, -3);
+}
+
+static void
_elua_color_fix(int *r, int *g, int *b, int *a)
{
if (*r > *a) *r = *a;
@@ -1338,6 +1407,65 @@
//-------------
static int
+_elua_color_class(lua_State *L)
+{
+ Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);
+ Edje_Color_Class *c_class;
+ const char *class = luaL_checkstring(L, 1);
+ int r, g, b, a;
+
+ if (!class) return 0;
+
+ if (_elua_4_int_get(L, 2, EINA_TRUE, "r", &r, "g", &g, "b", &b, "a", &a) > 0)
+ {
+ _elua_color_fix(&r, &g, &b, &a);
+ // This is the way that embryo does it -
+ //edje_object_color_class_set(ed->obj, class, r, g, b, a, r, g, b, a, r, g, b, a);
+ // But that deals with object scope, which is currently useless in lua,
+ // since we have no objects that can use color_class yet.
+ // So we do it at global scope instead.
+ // LATER - Should do both?
+ edje_color_class_set(class, r, g, b, a, r, g, b, a, r, g, b, a);
+ }
+
+ c_class = _edje_color_class_find(ed, class);
+ if (!c_class) return 0;
+
+ _elua_int_ret(L, "r", c_class->r);
+ _elua_int_ret(L, "g", c_class->g);
+ _elua_int_ret(L, "b", c_class->b);
+ _elua_int_ret(L, "a", c_class->a);
+ return 1;
+}
+
+static int
+_elua_text_class(lua_State *L)
+{
+ Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);
+ Edje_Text_Class *t_class;
+ const char *class = luaL_checkstring(L, 1);
+ char *font = NULL;
+ Evas_Font_Size size = 0;
+
+ if (!class) return 0;
+
+ // Just like color_class above, this does things differently from embryo,
+ // for the same reason.
+ if (_elua_str_int_get(L, 2, EINA_TRUE, "font", &font, "size", &size) > 0)
+ edje_text_class_set(class, font, size);
+
+ t_class = _edje_text_class_find(ed, class);
+ if (!t_class) return 0;
+
+ _elua_str_ret(L, "font", t_class->font);
+ _elua_int_ret(L, "size", t_class->size);
+ return 1;
+}
+
+//-------------
+//-------------
+
+static int
_elua_show(lua_State *L)
{
Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);
Index: src/examples/lua_script.edc
===================================================================
--- src/examples/lua_script.edc (revision 64519)
+++ src/examples/lua_script.edc (working copy)
@@ -1,3 +1,7 @@
+color_classes {
+ color_class { name: "test_colour"; color: 255 255 0 255; }
+}
+
collections {
group { name: "example";
lua_script_only: 1;
@@ -110,6 +114,16 @@
--// example of deleting something
--// D.tim:del();
+
+ --// test the color_class stuff
+ colour = edje.color_class("test_colour");
+ print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
+ colour = edje.color_class("test_colour", 0, 255, 255, 128);
+ print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
+ colour = edje.color_class("test_colour", { r=32, g=64, b=128, a=255 });
+ print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
+ colour = edje.color_class("test_colour");
+ print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
--// shutdown func - generally empty or not there. everything gcd for you
function shutdown ()
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Get your Android app more play: Bring it to the BlackBerry PlayBook in minutes. BlackBerry App World™ now supports Android™ Apps for the BlackBerry® PlayBook™. Discover just how easy and simple it is! http://p.sf.net/sfu/android-dev2dev
_______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
