ManaPlus
Public Member Functions | Static Protected Member Functions | Protected Attributes
SDLInput Class Reference

#include <sdlinput.h>

Public Member Functions

 SDLInput ()
 
void pushInput (const SDL_Event &event)
 
KeyInput dequeueKeyInput ()
 
bool isKeyQueueEmpty () const
 
bool isMouseQueueEmpty () const
 
MouseInput dequeueMouseInput ()
 
void simulateMouseClick (const int x, const int y, const MouseButtonT button)
 
void simulateMouseMove ()
 
void simulateKey (const int guiKey, const InputActionT actionId)
 

Static Protected Member Functions

static MouseButtonT convertMouseButton (const int button)
 
static int convertKeyCharacter (const SDL_Event &event)
 
static void convertKeyEventToKey (const SDL_Event &event, KeyInput &keyInput)
 

Protected Attributes

std::queue< KeyInputmKeyInputQueue
 
std::queue< MouseInputmMouseInputQueue
 
time_t mMouseMoveTime
 
bool mMouseDown
 
bool mMouseInWindow
 

Detailed Description

SDL implementation of SDLInput.

Definition at line 104 of file sdlinput.h.

Constructor & Destructor Documentation

◆ SDLInput()

SDLInput::SDLInput ( )

Constructor.

Definition at line 103 of file sdlinput.cpp.

103  :
104  mKeyInputQueue(),
106  mMouseMoveTime(0),
107  mMouseDown(false),
108  mMouseInWindow(true)
109 {
110 }
bool mMouseDown
Definition: sdlinput.h:384
time_t mMouseMoveTime
Definition: sdlinput.h:382
std::queue< KeyInput > mKeyInputQueue
Definition: sdlinput.h:380
std::queue< MouseInput > mMouseInputQueue
Definition: sdlinput.h:381
bool mMouseInWindow
Definition: sdlinput.h:385

Member Function Documentation

◆ convertKeyCharacter()

static int SDLInput::convertKeyCharacter ( const SDL_Event &  event)
inlinestaticprotected

Converts an SDL event key to a key value.

Parameters
eventan SDL event with a key to convert.
Returns
a key value.
See also
Key

Definition at line 157 of file sdlinput.h.

