summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Olivier Galibert <galibert@pobox.com>2015-03-24 10:14:32 +0100
committer Olivier Galibert <galibert@pobox.com>2015-03-24 10:14:32 +0100
commit1e09899b01151de732552bc8b093cba0e5fc64f2 (patch)
tree8b29ee68fd6d8d24cbb5dbd4c4169884647e3553 /src
parentd044c6b161757d93eb9575774bd131b5bb2a8214 (diff)
parent1fa8b4ea4febee62516ea45a57568d0274cbd09a (diff)
Merge pull request #148 from lucab/lucab/mame-lua/misc
luaengine: screen drawing fixes and initial docs
Diffstat (limited to 'src')
-rw-r--r--src/emu/luaengine.c26
-rw-r--r--src/emu/render.c39
-rw-r--r--src/emu/render.h2
-rw-r--r--src/emu/ui/ui.c4
4 files changed, 46 insertions, 25 deletions
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c
index 256fa460be6..c8bb21eedc3 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.)
diff --git a/src/emu/render.c b/src/emu/render.c
index 2eed9176550..46ae77e8909 100644
--- a/src/emu/render.c
+++ b/src/emu/render.c
@@ -2483,26 +2483,41 @@ render_target *render_manager::target_by_index(int index) const
// fonts
//-------------------------------------------------
-float render_manager::ui_aspect()
+float render_manager::ui_aspect(render_container *rc)
{
- int orient = orientation_add(m_ui_target->orientation(), m_ui_container->orientation());
+ int orient = 0;
+ float aspect = 1.0f;
- // based on the orientation of the target, compute height/width or width/height
- float aspect;
- if (!(orient & ORIENTATION_SWAP_XY))
- aspect = (float)m_ui_target->height() / (float)m_ui_target->width();
- else
- aspect = (float)m_ui_target->width() / (float)m_ui_target->height();
+ if (rc == m_ui_container || rc == NULL) {
+ // ui container, aggregated multi-screen target
- // if we have a valid pixel aspect, apply that and return
- if (m_ui_target->pixel_aspect() != 0.0f)
- return aspect / m_ui_target->pixel_aspect();
+ orient = orientation_add(m_ui_target->orientation(), m_ui_container->orientation());
+ // based on the orientation of the target, compute height/width or width/height
+ if (!(orient & ORIENTATION_SWAP_XY))
+ aspect = (float)m_ui_target->height() / (float)m_ui_target->width();
+ else
+ aspect = (float)m_ui_target->width() / (float)m_ui_target->height();
+
+ // if we have a valid pixel aspect, apply that and return
+ if (m_ui_target->pixel_aspect() != 0.0f)
+ return (aspect / m_ui_target->pixel_aspect());
+ } else {
+ // single screen container
+
+ orient = rc->orientation();
+ // based on the orientation of the target, compute height/width or width/height
+ if (!(orient & ORIENTATION_SWAP_XY))
+ aspect = (float)rc->screen()->visible_area().height() / (float)rc->screen()->visible_area().width();
+ else
+ aspect = (float)rc->screen()->visible_area().width() / (float)rc->screen()->visible_area().height();
+ }
- // if not, clamp for extreme proportions
+ // clamp for extreme proportions
if (aspect < 0.66f)
aspect = 0.66f;
if (aspect > 1.5f)
aspect = 1.5f;
+
return aspect;
}
diff --git a/src/emu/render.h b/src/emu/render.h
index 2ee8e108a09..bf058258577 100644
--- a/src/emu/render.h
+++ b/src/emu/render.h
@@ -744,7 +744,7 @@ public:
// UI targets
render_target &ui_target() const { assert(m_ui_target != NULL); return *m_ui_target; }
void set_ui_target(render_target &target) { m_ui_target = &target; }
- float ui_aspect();
+ float ui_aspect(render_container *rc = NULL);
// UI containers
render_container &ui_container() const { assert(m_ui_container != NULL); return *m_ui_container; }
diff --git a/src/emu/ui/ui.c b/src/emu/ui/ui.c
index 664775f2b1b..b968937cbea 100644
--- a/src/emu/ui/ui.c
+++ b/src/emu/ui/ui.c
@@ -456,7 +456,7 @@ void ui_manager::update_and_render(render_container *container)
{
float mouse_y=-1,mouse_x=-1;
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, *container, mouse_x, mouse_y)) {
- container->add_quad(mouse_x,mouse_y,mouse_x + 0.05*container->manager().ui_aspect(),mouse_y + 0.05,UI_TEXT_COLOR,m_mouse_arrow_texture,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
+ container->add_quad(mouse_x,mouse_y,mouse_x + 0.05*container->manager().ui_aspect(container),mouse_y + 0.05,UI_TEXT_COLOR,m_mouse_arrow_texture,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
}
}
}
@@ -600,7 +600,7 @@ void ui_manager::draw_text_full(render_container *container, const char *origs,
const char *linestart;
float cury = y;
float maxwidth = 0;
- float aspect = machine().render().ui_aspect();
+ float aspect = machine().render().ui_aspect(container);
// if we don't want wrapping, guarantee a huge wrapwidth
if (wrap == WRAP_NEVER)