Skip to content

Commit

Permalink
[core] Add getScale() to TextureRegion, and add a parameter to get @1
Browse files Browse the repository at this point in the history
sizes from getRegion()
  • Loading branch information
hgy29 committed Aug 2, 2018
1 parent c0d6668 commit a42774a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
7 changes: 7 additions & 0 deletions docsrc/TextureRegion.xml
Expand Up @@ -43,6 +43,7 @@ Returns the coordinates of the region.<br />
If transparent areas were trimmed during texture pack export, also reports the amount trimmed.
<br />
]]>
<parameter name="baseCoordiniates" optional="true" type="boolean"><![CDATA[Returns values in base (@1) size]]></parameter>
<return type="number"><![CDATA[x coordinate from texture]]></return>
<return type="number"><![CDATA[y coordinate from texture]]></return>
<return type="number"><![CDATA[width of region]]></return>
Expand All @@ -52,6 +53,12 @@ If transparent areas were trimmed during texture pack export, also reports the a
<return type="number"><![CDATA[right trim]]></return>
<return type="number"><![CDATA[bottom trim]]></return>
</method>
<method name="TextureRegion:getScale" page="getScale" shortdesc="returns the scale ratio of the underlying atlas" version="Gideros 2018.6.3"><![CDATA[<br />
Returns the scale factor of the underlying atlas
<br />
]]>
<return type="number"><![CDATA[scale]]></return>
</method>
<example name=""><![CDATA[local texture = Texture.new(&quot;atlas.png&quot;)<br />
<br />
-- define 4 equal regions of size 100x100 from &quot;atlas.png&quot;<br />
Expand Down
44 changes: 36 additions & 8 deletions luabinding/bitmapdatabinder.cpp
Expand Up @@ -10,6 +10,7 @@ BitmapDataBinder::BitmapDataBinder(lua_State* L)
static const luaL_Reg functionList[] = {
{"setRegion", setRegion},
{"getRegion", getRegion},
{"getScale", getScale},
{NULL, NULL},
};

Expand Down Expand Up @@ -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<BitmapData*>(binder.getInstance("TextureRegion", 1));

TextureBase *t=bitmapData->texture();
lua_pushnumber(L,t?t->data->scale:1);

return 1;
}
1 change: 1 addition & 0 deletions luabinding/bitmapdatabinder.h
Expand Up @@ -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

0 comments on commit a42774a

Please sign in to comment.