Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. void InputCore::OnEvent(SDL_Event* pEvent)
  2. {
  3. //When this function is called, pEvent will be filled with information regarding
  4. //an event. By checking the type, we can call our respective virtual functions
  5. //to make life simpler =D!
  6. switch(pEvent->type)
  7. {
  8.  
  9. // basically my problem is, that I'm not sure how to implement OnKeyPress()
  10.  
  11. case SDL_KEYDOWN:
  12. OnKeyPress(pEvent->key.keysym.sym, pEvent->key.keysym.mod,
  13. pEvent->key.keysym.unicode);
  14. break;
  15.  
  16. case SDL_KEYUP:
  17. OnKeyRelease(pEvent->key.keysym.sym, pEvent->key.keysym.mod,
  18. pEvent->key.keysym.unicode);
  19. break;
  20.  
  21. case SDL_MOUSEMOTION:
  22. OnMouseMotion(pEvent->motion.x, pEvent->motion.y,
  23. pEvent->motion.xrel, pEvent->motion.yrel,
  24. (pEvent->motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0,
  25. (pEvent->motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0,
  26. (pEvent->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0);
  27. break;
  28.  
  29. case SDL_MOUSEBUTTONDOWN:
  30. OnMousePress(pEvent->button.button, pEvent->button.x, pEvent->button.y);
  31. break;
  32.  
  33. case SDL_MOUSEBUTTONUP:
  34. OnMouseRelease(pEvent->button.button, pEvent->button.x, pEvent->button.y);
  35. break;
  36.  
  37. case SDL_ACTIVEEVENT:
  38. OnFocusChange(pEvent->active.state, pEvent->active.gain);
  39. break;
  40.  
  41. case SDL_VIDEORESIZE:
  42. OnResize(pEvent->resize.w, pEvent->resize.h);
  43. break;
  44.  
  45. case SDL_QUIT:
  46. OnExit();
  47. break;
  48.  
  49. default:;
  50. }
  51. }
  52.  
  53. //this is from my application where I hande input
  54.  
  55. void Application::TakeInput(SDL_Event* pEvent)
  56. {
  57. //We'll use this function to take input from the user and act upon it
  58. while(SDL_PollEvent(pEvent))
  59. {
  60. OnEvent(pEvent);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement