summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Luca Bruno <lucab@debian.org>2015-03-09 08:43:17 +0100
committer Luca Bruno <lucab@debian.org>2015-03-16 11:42:46 +0100
commit05609ab9b1504a2ba62a6a23955590c82fd3865d (patch)
treeb4dbfc553978143df43a858a45785ccae2ab1f1d
parentb1a0e0167d8655e75275f7560958580ebce2d077 (diff)
luaengine: clip screen coordinates to screen size
Several users reported that negative coordinates are wrongly handled. This happens because we assumed using unsigned values only, while unfortunately in many real cases negative values happen when tracking objects partly off-screen. This patch makes all screen drawing methods accept unsigned values, but crop them between 0 and screen size values. Signed-off-by: Luca Bruno <lucab@debian.org>
-rw-r--r--src/emu/luaengine.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c
index 59eae3870d5..f066bdeda6d 100644
--- a/src/emu/luaengine.c
+++ b/src/emu/luaengine.c
@@ -639,11 +639,13 @@ int lua_engine::lua_screen::l_draw_box(lua_State *L)
luaL_argcheck(L, lua_isnumber(L, 7), 7, "outline color (integer) expected");
// retrieve all parameters
+ int sc_width = sc->visible_area().width();
+ int sc_height = sc->visible_area().height();
float x1, y1, x2, y2;
- x1 = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
- y1 = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
- x2 = MIN(lua_tounsigned(L, 4) / static_cast<float>(sc->visible_area().width()) , 1.0f);
- y2 = MIN(lua_tounsigned(L, 5) / static_cast<float>(sc->visible_area().height()), 1.0f);
+ x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
+ x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
+ y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
UINT32 bgcolor = lua_tounsigned(L, 6);
UINT32 fgcolor = lua_tounsigned(L, 7);
@@ -675,11 +677,13 @@ int lua_engine::lua_screen::l_draw_line(lua_State *L)
luaL_argcheck(L, lua_isnumber(L, 6), 6, "color (integer) expected");
// retrieve all parameters
+ int sc_width = sc->visible_area().width();
+ int sc_height = sc->visible_area().height();
float x1, y1, x2, y2;
- x1 = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
- y1 = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
- x2 = MIN(lua_tounsigned(L, 4) / static_cast<float>(sc->visible_area().width()) , 1.0f);
- y2 = MIN(lua_tounsigned(L, 5) / static_cast<float>(sc->visible_area().height()), 1.0f);
+ x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
+ x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
+ y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
UINT32 color = lua_tounsigned(L, 6);
// draw the line
@@ -705,8 +709,10 @@ int lua_engine::lua_screen::l_draw_text(lua_State *L)
luaL_argcheck(L, lua_isstring(L, 4), 4, "message (string) expected");
// retrieve all parameters
- float x = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
- float y = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
+ int sc_width = sc->visible_area().width();
+ int sc_height = sc->visible_area().height();
+ float x = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
+ float y = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
const char *msg = luaL_checkstring(L,4);
// TODO: add optional parameters (colors, etc.)