mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Only enable/disable input system on open/close events
Previously we enabled/disabled the input system each frame, depending on the state of the ImGui windows. This commit changes the behavior into only enabling/disabling when the menu's are closed (either through the keyboard or the close button). I added a simple callback to ImGui::Begin which will be called when the close button on the ImGui panel is pressed and the callback pointer isn't nullptr, this was required as there was otherwise no way to determine when the close button was clicked.
This commit is contained in:
parent
44f2f87460
commit
31845425d6
@ -100,7 +100,7 @@ void CBrowser::RunFrame(void)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); nVars++;
|
||||
}
|
||||
|
||||
if (!ImGui::Begin(m_pszBrowserTitle, &m_bActivate, ImGuiWindowFlags_NoScrollbar))
|
||||
if (!ImGui::Begin(m_pszBrowserTitle, &m_bActivate, ImGuiWindowFlags_NoScrollbar, &ResetInput))
|
||||
{
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(nVars);
|
||||
|
@ -69,7 +69,6 @@ CConsole::CConsole(void)
|
||||
ImGuiWindowFlags_HorizontalScrollbar |
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar;
|
||||
|
||||
|
||||
memset(m_szInputBuf, '\0', sizeof(m_szInputBuf));
|
||||
memset(m_szWindowLabel, '\0', sizeof(m_szWindowLabel));
|
||||
snprintf(m_szSummary, sizeof(m_szSummary), "%zu history items", m_vHistory.size());
|
||||
@ -203,7 +202,7 @@ void CConsole::Think(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::DrawSurface(void)
|
||||
{
|
||||
if (!ImGui::Begin(m_pszConsoleLabel, &m_bActivate))
|
||||
if (!ImGui::Begin(m_pszConsoleLabel, &m_bActivate, ImGuiWindowFlags_None, &ResetInput))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
@ -290,13 +289,13 @@ void CConsole::DrawSurface(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-focus on window apparition.
|
||||
//ImGui::SetItemDefaultFocus();
|
||||
// Auto-focus input field on window apparition.
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
// Auto-focus previous widget.
|
||||
// Auto-focus input field if reclaim is demanded.
|
||||
if (m_bReclaimFocus)
|
||||
{
|
||||
ImGui::SetKeyboardFocusHere(-1);
|
||||
ImGui::SetKeyboardFocusHere(-1); // -1 means previous widget.
|
||||
m_bReclaimFocus = false;
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@ public:
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
extern CInputSystem* g_pInputSystem
|
||||
;
|
||||
extern CInputSystem* g_pInputSystem;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class VInputSystem : public IDetour
|
||||
{
|
||||
|
2
r5dev/thirdparty/imgui/include/imgui.h
vendored
2
r5dev/thirdparty/imgui/include/imgui.h
vendored
@ -323,7 +323,7 @@ namespace ImGui
|
||||
// BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function
|
||||
// returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.]
|
||||
// - Note that the bottom of window stack always contains a window called "Debug".
|
||||
IMGUI_API bool Begin(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0);
|
||||
IMGUI_API bool Begin(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0, void* close_callback = nullptr);
|
||||
IMGUI_API void End();
|
||||
|
||||
// Child Windows
|
||||
|
@ -2136,6 +2136,7 @@ struct IMGUI_API ImGuiWindow
|
||||
int MemoryDrawListIdxCapacity; // Backup of last idx/vtx count, so when waking up the window we can preallocate and avoid iterative alloc/copy
|
||||
int MemoryDrawListVtxCapacity;
|
||||
bool MemoryCompacted; // Set when window extraneous data have been garbage collected
|
||||
void* CloseCallback; // Callback ran when the close button is pressed.
|
||||
|
||||
public:
|
||||
ImGuiWindow(ImGuiContext* context, const char* name);
|
||||
|
9
r5dev/thirdparty/imgui/src/imgui.cpp
vendored
9
r5dev/thirdparty/imgui/src/imgui.cpp
vendored
@ -5913,8 +5913,14 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
||||
|
||||
// Close button
|
||||
if (has_close_button)
|
||||
{
|
||||
if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
|
||||
{
|
||||
*p_open = false;
|
||||
if (window->CloseCallback)
|
||||
((void(*)(void))window->CloseCallback)();
|
||||
}
|
||||
}
|
||||
|
||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
||||
g.CurrentItemFlags = item_flags_backup;
|
||||
@ -6012,7 +6018,7 @@ static ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
|
||||
// You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
|
||||
// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
|
||||
// - Passing 'bool* p_open' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
|
||||
bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags, void* close_callback)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
@ -6160,6 +6166,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0);
|
||||
window->Active = true;
|
||||
window->HasCloseButton = (p_open != NULL);
|
||||
window->CloseCallback = close_callback;
|
||||
window->ClipRect = ImVec4(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX);
|
||||
window->IDStack.resize(1);
|
||||
window->DrawList->_ResetForNewFrame();
|
||||
|
@ -29,16 +29,12 @@ typedef BOOL(WINAPI* IPostMessageA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM l
|
||||
typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
static BOOL g_bInitMenu = false;
|
||||
static BOOL g_bInitialized = false;
|
||||
static BOOL g_bPresentHooked = false;
|
||||
static BOOL g_bImGuiInitialized = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
static WNDPROC g_oWndProc = NULL;
|
||||
static HWND g_hGameWindow = NULL;
|
||||
extern DWORD g_dThreadId = NULL;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
static IPostMessageA g_oPostMessageA = NULL;
|
||||
static IPostMessageW g_oPostMessageW = NULL;
|
||||
@ -70,11 +66,13 @@ LRESULT CALLBACK HwndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
if (wParam == g_pImGuiConfig->IConsole_Config.m_nBind0 || wParam == g_pImGuiConfig->IConsole_Config.m_nBind1)
|
||||
{
|
||||
g_pConsole->m_bActivate ^= true;
|
||||
ResetInput(); // Disable input to game when console is drawn.
|
||||
}
|
||||
|
||||
if (wParam == g_pImGuiConfig->IBrowser_Config.m_nBind0 || wParam == g_pImGuiConfig->IBrowser_Config.m_nBind1)
|
||||
{
|
||||
g_pBrowser->m_bActivate ^= true;
|
||||
ResetInput(); // Disable input to game when browser is drawn.
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +219,6 @@ void GetPresent()
|
||||
pDevice->Release();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
g_bPresentHooked = true;
|
||||
}
|
||||
|
||||
//#################################################################################
|
||||
@ -254,20 +251,8 @@ void DrawImGui()
|
||||
g_pBrowser->RunTask();
|
||||
g_pConsole->RunTask();
|
||||
|
||||
if (g_pBrowser->m_bActivate)
|
||||
{
|
||||
g_pInputSystem->EnableInput(false); // Disable input to game when browser is drawn.
|
||||
g_pBrowser->RunFrame();
|
||||
}
|
||||
if (g_pConsole->m_bActivate)
|
||||
{
|
||||
g_pInputSystem->EnableInput(false); // Disable input to game when console is drawn.
|
||||
g_pConsole->RunFrame();
|
||||
}
|
||||
if (!g_pConsole->m_bActivate && !g_pBrowser->m_bActivate)
|
||||
{
|
||||
g_pInputSystem->EnableInput(true); // Enable input to game when both are not drawn.
|
||||
}
|
||||
g_pBrowser->RunFrame();
|
||||
g_pConsole->RunFrame();
|
||||
|
||||
ImGui::EndFrame();
|
||||
ImGui::Render();
|
||||
@ -353,7 +338,6 @@ HRESULT __stdcall GetResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount
|
||||
g_pConsole->m_bActivate = false;
|
||||
g_pBrowser->m_bActivate = false;
|
||||
g_bInitialized = false;
|
||||
g_bPresentHooked = false;
|
||||
|
||||
g_nWindowWidth = nWidth;
|
||||
g_nWindowHeight = nHeight;
|
||||
@ -451,6 +435,12 @@ bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView*
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResetInput()
|
||||
{
|
||||
g_pInputSystem->EnableInput( // Enables the input system when both are not drawn.
|
||||
!g_pBrowser->m_bActivate && !g_pConsole->m_bActivate);
|
||||
}
|
||||
|
||||
//#################################################################################
|
||||
// MANAGEMENT
|
||||
//#################################################################################
|
||||
@ -538,7 +528,7 @@ void DirectX_Init()
|
||||
{
|
||||
// Create a worker thread for the in-game console frontend
|
||||
DWORD __stdcall DXSwapChainWorker(LPVOID);
|
||||
HANDLE hThread = CreateThread(NULL, 0, DXSwapChainWorker, NULL, 0, &g_dThreadId);
|
||||
HANDLE hThread = CreateThread(NULL, 0, DXSwapChainWorker, NULL, 0, NULL);
|
||||
|
||||
if (hThread)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam
|
||||
extern HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT nFlags);
|
||||
//extern bool LoadTextureBuffer(unsigned char* image_data, const int& image_width, const int& image_height, ID3D11ShaderResourceView** out_srv);
|
||||
extern bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView** out_srv, int* out_width, int* out_height);
|
||||
extern void ResetInput();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Typedefs
|
||||
@ -27,7 +28,6 @@ typedef HRESULT(__stdcall* IDXGIResizeBuffers) (IDXGISwapChain* pSwapChain, UI
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Globals
|
||||
extern DWORD g_dThreadId;
|
||||
inline INT g_nWindowWidth;
|
||||
inline INT g_nWindowHeight;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user