Fix up a problem with geom and friends when some external thingy moves stuff behind our backs.

This happens during startup at least and did cause problems.

Restrict image loading to images from the same edje file we are in, as per rasters request.

Some minor cleanups.

This commit fixes the last of the known problems.
So it's ready for release, except for adding docs.
I'll be adding docs over the next week anyway.


SVN revision: 65136
This commit is contained in:
David Walter Seikel 2011-11-13 17:58:11 +00:00
parent 5d07e7691f
commit 04541d0f31
2 changed files with 76 additions and 33 deletions

View File

@ -22,6 +22,7 @@ collections {
local D;
local count = 0;
local fndata = 99;
local text_geom;
local function mycb3 (v)
print("lua::callback transition " .. D.val .. " v: " .. v);
@ -138,6 +139,7 @@ collections {
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();
@ -224,28 +226,32 @@ collections {
function shutdown ()
print("lua::shutdown ... " .. D.val);
end
function show ()
print("lua::show ... " .. D.val);
end
function hide ()
print("lua::hide ... " .. D.val);
end
function move (x, y)
print("lua::move ... " .. D.val);
print(" x=" .. x .. " x=" .. y);
print("lua::move x=" .. x .. " x=" .. y);
end
function resize (w, h)
print("lua::resize ... " .. D.val);
print(" w=" .. w .. " h=" .. h);
print("lua::resize w=" .. w .. " h=" .. h);
D.text:move((w - text_geom.w) / 2, (h - text_geom.h) / 8);
end
function message (id, type, v1, v2)
print("lua::message ... " .. D.val);
print(" id=" .. id .. " type=" .. type);
print("lua::message id=" .. id .. " type=" .. type);
--// handle your message type here. check id + type then use v1
--// and/or v2 (or neither) appropriately. they are the same as
--// the 2nd and 3rd param passed to edje.messagesend() (if any
--// are passed at all)
end
function signal (sig, src)
print("lua::signal sig= " .. sig .. " src= " .. src);
end
@ -265,7 +271,7 @@ collections {
row = { };
for j = 1, bubbleCols do
image = edje.image();
image:image("bubble.png", "");
image:image("bubble.png");
image:show();
table.insert(row, image);
end
@ -273,9 +279,6 @@ collections {
end
function resize (w, h)
--// Don't ask why. lol (This should go away soon.)
bubbles[1][1]:move(12345, 12345);
for i = 1, bubbleRows do
for j = 1, bubbleCols do
w1 = w / bubbleCols;

View File

@ -953,7 +953,7 @@ _elua_animator(lua_State *L)
luaL_checkany(L, 1);
// FIXME: This, and the other two timer thingies, should be it's own class I think.
// FIXME: This, and the other two timer thingies, should be it's own class I think. But that might be API change, so wait until after the freeze.
ela = (Edje_Lua_Animator *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Animator), _elua_evas_meta);
ela->obj.free_func = _elua_animator_free;
ela->animator = ecore_animator_add(_elua_animator_cb, ela);
@ -1159,9 +1159,8 @@ static void
_elua_evas_obj_free(void *obj)
{
Edje_Lua_Evas_Object *elo = obj;
// lua_State *L;
if (!elo->obj.ed) return;
// L = elo->obj.ed->L;
evas_object_del(elo->evas_obj);
elo->evas_obj = NULL;
}
@ -1522,26 +1521,26 @@ _elua_geom(lua_State *L)
{
Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);
Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
Evas_Coord ow, oh;
Evas_Coord ox, oy, ow, oh;
int x, y, w, h;
if (!_elua_isa(obj, _elua_evas_meta)) return 0;
evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
if (_elua_scan_params(L, 2, EINA_TRUE, "%x %y %w %h", &x, &y, &w, &h) > 0)
{
if ((x != elo->x) || (y != elo->y))
if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
{
elo->x = x;
elo->y = y;
evas_object_move(elo->evas_obj,
obj->ed->x + elo->x,
obj->ed->y + elo->y);
obj->ed->x + x,
obj->ed->y + y);
}
if ((w != ow) || (h != oh))
{
evas_object_resize(elo->evas_obj, w, h);
evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
}
evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
elo->x = ox - obj->ed->x;
elo->y = oy - obj->ed->y;
}
_elua_ret(L, "%x %y %w %h", elo->x, elo->y, ow, oh);
return 1;
@ -1552,19 +1551,22 @@ _elua_move(lua_State *L)
{
Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);
Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
Evas_Coord ox, oy;
int x, y;
if (!_elua_isa(obj, _elua_evas_meta)) return 0;
evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
if (_elua_scan_params(L, 2, EINA_TRUE, "%x %y", &x, &y) > 0)
{
if ((x != elo->x) || (y != elo->y))
if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
{
elo->x = x;
elo->y = y;
evas_object_move(elo->evas_obj,
obj->ed->x + elo->x,
obj->ed->y + elo->y);
obj->ed->x + x,
obj->ed->y + y);
evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
}
elo->x = ox - obj->ed->x;
elo->y = oy - obj->ed->y;
}
_elua_ret(L, "%x %y", elo->x, elo->y);
return 1;
@ -1906,24 +1908,62 @@ _elua_image_image(lua_State *L)
Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);
Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
const char *file = NULL, *key = NULL;
int n;
int n, id = -1;
if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
n = lua_gettop(L);
if (3 == n)
n = _elua_scan_params(L, 2, EINA_TRUE, "$file $key", &file, &key);
else if (2 == n)
n = _elua_scan_params(L, 2, EINA_TRUE, "$file $key", &file, &key);
if (0 >= n)
{
file = (char *) obj->ed->file->path;
key = (char *) lua_tostring(L, 2);
n = 2;
}
if (1 < n)
{
// FIXME: Sandbox lua - Only allow access to images within the same file.
evas_object_image_file_set(elo->evas_obj, file, key);
if (obj->ed->file->image_dir)
{
Edje_Image_Directory_Entry *de;
unsigned int i;
char *name;
/* Image name */
if ((name = strrchr(key, '/'))) name++;
else name = (char *)key;
/* Loop through image directory to find if image exists */
for (i = 0; i < obj->ed->file->image_dir->entries_count; ++i)
{
de = obj->ed->file->image_dir->entries + i;
if (de->entry)
{
if (strcmp(name, de->entry) == 0)
{
char buf[32];
id = i;
// This is copied from _edje_image_recalc_apply()), dunno if it provides any benefit over sprintf().
/* Replace snprint("edje/images/%i") == memcpy + itoa */
#define IMAGES "edje/images/"
memcpy(buf, IMAGES, strlen(IMAGES));
eina_convert_itoa(id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characters. */
evas_object_image_file_set(elo->evas_obj, obj->ed->file->path, buf);
break;
}
}
}
}
/* Sandbox lua - Only allow access to images within the same edje file. I'm not so sure we need this level of sandboxing though. So leaving it here, just in case. */
if (-1 == id)
{
printf("Image %s not found in our edje file, trying external image file %s.\n", key, file);
evas_object_image_file_set(elo->evas_obj, file, key);
}
/**/
}
evas_object_image_file_get(elo->evas_obj, &file, &key);
_elua_ret(L, "$file $key", file, key);