Extract UpdateMouseState function

This commit is contained in:
Robert Müller 2022-06-06 20:18:33 +02:00
parent 9a17617a28
commit ff43b32257
2 changed files with 27 additions and 20 deletions

View file

@ -160,6 +160,29 @@ bool CInput::KeyState(int Key) const
return m_aInputState[Key];
}
void CInput::UpdateMouseState()
{
const int MouseState = SDL_GetMouseState(NULL, NULL);
if(MouseState & SDL_BUTTON(SDL_BUTTON_LEFT))
m_aInputState[KEY_MOUSE_1] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_RIGHT))
m_aInputState[KEY_MOUSE_2] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_MIDDLE))
m_aInputState[KEY_MOUSE_3] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_X1))
m_aInputState[KEY_MOUSE_4] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_X2))
m_aInputState[KEY_MOUSE_5] = 1;
if(MouseState & SDL_BUTTON(6))
m_aInputState[KEY_MOUSE_6] = 1;
if(MouseState & SDL_BUTTON(7))
m_aInputState[KEY_MOUSE_7] = 1;
if(MouseState & SDL_BUTTON(8))
m_aInputState[KEY_MOUSE_8] = 1;
if(MouseState & SDL_BUTTON(9))
m_aInputState[KEY_MOUSE_9] = 1;
}
bool CInput::GetIMEState()
{
return m_NumTextInputInstances > 0;
@ -228,26 +251,8 @@ int CInput::Update()
if(m_EditingTextLen == 0)
m_EditingTextLen = -1;
// these states must always be updated manually because they are not in the GetKeyState from SDL
const int MouseState = SDL_GetMouseState(NULL, NULL);
if(MouseState & SDL_BUTTON(SDL_BUTTON_LEFT))
m_aInputState[KEY_MOUSE_1] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_RIGHT))
m_aInputState[KEY_MOUSE_2] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_MIDDLE))
m_aInputState[KEY_MOUSE_3] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_X1))
m_aInputState[KEY_MOUSE_4] = 1;
if(MouseState & SDL_BUTTON(SDL_BUTTON_X2))
m_aInputState[KEY_MOUSE_5] = 1;
if(MouseState & SDL_BUTTON(6))
m_aInputState[KEY_MOUSE_6] = 1;
if(MouseState & SDL_BUTTON(7))
m_aInputState[KEY_MOUSE_7] = 1;
if(MouseState & SDL_BUTTON(8))
m_aInputState[KEY_MOUSE_8] = 1;
if(MouseState & SDL_BUTTON(9))
m_aInputState[KEY_MOUSE_9] = 1;
// these states must always be updated manually because they are not in the SDL_GetKeyboardState from SDL
UpdateMouseState();
SDL_Event Event;
bool IgnoreKeys = false;

View file

@ -31,6 +31,8 @@ class CInput : public IEngineInput
unsigned char m_aInputState[g_MaxKeys]; // SDL_SCANCODE
int m_InputCounter;
void UpdateMouseState();
// IME support
int m_NumTextInputInstances;
char m_aEditingText[INPUT_TEXT_SIZE];