mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-14 04:13:59 +02:00
zoom api changes: throw errors instead of returning bools, zoomEnabled takes book as arg, some small refactoring
This commit is contained in:
@@ -2292,8 +2292,10 @@ int LuaScriptInterface::renderer_zoomEnabled(lua_State * l)
|
|||||||
lua_pushboolean(l, luacon_ren->zoomEnabled);
|
lua_pushboolean(l, luacon_ren->zoomEnabled);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
luacon_ren->zoomEnabled = luaL_optint(l, 1, 0);
|
{
|
||||||
|
luaL_checktype(l, -1, LUA_TBOOLEAN);
|
||||||
|
luacon_ren->zoomEnabled = lua_toboolean(l, -1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2304,26 +2306,28 @@ int LuaScriptInterface::renderer_zoomWindowInfo(lua_State * l)
|
|||||||
ui::Point location = luacon_ren->zoomWindowPosition;
|
ui::Point location = luacon_ren->zoomWindowPosition;
|
||||||
lua_pushnumber(l, location.X);
|
lua_pushnumber(l, location.X);
|
||||||
lua_pushnumber(l, location.Y);
|
lua_pushnumber(l, location.Y);
|
||||||
lua_pushnumber(l, luacon_ren->zoomScopeSize*luacon_ren->ZFACTOR);
|
|
||||||
lua_pushnumber(l, luacon_ren->ZFACTOR);
|
lua_pushnumber(l, luacon_ren->ZFACTOR);
|
||||||
|
lua_pushnumber(l, luacon_ren->zoomScopeSize * luacon_ren->ZFACTOR);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
int x = luaL_optint(l, 1, 0);
|
int x = luaL_optint(l, 1, 0);
|
||||||
int y = luaL_optint(l, 2, 0);
|
int y = luaL_optint(l, 2, 0);
|
||||||
int f = luaL_optint(l, 3, 0);
|
int f = luaL_optint(l, 3, 0);
|
||||||
if (luacon_ren->zoomScopeSize*f + x <= XRES && luacon_ren->zoomScopeSize*f + y <= YRES && x >= 0 && y >= 0) //To prevent crash when zoom window is outside screen
|
if (f <= 0)
|
||||||
{
|
return luaL_error(l, "Zoom factor must be greater than 0");
|
||||||
|
|
||||||
|
// To prevent crash when zoom window is outside screen
|
||||||
|
if (x < 0 || y < 0 || luacon_ren->zoomScopeSize * f + x > XRES || luacon_ren->zoomScopeSize * f + y > YRES)
|
||||||
|
return luaL_error(l, "Zoom window outside of bounds");
|
||||||
|
|
||||||
luacon_ren->zoomWindowPosition = ui::Point(x, y);
|
luacon_ren->zoomWindowPosition = ui::Point(x, y);
|
||||||
luacon_ren->ZFACTOR = f;
|
luacon_ren->ZFACTOR = f;
|
||||||
lua_pushboolean(l, true);
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
lua_pushboolean(l, false);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
int LuaScriptInterface::renderer_zoomScopeInfo(lua_State * l)
|
int LuaScriptInterface::renderer_zoomScopeInfo(lua_State * l)
|
||||||
{
|
{
|
||||||
if (lua_gettop(l) == 0) {
|
if (lua_gettop(l) == 0)
|
||||||
|
{
|
||||||
ui::Point location = luacon_ren->zoomScopePosition;
|
ui::Point location = luacon_ren->zoomScopePosition;
|
||||||
lua_pushnumber(l, location.X);
|
lua_pushnumber(l, location.X);
|
||||||
lua_pushnumber(l, location.Y);
|
lua_pushnumber(l, location.Y);
|
||||||
@@ -2333,17 +2337,20 @@ int LuaScriptInterface::renderer_zoomScopeInfo(lua_State * l)
|
|||||||
int x = luaL_optint(l, 1, 0);
|
int x = luaL_optint(l, 1, 0);
|
||||||
int y = luaL_optint(l, 2, 0);
|
int y = luaL_optint(l, 2, 0);
|
||||||
int s = luaL_optint(l, 3, 0);
|
int s = luaL_optint(l, 3, 0);
|
||||||
if (luacon_ren->ZFACTOR*s + luacon_ren->zoomWindowPosition.X <= XRES && luacon_ren->ZFACTOR*s + luacon_ren->zoomWindowPosition.Y <= YRES
|
if (s <= 0)
|
||||||
&& x >= 0 && y >= 0 && x <= XRES && y <= YRES) //To prevent crash when zoom or scope window is outside screen
|
return luaL_error(l, "Zoom scope size must be greater than 0");
|
||||||
{
|
|
||||||
|
// To prevent crash when zoom or scope window is outside screen
|
||||||
|
int windowEdgeRight = luacon_ren->ZFACTOR * s + luacon_ren->zoomWindowPosition.X;
|
||||||
|
int windowEdgeBottom = luacon_ren->ZFACTOR * s + luacon_ren->zoomWindowPosition.Y;
|
||||||
|
if (x < 0 || y < 0 || x + s > XRES || y + s > YRES)
|
||||||
|
return luaL_error(l, "Zoom scope outside of bounds");
|
||||||
|
if (windowEdgeRight > XRES || windowEdgeBottom > YRES)
|
||||||
|
return luaL_error(l, "Zoom window outside of bounds");
|
||||||
|
|
||||||
luacon_ren->zoomScopePosition = ui::Point(x, y);
|
luacon_ren->zoomScopePosition = ui::Point(x, y);
|
||||||
luacon_ren->zoomScopeSize = s;
|
luacon_ren->zoomScopeSize = s;
|
||||||
lua_pushboolean(l, true);
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
lua_pushboolean(l, false);
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::initElementsAPI()
|
void LuaScriptInterface::initElementsAPI()
|
||||||
|
Reference in New Issue
Block a user