Re: [E-devel] [PATCH] Edje lua color_class AND text_class functions.

2011-10-31 Thread David Seikel
On Mon, 31 Oct 2011 15:09:33 +1000 David Seikel onef...@gmail.com
wrote:

 So try this one instead.  It works.  B-)

Now here is a patch for text_class, it includes the last one.


Next I'll work on accessing edje parts in other groups, to set their
text and state at least.  Coz I need it, and coz raster said that's one
of the goals of lua script only groups.

The API I'm thinking of might look something like this -

edje.[my/group/name].my_part.state.default[1.0].text.text = Some
text.;

shown = edje.[edje/group/name].my_part.state.default[1.0].visible;

edje.[my/group/name].my_part.state:state_set(other_state, 1.0);

I've experimented with this a bit already.  There is a bit of a
problem.  The lua developers say that arrays start at one.  In reality -

Tables are associative arrays, that may have any type or value as a
key, except nil.

Tables with keys that are positive integers greater than 0 are
treated syntactically as arrays.  There are some functions that deal
with them that way.

Here's the kicker -

Tables with numeric keys that are equal to 0 only work sometimes.
Sometimes they are just keys can be anything, and work fine.  Other
times lua thinks Hey, this is an integer, and you can't have an
integer key of 0, coz arrays start at 1.  And btw, in lua 0 and 0.0
are the same.  There really is no integer type.

The reason why this is important - in the above examples of API, I used
state.default[1.0] coz state.default[0.0] or even
state.default[0] don't work.  And since edje state indexes are between
0.0, and 1.0, as well as the requirement for every part to have at
least default 0.0, we gotta deal with zeros in a language that does
not like them.  So we gotta add 1.  sigh

Might be better off just treating them like strings,
state.default[0.0].

-- 
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.


signature.asc
Description: PGP signature
--
Get your Android app more play: Bring it to the BlackBerry PlayBook 
in minutes. BlackBerry App World#153; now supports Android#153; Apps 
for the BlackBerryreg; PlayBook#153;. Discover just how easy and simple 
it is! http://p.sf.net/sfu/android-dev2dev
___
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


Re: [E-devel] [PATCH] Edje lua color_class AND text_class functions.

2011-10-31 Thread David Seikel
On Tue, 1 Nov 2011 00:14:08 +1000 David Seikel onef...@gmail.com
wrote:

 On Mon, 31 Oct 2011 15:09:33 +1000 David Seikel onef...@gmail.com
 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