159  {
160  const SDL_keysym keysym = event.key.keysym;
161 #ifdef USE_SDL2
162  int value = keysym.scancode;
163 #else // USE_SDL2
164 
165  int value = keysym.unicode;
166 #endif // USE_SDL2
167 
168  PRAGMA45(GCC diagnostic push)
169  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
170  switch (keysym.sym)
171  {
172  case SDLK_TAB:
173  value = KeyValue::TAB;
174  break;
175  case SDLK_LALT:
176  value = KeyValue::LEFT_ALT;
177  break;
178  case SDLK_RALT:
179  value = KeyValue::RIGHT_ALT;
180  break;
181  case SDLK_LSHIFT:
182  value = KeyValue::LEFT_SHIFT;
183  break;
184  case SDLK_RSHIFT:
185  value = KeyValue::RIGHT_SHIFT;
186  break;
187  case SDLK_LCTRL:
188  value = KeyValue::LEFT_CONTROL;
189  break;
190  case SDLK_RCTRL:
191  value = KeyValue::RIGHT_CONTROL;
192  break;
193  case SDLK_BACKSPACE:
194  value = KeyValue::BACKSPACE;
195  break;
196  case SDLK_PAUSE:
197  value = KeyValue::PAUSE;
198  break;
199  case SDLK_SPACE:
200  // Special characters like ~ (tilde) ends up
201  // with the keysym.sym SDLK_SPACE which
202  // without this check would be lost. The check
203  // is only valid on key down events in SDL.
204 #ifndef USE_SDL2
205  if (event.type == SDL_KEYUP ||
206  keysym.unicode == ' ')
207 #endif // USE_SDL2
208  {
209  value = KeyValue::SPACE;
210  }
211  break;
212  case SDLK_ESCAPE:
213 #ifdef USE_SDL2
214  case SDLK_AC_BACK:
215 #endif // USE_SDL2
216  value = KeyValue::ESCAPE;
217  break;
218  case SDLK_DELETE:
219  value = KeyValue::DELETE_;
220  break;
221  case SDLK_INSERT:
222  value = KeyValue::INSERT;
223  break;
224  case SDLK_HOME:
225  value = KeyValue::HOME;
226  break;
227  case SDLK_END:
228  value = KeyValue::END;
229  break;
230  case SDLK_PAGEUP:
231  value = KeyValue::PAGE_UP;
232  break;
233  case SDLK_PRINT:
234  value = KeyValue::PRINT_SCREEN;
235  break;
236  case SDLK_PAGEDOWN:
237  value = KeyValue::PAGE_DOWN;
238  break;
239  case SDLK_F1:
240  value = KeyValue::F1;
241  break;
242  case SDLK_F2:
243  value = KeyValue::F2;
244  break;
245  case SDLK_F3:
246  value = KeyValue::F3;
247  break;
248  case SDLK_F4:
249  value = KeyValue::F4;
250  break;
251  case SDLK_F5:
252  value = KeyValue::F5;
253  break;
254  case SDLK_F6:
255  value = KeyValue::F6;
256  break;
257  case SDLK_F7:
258  value = KeyValue::F7;
259  break;
260  case SDLK_F8:
261  value = KeyValue::F8;
262  break;
263  case SDLK_F9:
264  value = KeyValue::F9;
265  break;
266  case SDLK_F10:
267  value = KeyValue::F10;
268  break;
269  case SDLK_F11:
270  value = KeyValue::F11;
271  break;
272  case SDLK_F12:
273  value = KeyValue::F12;
274  break;
275  case SDLK_F13:
276  value = KeyValue::F13;
277  break;
278  case SDLK_F14:
279  value = KeyValue::F14;
280  break;
281  case SDLK_F15:
282  value = KeyValue::F15;
283  break;
284  case SDLK_NUMLOCK:
285  value = KeyValue::NUM_LOCK;
286  break;
287  case SDLK_CAPSLOCK:
288  value = KeyValue::CAPS_LOCK;
289  break;
290  case SDLK_SCROLLOCK:
291  value = KeyValue::SCROLL_LOCK;
292  break;
293  case SDLK_RMETA:
294  value = KeyValue::RIGHT_META;
295  break;
296  case SDLK_LMETA:
297  value = KeyValue::LEFT_META;
298  break;
299 #ifndef USE_SDL2
300  case SDLK_LSUPER:
301  value = KeyValue::LEFT_SUPER;
302  break;
303  case SDLK_RSUPER:
304  value = KeyValue::RIGHT_SUPER;
305  break;
306 #endif // USE_SDL2
307 
308  case SDLK_MODE:
309  value = KeyValue::ALT_GR;
310  break;
311  case SDLK_UP:
312  value = KeyValue::UP;
313  break;
314  case SDLK_DOWN:
315  value = KeyValue::DOWN;
316  break;
317  case SDLK_LEFT:
318  value = KeyValue::LEFT;
319  break;
320  case SDLK_RIGHT:
321  value = KeyValue::RIGHT;
322  break;
323  case SDLK_RETURN:
324  case SDLK_KP_ENTER:
325  value = KeyValue::ENTER;
326  break;
327 
328  default:
329  break;
330  }
331  PRAGMA45(GCC diagnostic pop)
332 
333  if ((CAST_U32(keysym.mod) & KMOD_NUM) == 0U)
334  {
335  PRAGMA45(GCC diagnostic push)
336  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
337  switch (keysym.sym)
338  {
339  case SDLK_KP0:
340  value = KeyValue::INSERT;
341  break;
342  case SDLK_KP1:
343  value = KeyValue::END;
344  break;
345  case SDLK_KP2:
346  value = KeyValue::DOWN;
347  break;
348  case SDLK_KP3:
349  value = KeyValue::PAGE_DOWN;
350  break;
351  case SDLK_KP4:
352  value = KeyValue::LEFT;
353  break;
354  case SDLK_KP5:
355  value = 0;
356  break;
357  case SDLK_KP6:
358  value = KeyValue::RIGHT;
359  break;
360  case SDLK_KP7:
361  value = KeyValue::HOME;
362  break;
363  case SDLK_KP8:
364  value = KeyValue::UP;
365  break;
366  case SDLK_KP9:
367  value = KeyValue::PAGE_UP;
368  break;
369  default:
370  break;
371  }
372  PRAGMA45(GCC diagnostic pop)
373  }
374  return value;
375  }
#define CAST_U32
Definition: cast.h:31
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
@ ENTER
Definition: keyvalue.h:83
@ HOME
Definition: keyvalue.h:96
@ PAGE_DOWN
Definition: keyvalue.h:100
@ BACKSPACE
Definition: keyvalue.h:103
@ PRINT_SCREEN
Definition: keyvalue.h:119
@ SPACE
Definition: keyvalue.h:81
@ RIGHT_META
Definition: keyvalue.h:92
@ LEFT_SUPER
Definition: keyvalue.h:93
@ RIGHT_SHIFT
Definition: keyvalue.h:88
@ SCROLL_LOCK
Definition: keyvalue.h:120
@ LEFT_META
Definition: keyvalue.h:91
@ ALT_GR
Definition: keyvalue.h:123
@ PAGE_UP
Definition: keyvalue.h:97
@ NUM_LOCK
Definition: keyvalue.h:122
@ LEFT_CONTROL
Definition: keyvalue.h:89
@ INSERT
Definition: keyvalue.h:95
@ LEFT_SHIFT
Definition: keyvalue.h:87
@ DELETE_
Definition: keyvalue.h:98
@ ESCAPE
Definition: keyvalue.h:101
@ RIGHT_CONTROL
Definition: keyvalue.h:90
@ RIGHT_ALT
Definition: keyvalue.h:86
@ LEFT_ALT
Definition: keyvalue.h:85
@ CAPS_LOCK
Definition: keyvalue.h:102
@ RIGHT_SUPER
Definition: keyvalue.h:94

