2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
|
|
|
|
#include <base/system.h>
|
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/input.h>
|
|
|
|
#include <engine/keys.h>
|
2020-09-22 16:02:03 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
//print >>f, "int inp_key_code(const char *key_name) { int i; if (!strcmp(key_name, \"-?-\")) return -1; else for (i = 0; i < 512; i++) if (!strcmp(key_strings[i], key_name)) return i; return -1; }"
|
|
|
|
|
|
|
|
// this header is protected so you don't include it from anywere
|
|
|
|
#define KEYS_INCLUDE
|
|
|
|
#include "keynames.h"
|
|
|
|
#undef KEYS_INCLUDE
|
|
|
|
|
2016-04-30 02:02:32 +00:00
|
|
|
void CInput::AddEvent(char *pText, int Key, int Flags)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
if(m_NumEvents != INPUT_BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
m_aInputEvents[m_NumEvents].m_Key = Key;
|
|
|
|
m_aInputEvents[m_NumEvents].m_Flags = Flags;
|
2016-04-30 02:02:32 +00:00
|
|
|
if(!pText)
|
|
|
|
m_aInputEvents[m_NumEvents].m_aText[0] = 0;
|
|
|
|
else
|
2020-09-06 19:54:57 +00:00
|
|
|
str_utf8_copy(m_aInputEvents[m_NumEvents].m_aText, pText, sizeof(m_aInputEvents[m_NumEvents].m_aText));
|
2016-04-30 18:11:26 +00:00
|
|
|
m_aInputEvents[m_NumEvents].m_InputCount = m_InputCounter;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_NumEvents++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CInput::CInput()
|
|
|
|
{
|
|
|
|
mem_zero(m_aInputCount, sizeof(m_aInputCount));
|
|
|
|
mem_zero(m_aInputState, sizeof(m_aInputState));
|
|
|
|
|
2016-04-30 18:11:26 +00:00
|
|
|
m_InputCounter = 1;
|
2021-10-23 11:48:21 +00:00
|
|
|
m_InputGrabbed = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
m_LastRelease = 0;
|
|
|
|
m_ReleaseDelta = -1;
|
|
|
|
|
|
|
|
m_NumEvents = 0;
|
2016-05-01 12:00:53 +00:00
|
|
|
m_MouseFocus = true;
|
2014-06-16 11:29:18 +00:00
|
|
|
|
|
|
|
m_VideoRestartNeeded = 0;
|
2015-08-26 14:35:32 +00:00
|
|
|
m_pClipboardText = NULL;
|
2016-08-15 04:01:31 +00:00
|
|
|
|
2020-10-25 15:48:12 +00:00
|
|
|
m_NumTextInputInstances = 0;
|
2020-09-22 16:01:13 +00:00
|
|
|
m_EditingTextLen = -1;
|
|
|
|
m_aEditingText[0] = 0;
|
2021-10-23 11:48:21 +00:00
|
|
|
|
|
|
|
m_LastX = 0;
|
|
|
|
m_LastY = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInput::Init()
|
|
|
|
{
|
|
|
|
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
|
2015-08-24 20:46:28 +00:00
|
|
|
|
2020-09-22 16:01:13 +00:00
|
|
|
// increase ime instance counter for menu
|
|
|
|
SetIMEState(true);
|
2015-08-24 23:48:08 +00:00
|
|
|
MouseModeRelative();
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 11:48:21 +00:00
|
|
|
void CInput::MouseRelative(float *x, float *y)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2021-10-23 11:48:21 +00:00
|
|
|
if(!m_MouseFocus || !m_InputGrabbed)
|
|
|
|
return;
|
2016-05-01 12:00:53 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int nx = 0, ny = 0;
|
2019-01-11 08:39:53 +00:00
|
|
|
float Sens = g_Config.m_InpMousesens / 100.0f;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-08-24 10:18:20 +00:00
|
|
|
#if defined(CONF_PLATFORM_ANDROID) // No relative mouse on Android
|
|
|
|
SDL_GetMouseState(&nx, &ny);
|
|
|
|
int XTmp = nx - m_LastX;
|
|
|
|
int YTmp = ny - m_LastY;
|
|
|
|
m_LastX = nx;
|
|
|
|
m_LastY = ny;
|
|
|
|
nx = XTmp;
|
|
|
|
ny = YTmp;
|
|
|
|
Sens = 1;
|
|
|
|
#else
|
2020-09-22 16:02:03 +00:00
|
|
|
SDL_GetRelativeMouseState(&nx, &ny);
|
2021-08-24 10:18:20 +00:00
|
|
|
#endif
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
*x = nx * Sens;
|
|
|
|
*y = ny * Sens;
|
2021-09-15 21:52:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 11:48:21 +00:00
|
|
|
void CInput::MouseModeAbsolute()
|
2021-09-15 21:52:09 +00:00
|
|
|
{
|
2021-10-23 11:48:21 +00:00
|
|
|
m_InputGrabbed = 0;
|
|
|
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
|
|
|
Graphics()->SetWindowGrab(false);
|
2021-09-15 21:52:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 11:48:21 +00:00
|
|
|
void CInput::MouseModeRelative()
|
2021-09-15 21:52:09 +00:00
|
|
|
{
|
2021-10-23 11:48:21 +00:00
|
|
|
m_InputGrabbed = 1;
|
|
|
|
#if !defined(CONF_PLATFORM_ANDROID) // No relative mouse on Android
|
2021-09-15 21:52:09 +00:00
|
|
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
2021-10-23 11:48:21 +00:00
|
|
|
#endif
|
2015-08-24 23:01:38 +00:00
|
|
|
Graphics()->SetWindowGrab(true);
|
2021-10-23 11:48:21 +00:00
|
|
|
// Clear pending relative mouse motion
|
2021-06-25 12:51:21 +00:00
|
|
|
SDL_GetRelativeMouseState(0x0, 0x0);
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 17:32:00 +00:00
|
|
|
void CInput::NativeMousePos(int *x, int *y) const
|
|
|
|
{
|
|
|
|
int nx = 0, ny = 0;
|
|
|
|
SDL_GetMouseState(&nx, &ny);
|
|
|
|
|
|
|
|
*x = nx;
|
|
|
|
*y = ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CInput::NativeMousePressed(int index)
|
|
|
|
{
|
|
|
|
int i = SDL_GetMouseState(NULL, NULL);
|
|
|
|
return (i & SDL_BUTTON(index)) != 0;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CInput::MouseDoubleClick()
|
|
|
|
{
|
2014-11-25 20:30:16 +00:00
|
|
|
if(m_ReleaseDelta >= 0 && m_ReleaseDelta < (time_freq() / 3))
|
2010-09-03 17:39:20 +00:00
|
|
|
{
|
|
|
|
m_LastRelease = 0;
|
|
|
|
m_ReleaseDelta = -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
const char *CInput::GetClipboardText()
|
2015-08-25 12:24:46 +00:00
|
|
|
{
|
|
|
|
if(m_pClipboardText)
|
|
|
|
{
|
2015-08-26 14:34:33 +00:00
|
|
|
SDL_free(m_pClipboardText);
|
2015-08-25 12:24:46 +00:00
|
|
|
}
|
|
|
|
m_pClipboardText = SDL_GetClipboardText();
|
|
|
|
return m_pClipboardText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInput::SetClipboardText(const char *Text)
|
|
|
|
{
|
|
|
|
SDL_SetClipboardText(Text);
|
|
|
|
}
|
|
|
|
|
2016-04-30 18:11:26 +00:00
|
|
|
void CInput::Clear()
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
mem_zero(m_aInputState, sizeof(m_aInputState));
|
|
|
|
mem_zero(m_aInputCount, sizeof(m_aInputCount));
|
2016-04-30 18:11:26 +00:00
|
|
|
m_NumEvents = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-30 18:11:26 +00:00
|
|
|
bool CInput::KeyState(int Key) const
|
2016-04-29 19:51:54 +00:00
|
|
|
{
|
2017-07-21 17:53:49 +00:00
|
|
|
if(Key < 0 || Key >= KEY_LAST)
|
|
|
|
return false;
|
|
|
|
return m_aInputState[Key];
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-30 22:18:25 +00:00
|
|
|
void CInput::NextFrame()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const Uint8 *pState = SDL_GetKeyboardState(&i);
|
|
|
|
if(i >= KEY_LAST)
|
2020-09-22 16:02:03 +00:00
|
|
|
i = KEY_LAST - 1;
|
2016-04-30 22:18:25 +00:00
|
|
|
mem_copy(m_aInputState, pState, i);
|
2020-09-22 16:01:13 +00:00
|
|
|
if(m_EditingTextLen == 0)
|
|
|
|
m_EditingTextLen = -1;
|
2016-04-30 22:18:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 05:16:06 +00:00
|
|
|
bool CInput::GetIMEState()
|
|
|
|
{
|
2020-10-25 15:48:12 +00:00
|
|
|
return m_NumTextInputInstances > 0;
|
2016-08-15 05:16:06 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:25:36 +00:00
|
|
|
void CInput::SetIMEState(bool Activate)
|
2016-08-15 04:01:31 +00:00
|
|
|
{
|
2017-07-15 13:25:36 +00:00
|
|
|
if(Activate)
|
|
|
|
{
|
2020-10-25 15:48:12 +00:00
|
|
|
if(m_NumTextInputInstances == 0)
|
2017-07-15 13:25:36 +00:00
|
|
|
SDL_StartTextInput();
|
2020-10-25 15:48:12 +00:00
|
|
|
m_NumTextInputInstances++;
|
2017-07-15 13:25:36 +00:00
|
|
|
}
|
2016-08-15 04:01:31 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-25 15:48:12 +00:00
|
|
|
if(m_NumTextInputInstances == 0)
|
2017-07-15 13:25:36 +00:00
|
|
|
return;
|
2020-10-25 15:48:12 +00:00
|
|
|
m_NumTextInputInstances--;
|
|
|
|
if(m_NumTextInputInstances == 0)
|
2017-07-15 13:25:36 +00:00
|
|
|
SDL_StopTextInput();
|
2016-08-15 04:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 15:48:12 +00:00
|
|
|
const char *CInput::GetIMEEditingText()
|
2016-08-15 04:01:31 +00:00
|
|
|
{
|
2020-09-22 16:01:13 +00:00
|
|
|
if(m_EditingTextLen > 0)
|
2017-07-26 01:58:00 +00:00
|
|
|
return m_aEditingText;
|
2016-08-15 04:01:31 +00:00
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
int CInput::GetEditingCursor()
|
|
|
|
{
|
|
|
|
return m_EditingCursor;
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:01:13 +00:00
|
|
|
void CInput::SetEditingPosition(float X, float Y)
|
|
|
|
{
|
|
|
|
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
|
|
|
int ScreenWidth = Graphics()->ScreenWidth();
|
|
|
|
int ScreenHeight = Graphics()->ScreenHeight();
|
|
|
|
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
vec2 ScreenScale = vec2(ScreenWidth / (ScreenX1 - ScreenX0), ScreenHeight / (ScreenY1 - ScreenY0));
|
2020-09-22 16:01:13 +00:00
|
|
|
|
|
|
|
SDL_Rect ImeWindowRect;
|
|
|
|
ImeWindowRect.x = X * ScreenScale.x;
|
|
|
|
ImeWindowRect.y = Y * ScreenScale.y;
|
|
|
|
ImeWindowRect.h = 60;
|
|
|
|
ImeWindowRect.w = 1000;
|
|
|
|
|
|
|
|
SDL_SetTextInputRect(&ImeWindowRect);
|
|
|
|
}
|
|
|
|
|
2010-12-11 21:04:50 +00:00
|
|
|
int CInput::Update()
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2016-04-30 18:11:26 +00:00
|
|
|
// keep the counter between 1..0xFFFF, 0 means not pressed
|
2020-09-22 16:02:03 +00:00
|
|
|
m_InputCounter = (m_InputCounter % 0xFFFF) + 1;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
// these states must always be updated manually because they are not in the GetKeyState from SDL
|
|
|
|
int i = SDL_GetMouseState(NULL, NULL);
|
2020-09-22 16:02:03 +00:00
|
|
|
if(i & SDL_BUTTON(1))
|
|
|
|
m_aInputState[KEY_MOUSE_1] = 1; // 1 is left
|
|
|
|
if(i & SDL_BUTTON(3))
|
|
|
|
m_aInputState[KEY_MOUSE_2] = 1; // 3 is right
|
|
|
|
if(i & SDL_BUTTON(2))
|
|
|
|
m_aInputState[KEY_MOUSE_3] = 1; // 2 is middle
|
|
|
|
if(i & SDL_BUTTON(4))
|
|
|
|
m_aInputState[KEY_MOUSE_4] = 1;
|
|
|
|
if(i & SDL_BUTTON(5))
|
|
|
|
m_aInputState[KEY_MOUSE_5] = 1;
|
|
|
|
if(i & SDL_BUTTON(6))
|
|
|
|
m_aInputState[KEY_MOUSE_6] = 1;
|
|
|
|
if(i & SDL_BUTTON(7))
|
|
|
|
m_aInputState[KEY_MOUSE_7] = 1;
|
|
|
|
if(i & SDL_BUTTON(8))
|
|
|
|
m_aInputState[KEY_MOUSE_8] = 1;
|
|
|
|
if(i & SDL_BUTTON(9))
|
|
|
|
m_aInputState[KEY_MOUSE_9] = 1;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SDL_Event Event;
|
2016-04-30 18:27:47 +00:00
|
|
|
bool IgnoreKeys = false;
|
2010-05-29 07:25:38 +00:00
|
|
|
while(SDL_PollEvent(&Event))
|
|
|
|
{
|
2016-04-29 19:51:54 +00:00
|
|
|
int Scancode = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
int Action = IInput::FLAG_PRESS;
|
2017-07-15 13:25:36 +00:00
|
|
|
switch(Event.type)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
case SDL_TEXTEDITING:
|
|
|
|
{
|
|
|
|
m_EditingTextLen = str_length(Event.edit.text);
|
|
|
|
if(m_EditingTextLen)
|
2016-08-15 04:01:31 +00:00
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
str_copy(m_aEditingText, Event.edit.text, sizeof(m_aEditingText));
|
|
|
|
m_EditingCursor = 0;
|
|
|
|
for(int i = 0; i < Event.edit.start; i++)
|
|
|
|
m_EditingCursor = str_utf8_forward(m_aEditingText, m_EditingCursor);
|
2016-08-15 04:01:31 +00:00
|
|
|
}
|
2020-10-25 15:48:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_aEditingText[0] = 0;
|
|
|
|
}
|
2020-09-22 16:02:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_TEXTINPUT:
|
2020-10-25 17:44:10 +00:00
|
|
|
m_EditingTextLen = -1;
|
2020-09-22 16:02:03 +00:00
|
|
|
AddEvent(Event.text.text, 0, IInput::FLAG_TEXT);
|
|
|
|
break;
|
|
|
|
// handle keys
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
// See SDL_Keymod for possible modifiers:
|
|
|
|
// NONE = 0
|
|
|
|
// LSHIFT = 1
|
|
|
|
// RSHIFT = 2
|
|
|
|
// LCTRL = 64
|
|
|
|
// RCTRL = 128
|
|
|
|
// LALT = 256
|
|
|
|
// RALT = 512
|
|
|
|
// LGUI = 1024
|
|
|
|
// RGUI = 2048
|
|
|
|
// NUM = 4096
|
|
|
|
// CAPS = 8192
|
|
|
|
// MODE = 16384
|
|
|
|
// Sum if you want to ignore multiple modifiers.
|
|
|
|
if(!(Event.key.keysym.mod & g_Config.m_InpIgnoredModifiers))
|
|
|
|
{
|
2016-04-29 19:51:54 +00:00
|
|
|
Scancode = Event.key.keysym.scancode;
|
2020-09-22 16:02:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
|
|
|
Action = IInput::FLAG_RELEASE;
|
|
|
|
Scancode = Event.key.keysym.scancode;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// handle mouse buttons
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
Action = IInput::FLAG_RELEASE;
|
|
|
|
|
|
|
|
if(Event.button.button == 1) // ignore_convention
|
|
|
|
{
|
|
|
|
m_ReleaseDelta = time_get() - m_LastRelease;
|
|
|
|
m_LastRelease = time_get();
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
// fall through
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
if(Event.button.button == SDL_BUTTON_LEFT)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_1; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == SDL_BUTTON_RIGHT)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_2; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == SDL_BUTTON_MIDDLE)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_3; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == SDL_BUTTON_X1)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_4; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == SDL_BUTTON_X2)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_5; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == 6)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_6; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == 7)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_7; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == 8)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_8; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.button.button == 9)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_9; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
if(Event.wheel.y > 0)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_WHEEL_UP; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.wheel.y < 0)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_WHEEL_DOWN; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.wheel.x > 0)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_WHEEL_LEFT; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Event.wheel.x < 0)
|
2020-10-12 14:18:06 +00:00
|
|
|
Scancode = KEY_MOUSE_WHEEL_RIGHT; // ignore_convention
|
2020-09-22 16:02:03 +00:00
|
|
|
Action |= IInput::FLAG_RELEASE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
// Ignore keys following a focus gain as they may be part of global
|
|
|
|
// shortcuts
|
|
|
|
switch(Event.window.event)
|
|
|
|
{
|
2021-08-24 16:22:31 +00:00
|
|
|
// listen to size changes, this includes our manual changes and the ones by the window manager
|
|
|
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
2021-08-21 19:41:51 +00:00
|
|
|
Graphics()->Resize(Event.window.data1, Event.window.data2, -1);
|
2010-05-29 07:25:38 +00:00
|
|
|
break;
|
2020-09-22 16:02:03 +00:00
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
2021-10-23 11:48:21 +00:00
|
|
|
if(m_InputGrabbed)
|
|
|
|
MouseModeRelative();
|
2020-09-22 16:02:03 +00:00
|
|
|
m_MouseFocus = true;
|
|
|
|
IgnoreKeys = true;
|
2015-08-24 20:46:28 +00:00
|
|
|
break;
|
2020-09-22 16:02:03 +00:00
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
m_MouseFocus = false;
|
|
|
|
IgnoreKeys = true;
|
2021-10-23 11:48:21 +00:00
|
|
|
if(m_InputGrabbed)
|
2021-04-02 20:45:49 +00:00
|
|
|
{
|
2021-10-23 11:48:21 +00:00
|
|
|
MouseModeAbsolute();
|
|
|
|
// Remember that we had relative mouse
|
|
|
|
m_InputGrabbed = true;
|
2021-04-02 20:45:49 +00:00
|
|
|
}
|
2016-04-30 01:32:23 +00:00
|
|
|
break;
|
2021-08-24 10:18:20 +00:00
|
|
|
case SDL_WINDOWEVENT_MINIMIZED:
|
|
|
|
Graphics()->WindowDestroyNtf(Event.window.windowID);
|
|
|
|
break;
|
2020-09-22 16:02:03 +00:00
|
|
|
case SDL_WINDOWEVENT_MAXIMIZED:
|
2021-10-23 11:48:21 +00:00
|
|
|
#if defined(CONF_PLATFORM_MACOS) // Todo: remove this when fixed in SDL
|
|
|
|
MouseModeAbsolute();
|
|
|
|
MouseModeRelative();
|
|
|
|
#endif
|
2021-08-24 10:18:20 +00:00
|
|
|
// fallthrough
|
|
|
|
case SDL_WINDOWEVENT_RESTORED:
|
|
|
|
Graphics()->WindowCreateNtf(Event.window.windowID);
|
|
|
|
break;
|
2020-09-22 16:02:03 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-29 22:34:12 +00:00
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
// other messages
|
|
|
|
case SDL_QUIT:
|
|
|
|
return 1;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 16:01:13 +00:00
|
|
|
if(Scancode > KEY_FIRST && Scancode < g_MaxKeys && !IgnoreKeys && (!SDL_IsTextInputActive() || m_EditingTextLen == -1))
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
if(Action & IInput::FLAG_PRESS)
|
2016-04-30 18:11:26 +00:00
|
|
|
{
|
|
|
|
m_aInputState[Scancode] = 1;
|
2017-07-21 17:53:49 +00:00
|
|
|
m_aInputCount[Scancode] = m_InputCounter;
|
2016-04-30 18:11:26 +00:00
|
|
|
}
|
2017-07-21 17:53:49 +00:00
|
|
|
AddEvent(0, Scancode, Action);
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-11 21:04:50 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 11:29:18 +00:00
|
|
|
int CInput::VideoRestartNeeded()
|
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
if(m_VideoRestartNeeded)
|
2014-06-16 11:29:18 +00:00
|
|
|
{
|
|
|
|
m_VideoRestartNeeded = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-09-22 16:02:03 +00:00
|
|
|
IEngineInput *CreateEngineInput()
|
|
|
|
{
|
|
|
|
return new CInput;
|
|
|
|
}
|