diff --git a/docsrc/TextureRegion.xml b/docsrc/TextureRegion.xml
index c199a77dd..700875f52 100644
--- a/docsrc/TextureRegion.xml
+++ b/docsrc/TextureRegion.xml
@@ -43,6 +43,7 @@ Returns the coordinates of the region.
If transparent areas were trimmed during texture pack export, also reports the amount trimmed.
]]>
+
@@ -52,6 +53,12 @@ If transparent areas were trimmed during texture pack export, also reports the a
+
+Returns the scale factor of the underlying atlas
+
+]]>
+
+
-- define 4 equal regions of size 100x100 from "atlas.png"
diff --git a/luabinding/bitmapdatabinder.cpp b/luabinding/bitmapdatabinder.cpp
index d190f66c7..8ed7279e8 100644
--- a/luabinding/bitmapdatabinder.cpp
+++ b/luabinding/bitmapdatabinder.cpp
@@ -10,6 +10,7 @@ BitmapDataBinder::BitmapDataBinder(lua_State* L)
static const luaL_Reg functionList[] = {
{"setRegion", setRegion},
{"getRegion", getRegion},
+ {"getScale", getScale},
{NULL, NULL},
};
@@ -84,14 +85,41 @@ int BitmapDataBinder::getRegion(lua_State *L)
int x, y, width, height, dx1, dy1, dx2, dy2;
bitmapData->getRegion(&x, &y, &width, &height, &dx1, &dy1, &dx2, &dy2);
- lua_pushinteger(L, x);
- lua_pushinteger(L, y);
- lua_pushinteger(L, width);
- lua_pushinteger(L, height);
- lua_pushinteger(L, dx1);
- lua_pushinteger(L, dy1);
- lua_pushinteger(L, dx2);
- lua_pushinteger(L, dy2);
+ if (lua_toboolean(L,1))
+ {
+ TextureBase *t=bitmapData->texture();
+ float sc=t?(1.0/t->data->scale):1.0;
+ lua_pushnumber(L, sc*x);
+ lua_pushnumber(L, sc*y);
+ lua_pushnumber(L, sc*width);
+ lua_pushnumber(L, sc*height);
+ lua_pushnumber(L, sc*dx1);
+ lua_pushnumber(L, sc*dy1);
+ lua_pushnumber(L, sc*dx2);
+ lua_pushnumber(L, sc*dy2);
+ }
+ else {
+ lua_pushinteger(L, x);
+ lua_pushinteger(L, y);
+ lua_pushinteger(L, width);
+ lua_pushinteger(L, height);
+ lua_pushinteger(L, dx1);
+ lua_pushinteger(L, dy1);
+ lua_pushinteger(L, dx2);
+ lua_pushinteger(L, dy2);
+ }
return 8;
}
+
+int BitmapDataBinder::getScale(lua_State *L)
+{
+ Binder binder(L);
+
+ BitmapData* bitmapData = static_cast(binder.getInstance("TextureRegion", 1));
+
+ TextureBase *t=bitmapData->texture();
+ lua_pushnumber(L,t?t->data->scale:1);
+
+ return 1;
+}
diff --git a/luabinding/bitmapdatabinder.h b/luabinding/bitmapdatabinder.h
index 0e1fe5759..c7cfefdd5 100644
--- a/luabinding/bitmapdatabinder.h
+++ b/luabinding/bitmapdatabinder.h
@@ -14,6 +14,7 @@ class BitmapDataBinder
static int setRegion(lua_State *L);
static int getRegion(lua_State *L);
+ static int getScale(lua_State *L);
};
#endif