References KeyValue::ALT_GR, KeyValue::BACKSPACE, KeyValue::CAPS_LOCK, CAST_U32, KeyValue::DELETE_, KeyValue::DOWN, KeyValue::END, KeyValue::ENTER, KeyValue::ESCAPE, KeyValue::F1, KeyValue::F10, KeyValue::F11, KeyValue::F12, KeyValue::F13, KeyValue::F14, KeyValue::F15, KeyValue::F2, KeyValue::F3, KeyValue::F4, KeyValue::F5, KeyValue::F6, KeyValue::F7, KeyValue::F8, KeyValue::F9, KeyValue::HOME, KeyValue::INSERT, KeyValue::LEFT, KeyValue::LEFT_ALT, KeyValue::LEFT_CONTROL, KeyValue::LEFT_META, KeyValue::LEFT_SHIFT, KeyValue::LEFT_SUPER, KeyValue::NUM_LOCK, KeyValue::PAGE_DOWN, KeyValue::PAGE_UP, KeyValue::PAUSE, PRAGMA45(), KeyValue::PRINT_SCREEN, KeyValue::RIGHT, KeyValue::RIGHT_ALT, KeyValue::RIGHT_CONTROL, KeyValue::RIGHT_META, KeyValue::RIGHT_SHIFT, KeyValue::RIGHT_SUPER, KeyValue::SCROLL_LOCK, KeyValue::SPACE, KeyValue::TAB, and KeyValue::UP.

Referenced by convertKeyEventToKey().

◆ convertKeyEventToKey()

void SDLInput::convertKeyEventToKey ( const SDL_Event &  event,
KeyInput keyInput 
)
staticprotected

Definition at line 329 of file sdlinput.cpp.

330 {
331  keyInput.setKey(Key(convertKeyCharacter(event)));
332  const InputActionT actionId = inputManager.getActionByKey(event);
333  if (actionId > InputAction::NO_VALUE)
334  keyInput.setActionId(actionId);
335 }
InputActionT getActionByKey(const SDL_Event &event) const
void setKey(const Key &key)
Definition: keyinput.h:128
void setActionId(const InputActionT n)
Definition: keyinput.h:138
Definition: key.h:81
static int convertKeyCharacter(const SDL_Event &event)
Definition: sdlinput.h:157
InputAction ::T InputActionT
Definition: inputaction.h:717
InputManager inputManager

