| 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 |
| r245107 | r245108 | |
|---|---|---|
| 639 | 639 | luaL_argcheck(L, lua_isnumber(L, 7), 7, "outline color (integer) expected"); |
| 640 | 640 | |
| 641 | 641 | // retrieve all parameters |
| 642 | int sc_width = sc->visible_area().width(); | |
| 643 | int sc_height = sc->visible_area().height(); | |
| 642 | 644 | 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); | |
| 647 | 649 | UINT32 bgcolor = lua_tounsigned(L, 6); |
| 648 | 650 | UINT32 fgcolor = lua_tounsigned(L, 7); |
| 649 | 651 | |
| r245107 | r245108 | |
| 675 | 677 | luaL_argcheck(L, lua_isnumber(L, 6), 6, "color (integer) expected"); |
| 676 | 678 | |
| 677 | 679 | // retrieve all parameters |
| 680 | int sc_width = sc->visible_area().width(); | |
| 681 | int sc_height = sc->visible_area().height(); | |
| 678 | 682 | 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); | |
| 683 | 687 | UINT32 color = lua_tounsigned(L, 6); |
| 684 | 688 | |
| 685 | 689 | // draw the line |
| r245107 | r245108 | |
| 705 | 709 | luaL_argcheck(L, lua_isstring(L, 4), 4, "message (string) expected"); |
| 706 | 710 | |
| 707 | 711 | // 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); | |
| 710 | 716 | const char *msg = luaL_checkstring(L,4); |
| 711 | 717 | // TODO: add optional parameters (colors, etc.) |
| 712 | 718 |
| Previous | 199869 Revisions | Next |