EventDispatcher.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "List.h"
  25. #include "Mouse.h"
  26. #include "Keyboard.h"
  27. #include "Touch.h"
  28. #include "Accelerometer.h"
  29. namespace crown
  30. {
  31. class EventDispatcher
  32. {
  33. typedef List<MouseListener*> MouseListenerList;
  34. typedef List<KeyboardListener*> KeyboardListenerList;
  35. typedef List<TouchListener*> TouchListenerList;
  36. typedef List<AccelerometerListener*> AccelerometerListenerList;
  37. public:
  38. EventDispatcher();
  39. ~EventDispatcher();
  40. void add_mouse_listener(MouseListener* listener);
  41. void add_keyboard_listener(KeyboardListener* listener);
  42. void add_touch_listener(TouchListener* listener);
  43. void add_accelerometer_listener(AccelerometerListener* listener);
  44. void button_pressed(const MouseEvent&);
  45. void button_released(const MouseEvent&);
  46. void cursor_moved(const MouseEvent&);
  47. void key_pressed(const KeyboardEvent&);
  48. void key_released(const KeyboardEvent&);
  49. void text_input(const KeyboardEvent&);
  50. void touch_down(const TouchEvent& event);
  51. void touch_up(const TouchEvent& event);
  52. void touch_move(const TouchEvent& event);
  53. void touch_cancel(const TouchEvent& event);
  54. void accelerometer_changed(const AccelerometerEvent& event);
  55. private:
  56. MouseListenerList m_mouse_listener_list;
  57. KeyboardListenerList m_keyboard_listener_list;
  58. TouchListenerList m_touch_listener_list;
  59. AccelerometerListenerList m_acc_listener_list;
  60. };
  61. } // namespace crown