References convertKeyCharacter(), InputManager::getActionByKey(), inputManager, InputAction::NO_VALUE, KeyInput::setActionId(), and KeyInput::setKey().

Referenced by pushInput().

◆ convertMouseButton()

MouseButtonT SDLInput::convertMouseButton ( const int  button)
staticprotected

Converts a mouse button from SDL to a Guichan mouse button representation.

Parameters
buttonan SDL mouse button.
Returns
a Guichan mouse button.

Definition at line 337 of file sdlinput.cpp.

338 {
339  switch (button)
340  {
341  case SDL_BUTTON_LEFT:
342  return MouseButton::LEFT;
343  case SDL_BUTTON_RIGHT:
344  return MouseButton::RIGHT;
345  case SDL_BUTTON_MIDDLE:
346  return MouseButton::MIDDLE;
347 #ifndef USE_SDL2
348  case SDL_BUTTON_WHEELUP:
349  case SDL_BUTTON_WHEELDOWN:
350  return MouseButton::EMPTY;
351 #endif // USE_SDL2
352 
353  default:
354  // We have an unknown mouse type which is ignored.
355  logger->log("unknown button type: %d", button);
356  return MouseButton::EMPTY;
357  }
358 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References MouseButton::EMPTY, MouseButton::LEFT, Logger::log(), logger, MouseButton::MIDDLE, and MouseButton::RIGHT.

Referenced by pushInput().

◆ dequeueKeyInput()

KeyInput SDLInput::dequeueKeyInput ( )

Definition at line 112 of file sdlinput.cpp.

113 {
114  if (mKeyInputQueue.empty())
115  return KeyInput();
116 
117  KeyInput keyInput = mKeyInputQueue.front();
118  mKeyInputQueue.pop();
119 
120  return keyInput;
121 }

References mKeyInputQueue.

Referenced by Gui::handleKeyInput().

◆ dequeueMouseInput()

MouseInput SDLInput::dequeueMouseInput ( )

Definition at line 123 of file sdlinput.cpp.

124 {
125  MouseInput mouseInput;
126 
127  if (mMouseInputQueue.empty())
128  return MouseInput();
129 
130  mouseInput = mMouseInputQueue.front();
131  mMouseInputQueue.pop();
132 
133  return mouseInput;
134 }

References mMouseInputQueue.

Referenced by Gui::handleMouseInput().

◆ isKeyQueueEmpty()

bool SDLInput::isKeyQueueEmpty ( ) const
inline

Definition at line 124 of file sdlinput.h.

125  { return mKeyInputQueue.empty(); }

References mKeyInputQueue.

Referenced by Gui::handleKeyInput().

◆ isMouseQueueEmpty()

bool SDLInput::isMouseQueueEmpty ( ) const
inline

Definition at line 127 of file sdlinput.h.

128  { return mMouseInputQueue.empty(); }

References mMouseInputQueue.

Referenced by Gui::handleMouseInput().

◆ pushInput()

void SDLInput::pushInput ( const SDL_Event &  event)

Pushes an SDL event. It should be called at least once per frame to update input with user input.

Parameters
eventan event from SDL.

< The app has mouse coverage

< The app has mouse coverage

Definition at line 136 of file sdlinput.cpp.

137 {
138  BLOCK_START("SDLInput::pushInput")
139  KeyInput keyInput;
140  MouseInput mouseInput;
141 
142 #ifdef __SWITCH__
143  // send an enter/select key on keyboard dismiss event
144  bool visible = SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
145  if (visible)
146  {
147  keyboardClosed = false;
148  }
149  else if (!keyboardClosed)
150  {
152  keyboardClosed = true;
153  }
154 #endif
155 
156  switch (event.type)
157  {
158  case SDL_KEYDOWN:
159  {
160  keyInput.setType(KeyEventType::PRESSED);
161  convertKeyEventToKey(event, keyInput);
162  mKeyInputQueue.push(keyInput);
163  break;
164  }
165 
166  case SDL_KEYUP:
167  {
169  convertKeyEventToKey(event, keyInput);
170  mKeyInputQueue.push(keyInput);
171  break;
172  }
173 
174 #ifdef USE_SDL2
175  case SDL_TEXTINPUT:
176  keyInput.setType(KeyEventType::PRESSED);
177  keyInput.setKey(Key(KeyValue::TEXTINPUT));
178  keyInput.setText(event.text.text);
179  mKeyInputQueue.push(keyInput);
180  break;
181 
182  case SDL_MOUSEWHEEL:
183  {
184  const int y = event.wheel.y;
185  if (y)
186  {
187  mouseInput.setX(gui->getLastMouseX());
188  mouseInput.setY(gui->getLastMouseY());
189 #ifdef ANDROID
190  mouseInput.setReal(0, 0);
191 #endif // ANDROID
192 
193  mouseInput.setButton(MouseButton::WHEEL);
194  if (y > 0)
196  else
198  mouseInput.setTimeStamp(SDL_GetTicks());
199  mMouseInputQueue.push(mouseInput);
200  }
201 
202  break;
203  }
204 #endif // USE_SDL2
205 
206 #ifdef ANDROID
207 #ifndef USE_SDL2
208  case SDL_ACCELEROMETER:
209  break;
210 #endif // USE_SDL2
211 #endif // ANDROID
212 
213  case SDL_MOUSEBUTTONDOWN:
214  {
215  mMouseDown = true;
216  const int scale = mainGraphics->getScale();
217  const int x = event.button.x / scale;
218  const int y = event.button.y / scale;
219  mouseInput.setX(x);
220  mouseInput.setY(y);
221 #ifdef ANDROID
222 #ifdef USE_SDL2
223  mouseInput.setReal(x, y);
224 #else // USE_SDL2
225 
226  mouseInput.setReal(event.button.realx / scale,
227  event.button.realy / scale);
228 #endif // USE_SDL2
229 #endif // ANDROID
230 
231  mouseInput.setButton(convertMouseButton(event.button.button));
232 
233 #ifndef USE_SDL2
234  if (event.button.button == SDL_BUTTON_WHEELDOWN)
236  else if (event.button.button == SDL_BUTTON_WHEELUP)
238  else
239 #endif // USE_SDL2
240  mouseInput.setType(MouseEventType::PRESSED);
241  mouseInput.setTimeStamp(SDL_GetTicks());
242  mMouseInputQueue.push(mouseInput);
243  break;
244  }
245  case SDL_MOUSEBUTTONUP:
246  {
247  mMouseDown = false;
248  const int scale = mainGraphics->getScale();
249  const int x = event.button.x / scale;
250  const int y = event.button.y / scale;
251  mouseInput.setX(x);
252  mouseInput.setY(y);
253 #ifdef ANDROID
254 #ifdef USE_SDL2
255  mouseInput.setReal(x, y);
256 #else // USE_SDL2
257 
258  mouseInput.setReal(event.button.realx / scale,
259  event.button.realy / scale);
260 #endif // USE_SDL2
261 #endif // ANDROID
262 
263  mouseInput.setButton(convertMouseButton(event.button.button));
264  mouseInput.setType(MouseEventType::RELEASED);
265  mouseInput.setTimeStamp(SDL_GetTicks());
266  mMouseInputQueue.push(mouseInput);
267  break;
268  }
269  case SDL_MOUSEMOTION:
270  {
271  const int scale = mainGraphics->getScale();
272  const int x = event.motion.x / scale;
273  const int y = event.motion.y / scale;
274  mouseInput.setX(x);
275  mouseInput.setY(y);
276 #ifdef ANDROID
277 #ifdef USE_SDL2
278  mouseInput.setReal(x, y);
279 #else // USE_SDL2
280 
281  mouseInput.setReal(event.motion.realx / scale,
282  event.motion.realy / scale);
283 #endif // USE_SDL2
284 #endif // ANDROID
285 
286  mouseInput.setButton(MouseButton::EMPTY);
287  mouseInput.setType(MouseEventType::MOVED);
288  mouseInput.setTimeStamp(SDL_GetTicks());
289  mMouseInputQueue.push(mouseInput);
291  break;
292  }
293 #ifndef USE_SDL2
294  case SDL_ACTIVEEVENT:
295  /*
296  * This occurs when the mouse leaves the window and the Gui-chan
297  * application loses its mousefocus.
298  */
299  if ((event.active.state & SDL_APPMOUSEFOCUS) != 0 &&
300  event.active.gain == 0U)
301  {
302  mMouseInWindow = false;
303 
304  if (!mMouseDown)
305  {
306  mouseInput.setX(-1);
307  mouseInput.setY(-1);
308  mouseInput.setButton(MouseButton::EMPTY);
309  mouseInput.setType(MouseEventType::MOVED);
310  mMouseInputQueue.push(mouseInput);
312  }
313  }
314 
315  if ((event.active.state & SDL_APPMOUSEFOCUS) != 0 &&
316  event.active.gain != 0U)
317  {
318  mMouseInWindow = true;
319  }
320  break;
321 #endif // USE_SDL2
322 
323  default:
324  break;
325  } // end switch
326  BLOCK_END("SDLInput::pushInput")
327 }
int getScale() const
Definition: graphics.h:366
int getLastMouseX() const
Definition: gui.h:224
int getLastMouseY() const
Definition: gui.h:227
void setType(KeyEventTypeT type)
Definition: keyinput.h:118
void setY(int y)
Definition: mouseinput.h:154
void setButton(MouseButtonT button)
Definition: mouseinput.h:124
void setReal(const int x, const int y)
Definition: mouseinput.h:164
void setTimeStamp(int timeStamp)
Definition: mouseinput.h:139
void setX(int x)
Definition: mouseinput.h:144
void setType(MouseEventTypeT type)
Definition: mouseinput.h:114
static MouseButtonT convertMouseButton(const int button)
Definition: sdlinput.cpp:337
static void convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput)
Definition: sdlinput.cpp:329
void simulateKey(const int guiKey, const InputActionT actionId)
Definition: sdlinput.cpp:403
Graphics * mainGraphics
Definition: graphics.cpp:109
Gui * gui
Definition: gui.cpp:111
@ TEXTINPUT
Definition: keyvalue.h:128
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
volatile time_t cur_time
Definition: timer.cpp:58

