Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Source/GUI/GUIInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,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;
}
}
7 changes: 7 additions & 0 deletions Source/GUI/GUIInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Source/GUI/GUITextPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Source/GUI/GUITextPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions Source/GUI/Wrappers/GUIInputWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "GUI.h"
#include "GUIInputWrapper.h"
#include "SDL3/SDL.h"
#include "WindowMan.h"
#include "FrameMan.h"
#include "UInputMan.h"
Expand Down Expand Up @@ -62,6 +63,18 @@ void GUIInputWrapper::Update() {
m_MouseY = static_cast<int>(mousePos.GetY() / static_cast<float>(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);
Expand Down
6 changes: 5 additions & 1 deletion Source/GUI/Wrappers/GUIInputWrapper.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "GUIInput.h"
#include <SDL3/SDL_scancode.h>
#include "SDL3/SDL_scancode.h"

#include <array>
#include <memory>
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 18 additions & 3 deletions Source/Managers/WindowMan.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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, &currentDisplayBounds);

m_PrimaryWindowDisplayWidth = currentDisplayBounds.w;
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -800,4 +815,4 @@ void WindowMan::Present() {
SDL_GL_SwapWindow(m_MultiDisplayWindows.at(i).get());
}
}
}
}