| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*
- Copyright (c) 2013 Daniele Bartolini, Michele Rossi
- Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
- #include "EventDispatcher.h"
- #include "Allocator.h"
- #include "Log.h"
- namespace crown
- {
- //-----------------------------------------------------------------------------
- EventDispatcher::EventDispatcher() :
- m_mouse_listener_list(default_allocator()),
- m_keyboard_listener_list(default_allocator()),
- m_touch_listener_list(default_allocator()),
- m_acc_listener_list(default_allocator())
- {
- }
- //-----------------------------------------------------------------------------
- EventDispatcher::~EventDispatcher()
- {
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::add_mouse_listener(MouseListener* listener)
- {
- CE_ASSERT(listener != NULL, "Listener must be != NULL");
- m_mouse_listener_list.push_back(listener);
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::add_keyboard_listener(KeyboardListener* listener)
- {
- CE_ASSERT(listener != NULL, "Listener must be != NULL");
- m_keyboard_listener_list.push_back(listener);
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::add_touch_listener(TouchListener* listener)
- {
- CE_ASSERT(listener != NULL, "Listener must be != NULL");
- m_touch_listener_list.push_back(listener);
- }
- void EventDispatcher::add_accelerometer_listener(AccelerometerListener* listener)
- {
- CE_ASSERT(listener != NULL, "Listener must be != NULL");
- m_acc_listener_list.push_back(listener);
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::button_pressed(const MouseEvent& event)
- {
- for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
- {
- m_mouse_listener_list[i]->button_pressed(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::button_released(const MouseEvent& event)
- {
- for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
- {
- m_mouse_listener_list[i]->button_released(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::cursor_moved(const MouseEvent& event)
- {
- for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
- {
- m_mouse_listener_list[i]->cursor_moved(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::key_pressed(const KeyboardEvent& event)
- {
- for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
- {
- m_keyboard_listener_list[i]->key_pressed(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::key_released(const KeyboardEvent& event)
- {
- for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
- {
- m_keyboard_listener_list[i]->key_released(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::text_input(const KeyboardEvent& event)
- {
- for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
- {
- m_keyboard_listener_list[i]->text_input(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::touch_down(const TouchEvent& event)
- {
- for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
- {
- m_touch_listener_list[i]->touch_down(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::touch_up(const TouchEvent& event)
- {
- for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
- {
- m_touch_listener_list[i]->touch_up(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::touch_move(const TouchEvent& event)
- {
- for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
- {
- m_touch_listener_list[i]->touch_move(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::touch_cancel(const TouchEvent& event)
- {
- for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
- {
- m_touch_listener_list[i]->touch_cancel(event);
- }
- }
- //-----------------------------------------------------------------------------
- void EventDispatcher::accelerometer_changed(const AccelerometerEvent& event)
- {
- for (uint32_t i = 0; i < m_acc_listener_list.size(); i++)
- {
- m_acc_listener_list[i]->accelerometer_changed(event);
- }
- }
- } // namespace crown
|