References BLOCK_END, BLOCK_START, convertKeyEventToKey(), convertMouseButton(), cur_time, MouseButton::EMPTY, KeyValue::ENTER, Gui::getLastMouseX(), Gui::getLastMouseY(), Graphics::getScale(), gui, InputAction::GUI_SELECT2, mainGraphics, mKeyInputQueue, mMouseDown, mMouseInputQueue, mMouseInWindow, mMouseMoveTime, MouseEventType::MOVED, KeyEventType::PRESSED, MouseEventType::PRESSED, KeyEventType::RELEASED, MouseEventType::RELEASED, MouseInput::setButton(), KeyInput::setKey(), MouseInput::setReal(), MouseInput::setTimeStamp(), KeyInput::setType(), MouseInput::setType(), MouseInput::setX(), MouseInput::setY(), simulateKey(), KeyValue::TEXTINPUT, MouseButton::WHEEL, MouseEventType::WHEEL_MOVED_DOWN, MouseEventType::WHEEL_MOVED_UP, x, and y.

Referenced by InputManager::handleEvent().

◆ simulateKey()

void SDLInput::simulateKey ( const int  guiKey,
const InputActionT  actionId 
)

Definition at line 403 of file sdlinput.cpp.

405 {
406  KeyInput keyInput;
407  keyInput.setType(KeyEventType::PRESSED);
408 #ifdef USE_SDL2
409  char str[2];
410  str[0] = CAST_S8(guiKey);
411  str[1] = 0;
412 
413  keyInput.setKey(Key(KeyValue::TEXTINPUT));
414  keyInput.setText(str);
415  if (guiKey >= 32)
416  mKeyInputQueue.push(keyInput);
417 #endif // USE_SDL2
418 
419  keyInput.setKey(Key(guiKey));
420  if (actionId > InputAction::NO_VALUE)
421  keyInput.setActionId(actionId);
422  mKeyInputQueue.push(keyInput);
424  mKeyInputQueue.push(keyInput);
425 }
#define CAST_S8
Definition: cast.h:26

