Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Jan 4, 2024
1 parent d330b95 commit d0a73ab
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 50 deletions.
27 changes: 24 additions & 3 deletions Misc/qs_pak/scripts/qimgui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local tools = qimgui.tools
local windows = qimgui.windows

function qimgui.updatetools()
local function updatetools()
for _, tool in ipairs(tools) do
local title = tool.title
local wasopen = windows[title]
Expand All @@ -25,7 +25,24 @@ local function foreachwindow(funcname)
end

function qimgui.onupdate()
foreachwindow('onupdate')
imgui.SetNextWindowPos(0, 0, imgui.constant.Cond.FirstUseEver)
imgui.Begin("Tools", nil, imgui.constant.WindowFlags.AlwaysAutoResize | imgui.constant.WindowFlags.NoResize | imgui.constant.WindowFlags.NoScrollbar | imgui.constant.WindowFlags.NoCollapse)

updatetools()

imgui.Spacing()
imgui.Separator()
imgui.Spacing()

local shouldexit = imgui.Button("Press ESC to exit")

imgui.End()

if shouldexit then
qimgui.close()
else
foreachwindow('onupdate')
end
end

function qimgui.onopen()
Expand All @@ -51,6 +68,7 @@ function qimgui.scratchpad()
local title = 'Scratchpad'

local onupdate = function (self)
-- TODO: center window via imgui.SetNextWindowPos(?, ?, 0, 0.5, 0.5)
imgui.SetNextWindowSize(320, 240)

if imgui.Begin(title) then
Expand All @@ -65,4 +83,7 @@ function qimgui.scratchpad()
return scratchpad
end

table.insert(qimgui.tools, qimgui.scratchpad())
table.insert(tools, qimgui.scratchpad())

local imguidemo = qimgui.basictool('Dear ImGui Demo', imgui.ShowDemoWindow)
table.insert(tools, imguidemo)
81 changes: 34 additions & 47 deletions Quake/ig_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ extern "C"
#include "quakedef.h"
#include "ls_common.h"

#ifndef NDEBUG
static bool ig_showdemo;
#endif // !NDEBUG

static bool ig_active;
static char ig_justactived;

Expand All @@ -53,24 +49,6 @@ static void* ig_eventuserdata;

static const char* ls_qimgui_name = "qimgui";

void LS_InitImGuiModule(lua_State* state)
{
void ImLoadBindings(lua_State* state);
ImLoadBindings(state);

// Register tables for scripted ImGui windows
lua_newtable(state);
lua_pushvalue(state, -1); // copy for lua_setfield()
lua_setglobal(state, ls_qimgui_name);
lua_createtable(state, 0, 16);
lua_setfield(state, -2, "windows");
lua_createtable(state, 0, 16);
lua_setfield(state, -2, "tools");
lua_pop(state, 1); // remove qimgui global table

LS_LoadScript(state, "scripts/qimgui.lua");
}

static void LS_CallQImGuiFunction(const char* const name)
{
lua_State* state = LS_GetState();
Expand All @@ -87,9 +65,11 @@ static void LS_CallQImGuiFunction(const char* const name)
void ImClearStack();
ImClearStack();
}
else
lua_pop(state, 1); // remove incorrect value for given function
}

lua_pop(state, 1); // remove tools table
lua_pop(state, 1); // remove qimgui table
assert(lua_gettop(state) == 0);
}

Expand Down Expand Up @@ -199,30 +179,6 @@ void IG_Update()
SDL_StartTextInput();
}

ImGui::SetNextWindowPos(ImVec2(), ImGuiCond_FirstUseEver);
ImGui::Begin("Tools", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse);

#ifdef USE_LUA_SCRIPTING
LS_CallQImGuiFunction("updatetools");
#endif // USE_LUA_SCRIPTING

#ifndef NDEBUG
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::Checkbox("Demo Window", &ig_showdemo);

if (ig_showdemo)
ImGui::ShowDemoWindow(&ig_showdemo);
#endif // !NDEBUG

ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
if (ImGui::Button("Press ESC to exit"))
IG_Close();
ImGui::End();

#ifdef USE_LUA_SCRIPTING
LS_CallQImGuiFunction("onupdate");
#endif // USE_LUA_SCRIPTING
Expand Down Expand Up @@ -268,6 +224,37 @@ qboolean IG_ProcessEvent(const SDL_Event* event)
return ImGui_ImplSDL2_ProcessEvent(event);
}


#ifdef USE_LUA_SCRIPTING

static int LS_qimgui_close(lua_State* state)
{
IG_Close();
return 0;
}

void LS_InitImGuiModule(lua_State* state)
{
void ImLoadBindings(lua_State* state);
ImLoadBindings(state);

// Register tables for scripted ImGui windows
lua_newtable(state);
lua_pushvalue(state, -1); // copy for lua_setfield()
lua_setglobal(state, ls_qimgui_name);
lua_createtable(state, 0, 16);
lua_setfield(state, -2, "windows");
lua_createtable(state, 0, 16);
lua_setfield(state, -2, "tools");
lua_pushcfunction(state, LS_qimgui_close);
lua_setfield(state, -2, "close");
lua_pop(state, 1); // remove qimgui global table

LS_LoadScript(state, "scripts/qimgui.lua");
}

#endif // USE_LUA_SCRIPTING

} // extern "C"

#endif // USE_IMGUI

0 comments on commit d0a73ab

Please sign in to comment.