Previous 199869 Revisions Next

r36596 Monday 16th March, 2015 at 10:42:46 UTC by Luca Bruno
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>
[src/emu]luaengine.c

trunk/src/emu/luaengine.c
r245107r245108
639639   luaL_argcheck(L, lua_isnumber(L, 7), 7, "outline color (integer) expected");
640640
641641   // retrieve all parameters
642   int sc_width = sc->visible_area().width();
643   int sc_height = sc->visible_area().height();
642644   float x1, y1, x2, y2;
643   x1 = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
644   y1 = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
645   x2 = MIN(lua_tounsigned(L, 4) / static_cast<float>(sc->visible_area().width()) , 1.0f);
646   y2 = MIN(lua_tounsigned(L, 5) / static_cast<float>(sc->visible_area().height()), 1.0f);
645   x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
646   y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
647   x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
648   y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
647649   UINT32 bgcolor = lua_tounsigned(L, 6);
648650   UINT32 fgcolor = lua_tounsigned(L, 7);
649651
r245107r245108
675677   luaL_argcheck(L, lua_isnumber(L, 6), 6, "color (integer) expected");
676678
677679   // retrieve all parameters
680   int sc_width = sc->visible_area().width();
681   int sc_height = sc->visible_area().height();
678682   float x1, y1, x2, y2;
679   x1 = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
680   y1 = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
681   x2 = MIN(lua_tounsigned(L, 4) / static_cast<float>(sc->visible_area().width()) , 1.0f);
682   y2 = MIN(lua_tounsigned(L, 5) / static_cast<float>(sc->visible_area().height()), 1.0f);
683   x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
684   y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
685   x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast<float>(sc_width);
686   y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast<float>(sc_height);
683687   UINT32 color = lua_tounsigned(L, 6);
684688
685689   // draw the line
r245107r245108
705709   luaL_argcheck(L, lua_isstring(L, 4), 4, "message (string) expected");
706710
707711   // retrieve all parameters
708   float x = MIN(lua_tounsigned(L, 2) / static_cast<float>(sc->visible_area().width()) , 1.0f);
709   float y = MIN(lua_tounsigned(L, 3) / static_cast<float>(sc->visible_area().height()), 1.0f);
712   int sc_width = sc->visible_area().width();
713   int sc_height = sc->visible_area().height();
714   float x = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast<float>(sc_width);
715   float y = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast<float>(sc_height);
710716   const char *msg = luaL_checkstring(L,4);
711717   // TODO: add optional parameters (colors, etc.)
712718

Previous 199869 Revisions Next


© 1997-2024 The MAME Team