On Tue, 1 Nov 2011 00:14:08 +1000 David Seikel
wrote:
> On Mon, 31 Oct 2011 15:09:33 +1000 David Seikel
> 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 *)_e