From 01c6d05775e9a1ae2695185678bd9c65046533d0 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 25 Mar 2015 17:55:56 -0400 Subject: [PATCH] Add custom enabler::zoom_display() method (screen.zoom in Lua) --- library/LuaApi.cpp | 19 +++++++++++++++++++ library/include/df/custom/enabler.methods.inc | 6 ++++++ 2 files changed, 25 insertions(+) create mode 100644 library/include/df/custom/enabler.methods.inc diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index eb567e1f7..9af7ed563 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -86,6 +86,7 @@ distribution. #include "df/unit_misc_trait.h" #include "df/proj_itemst.h" #include "df/itemdef.h" +#include "df/enabler.h" #include #include @@ -2013,6 +2014,23 @@ static int screen_charToKey(lua_State *L) return 1; } +static int screen_zoom(lua_State *L) +{ + using df::global::enabler; + df::zoom_commands cmd = (df::zoom_commands)luaL_checkint(L, 1); + if (cmd < df::enum_traits::first_item_value || + cmd > df::enum_traits::last_item_value) + { + luaL_error(L, "Invalid zoom command: %d", cmd); + } + if (!enabler) + { + luaL_error(L, "enabler unavailable"); + } + enabler->zoom_display(cmd); + return 0; +} + } static const luaL_Reg dfhack_screen_funcs[] = { @@ -2029,6 +2047,7 @@ static const luaL_Reg dfhack_screen_funcs[] = { { "_doSimulateInput", screen_doSimulateInput }, { "keyToChar", screen_keyToChar }, { "charToKey", screen_charToKey }, + { "zoom", screen_zoom }, { NULL, NULL } }; diff --git a/library/include/df/custom/enabler.methods.inc b/library/include/df/custom/enabler.methods.inc new file mode 100644 index 000000000..26a23a4dd --- /dev/null +++ b/library/include/df/custom/enabler.methods.inc @@ -0,0 +1,6 @@ +void zoom_display(df::zoom_commands command) { + SDL_SemWait(async_zoom.sem); + async_zoom.queue.push_back(command); + SDL_SemPost(async_zoom.sem); + SDL_SemPost(async_zoom.sem_fill); +}