From b6bace77bee832737f9a0f72e1a41fe0c1616f16 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 4 Jun 2025 00:34:44 +0200 Subject: [PATCH 1/3] default primary display is no longer 0! --- Source/Managers/WindowMan.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/Managers/WindowMan.cpp b/Source/Managers/WindowMan.cpp index adfa755f09..6a2772f4de 100644 --- a/Source/Managers/WindowMan.cpp +++ b/Source/Managers/WindowMan.cpp @@ -1,4 +1,7 @@ #include "WindowMan.h" +#include "RTEError.h" +#include "SDL3/SDL_error.h" +#include "SDL3/SDL_video.h" #include "SettingsMan.h" #include "FrameMan.h" #include "ActivityMan.h" @@ -96,7 +99,20 @@ void WindowMan::Destroy() { void WindowMan::Initialize() { SDL_free(SDL_GetDisplays(&m_NumDisplays)); - SDL_Rect currentDisplayBounds; + m_PrimaryWindowDisplayIndex = SDL_GetPrimaryDisplay(); + if (m_PrimaryWindowDisplayIndex == 0) { + g_ConsoleMan.PrintString("ERROR: Failed to get primary display!" + std::string(SDL_GetError())); + int count{0}; + SDL_DisplayID* displays = SDL_GetDisplays(&count); + if (displays) { + m_PrimaryWindowDisplayIndex = displays[0]; + } else { + RTEAbort("No displays detetected somehow! " + std::string(SDL_GetError())); + } + SDL_free(displays); + } + + SDL_Rect currentDisplayBounds{}; SDL_GetDisplayBounds(m_PrimaryWindowDisplayIndex, ¤tDisplayBounds); m_PrimaryWindowDisplayWidth = currentDisplayBounds.w; @@ -160,7 +176,6 @@ void WindowMan::CreatePrimaryWindow() { int windowPosX = (m_ResX * m_ResMultiplier <= m_PrimaryWindowDisplayWidth) ? SDL_WINDOWPOS_CENTERED : (m_MaxResX - (m_ResX * m_ResMultiplier)) / 2; int windowPosY = SDL_WINDOWPOS_CENTERED; - int windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; SDL_PropertiesID windowProps = SDL_CreateProperties(); RTEAssert(windowProps, "Unable to create window properties! " + std::string(SDL_GetError())); @@ -800,4 +815,4 @@ void WindowMan::Present() { SDL_GL_SwapWindow(m_MultiDisplayWindows.at(i).get()); } } -} \ No newline at end of file +} From bd009a1226602e49407612af3f1ef977a81cce04 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 4 Jun 2025 21:08:13 +0200 Subject: [PATCH 2/3] Enable text input for text input panels. Was not explicitly enabled before (which should not have worked in SDL2 either), now is explicitly enabled when text panels have focus --- Source/GUI/GUIInput.cpp | 12 ++++++++++++ Source/GUI/GUIInput.h | 7 +++++++ Source/GUI/GUITextPanel.cpp | 8 ++++++++ Source/GUI/GUITextPanel.h | 9 +++++++++ Source/GUI/Wrappers/GUIInputWrapper.cpp | 14 ++++++++++++++ Source/GUI/Wrappers/GUIInputWrapper.h | 4 ++++ 6 files changed, 54 insertions(+) diff --git a/Source/GUI/GUIInput.cpp b/Source/GUI/GUIInput.cpp index a5b1aedaf3..2c43c31ea2 100644 --- a/Source/GUI/GUIInput.cpp +++ b/Source/GUI/GUIInput.cpp @@ -1,3 +1,4 @@ +#include "GUIInput.h" #include "GUI.h" using namespace RTE; @@ -148,3 +149,14 @@ void GUIInput::Update() { int GUIInput::GetModifier() const { return m_Modifier; } + +void GUIInput::StartTextInput() { + m_TextInputActive++; +} + +void GUIInput::StopTextInput() { + m_TextInputActive--; + if (m_TextInputActive < 0) { + m_TextInputActive = 0; + } +} diff --git a/Source/GUI/GUIInput.h b/Source/GUI/GUIInput.h index f3a77efc73..415dcba4c9 100644 --- a/Source/GUI/GUIInput.h +++ b/Source/GUI/GUIInput.h @@ -122,6 +122,12 @@ namespace RTE { /// @param enableKeyJoyMouseCursor Whether the keyboard and joysticks also control the mouse or not. void SetKeyJoyMouseCursor(bool enableKeyJoyMouseCursor) { m_KeyJoyMouseCursor = enableKeyJoyMouseCursor; } + /// Enables receiving text input events. + virtual void StartTextInput(); + + /// Disables receiving text input events. + virtual void StopTextInput(); + protected: enum Constants { KEYBOARD_BUFFER_SIZE = 256 @@ -132,6 +138,7 @@ namespace RTE { unsigned char m_ScanCodeState[KEYBOARD_BUFFER_SIZE]; std::string m_TextInput; bool m_HasTextInput; + int m_TextInputActive{0}; // Mouse button states // Order: Left, Middle, Right diff --git a/Source/GUI/GUITextPanel.cpp b/Source/GUI/GUITextPanel.cpp index 706cfb9f43..e294ef3aef 100644 --- a/Source/GUI/GUITextPanel.cpp +++ b/Source/GUI/GUITextPanel.cpp @@ -140,6 +140,14 @@ void GUITextPanel::Draw(GUIScreen* Screen) { Screen->GetBitmap()->SetClipRect(nullptr); } +void GUITextPanel::OnGainFocus() { + m_Manager->GetInputController()->StartTextInput(); +} + +void GUITextPanel::OnLoseFocus() { + m_Manager->GetInputController()->StopTextInput(); +} + void GUITextPanel::OnKeyPress(int KeyCode, int Modifier) { // TODO: Figure out what the "performance bitching" is. // Condition here to stop the compiler bitching about performance diff --git a/Source/GUI/GUITextPanel.h b/Source/GUI/GUITextPanel.h index 26a3ce3172..9e9e7664b5 100644 --- a/Source/GUI/GUITextPanel.h +++ b/Source/GUI/GUITextPanel.h @@ -35,6 +35,14 @@ namespace RTE { /// @param Screen Screen class void Draw(GUIScreen* Screen) override; + /// Called when this panel gains focus. + /// Start text input events. + void OnGainFocus() override; + + /// Called when this panel loses focus. + /// Stops text input events. + void OnLoseFocus() override; + /// Called when the mouse goes down on the panel /// @param X Mouse Position, Mouse Buttons, Modifier. void OnMouseDown(int X, int Y, int Buttons, int Modifier) override; @@ -51,6 +59,7 @@ namespace RTE { /// @param KeyCode KeyCode, Modifier. void OnKeyPress(int KeyCode, int Modifier) override; + /// Called when text input is received void OnTextInput(std::string_view inputText) override; /// Sets the text in the textpanel. diff --git a/Source/GUI/Wrappers/GUIInputWrapper.cpp b/Source/GUI/Wrappers/GUIInputWrapper.cpp index e763c99780..af49d011a7 100644 --- a/Source/GUI/Wrappers/GUIInputWrapper.cpp +++ b/Source/GUI/Wrappers/GUIInputWrapper.cpp @@ -1,5 +1,7 @@ #include "GUI.h" #include "GUIInputWrapper.h" +#include "GUIInput.h" +#include "SDL3/SDL_keyboard.h" #include "WindowMan.h" #include "FrameMan.h" #include "UInputMan.h" @@ -62,6 +64,18 @@ void GUIInputWrapper::Update() { m_MouseY = static_cast(mousePos.GetY() / static_cast(g_WindowMan.GetResMultiplier())); } +void GUIInputWrapper::StartTextInput() { + GUIInput::StartTextInput(); + SDL_StartTextInput(g_WindowMan.GetWindow()); +} + +void GUIInputWrapper::StopTextInput() { + GUIInput::StopTextInput(); + if (m_TextInputActive <= 0) { + SDL_StopTextInput(g_WindowMan.GetWindow()); + } +} + void GUIInputWrapper::UpdateKeyboardInput(float keyElapsedTime) { // Clear the keyboard buffer, we need it to check for changes. memset(m_KeyboardBuffer, 0, sizeof(uint8_t) * GUIInput::Constants::KEYBOARD_BUFFER_SIZE); diff --git a/Source/GUI/Wrappers/GUIInputWrapper.h b/Source/GUI/Wrappers/GUIInputWrapper.h index caf38a6d4b..4a2390cb38 100644 --- a/Source/GUI/Wrappers/GUIInputWrapper.h +++ b/Source/GUI/Wrappers/GUIInputWrapper.h @@ -29,6 +29,10 @@ namespace RTE { #pragma region Virtual Override Methods /// Updates the input. void Update() override; + + void StartTextInput() override; + + void StopTextInput() override; #pragma endregion private: From 68063cab1fd98b80d2a95365b46cc696090941ad Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 4 Jun 2025 21:25:03 +0200 Subject: [PATCH 3/3] thanks clangd, but no --- Source/GUI/GUIInput.cpp | 1 - Source/GUI/Wrappers/GUIInputWrapper.cpp | 3 +-- Source/GUI/Wrappers/GUIInputWrapper.h | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/GUI/GUIInput.cpp b/Source/GUI/GUIInput.cpp index 2c43c31ea2..fb068ddd6f 100644 --- a/Source/GUI/GUIInput.cpp +++ b/Source/GUI/GUIInput.cpp @@ -1,4 +1,3 @@ -#include "GUIInput.h" #include "GUI.h" using namespace RTE; diff --git a/Source/GUI/Wrappers/GUIInputWrapper.cpp b/Source/GUI/Wrappers/GUIInputWrapper.cpp index af49d011a7..2faf180e97 100644 --- a/Source/GUI/Wrappers/GUIInputWrapper.cpp +++ b/Source/GUI/Wrappers/GUIInputWrapper.cpp @@ -1,7 +1,6 @@ #include "GUI.h" #include "GUIInputWrapper.h" -#include "GUIInput.h" -#include "SDL3/SDL_keyboard.h" +#include "SDL3/SDL.h" #include "WindowMan.h" #include "FrameMan.h" #include "UInputMan.h" diff --git a/Source/GUI/Wrappers/GUIInputWrapper.h b/Source/GUI/Wrappers/GUIInputWrapper.h index 4a2390cb38..712f0e9d63 100644 --- a/Source/GUI/Wrappers/GUIInputWrapper.h +++ b/Source/GUI/Wrappers/GUIInputWrapper.h @@ -1,7 +1,7 @@ #pragma once #include "GUIInput.h" -#include +#include "SDL3/SDL_scancode.h" #include #include