lua/wrappers/gfx/lua_asset.cpp
/**
	 * Sets the texture window rectangle for this asset from a table.
	 * Each value should be treated like a pixel coordinate.
	 * This function will fail if a texture has not been set onto the asset.
	 * We may lift this restriction in future if it is required.
	 *
	 * The table is expected to have the values for "left_x", "right_x", "top_y" and "bottom_y".
	 * If these values are not defined, left_x and top_y default to 0 and right_x and bottom_y will default to the texture width.
	 * 
	 * @param table values A table of values defining the texture window in pixel coordinates.
	 * @returns am.asset This
	 */
Sets the texture window rectangle for this asset from a table.
Each value should be treated like a pixel coordinate.
This function will fail if a texture has not been set onto the asset.
We may lift this restriction in future if it is required.



@param table values A table of values defining the texture window in pixel coordinates.
Sets the texture window rectangle for this asset from a table . Each value should be treated like a pixel coordinate . This function will fail if a texture has not been set onto the asset . We may lift this restriction in future if it is required . @param table values A table of values defining the texture window in pixel coordinates .
int Asset_texture_window_pixel(lua_State *lua)
	{
		Asset *asset = castUData<Asset>(lua, 1);
		if (asset)
		{
			if (lua_gettop(lua) == 1)
			{
				const TextureWindow &win = asset->getTextureWindow();
				const Texture *texture = asset->getTexture();
				if (!texture)
				{
					LuaState::warning(lua, "Unable to get pixel texture coordinates from an asset that has no texture defined.");
					lua_pushnil(lua);
					return 1;
				}
				lua_createtable(lua, 0, 4);
				LuaState L(lua);
				L.setTableValue("left_x", win.getLeftX() * static_cast<float>(texture->getWidth()));
				L.setTableValue("right_x", win.getRightX() * static_cast<float>(texture->getWidth()));
				L.setTableValue("top_y", win.getTopY() * static_cast<float>(texture->getHeight()));
				L.setTableValue("bottom_y", win.getBottomY() * static_cast<float>(texture->getHeight()));
				return 1;
			}
			else if (lua_istable(lua, 2))
			{
				LuaState L(lua);
				const Texture *texture = asset->getTexture();
				if (texture)
				{
					double width = static_cast<double>(texture->getWidth()), height = static_cast<double>(texture->getHeight());
					double leftX = 0.0, rightX = width, topY = 0.0, bottomY = height;
					L.getTableDouble("left_x", leftX);
					L.getTableDouble("right_x", rightX);
					L.getTableDouble("top_y", topY);
					L.getTableDouble("bottom_y", bottomY);
					TextureWindow win;
					win.setValues(math::abs(rightX - leftX), math::abs(bottomY - topY), 
						topY / height, bottomY / height, 
						leftX / width, rightX / width);
					asset->setTextureWindow(win);
				}
				else
				{
					LuaState::warning(lua, "Unable to set pixel texture coordinates onto asset that has not texture.");
				}
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "texture_window_pixel", "table values");
		}
		return LuaState::expectedContext(lua, "texture_window_pixel", "am.asset");
	}
int Asset_texture_window_pixel ( lua_State * lua ) { Asset * asset = castUData < Asset > ( lua , 1 ) ; if ( asset ) { if ( lua_gettop ( lua ) == 1 ) { const TextureWindow & win = asset -> getTextureWindow ( ) ; const Texture * texture = asset -> getTexture ( ) ; if ( ! texture ) { LuaState :: warning ( lua , " " ) ; lua_pushnil ( lua ) ; return 1 ; } lua_createtable ( lua , 0 , 4 ) ; LuaState L ( lua ) ; L . setTableValue ( " " , win . getLeftX ( ) * static_cast < float > ( texture -> getWidth ( ) ) ) ; L . setTableValue ( " " , win . getRightX ( ) * static_cast < float > ( texture -> getWidth ( ) ) ) ; L . setTableValue ( " " , win . getTopY ( ) * static_cast < float > ( texture -> getHeight ( ) ) ) ; L . setTableValue ( " " , win . getBottomY ( ) * static_cast < float > ( texture -> getHeight ( ) ) ) ; return 1 ; } else if ( lua_istable ( lua , 2 ) ) { LuaState L ( lua ) ; const Texture * texture = asset -> getTexture ( ) ; if ( texture ) { double width = static_cast < double > ( texture -> getWidth ( ) ) , height = static_cast < double > ( texture -> getHeight ( ) ) ; double leftX = 0.0 , rightX = width , topY = 0.0 , bottomY = height ; L . getTableDouble ( " " , leftX ) ; L . getTableDouble ( " " , rightX ) ; L . getTableDouble ( " " , topY ) ; L . getTableDouble ( " " , bottomY ) ; TextureWindow win ; win . setValues ( math :: abs ( rightX - leftX ) , math :: abs ( bottomY - topY ) , topY / height , bottomY / height , leftX / width , rightX / width ) ; asset -> setTextureWindow ( win ) ; } else { LuaState :: warning ( lua , " " ) ; } lua_first ( lua ) ; } return LuaState :: expectedArgs ( lua , " " , " " ) ; } return LuaState :: expectedContext ( lua , " " , " " ) ; }
Sets the texture window rectangle for this asset from a table.
Sets the texture window rectangle for this asset from a table .