Skip to content

Commit 3469103

Browse files
authored
Merge pull request #197 from cortex-command-community/fix-init-resolution
Fix init resolution check
2 parents a0f7656 + 68063ca commit 3469103

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

Source/GUI/GUIInput.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,14 @@ void GUIInput::Update() {
148148
int GUIInput::GetModifier() const {
149149
return m_Modifier;
150150
}
151+
152+
void GUIInput::StartTextInput() {
153+
m_TextInputActive++;
154+
}
155+
156+
void GUIInput::StopTextInput() {
157+
m_TextInputActive--;
158+
if (m_TextInputActive < 0) {
159+
m_TextInputActive = 0;
160+
}
161+
}

Source/GUI/GUIInput.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ namespace RTE {
122122
/// @param enableKeyJoyMouseCursor Whether the keyboard and joysticks also control the mouse or not.
123123
void SetKeyJoyMouseCursor(bool enableKeyJoyMouseCursor) { m_KeyJoyMouseCursor = enableKeyJoyMouseCursor; }
124124

125+
/// Enables receiving text input events.
126+
virtual void StartTextInput();
127+
128+
/// Disables receiving text input events.
129+
virtual void StopTextInput();
130+
125131
protected:
126132
enum Constants {
127133
KEYBOARD_BUFFER_SIZE = 256
@@ -132,6 +138,7 @@ namespace RTE {
132138
unsigned char m_ScanCodeState[KEYBOARD_BUFFER_SIZE];
133139
std::string m_TextInput;
134140
bool m_HasTextInput;
141+
int m_TextInputActive{0};
135142

136143
// Mouse button states
137144
// Order: Left, Middle, Right

Source/GUI/GUITextPanel.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ void GUITextPanel::Draw(GUIScreen* Screen) {
140140
Screen->GetBitmap()->SetClipRect(nullptr);
141141
}
142142

143+
void GUITextPanel::OnGainFocus() {
144+
m_Manager->GetInputController()->StartTextInput();
145+
}
146+
147+
void GUITextPanel::OnLoseFocus() {
148+
m_Manager->GetInputController()->StopTextInput();
149+
}
150+
143151
void GUITextPanel::OnKeyPress(int KeyCode, int Modifier) {
144152
// TODO: Figure out what the "performance bitching" is.
145153
// Condition here to stop the compiler bitching about performance

Source/GUI/GUITextPanel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ namespace RTE {
3535
/// @param Screen Screen class
3636
void Draw(GUIScreen* Screen) override;
3737

38+
/// Called when this panel gains focus.
39+
/// Start text input events.
40+
void OnGainFocus() override;
41+
42+
/// Called when this panel loses focus.
43+
/// Stops text input events.
44+
void OnLoseFocus() override;
45+
3846
/// Called when the mouse goes down on the panel
3947
/// @param X Mouse Position, Mouse Buttons, Modifier.
4048
void OnMouseDown(int X, int Y, int Buttons, int Modifier) override;
@@ -51,6 +59,7 @@ namespace RTE {
5159
/// @param KeyCode KeyCode, Modifier.
5260
void OnKeyPress(int KeyCode, int Modifier) override;
5361

62+
/// Called when text input is received
5463
void OnTextInput(std::string_view inputText) override;
5564

5665
/// Sets the text in the textpanel.

Source/GUI/Wrappers/GUIInputWrapper.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "GUI.h"
22
#include "GUIInputWrapper.h"
3+
#include "SDL3/SDL.h"
34
#include "WindowMan.h"
45
#include "FrameMan.h"
56
#include "UInputMan.h"
@@ -62,6 +63,18 @@ void GUIInputWrapper::Update() {
6263
m_MouseY = static_cast<int>(mousePos.GetY() / static_cast<float>(g_WindowMan.GetResMultiplier()));
6364
}
6465

66+
void GUIInputWrapper::StartTextInput() {
67+
GUIInput::StartTextInput();
68+
SDL_StartTextInput(g_WindowMan.GetWindow());
69+
}
70+
71+
void GUIInputWrapper::StopTextInput() {
72+
GUIInput::StopTextInput();
73+
if (m_TextInputActive <= 0) {
74+
SDL_StopTextInput(g_WindowMan.GetWindow());
75+
}
76+
}
77+
6578
void GUIInputWrapper::UpdateKeyboardInput(float keyElapsedTime) {
6679
// Clear the keyboard buffer, we need it to check for changes.
6780
memset(m_KeyboardBuffer, 0, sizeof(uint8_t) * GUIInput::Constants::KEYBOARD_BUFFER_SIZE);

Source/GUI/Wrappers/GUIInputWrapper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "GUIInput.h"
4-
#include <SDL3/SDL_scancode.h>
4+
#include "SDL3/SDL_scancode.h"
55

66
#include <array>
77
#include <memory>
@@ -29,6 +29,10 @@ namespace RTE {
2929
#pragma region Virtual Override Methods
3030
/// Updates the input.
3131
void Update() override;
32+
33+
void StartTextInput() override;
34+
35+
void StopTextInput() override;
3236
#pragma endregion
3337

3438
private:

Source/Managers/WindowMan.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "WindowMan.h"
2+
#include "RTEError.h"
3+
#include "SDL3/SDL_error.h"
4+
#include "SDL3/SDL_video.h"
25
#include "SettingsMan.h"
36
#include "FrameMan.h"
47
#include "ActivityMan.h"
@@ -96,7 +99,20 @@ void WindowMan::Destroy() {
9699
void WindowMan::Initialize() {
97100
SDL_free(SDL_GetDisplays(&m_NumDisplays));
98101

99-
SDL_Rect currentDisplayBounds;
102+
m_PrimaryWindowDisplayIndex = SDL_GetPrimaryDisplay();
103+
if (m_PrimaryWindowDisplayIndex == 0) {
104+
g_ConsoleMan.PrintString("ERROR: Failed to get primary display!" + std::string(SDL_GetError()));
105+
int count{0};
106+
SDL_DisplayID* displays = SDL_GetDisplays(&count);
107+
if (displays) {
108+
m_PrimaryWindowDisplayIndex = displays[0];
109+
} else {
110+
RTEAbort("No displays detetected somehow! " + std::string(SDL_GetError()));
111+
}
112+
SDL_free(displays);
113+
}
114+
115+
SDL_Rect currentDisplayBounds{};
100116
SDL_GetDisplayBounds(m_PrimaryWindowDisplayIndex, &currentDisplayBounds);
101117

102118
m_PrimaryWindowDisplayWidth = currentDisplayBounds.w;
@@ -160,7 +176,6 @@ void WindowMan::CreatePrimaryWindow() {
160176

161177
int windowPosX = (m_ResX * m_ResMultiplier <= m_PrimaryWindowDisplayWidth) ? SDL_WINDOWPOS_CENTERED : (m_MaxResX - (m_ResX * m_ResMultiplier)) / 2;
162178
int windowPosY = SDL_WINDOWPOS_CENTERED;
163-
int windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
164179

165180
SDL_PropertiesID windowProps = SDL_CreateProperties();
166181
RTEAssert(windowProps, "Unable to create window properties! " + std::string(SDL_GetError()));
@@ -798,4 +813,4 @@ void WindowMan::Present() {
798813
SDL_GL_SwapWindow(m_MultiDisplayWindows.at(i).get());
799814
}
800815
}
801-
}
816+
}

0 commit comments

Comments
 (0)