References CAST_S8, mKeyInputQueue, InputAction::NO_VALUE, KeyEventType::PRESSED, KeyEventType::RELEASED, KeyInput::setActionId(), KeyInput::setKey(), KeyInput::setType(), and KeyValue::TEXTINPUT.

Referenced by pushInput().

◆ simulateMouseClick()

void SDLInput::simulateMouseClick ( const int  x,
const int  y,
const MouseButtonT  button 
)

Definition at line 360 of file sdlinput.cpp.

362 {
363  MouseInput mouseInput;
364  mouseInput.setX(x);
365  mouseInput.setY(y);
366  mouseInput.setReal(x, y);
367  mouseInput.setButton(MouseButton::EMPTY);
368  mouseInput.setType(MouseEventType::MOVED);
369  mouseInput.setTimeStamp(SDL_GetTicks());
370  mMouseInputQueue.push(mouseInput);
371  mouseInput.setButton(button);
372  mouseInput.setType(MouseEventType::PRESSED);
373  mouseInput.setTimeStamp(SDL_GetTicks());
374  mMouseInputQueue.push(mouseInput);
375  mouseInput.setType(MouseEventType::RELEASED);
376  mouseInput.setTimeStamp(SDL_GetTicks());
377  mMouseInputQueue.push(mouseInput);
378 }

References MouseButton::EMPTY, mMouseInputQueue, MouseEventType::MOVED, MouseEventType::PRESSED, MouseEventType::RELEASED, MouseInput::setButton(), MouseInput::setReal(), MouseInput::setTimeStamp(), MouseInput::setType(), MouseInput::setX(), MouseInput::setY(), x, and y.

◆ simulateMouseMove()

void SDLInput::simulateMouseMove ( )

Definition at line 380 of file sdlinput.cpp.

381 {
382  if (gui == nullptr)
383  return;
384 
385  if (mMouseMoveTime == cur_time)
386  return;
387 
389  int x;
390  int y;
392 
393  MouseInput mouseInput;
394  mouseInput.setX(x);
395  mouseInput.setY(y);
396  mouseInput.setReal(x, y);
397  mouseInput.setButton(MouseButton::EMPTY);
398  mouseInput.setType(MouseEventType::MOVED);
399  mouseInput.setTimeStamp(SDL_GetTicks());
400  mMouseInputQueue.push(mouseInput);
401 }
static uint8_t getMouseState(int &x, int &y)
Definition: gui.cpp:1171

References cur_time, MouseButton::EMPTY, Gui::getMouseState(), gui, mMouseInputQueue, mMouseMoveTime, MouseEventType::MOVED, MouseInput::setButton(), MouseInput::setReal(), MouseInput::setTimeStamp(), MouseInput::setType(), MouseInput::setX(), MouseInput::setY(), x, and y.

Referenced by ActorManager::addChar(), and Gui::slowLogic().

Field Documentation

◆ mKeyInputQueue

std::queue<KeyInput> SDLInput::mKeyInputQueue
protected

Definition at line 380 of file sdlinput.h.

Referenced by dequeueKeyInput(), isKeyQueueEmpty(), pushInput(), and simulateKey().

◆ mMouseDown

bool SDLInput::mMouseDown
protected

Definition at line 384 of file sdlinput.h.

Referenced by pushInput().

◆ mMouseInputQueue

std::queue<MouseInput> SDLInput::mMouseInputQueue
protected

◆ mMouseInWindow

bool SDLInput::mMouseInWindow
protected

Definition at line 385 of file sdlinput.h.

Referenced by pushInput().

◆ mMouseMoveTime

time_t SDLInput::mMouseMoveTime
protected

Definition at line 382 of file sdlinput.h.

Referenced by pushInput(), and simulateMouseMove().


The documentation for this class was generated from the following files: