From 0d7860c6753dcaf6cc98c8395f4b4a915500c4d5 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sat, 18 Apr 2015 10:45:08 +0200 Subject: [PATCH 1/4] ui: avoid infinite loop when word-wrapping This commit fixes an infinite loop in draw_text_full(), happening when there is not enough space to draw even a single a char before trying to word-wrap. Signed-off-by: Luca Bruno --- src/emu/ui/ui.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/emu/ui/ui.c b/src/emu/ui/ui.c index 7daee1fe5d1c9..8c43d20181c2e 100644 --- a/src/emu/ui/ui.c +++ b/src/emu/ui/ui.c @@ -694,6 +694,9 @@ void ui_manager::draw_text_full(render_container *container, const char *origs, break; curwidth -= get_font()->char_width(lineheight, aspect, schar); + // if back to 0, there is no space to draw even a single char + if (curwidth <= 0) + break; } } From d1436e698aeb269e6f024bae5d78307d5258b00b Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sat, 18 Apr 2015 10:48:31 +0200 Subject: [PATCH 2/4] luaengine: accept any LUA number type as coordinate This commit fixes a type confusion bug in all draw_*() API methods. When decimal (ie. subpixels) values were passed by user scripts, they were incorrectly casted from float to plain integers, resulting in incorrect graphical artifacts. As this may happen quite often within scripts manipulating numerical values in LUA, we now also accept decimal values as coordinates. Signed-off-by: Luca Bruno --- src/emu/luaengine.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c index 12be9947caed1..98a0f1a86c9e7 100644 --- a/src/emu/luaengine.c +++ b/src/emu/luaengine.c @@ -642,10 +642,10 @@ int lua_engine::lua_screen::l_draw_box(lua_State *L) int sc_width = sc->visible_area().width(); int sc_height = sc->visible_area().height(); float x1, y1, x2, y2; - x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast(sc_width); - y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast(sc_height); - x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast(sc_width); - y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast(sc_height); + x1 = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast(sc_width); + y1 = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast(sc_height); + x2 = MIN(MAX(0, lua_tonumber(L, 4)), sc_width-1) / static_cast(sc_width); + y2 = MIN(MAX(0, lua_tonumber(L, 5)), sc_height-1) / static_cast(sc_height); UINT32 bgcolor = lua_tounsigned(L, 6); UINT32 fgcolor = lua_tounsigned(L, 7); @@ -680,10 +680,10 @@ int lua_engine::lua_screen::l_draw_line(lua_State *L) int sc_width = sc->visible_area().width(); int sc_height = sc->visible_area().height(); float x1, y1, x2, y2; - x1 = MIN(MAX(0, lua_tointeger(L, 2)), sc_width-1) / static_cast(sc_width); - y1 = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast(sc_height); - x2 = MIN(MAX(0, lua_tointeger(L, 4)), sc_width-1) / static_cast(sc_width); - y2 = MIN(MAX(0, lua_tointeger(L, 5)), sc_height-1) / static_cast(sc_height); + x1 = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast(sc_width); + y1 = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast(sc_height); + x2 = MIN(MAX(0, lua_tonumber(L, 4)), sc_width-1) / static_cast(sc_width); + y2 = MIN(MAX(0, lua_tonumber(L, 5)), sc_height-1) / static_cast(sc_height); UINT32 color = lua_tounsigned(L, 6); // draw the line @@ -711,8 +711,8 @@ int lua_engine::lua_screen::l_draw_text(lua_State *L) // retrieve all parameters 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(sc_width); - float y = MIN(MAX(0, lua_tointeger(L, 3)), sc_height-1) / static_cast(sc_height); + float x = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast(sc_width); + float y = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast(sc_height); const char *msg = luaL_checkstring(L,4); // TODO: add optional parameters (colors, etc.) From a70514fc32a89cfeca9226891a04063cb74790f4 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Mon, 20 Apr 2015 17:08:42 +0200 Subject: [PATCH 3/4] luaengine: optional text color for to draw_text() draw_text() now accepts an optional fourth parameter to specify text color, in ARGB format. Signed-off-by: Luca Bruno --- src/emu/luaengine.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c index 98a0f1a86c9e7..9084a97dc4635 100644 --- a/src/emu/luaengine.c +++ b/src/emu/luaengine.c @@ -707,6 +707,7 @@ int lua_engine::lua_screen::l_draw_text(lua_State *L) luaL_argcheck(L, lua_isnumber(L, 2), 2, "x (integer) expected"); luaL_argcheck(L, lua_isnumber(L, 3), 3, "y (integer) expected"); luaL_argcheck(L, lua_isstring(L, 4), 4, "message (string) expected"); + luaL_argcheck(L, lua_isinteger(L, 5) || lua_isnone(L, 5), 5, "optional argument: text color, integer expected (default: 0xffffffff)"); // retrieve all parameters int sc_width = sc->visible_area().width(); @@ -714,13 +715,16 @@ int lua_engine::lua_screen::l_draw_text(lua_State *L) float x = MIN(MAX(0, lua_tonumber(L, 2)), sc_width-1) / static_cast(sc_width); float y = MIN(MAX(0, lua_tonumber(L, 3)), sc_height-1) / static_cast(sc_height); const char *msg = luaL_checkstring(L,4); - // TODO: add optional parameters (colors, etc.) + rgb_t textcolor = UI_TEXT_COLOR; + if (!lua_isnone(L, 5)) { + textcolor = rgb_t(lua_tounsigned(L, 5)); + } // draw the text render_container &rc = sc->container(); ui_manager &ui = sc->machine().ui(); ui.draw_text_full(&rc, msg, x, y , (1.0f - x), - JUSTIFY_LEFT, WRAP_WORD, DRAW_NORMAL, UI_TEXT_COLOR, + JUSTIFY_LEFT, WRAP_WORD, DRAW_NORMAL, textcolor, UI_TEXT_BG_COLOR, NULL, NULL); return 0; From 87babe720a5dbdd448ec0d791d36a13fa3bea96f Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Mon, 20 Apr 2015 17:13:38 +0200 Subject: [PATCH 4/4] docs: document LUA color format and screen origin Signed-off-by: Luca Bruno --- docs/luaengine.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/luaengine.md b/docs/luaengine.md index c2f2b961492de..a17cefcdb8021 100644 --- a/docs/luaengine.md +++ b/docs/luaengine.md @@ -112,6 +112,9 @@ your hook to be called on every frame repaint: > emu.sethook(draw_hud, "frame") ``` +All colors are expected in ARGB format (32b unsigned), while screen origin (0,0) +normally corresponds to the top-left corner. + Similarly to screens, you can inspect all the devices attached to a machine: ```