-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ImGui input controls for plugins (#1182)
Add bindings for ImGui input functions. This will at least let plugins do some basic input instead of checkboxes and buttons. Rearrange files for the imgui project to `inc` and `src` - will probably do this for the rest of the projects at some point too. #1129
- Loading branch information
Showing
13 changed files
with
654 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include "pch.h" | ||
#include "tables.h" | ||
|
||
namespace trview | ||
{ | ||
namespace lua | ||
{ | ||
double get_double(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
double value = lua_tonumber(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
float get_float(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
float value = lua_tonumber(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
int get_integer(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
int value = lua_tointeger(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
std::optional<double> get_optional_double(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
if (lua_isnil(L, -1)) | ||
{ | ||
lua_pop(L, 1); | ||
return std::nullopt; | ||
} | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
double value = lua_tonumber(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
std::optional<float> get_optional_float(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
if (lua_isnil(L, -1)) | ||
{ | ||
lua_pop(L, 1); | ||
return std::nullopt; | ||
} | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
float value = lua_tonumber(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
std::optional<int> get_optional_integer(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
if (lua_isnil(L, -1)) | ||
{ | ||
lua_pop(L, 1); | ||
return std::nullopt; | ||
} | ||
luaL_checktype(L, -1, LUA_TNUMBER); | ||
int value = lua_tointeger(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
std::optional<std::string> get_optional_string(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
if (lua_isnil(L, -1)) | ||
{ | ||
lua_pop(L, 1); | ||
return std::nullopt; | ||
} | ||
luaL_checktype(L, -1, LUA_TSTRING); | ||
std::string value = lua_tostring(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
std::string get_string(lua_State* L, int index, const std::string& name) | ||
{ | ||
luaL_checktype(L, index, LUA_TTABLE); | ||
lua_getfield(L, index, name.c_str()); | ||
luaL_checktype(L, -1, LUA_TSTRING); | ||
std::string value = lua_tostring(L, -1); | ||
lua_pop(L, 1); | ||
return value; | ||
} | ||
|
||
void set_enum(lua_State* L, const std::string& name, int index, const std::vector<EnumValue>& values) | ||
{ | ||
if (index < 0) | ||
{ | ||
index += lua_gettop(L) + 1; | ||
} | ||
|
||
lua_newtable(L); | ||
for (const auto& v : values) | ||
{ | ||
set_integer(L, -1, v.name.c_str(), v.value); | ||
} | ||
lua_setfield(L, index, name.c_str()); | ||
} | ||
|
||
void set_integer(lua_State* L, int index, const std::string& name, int value) | ||
{ | ||
if (index < 0) | ||
{ | ||
index += lua_gettop(L) + 1; | ||
} | ||
lua_pushinteger(L, value); | ||
lua_setfield(L, index, name.c_str()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
struct lua_State; | ||
|
||
namespace trview | ||
{ | ||
namespace lua | ||
{ | ||
double get_double(lua_State* L, int index, const std::string& name); | ||
float get_float(lua_State* L, int index, const std::string& name); | ||
int get_integer(lua_State* L, int index, const std::string& name); | ||
std::optional<double> get_optional_double(lua_State* L, int index, const std::string& name); | ||
std::optional<float> get_optional_float(lua_State* L, int index, const std::string& name); | ||
std::optional<int> get_optional_integer(lua_State* L, int index, const std::string& name); | ||
std::optional<std::string> get_optional_string(lua_State* L, int index, const std::string& name); | ||
std::string get_string(lua_State* L, int index, const std::string& name); | ||
|
||
struct EnumValue | ||
{ | ||
std::string name; | ||
int value; | ||
}; | ||
|
||
void set_enum(lua_State* L, const std::string& name, int index, const std::vector<EnumValue>& values); | ||
void set_integer(lua_State* L, int index, const std::string& name, int value); | ||
} | ||
} |
Oops, something went wrong.