You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 regels
1.9 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <SDL.h>
  14. #include "core.h"
  15. #include "sdlinput.h"
  16. /*
  17. * SDL Input implementation class
  18. */
  19. class SdlInputData
  20. {
  21. friend class SdlInput;
  22. private:
  23. int mx, my;
  24. };
  25. /*
  26. * Public SdlInput class
  27. */
  28. SdlInput::SdlInput()
  29. : data(new SdlInputData())
  30. {
  31. SDL_Init(SDL_INIT_TIMER);
  32. SDL_GetMouseState(&data->mx, &data->my);
  33. gamegroup = GAMEGROUP_BEFORE;
  34. }
  35. void SdlInput::TickGame(float deltams)
  36. {
  37. Entity::TickGame(deltams);
  38. /* Handle mouse input */
  39. int2 mouse;
  40. if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
  41. {
  42. SDL_GetMouseState(&mouse.x, &mouse.y);
  43. mouse.y = Video::GetHeight() - 1 - mouse.y;
  44. }
  45. else
  46. mouse.x = mouse.y = -1;
  47. Input::SetMousePos(mouse);
  48. /* Handle keyboard and WM events */
  49. SDL_Event event;
  50. while (SDL_PollEvent(&event))
  51. {
  52. if (event.type == SDL_QUIT)
  53. Ticker::Shutdown();
  54. #if 0
  55. else if (event.type == SDL_KEYDOWN)
  56. Input::KeyPressed(event.key.keysym.sym, deltams);
  57. #endif
  58. else if (event.type == SDL_MOUSEBUTTONDOWN)
  59. Input::SetMouseButton(event.button.button - 1);
  60. else if (event.type == SDL_MOUSEBUTTONUP)
  61. Input::UnsetMouseButton(event.button.button - 1);
  62. }
  63. /* Send the whole keyboard state to the input system */
  64. #if 0
  65. Uint8 *keystate = SDL_GetKeyState(NULL);
  66. for (int i = 0; i < 256; i++)
  67. if (keystate[i])
  68. Input::KeyPressed(i, deltams);
  69. #endif
  70. }
  71. SdlInput::~SdlInput()
  72. {
  73. delete data;
  74. }