From a7ac9e12a08f70ae0d16a447658042acb8712067 Mon Sep 17 00:00:00 2001 From: motoschifo Date: Sat, 12 Mar 2016 14:52:37 +0100 Subject: Update luaengine.cpp --- src/emu/luaengine.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/emu/luaengine.cpp') diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index 4ffee509693..884284d7c3c 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -838,6 +838,43 @@ int lua_engine::lua_screen::l_width(lua_State *L) return 1; } +//------------------------------------------------- +// screen_orientation - return screen orientation degrees (0, 90, 180, 270) +// -> manager:machine().screens[":screen"]:rotate() +//------------------------------------------------- + +int lua_engine::lua_screen::l_rotate(lua_State *L) +{ + switch (luaThis->machine().system().flags & ORIENTATION_MASK) + { + case ORIENTATION_FLIP_X: + lua_pushunsigned(L, 0); + break; + case ORIENTATION_FLIP_Y: + lua_pushunsigned(L, 180); + break; + case ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y: + lua_pushunsigned(L, 180); + break; + case ORIENTATION_SWAP_XY: + lua_pushunsigned(L, 90); + break; + case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X: + lua_pushunsigned(L, 90); + break; + case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y: + lua_pushunsigned(L, 270); + break; + case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y: + lua_pushunsigned(L, 270); + break; + default: + lua_pushunsigned(L, 0); + break; + } + return 1; +} + //------------------------------------------------- // screen_refresh - return screen refresh rate // -> manager:machine().screens[":screen"]:refresh() @@ -1579,6 +1616,7 @@ void lua_engine::initialize() .addCFunction ("draw_text", &lua_screen::l_draw_text) .addCFunction ("height", &lua_screen::l_height) .addCFunction ("width", &lua_screen::l_width) + .addCFunction ("rotate", &lua_screen::l_rotate) .addCFunction ("refresh", &lua_screen::l_refresh) .addCFunction ("snapshot", &lua_screen::l_snapshot) .addCFunction ("type", &lua_screen::l_type) -- cgit v1.2.3 From daa4f7044cfc13bbd771a93b5d40febc79d7f171 Mon Sep 17 00:00:00 2001 From: Michele Fochi Date: Mon, 14 Mar 2016 11:28:07 +0100 Subject: Added Lua function screen.orientation(). Return rotation_angle, flipx and flipy attributes. Example: s = manager:machine().screens[":screen"]:orientation() print (s.rotation_angle, s.flipx, s.flipy) --- src/emu/luaengine.cpp | 53 +++++++++++++++++++++++++++++++-------------------- src/emu/luaengine.h | 2 +- 2 files changed, 33 insertions(+), 22 deletions(-) (limited to 'src/emu/luaengine.cpp') diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index 884284d7c3c..fdc34ac63e2 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -838,40 +838,51 @@ int lua_engine::lua_screen::l_width(lua_State *L) return 1; } + //------------------------------------------------- -// screen_orientation - return screen orientation degrees (0, 90, 180, 270) -// -> manager:machine().screens[":screen"]:rotate() +// screen_orientation - return screen orientation +// -> manager:machine().screens[":screen"]:orientation() +// -> rotation_angle (0, 90, 180, 270) +// -> flipx (true, false) +// -> flipy (true, false) //------------------------------------------------- -int lua_engine::lua_screen::l_rotate(lua_State *L) +int lua_engine::lua_screen::l_orientation(lua_State *L) { - switch (luaThis->machine().system().flags & ORIENTATION_MASK) + UINT32 flags = (luaThis->machine().system().flags & ORIENTATION_MASK); + + int rotation_angle = 0; + switch (flags) { case ORIENTATION_FLIP_X: - lua_pushunsigned(L, 0); - break; - case ORIENTATION_FLIP_Y: - lua_pushunsigned(L, 180); - break; - case ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y: - lua_pushunsigned(L, 180); + rotation_angle = 0; break; case ORIENTATION_SWAP_XY: - lua_pushunsigned(L, 90); - break; case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X: - lua_pushunsigned(L, 90); + rotation_angle = 90; break; - case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y: - lua_pushunsigned(L, 270); + case ORIENTATION_FLIP_Y: + case ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y: + rotation_angle = 180; break; + case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y: case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y: - lua_pushunsigned(L, 270); - break; - default: - lua_pushunsigned(L, 0); + rotation_angle = 270; break; } + + lua_createtable(L, 2, 2); + lua_pushliteral(L, "rotation_angle"); + lua_pushinteger(L, rotation_angle); + + lua_settable(L, -3); + lua_pushliteral(L, "flipx"); + lua_pushboolean(L, (flags & ORIENTATION_FLIP_X)); + + lua_settable(L, -3); + lua_pushliteral(L, "flipy"); + lua_pushboolean(L, (flags & ORIENTATION_FLIP_Y)); + lua_settable(L, -3); return 1; } @@ -1616,7 +1627,7 @@ void lua_engine::initialize() .addCFunction ("draw_text", &lua_screen::l_draw_text) .addCFunction ("height", &lua_screen::l_height) .addCFunction ("width", &lua_screen::l_width) - .addCFunction ("rotate", &lua_screen::l_rotate) + .addCFunction ("orientation", &lua_screen::l_orientation) .addCFunction ("refresh", &lua_screen::l_refresh) .addCFunction ("snapshot", &lua_screen::l_snapshot) .addCFunction ("type", &lua_screen::l_type) diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h index 0098550e07c..0ec72f501d5 100644 --- a/src/emu/luaengine.h +++ b/src/emu/luaengine.h @@ -138,7 +138,7 @@ private: struct lua_screen { int l_height(lua_State *L); int l_width(lua_State *L); - int l_rotate(lua_State *L); + int l_orientation(lua_State *L); int l_refresh(lua_State *L); int l_type(lua_State *L); int l_snapshot(lua_State *L); -- cgit v1.2.3