From f95980456aea096a824f78acd266cc9834d18768 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 6 Aug 2015 17:51:28 +0200 Subject: [PATCH] Replace anonymous union in Event with pointer to appropriate struct --- src/app/app.cpp | 151 +++++++++++++++++-------- src/app/input.cpp | 64 ++++++----- src/common/event.cpp | 22 ++-- src/common/event.h | 135 ++++++++++++++++------ src/graphics/engine/camera.cpp | 2 +- src/graphics/engine/engine.cpp | 11 +- src/object/auto/autobase.cpp | 12 +- src/object/brain.cpp | 39 ++++--- src/object/robotmain.cpp | 96 +++++++++------- src/script/script.cpp | 4 +- src/ui/controls/button.cpp | 16 +-- src/ui/controls/check.cpp | 6 +- src/ui/controls/color.cpp | 13 +-- src/ui/controls/compass.cpp | 14 +-- src/ui/controls/control.cpp | 7 +- src/ui/controls/edit.cpp | 110 +++++++++--------- src/ui/controls/editvalue.cpp | 18 ++- src/ui/controls/gauge.cpp | 4 +- src/ui/controls/key.cpp | 8 +- src/ui/controls/list.cpp | 34 +++--- src/ui/controls/map.cpp | 8 +- src/ui/controls/scroll.cpp | 46 +++----- src/ui/controls/shortcut.cpp | 8 +- src/ui/controls/slider.cpp | 46 +++----- src/ui/controls/target.cpp | 18 ++- src/ui/controls/window.cpp | 13 ++- src/ui/displayinfo.cpp | 8 +- src/ui/maindialog.cpp | 4 +- src/ui/screen/screen_apperance.cpp | 8 +- src/ui/screen/screen_io_read.cpp | 4 +- src/ui/screen/screen_io_write.cpp | 2 +- src/ui/screen/screen_level_list.cpp | 2 +- src/ui/screen/screen_main_menu.cpp | 2 +- src/ui/screen/screen_player_select.cpp | 7 +- src/ui/screen/screen_quit.cpp | 2 +- src/ui/screen/screen_setup.cpp | 4 +- src/ui/studio.cpp | 20 +--- 37 files changed, 533 insertions(+), 435 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 063d2d28..85199230 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -941,12 +941,13 @@ int CApplication::Run() if (event.type == EVENT_SYS_QUIT) goto end; // exit the loop - if (event.type != EVENT_NULL) - m_eventQueue->AddEvent(event); - Event virtualEvent = CreateVirtualEvent(event); + + if (event.type != EVENT_NULL) + m_eventQueue->AddEvent(std::move(event)); + if (virtualEvent.type != EVENT_NULL) - m_eventQueue->AddEvent(virtualEvent); + m_eventQueue->AddEvent(std::move(virtualEvent)); } } @@ -961,15 +962,16 @@ int CApplication::Run() goto end; // exit the loop if (event.type != EVENT_NULL) - m_eventQueue->AddEvent(event); + m_eventQueue->AddEvent(std::move(event)); } // Enter game update & frame rendering only if active if (m_active) { - Event event; - while (m_eventQueue->GetEvent(event)) + while (! m_eventQueue->IsEmpty()) { + Event event = m_eventQueue->GetEvent(); + if (event.type == EVENT_SYS_QUIT || event.type == EVENT_QUIT) goto end; // exit both loops @@ -988,7 +990,7 @@ int CApplication::Run() StartPerformanceCounter(PCNT_UPDATE_ALL); // Prepare and process step simulation event - event = CreateUpdateEvent(); + Event event = CreateUpdateEvent(); if (event.type != EVENT_NULL && m_controller != nullptr) { LogEvent(event); @@ -1067,22 +1069,26 @@ Event CApplication::ProcessSystemEvent() else event.type = EVENT_KEY_UP; - event.key.virt = false; - event.key.key = m_private->currentEvent.key.keysym.sym; - event.key.unicode = m_private->currentEvent.key.keysym.unicode; + auto data = MakeUnique(); + + data->virt = false; + data->key = m_private->currentEvent.key.keysym.sym; + data->unicode = m_private->currentEvent.key.keysym.unicode; event.kmodState = m_private->currentEvent.key.keysym.mod; // Some keyboards return numerical enter keycode instead of normal enter // See issue #427 for details - if (event.key.key == KEY(KP_ENTER)) - event.key.key = KEY(RETURN); + if (data->key == KEY(KP_ENTER)) + data->key = KEY(RETURN); - if (event.key.key == KEY(TAB) && ((event.kmodState & KEY_MOD(ALT)) != 0)) + if (data->key == KEY(TAB) && ((event.kmodState & KEY_MOD(ALT)) != 0)) { GetLogger()->Debug("Minimize to taskbar\n"); SDL_WM_IconifyWindow(); event.type = EVENT_NULL; } + + event.data = std::move(data); } else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) || (m_private->currentEvent.type == SDL_MOUSEBUTTONUP) ) @@ -1090,23 +1096,34 @@ Event CApplication::ProcessSystemEvent() if ((m_private->currentEvent.button.button == SDL_BUTTON_WHEELUP) || (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN)) { + if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) // ignore the following up event { event.type = EVENT_MOUSE_WHEEL; + + auto data = MakeUnique(); + if (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN) - event.mouseWheel.dir = WHEEL_DOWN; + data->dir = WHEEL_DOWN; else - event.mouseWheel.dir = WHEEL_UP; + data->dir = WHEEL_UP; + + event.data = std::move(data); } + } else { + auto data = MakeUnique(); + if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) event.type = EVENT_MOUSE_BUTTON_DOWN; else event.type = EVENT_MOUSE_BUTTON_UP; - event.mouseButton.button = static_cast(1 << m_private->currentEvent.button.button); + data->button = static_cast(1 << m_private->currentEvent.button.button); + + event.data = std::move(data); } } else if (m_private->currentEvent.type == SDL_MOUSEMOTION) @@ -1119,8 +1136,10 @@ Event CApplication::ProcessSystemEvent() { event.type = EVENT_JOY_AXIS; - event.joyAxis.axis = m_private->currentEvent.jaxis.axis; - event.joyAxis.value = m_private->currentEvent.jaxis.value; + auto data = MakeUnique(); + data->axis = m_private->currentEvent.jaxis.axis; + data->value = m_private->currentEvent.jaxis.value; + event.data = std::move(data); } else if ( (m_private->currentEvent.type == SDL_JOYBUTTONDOWN) || (m_private->currentEvent.type == SDL_JOYBUTTONUP) ) @@ -1130,20 +1149,26 @@ Event CApplication::ProcessSystemEvent() else event.type = EVENT_JOY_BUTTON_UP; - event.joyButton.button = m_private->currentEvent.jbutton.button; + auto data = MakeUnique(); + data->button = m_private->currentEvent.jbutton.button; + event.data = std::move(data); } else if (m_private->currentEvent.type == SDL_ACTIVEEVENT) { event.type = EVENT_ACTIVE; - if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS) - event.active.flags |= ACTIVE_INPUT; - if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS) - event.active.flags |= ACTIVE_MOUSE; - if (m_private->currentEvent.active.type & SDL_APPACTIVE) - event.active.flags |= ACTIVE_APP; + auto data = MakeUnique(); - event.active.gain = m_private->currentEvent.active.gain == 1; + if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS) + data->flags |= ACTIVE_INPUT; + if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS) + data->flags |= ACTIVE_MOUSE; + if (m_private->currentEvent.active.type & SDL_APPACTIVE) + data->flags |= ACTIVE_APP; + + data->gain = m_private->currentEvent.active.gain == 1; + + event.data = std::move(data); } m_input->EventProcess(event); @@ -1176,29 +1201,47 @@ void CApplication::LogEvent(const Event &event) { case EVENT_KEY_DOWN: case EVENT_KEY_UP: - l->Trace(" virt = %s\n", (event.key.virt) ? "true" : "false"); - l->Trace(" key = %d\n", event.key.key); - l->Trace(" unicode = 0x%04x\n", event.key.unicode); + { + auto data = event.GetData(); + l->Trace(" virt = %s\n", data->virt ? "true" : "false"); + l->Trace(" key = %d\n", data->key); + l->Trace(" unicode = 0x%04x\n", data->unicode); break; + } case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: - l->Trace(" button = %d\n", event.mouseButton.button); + { + auto data = event.GetData(); + l->Trace(" button = %d\n", data->button); break; + } case EVENT_MOUSE_WHEEL: - l->Trace(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); - break; - case EVENT_JOY_AXIS: - l->Trace(" axis = %d\n", event.joyAxis.axis); - l->Trace(" value = %d\n", event.joyAxis.value); + { + auto data = event.GetData(); + l->Trace(" dir = %s\n", (data->dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); break; + } + case EVENT_JOY_AXIS: + { + auto data = event.GetData(); + l->Trace(" axis = %d\n", data->axis); + l->Trace(" value = %d\n", data->value); + break; + } case EVENT_JOY_BUTTON_DOWN: case EVENT_JOY_BUTTON_UP: - l->Trace(" button = %d\n", event.joyButton.button); + { + auto data = event.GetData(); + l->Trace(" button = %d\n", data->button); break; + } case EVENT_ACTIVE: - l->Trace(" flags = 0x%x\n", event.active.flags); - l->Trace(" gain = %s\n", event.active.gain ? "true" : "false"); + { + auto data = event.GetData(); + l->Trace(" flags = 0x%x\n", data->flags); + l->Trace(" gain = %s\n", data->gain ? "true" : "false"); break; + } default: break; } @@ -1221,13 +1264,23 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent) if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP)) { - virtualEvent.type = sourceEvent.type; - virtualEvent.key = sourceEvent.key; - virtualEvent.key.key = GetVirtualKey(sourceEvent.key.key); - virtualEvent.key.virt = true; + auto sourceData = sourceEvent.GetData(); + auto virtualKey = GetVirtualKey(sourceData->key); - if (virtualEvent.key.key == sourceEvent.key.key) + if (virtualKey == sourceData->key) + { virtualEvent.type = EVENT_NULL; + } + else + { + virtualEvent.type = sourceEvent.type; + + auto data = sourceData->Clone(); + auto keyData = static_cast(data.get()); + keyData->key = virtualKey; + keyData->virt = true; + virtualEvent.data = std::move(data); + } } else if ((sourceEvent.type == EVENT_JOY_BUTTON_DOWN) || (sourceEvent.type == EVENT_JOY_BUTTON_UP)) { @@ -1236,9 +1289,13 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent) else virtualEvent.type = EVENT_KEY_UP; - virtualEvent.key.virt = true; - virtualEvent.key.key = VIRTUAL_JOY(sourceEvent.joyButton.button); - virtualEvent.key.unicode = 0; + auto sourceData = sourceEvent.GetData(); + + auto data = MakeUnique(); + data->virt = true; + data->key = VIRTUAL_JOY(sourceData->button); + data->unicode = 0; + virtualEvent.data = std::move(data); } else { diff --git a/src/app/input.cpp b/src/app/input.cpp index e838a88a..2db0f5ca 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -78,8 +78,8 @@ CInput::CInput() void CInput::EventProcess(Event& event) { - if(event.type == EVENT_KEY_DOWN || - event.type == EVENT_KEY_UP) + if (event.type == EVENT_KEY_DOWN || + event.type == EVENT_KEY_UP) { // Use the occasion to update kmods m_kmodState = event.kmodState; @@ -88,18 +88,21 @@ void CInput::EventProcess(Event& event) // Use the occasion to update mouse button state if (event.type == EVENT_MOUSE_BUTTON_DOWN) { - m_mouseButtonsState |= event.mouseButton.button; + auto data = event.GetData(); + m_mouseButtonsState |= data->button; } - if(event.type == EVENT_MOUSE_BUTTON_UP) + if (event.type == EVENT_MOUSE_BUTTON_UP) { - m_mouseButtonsState &= ~event.mouseButton.button; + auto data = event.GetData(); + m_mouseButtonsState &= ~data->button; } - if(event.type == EVENT_KEY_DOWN || - event.type == EVENT_KEY_UP) + if (event.type == EVENT_KEY_DOWN || + event.type == EVENT_KEY_UP) { - event.key.slot = FindBinding(event.key.key); + auto data = event.GetData(); + data->slot = FindBinding(data->key); } event.kmodState = m_kmodState; @@ -110,7 +113,8 @@ void CInput::EventProcess(Event& event) if (event.type == EVENT_KEY_DOWN || event.type == EVENT_KEY_UP) { - m_keyPresses[event.key.slot] = (event.type == EVENT_KEY_DOWN); + auto data = event.GetData(); + m_keyPresses[data->slot] = (event.type == EVENT_KEY_DOWN); } @@ -119,41 +123,47 @@ void CInput::EventProcess(Event& event) if (event.type == EVENT_KEY_DOWN && !(event.kmodState & KEY_MOD(ALT) ) ) { - if (event.key.slot == INPUT_SLOT_UP ) m_keyMotion.y = 1.0f; - if (event.key.slot == INPUT_SLOT_DOWN ) m_keyMotion.y = -1.0f; - if (event.key.slot == INPUT_SLOT_LEFT ) m_keyMotion.x = -1.0f; - if (event.key.slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 1.0f; - if (event.key.slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f; - if (event.key.slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f; + auto data = event.GetData(); + + if (data->slot == INPUT_SLOT_UP ) m_keyMotion.y = 1.0f; + if (data->slot == INPUT_SLOT_DOWN ) m_keyMotion.y = -1.0f; + if (data->slot == INPUT_SLOT_LEFT ) m_keyMotion.x = -1.0f; + if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 1.0f; + if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f; + if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f; } else if (event.type == EVENT_KEY_UP) { - if (event.key.slot == INPUT_SLOT_UP ) m_keyMotion.y = 0.0f; - if (event.key.slot == INPUT_SLOT_DOWN ) m_keyMotion.y = 0.0f; - if (event.key.slot == INPUT_SLOT_LEFT ) m_keyMotion.x = 0.0f; - if (event.key.slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 0.0f; - if (event.key.slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f; - if (event.key.slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f; + auto data = event.GetData(); + + if (data->slot == INPUT_SLOT_UP ) m_keyMotion.y = 0.0f; + if (data->slot == INPUT_SLOT_DOWN ) m_keyMotion.y = 0.0f; + if (data->slot == INPUT_SLOT_LEFT ) m_keyMotion.x = 0.0f; + if (data->slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 0.0f; + if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f; + if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f; } else if (event.type == EVENT_JOY_AXIS) { - if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_X).axis) + auto data = event.GetData(); + + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_X).axis) { - m_joyMotion.x = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone); + m_joyMotion.x = Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); if (GetJoyAxisBinding(JOY_AXIS_SLOT_X).invert) m_joyMotion.x *= -1.0f; } - if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis) + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis) { - m_joyMotion.y = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone); + m_joyMotion.y = Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); if (GetJoyAxisBinding(JOY_AXIS_SLOT_Y).invert) m_joyMotion.y *= -1.0f; } - if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis) + if (data->axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis) { - m_joyMotion.z = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone); + m_joyMotion.z = Math::Neutral(data->value / 32768.0f, m_joystickDeadzone); if (GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert) m_joyMotion.z *= -1.0f; } diff --git a/src/common/event.cpp b/src/common/event.cpp index 9e03884c..bd515a7a 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -558,9 +558,14 @@ CEventQueue::CEventQueue() CEventQueue::~CEventQueue() {} +bool CEventQueue::IsEmpty() +{ + return m_head == m_tail; +} + /** If the maximum size of queue has been reached, returns \c false. Else, adds the event to the queue and returns \c true. */ -bool CEventQueue::AddEvent(const Event &event) +bool CEventQueue::AddEvent(Event&& event) { bool result{}; @@ -574,7 +579,7 @@ bool CEventQueue::AddEvent(const Event &event) } else { - m_fifo[m_head++] = event; + m_fifo[m_head++] = std::move(event); if (m_head >= MAX_EVENT_QUEUE) m_head = 0; @@ -589,31 +594,28 @@ bool CEventQueue::AddEvent(const Event &event) return result; } -/** If the queue is empty, returns \c false. - Else, gets the event from the front, puts it into \a event and returns \c true. */ -bool CEventQueue::GetEvent(Event &event) +Event CEventQueue::GetEvent() { - bool result{}; + Event event; SDL_LockMutex(*m_mutex); if (m_head == m_tail) { - result = false; + event.type = EVENT_NULL; } else { - event = m_fifo[m_tail++]; + event = std::move(m_fifo[m_tail++]); if (m_tail >= MAX_EVENT_QUEUE) m_tail = 0; m_total--; - result = true; } SDL_UnlockMutex(*m_mutex); - return result; + return event; } diff --git a/src/common/event.h b/src/common/event.h index cbb335b7..64a40214 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -24,14 +24,16 @@ #pragma once - #include "common/key.h" +#include "common/make_unique.h" #include "common/thread/sdl_mutex_wrapper.h" #include "math/point.h" #include "math/vector.h" +#include + /** \enum EventType \brief Type of event message @@ -543,13 +545,29 @@ enum EventType EVENT_FORCE_LONG = 0x7fffffff }; +/** + * \struct EventData + * \brief Base class for additional event data + */ +struct EventData +{ + virtual ~EventData() + {} + + virtual std::unique_ptr Clone() const = 0; +}; /** * \struct KeyEventData * \brief Additional data for keyboard event */ -struct KeyEventData +struct KeyEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! If true, the key is a virtual code generated by certain key modifiers or joystick buttons bool virt = false; //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h) @@ -580,8 +598,13 @@ enum MouseButton * \struct MouseButtonEventData * \brief Additional data mouse button event */ -struct MouseButtonEventData +struct MouseButtonEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! The mouse button MouseButton button = {}; }; @@ -600,8 +623,13 @@ enum WheelDirection * \struct MouseWheelEventData * \brief Additional data for mouse wheel event. */ -struct MouseWheelEventData +struct MouseWheelEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! Wheel direction WheelDirection dir = {}; }; @@ -610,8 +638,13 @@ struct MouseWheelEventData * \struct JoyAxisEventData * \brief Additional data for joystick axis event */ -struct JoyAxisEventData +struct JoyAxisEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! The joystick axis index unsigned char axis = 0; //! The axis value (range: -32768 to 32767) @@ -622,8 +655,13 @@ struct JoyAxisEventData * \struct JoyButtonEventData * \brief Additional data for joystick button event */ -struct JoyButtonEventData +struct JoyButtonEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! The joystick button index unsigned char button = 0; }; @@ -647,15 +685,19 @@ enum ActiveEventFlags * \struct ActiveEventData * \brief Additional data for active event */ -struct ActiveEventData +struct ActiveEventData : public EventData { + std::unique_ptr Clone() const override + { + return MakeUnique(*this); + } + //! Flags (bitmask of enum values ActiveEventFlags) unsigned char flags = 0; //! True if the focus was gained; false otherwise bool gain = false; }; - /** * \struct Event * \brief Event sent by system, interface or game @@ -669,6 +711,49 @@ struct ActiveEventData **/ struct Event { + explicit Event(EventType type = EVENT_NULL) + : type(type), + rTime(0.0f), + kmodState(0), + mouseButtonsState(0), + customParam(0) + {} + + //! Convenience function for getting appropriate EventData subclass + template + EventDataSubclass* GetData() + { + return static_cast(data.get()); + } + + //! Convenience function for getting appropriate EventData subclass + template + const EventDataSubclass* GetData() const + { + return static_cast(data.get()); + } + + //! Returns a clone of this event + Event Clone() const + { + Event clone; + + clone.type = type; + clone.rTime = rTime; + clone.motionInput = motionInput; + clone.kmodState = kmodState; + clone.mousePos = mousePos; + clone.mouseButtonsState = mouseButtonsState; + clone.customParam = customParam; + + if (data != nullptr) + { + clone.data = data->Clone(); + } + + return clone; + } + //! Type of event EventType type; @@ -697,30 +782,8 @@ struct Event //! Scope: some interface events long customParam; - //! Union with additional data, applicable only to some events - union - { - //! Additional data for EVENT_KEY_DOWN and EVENT_KEY_UP - KeyEventData key; - //! Additional data for EVENT_MOUSE_BUTTON_DOWN and EVENT_MOUSE_BUTTON_UP - MouseButtonEventData mouseButton; - //! Additional data for EVENT_MOUSE_WHEEL - MouseWheelEventData mouseWheel; - //! Additional data for EVENT_JOY - JoyAxisEventData joyAxis; - //! Additional data for EVENT_JOY_AXIS - JoyButtonEventData joyButton; - //! Additional data for EVENT_ACTIVE - ActiveEventData active; - }; - - explicit Event(EventType _type = EVENT_NULL) - : type(_type) - , rTime(0.0f) - , kmodState(0) - , mouseButtonsState(0) - , customParam(0) - {} + //! Additional data for some events + std::unique_ptr data; }; @@ -754,10 +817,12 @@ public: //! Object's destructor ~CEventQueue(); + //! Checks if queue is empty + bool IsEmpty(); //! Adds an event to the queue - bool AddEvent(const Event &event); - //! Removes and returns an event from queue front - bool GetEvent(Event &event); + bool AddEvent(Event&& event); + //! Removes and returns an event from queue front; if queue is empty, returns event of type EVENT_NULL + Event GetEvent(); protected: CSDLMutexWrapper m_mutex; diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index 36b1ca46..cb6d65a7 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1055,7 +1055,7 @@ bool CCamera::EventProcess(const Event &event) break; case EVENT_MOUSE_WHEEL: - EventMouseWheel(event.mouseWheel.dir); + EventMouseWheel(event.GetData()->dir); break; default: diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 4f3dca53..0185e809 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -407,19 +407,21 @@ bool CEngine::ProcessEvent(const Event &event) { if (event.type == EVENT_KEY_DOWN) { - if (event.key.key == KEY(F12)) + auto data = event.GetData(); + + if (data->key == KEY(F12)) { m_showStats = !m_showStats; return false; } - if (event.key.key == KEY(F11)) + if (data->key == KEY(F11)) { m_debugLights = !m_debugLights; return false; } - if (event.key.key == KEY(F10)) + if (data->key == KEY(F10)) { m_debugDumpLights = true; return false; @@ -524,8 +526,7 @@ void CEngine::WriteScreenShotThread(std::unique_ptr data) GetLogger()->Error("%s!\n", data->img->GetError().c_str()); } - Event event(EVENT_WRITE_SCENE_FINISHED); - CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(event); + CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_WRITE_SCENE_FINISHED)); } bool CEngine::GetPause() diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index a7cee73a..ba3c0786 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -120,7 +120,6 @@ void CAutoBase::Start(int param) bool CAutoBase::EventProcess(const Event &event) { Math::Matrix* mat; - Event newEvent; CObject* pObj; Math::Vector pos, speed, vibCir, iPos; Math::Point dim, p; @@ -804,8 +803,7 @@ begin: else { m_soundChannel = -1; - newEvent.type = EVENT_WIN; - m_eventQueue->AddEvent(newEvent); + m_eventQueue->AddEvent(Event(EVENT_WIN)); m_phase = ABP_WAIT; m_progress = 0.0f; @@ -1054,7 +1052,6 @@ begin: bool CAutoBase::Abort() { - Event newEvent; CObject* pObj; int i; @@ -1137,8 +1134,7 @@ bool CAutoBase::Abort() m_phase == ABP_TOWAIT || m_phase == ABP_TAKEOFF ) // off? { - newEvent.type = EVENT_WIN; - m_eventQueue->AddEvent(newEvent); + m_eventQueue->AddEvent(Event(EVENT_WIN)); } } @@ -1384,9 +1380,7 @@ Error CAutoBase::TakeOff(bool printMsg) m_main->SetMovieLock(true); // blocks everything until the end m_main->DeselectAll(); - Event newEvent; - newEvent.type = EVENT_UPDINTERFACE; - m_eventQueue->AddEvent(newEvent); + m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); diff --git a/src/object/brain.cpp b/src/object/brain.cpp index ff8090d8..4b051dee 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -226,9 +226,14 @@ bool CBrain::EventProcess(const Event &event) action = EVENT_NULL; - if ( event.type == EVENT_KEY_DOWN && - event.key.slot == INPUT_SLOT_ACTION && - !m_main->GetEditLock() ) + bool isActionSlot = false; + if (event.type == EVENT_KEY_DOWN && !m_main->GetEditLock()) + { + auto data = event.GetData(); + isActionSlot = data->slot == INPUT_SLOT_ACTION; + } + + if (isActionSlot) { pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw != 0 ) @@ -248,19 +253,21 @@ bool CBrain::EventProcess(const Event &event) action = event.type; } - if(event.type == EVENT_KEY_DOWN && m_object->GetSelect()) + if (event.type == EVENT_KEY_DOWN && m_object->GetSelect()) { - bool bControl = (event.kmodState & KEY_MOD(CTRL)) != 0; - bool bAlt = (event.kmodState & KEY_MOD(ALT)) != 0; + auto data = event.GetData(); + + bool control = (event.kmodState & KEY_MOD(CTRL)) != 0; + bool alt = (event.kmodState & KEY_MOD(ALT)) != 0; CEventQueue* queue = CApplication::GetInstancePointer()->GetEventQueue(); - if(event.key.slot == INPUT_SLOT_ACTION && bControl) + if (data->slot == INPUT_SLOT_ACTION && control) { queue->AddEvent(Event(m_studio == nullptr ? EVENT_OBJECT_PROGEDIT : EVENT_STUDIO_OK)); return false; } - if(event.key.slot == INPUT_SLOT_ACTION && bAlt) + if (data->slot == INPUT_SLOT_ACTION && alt) { pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( pw != 0 ) @@ -277,16 +284,16 @@ bool CBrain::EventProcess(const Event &event) return false; } - if(bAlt) + if (alt) { int index = GetSelScript(); - if(event.key.slot == INPUT_SLOT_UP) + if(data->slot == INPUT_SLOT_UP) index--; - else if(event.key.slot == INPUT_SLOT_DOWN) + else if(data->slot == INPUT_SLOT_DOWN) index++; - else if(event.key.key >= KEY(1) && event.key.key <= KEY(9)) - index = event.key.key-KEY(1); - else if(event.key.key == KEY(0)) + else if(data->key >= KEY(1) && data->key <= KEY(9)) + index = data->key-KEY(1); + else if(data->key == KEY(0)) index = 9; if(index < 0) index = m_program.size()-1; if(index > static_cast(m_program.size())-1) index = 0; @@ -295,9 +302,7 @@ bool CBrain::EventProcess(const Event &event) { SetSelScript(index); - Event newEvent = event; - newEvent.type = EVENT_OBJECT_PROGLIST; - queue->AddEvent(newEvent); + queue->AddEvent(Event(EVENT_OBJECT_PROGLIST)); return false; } } diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 47f241f5..2fff2221 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -666,11 +666,11 @@ bool CRobotMain::ProcessEvent(Event &event) // Management of the console. if (event.type == EVENT_KEY_DOWN && - event.key.key == KEY(BACKQUOTE)) // Pause ? + event.GetData()->key == KEY(BACKQUOTE)) // Pause ? { if (m_phase != PHASE_PLAYER_SELECT && - !m_movie->IsExist() && - !m_movieLock && !m_editLock) + !m_movie->IsExist() && + !m_movieLock && !m_editLock) { Ui::CEdit* pe = static_cast(m_interface->SearchControl(EVENT_CMD)); if (pe == nullptr) return false; @@ -681,8 +681,9 @@ bool CRobotMain::ProcessEvent(Event &event) } return false; } + if (event.type == EVENT_KEY_DOWN && - event.key.key == KEY(RETURN) && m_cmdEdit) + event.GetData()->key == KEY(RETURN) && m_cmdEdit) { char cmd[50]; Ui::CEdit* pe = static_cast(m_interface->SearchControl(EVENT_CMD)); @@ -724,9 +725,11 @@ bool CRobotMain::ProcessEvent(Event &event) if (event.type == EVENT_KEY_DOWN) { - if (event.key.slot == INPUT_SLOT_HELP || - event.key.slot == INPUT_SLOT_PROG || - event.key.key == KEY(ESCAPE)) + auto data = event.GetData(); + + if (data->slot == INPUT_SLOT_HELP || + data->slot == INPUT_SLOT_PROG || + data->key == KEY(ESCAPE)) { StopDisplayInfo(); } @@ -749,21 +752,24 @@ bool CRobotMain::ProcessEvent(Event &event) switch (event.type) { case EVENT_KEY_DOWN: - KeyCamera(event.type, event.key.slot); + { + auto data = event.GetData(); + + KeyCamera(event.type, data->slot); HiliteClear(); - if (event.key.key == KEY(F11)) + if (data->key == KEY(F11)) { m_particle->WriteWheelTrace("Savegame/t.png", 256, 256, Math::Vector(16.0f, 0.0f, -368.0f), Math::Vector(140.0f, 0.0f, -248.0f)); return false; } if (m_editLock) // current edition? { - if (event.key.slot == INPUT_SLOT_HELP) + if (data->slot == INPUT_SLOT_HELP) { StartDisplayInfo(SATCOM_HUSTON, false); return false; } - if (event.key.slot == INPUT_SLOT_PROG) + if (data->slot == INPUT_SLOT_PROG) { StartDisplayInfo(SATCOM_PROG, false); return false; @@ -772,8 +778,8 @@ bool CRobotMain::ProcessEvent(Event &event) } if (m_movieLock) // current movie? { - if (event.key.slot == INPUT_SLOT_QUIT || - event.key.key == KEY(ESCAPE)) + if (data->slot == INPUT_SLOT_QUIT || + data->key == KEY(ESCAPE)) { AbortMovie(); } @@ -781,18 +787,18 @@ bool CRobotMain::ProcessEvent(Event &event) } if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) { - if (event.key.slot == INPUT_SLOT_VISIT) + if (data->slot == INPUT_SLOT_VISIT) { StartDisplayVisit(EVENT_NULL); } - if (event.key.slot == INPUT_SLOT_QUIT || - event.key.key == KEY(ESCAPE)) + if (data->slot == INPUT_SLOT_QUIT || + data->key == KEY(ESCAPE)) { StopDisplayVisit(); } return false; } - if (event.key.slot == INPUT_SLOT_QUIT) + if (data->slot == INPUT_SLOT_QUIT) { if (m_movie->IsExist()) StartDisplayInfo(SATCOM_HUSTON, false); @@ -803,7 +809,7 @@ bool CRobotMain::ProcessEvent(Event &event) else if (!m_cmdEdit) m_ui->GetDialog()->StartPauseMenu(); // do you want to leave? } - if (event.key.slot == INPUT_SLOT_PAUSE) + if (data->slot == INPUT_SLOT_PAUSE) { if (!m_movieLock && !m_editLock && !m_cmdEdit && m_camera->GetType() != Gfx::CAM_TYPE_VISIT && @@ -812,70 +818,70 @@ bool CRobotMain::ProcessEvent(Event &event) ChangePause(m_pause->GetPause(PAUSE_USER) || m_pause->GetPause(PAUSE_CODE_BATTLE_LOCK) ? PAUSE_NONE : PAUSE_USER); } } - if (event.key.slot == INPUT_SLOT_CAMERA) + if (data->slot == INPUT_SLOT_CAMERA) { ChangeCamera(); } - if (event.key.slot == INPUT_SLOT_DESEL) + if (data->slot == INPUT_SLOT_DESEL) { if (m_shortCut) DeselectObject(); } - if (event.key.slot == INPUT_SLOT_HUMAN) + if (data->slot == INPUT_SLOT_HUMAN) { SelectHuman(); } - if (event.key.slot == INPUT_SLOT_NEXT && ((event.kmodState & KEY_MOD(CTRL)) != 0)) + if (data->slot == INPUT_SLOT_NEXT && ((event.kmodState & KEY_MOD(CTRL)) != 0)) { m_short->SelectShortcut(EVENT_OBJECT_SHORTCUT_MODE); // switch bots <-> buildings return false; } - if (event.key.slot == INPUT_SLOT_NEXT) + if (data->slot == INPUT_SLOT_NEXT) { if (m_shortCut) m_short->SelectNext(); } - if (event.key.slot == INPUT_SLOT_HELP) + if (data->slot == INPUT_SLOT_HELP) { StartDisplayInfo(SATCOM_HUSTON, true); } - if (event.key.slot == INPUT_SLOT_PROG) + if (data->slot == INPUT_SLOT_PROG) { StartDisplayInfo(SATCOM_PROG, true); } - if (event.key.slot == INPUT_SLOT_VISIT) + if (data->slot == INPUT_SLOT_VISIT) { StartDisplayVisit(EVENT_NULL); } - if (event.key.slot == INPUT_SLOT_SPEED05) + if (data->slot == INPUT_SLOT_SPEED05) { SetSpeed(0.5f); } - if (event.key.slot == INPUT_SLOT_SPEED10) + if (data->slot == INPUT_SLOT_SPEED10) { SetSpeed(1.0f); } - if (event.key.slot == INPUT_SLOT_SPEED15) + if (data->slot == INPUT_SLOT_SPEED15) { SetSpeed(1.5f); } - if (event.key.slot == INPUT_SLOT_SPEED20) + if (data->slot == INPUT_SLOT_SPEED20) { SetSpeed(2.0f); } - if (event.key.slot == INPUT_SLOT_SPEED30) + if (data->slot == INPUT_SLOT_SPEED30) { SetSpeed(3.0f); } - if (event.key.slot == INPUT_SLOT_SPEED40) + if (data->slot == INPUT_SLOT_SPEED40) { SetSpeed(4.0f); } - if (event.key.slot == INPUT_SLOT_SPEED60) + if (data->slot == INPUT_SLOT_SPEED60) { SetSpeed(6.0f); } - if (event.key.key == KEY(c) && ((event.kmodState & KEY_MOD(CTRL)) != 0) && m_engine->GetShowStats()) + if (data->key == KEY(c) && ((event.kmodState & KEY_MOD(CTRL)) != 0) && m_engine->GetShowStats()) { CObject* obj = GetSelect(); if (obj != nullptr) @@ -893,13 +899,18 @@ bool CRobotMain::ProcessEvent(Event &event) } } break; + } case EVENT_KEY_UP: - KeyCamera(event.type, event.key.slot); + { + auto data = event.GetData(); + KeyCamera(event.type, data->slot); break; + } case EVENT_MOUSE_BUTTON_DOWN: - if (event.mouseButton.button != MOUSE_BUTTON_LEFT) // only left mouse button + { + if (event.GetData()->button != MOUSE_BUTTON_LEFT) // only left mouse button break; obj = DetectObject(event.mousePos); @@ -917,11 +928,14 @@ bool CRobotMain::ProcessEvent(Event &event) } } else + { SelectObject(obj); + } break; + } case EVENT_MOUSE_BUTTON_UP: - if (event.mouseButton.button != MOUSE_BUTTON_LEFT) // only left mouse button + if (event.GetData()->button != MOUSE_BUTTON_LEFT) // only left mouse button break; m_cameraPan = 0.0f; @@ -1026,8 +1040,11 @@ bool CRobotMain::ProcessEvent(Event &event) switch (event.type) { case EVENT_KEY_DOWN: - if (event.key.key == KEY(ESCAPE) || - event.key.key == KEY(RETURN)) + { + auto data = event.GetData(); + + if (data->key == KEY(ESCAPE) || + data->key == KEY(RETURN)) { if (m_winTerminate) ChangePhase(PHASE_MAIN_MENU); @@ -1035,6 +1052,7 @@ bool CRobotMain::ProcessEvent(Event &event) ChangePhase(PHASE_LEVEL_LIST); } break; + } case EVENT_BUTTON_OK: if (m_winTerminate) diff --git a/src/script/script.cpp b/src/script/script.cpp index ef4a9bd0..593ee139 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -373,7 +373,7 @@ bool CScript::Continue(const Event &event) if( m_botProg == 0 ) return true; if ( !m_bRun ) return true; - m_event = event; + m_event = event.Clone(); if ( m_bStepMode ) // step by step mode? { @@ -452,7 +452,7 @@ bool CScript::Step(const Event &event) // TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms // ??? m_engine->SetPause(true); - m_event = event; + m_event = event.Clone(); if ( m_botProg->Run(m_object, 0) ) // step mode { diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 46b182fb..3185b7cf 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -89,16 +89,14 @@ bool CButton::EventProcess(const Event &event) { m_repeat = DELAY2; - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } } if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && + event.GetData()->button == MOUSE_BUTTON_LEFT && (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { @@ -109,9 +107,7 @@ bool CButton::EventProcess(const Event &event) if ( m_bImmediat || m_bRepeat ) { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } return false; } @@ -122,16 +118,14 @@ bool CButton::EventProcess(const Event &event) } if ( event.type == EVENT_MOUSE_BUTTON_UP && //left - event.mouseButton.button == MOUSE_BUTTON_LEFT && + event.GetData()->button == MOUSE_BUTTON_LEFT && m_bCapture ) { if ( CControl::Detect(event.mousePos) ) { if ( !m_bImmediat && !m_bRepeat ) { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } } diff --git a/src/ui/controls/check.cpp b/src/ui/controls/check.cpp index b674f7c1..b2f54112 100644 --- a/src/ui/controls/check.cpp +++ b/src/ui/controls/check.cpp @@ -70,15 +70,13 @@ bool CCheck::EventProcess(const Event &event) CControl::EventProcess(event); if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && + event.GetData()->button == MOUSE_BUTTON_LEFT && (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { if ( CControl::Detect(event.mousePos) ) { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index c3b5af87..d34aa354 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -93,16 +93,14 @@ bool CColor::EventProcess(const Event &event) { m_repeat = DELAY2; - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } } if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && + event.GetData()->button == MOUSE_BUTTON_LEFT && (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { @@ -110,14 +108,13 @@ bool CColor::EventProcess(const Event &event) { m_repeat = DELAY1; - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } - if ( event.type == EVENT_MOUSE_BUTTON_UP && event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_UP && + event.GetData()->button == MOUSE_BUTTON_LEFT) { m_repeat = 0.0f; } diff --git a/src/ui/controls/compass.cpp b/src/ui/controls/compass.cpp index 3c0acbeb..045676fc 100644 --- a/src/ui/controls/compass.cpp +++ b/src/ui/controls/compass.cpp @@ -62,16 +62,12 @@ bool CCompass::EventProcess(const Event &event) { CControl::EventProcess(event); - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT && + Detect(event.mousePos)) { - if ( CControl::Detect(event.mousePos) ) - { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); - return false; - } + m_event->AddEvent(Event(m_eventType)); + return false; } return true; diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index e601c518..d2208116 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -329,7 +329,8 @@ bool CControl::EventProcess(const Event &event) } } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT) { if ( Detect(event.mousePos) ) { @@ -350,7 +351,9 @@ bool CControl::EventProcess(const Event &event) } } - if ( event.type == EVENT_MOUSE_BUTTON_UP && m_bCapture && event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_UP && + m_bCapture && + event.GetData()->button == MOUSE_BUTTON_LEFT) { m_bCapture = false; ClearState(STATE_PRESS); diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 981142dc..b73be994 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -239,17 +239,17 @@ bool CEdit::EventProcess(const Event &event) if ( (m_state & STATE_VISIBLE) == 0 ) return true; if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_UP && - Detect(event.mousePos) ) + Detect(event.mousePos)) { - Scroll(m_lineFirst-3, true); - return true; - } - if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_DOWN && - Detect(event.mousePos) ) - { - Scroll(m_lineFirst+3, true); + auto data = event.GetData(); + if (data->dir == WHEEL_UP) + { + Scroll(m_lineFirst - 3, true); + } + else + { + Scroll(m_lineFirst + 3, true); + } return true; } @@ -307,95 +307,95 @@ bool CEdit::EventProcess(const Event &event) if ( event.type == EVENT_KEY_DOWN && m_bFocus ) { - if ( (event.key.key == KEY(x) && !bShift && bControl) || - (event.key.key == KEY(DELETE) && bShift && !bControl) ) + auto data = event.GetData(); + + if ( (data->key == KEY(x) && !bShift && bControl) || + (data->key == KEY(DELETE) && bShift && !bControl) ) { Cut(); return true; } - if ( (event.key.key == KEY(c) && !bShift && bControl) || - (event.key.key == KEY(INSERT) && !bShift && bControl) ) + if ( (data->key == KEY(c) && !bShift && bControl) || + (data->key == KEY(INSERT) && !bShift && bControl) ) { Copy(); return true; } - if ( (event.key.key == KEY(v) && !bShift && bControl) || - (event.key.key == KEY(INSERT) && bShift && !bControl) ) + if ( (data->key == KEY(v) && !bShift && bControl) || + (data->key == KEY(INSERT) && bShift && !bControl) ) { Paste(); return true; } - if ( event.key.key == KEY(a) && !bShift && bControl ) + if ( data->key == KEY(a) && !bShift && bControl ) { SetCursor(999999, 0); return true; } - if ( event.key.key == KEY(o) && !bShift && bControl ) + if ( data->key == KEY(o) && !bShift && bControl ) { - Event newEvent(EVENT_STUDIO_OPEN); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(EVENT_STUDIO_OPEN)); } - if ( event.key.key == KEY(s) && !bShift && bControl ) + if ( data->key == KEY(s) && !bShift && bControl ) { - Event newEvent( EVENT_STUDIO_SAVE ); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(EVENT_STUDIO_SAVE)); } - if ( event.key.key == KEY(z) && !bShift && bControl ) + if ( data->key == KEY(z) && !bShift && bControl ) { Undo(); return true; } - if ( event.key.key == KEY(u) && !bShift && bControl ) + if ( data->key == KEY(u) && !bShift && bControl ) { if ( MinMaj(false) ) return true; } - if ( event.key.key == KEY(u) && bShift && bControl ) + if ( data->key == KEY(u) && bShift && bControl ) { if ( MinMaj(true) ) return true; } - if ( event.key.key == KEY(TAB) && !bShift && !bControl && !m_bAutoIndent ) + if ( data->key == KEY(TAB) && !bShift && !bControl && !m_bAutoIndent ) { if ( Shift(false) ) return true; } - if ( event.key.key == KEY(TAB) && bShift && !bControl && !m_bAutoIndent ) + if ( data->key == KEY(TAB) && bShift && !bControl && !m_bAutoIndent ) { if ( Shift(true) ) return true; } if ( m_bEdit ) { - if ( event.key.key == KEY(LEFT) ) + if ( data->key == KEY(LEFT) ) { MoveChar(-1, bControl, bShift); return true; } - if ( event.key.key == KEY(RIGHT) ) + if ( data->key == KEY(RIGHT) ) { MoveChar(1, bControl, bShift); return true; } - if ( event.key.key == KEY(UP) && m_bMulti ) + if ( data->key == KEY(UP) && m_bMulti ) { MoveLine(-1, bControl, bShift); return true; } - if ( event.key.key == KEY(DOWN) && m_bMulti ) + if ( data->key == KEY(DOWN) && m_bMulti ) { MoveLine(1, bControl, bShift); return true; } - if ( event.key.key == KEY(PAGEUP) && m_bMulti ) // PageUp ? + if ( data->key == KEY(PAGEUP) && m_bMulti ) // PageUp ? { MoveLine(-(m_lineVisible-1), bControl, bShift); return true; } - if ( event.key.key == KEY(PAGEDOWN) && m_bMulti ) // PageDown ? + if ( data->key == KEY(PAGEDOWN) && m_bMulti ) // PageDown ? { MoveLine(m_lineVisible-1, bControl, bShift); return true; @@ -403,62 +403,62 @@ bool CEdit::EventProcess(const Event &event) } else { - if ( event.key.key == KEY(LEFT) || - event.key.key == KEY(UP) ) + if ( data->key == KEY(LEFT) || + data->key == KEY(UP) ) { Scroll(m_lineFirst-1, true); return true; } - if ( event.key.key == KEY(RIGHT) || - event.key.key == KEY(DOWN) ) + if ( data->key == KEY(RIGHT) || + data->key == KEY(DOWN) ) { Scroll(m_lineFirst+1, true); return true; } - if ( event.key.key == KEY(PAGEUP) ) // PageUp ? + if ( data->key == KEY(PAGEUP) ) // PageUp ? { Scroll(m_lineFirst-(m_lineVisible-1), true); return true; } - if ( event.key.key == KEY(PAGEDOWN) ) // PageDown ? + if ( data->key == KEY(PAGEDOWN) ) // PageDown ? { Scroll(m_lineFirst+(m_lineVisible-1), true); return true; } } - if ( event.key.key == KEY(HOME) ) + if ( data->key == KEY(HOME) ) { MoveHome(bControl, bShift); return true; } - if ( event.key.key == KEY(END) ) + if ( data->key == KEY(END) ) { MoveEnd(bControl, bShift); return true; } - if ( event.key.key == KEY(BACKSPACE) && !bControl ) // backspace ( <- ) ? + if ( data->key == KEY(BACKSPACE) && !bControl ) // backspace ( <- ) ? { Delete(-1); SendModifEvent(); return true; } - if ( event.key.key == KEY(DELETE) && !bControl ) + if ( data->key == KEY(DELETE) && !bControl ) { Delete(1); SendModifEvent(); return true; } - if ( event.key.key == KEY(RETURN) && !bControl ) + if ( data->key == KEY(RETURN) && !bControl ) { Insert('\n'); SendModifEvent(); return true; } - if ( event.key.key == KEY(TAB) && !bControl ) + if ( data->key == KEY(TAB) && !bControl ) { Insert('\t'); SendModifEvent(); @@ -468,9 +468,10 @@ bool CEdit::EventProcess(const Event &event) if ( event.type == EVENT_KEY_DOWN && !bControl && m_bFocus ) { - if (event.key.unicode >= ' ') + auto data = event.GetData(); + if (data->unicode >= ' ') { - Insert(static_cast(event.key.unicode)); // TODO: insert utf-8 char + Insert(static_cast(data->unicode)); // TODO: insert utf-8 char SendModifEvent(); return true; } @@ -488,8 +489,8 @@ bool CEdit::EventProcess(const Event &event) } } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT) { m_mouseFirstPos = event.mousePos; m_mouseLastPos = event.mousePos; @@ -519,8 +520,8 @@ bool CEdit::EventProcess(const Event &event) MouseMove(m_mouseLastPos); } - if ( event.type == EVENT_MOUSE_BUTTON_UP && - event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_UP && + event.GetData()->button == MOUSE_BUTTON_LEFT) { if ( Detect(event.mousePos) ) { @@ -548,10 +549,7 @@ bool CEdit::EventProcess(const Event &event) void CEdit::SendModifEvent() { - Event newEvent (m_eventType); - -// m_event->MakeEvent(newEvent, m_eventType); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index 78b3661e..674001d1 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -157,7 +157,7 @@ bool CEditValue::EventProcess(const Event &event) { if ( m_edit->GetFocus() && event.type == EVENT_KEY_DOWN && - event.key.key == KEY(RETURN) ) + event.GetData()->key == KEY(RETURN) ) { value = GetValue(); if ( value > m_maxValue ) value = m_maxValue; @@ -169,8 +169,7 @@ bool CEditValue::EventProcess(const Event &event) if ( event.type == m_edit->GetEventType() ) { - Event newEvent(m_eventType); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } } @@ -199,7 +198,7 @@ bool CEditValue::EventProcess(const Event &event) } if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_UP && + event.GetData()->dir == WHEEL_UP && Detect(event.mousePos)) { value = GetValue()+m_stepValue; @@ -207,8 +206,8 @@ bool CEditValue::EventProcess(const Event &event) SetValue(value, true); HiliteValue(event); } - if ( event.type == EVENT_KEY_DOWN && - event.mouseWheel.dir == WHEEL_DOWN && + if ( event.type == EVENT_MOUSE_WHEEL && + event.GetData()->dir == WHEEL_DOWN && Detect(event.mousePos)) { value = GetValue()-m_stepValue; @@ -238,10 +237,10 @@ void CEditValue::HiliteValue(const Event &event) m_edit->SetCursor(pos, 0); m_interface->SetFocus(m_edit); - Event newEvent = event; + Event newEvent = event.Clone(); newEvent.type = EVENT_FOCUS; newEvent.customParam = m_edit->GetEventType(); - m_event->AddEvent(newEvent); // defocus the other objects + m_event->AddEvent(std::move(newEvent)); // defocus the other objects } @@ -315,8 +314,7 @@ void CEditValue::SetValue(float value, bool bSendMessage) if ( bSendMessage ) { - Event newEvent(m_eventType); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } } diff --git a/src/ui/controls/gauge.cpp b/src/ui/controls/gauge.cpp index 4b3f5529..870ae3d2 100644 --- a/src/ui/controls/gauge.cpp +++ b/src/ui/controls/gauge.cpp @@ -60,9 +60,7 @@ bool CGauge::EventProcess(const Event &event) { if ( CControl::Detect(event.mousePos) ) { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index f760c6d6..3b4a5899 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -68,14 +68,14 @@ bool CKey::EventProcess(const Event &event) if (event.type == EVENT_MOUSE_BUTTON_DOWN) { - if (event.mouseButton.button == MOUSE_BUTTON_LEFT) // left + if (event.GetData()->button == MOUSE_BUTTON_LEFT) // left m_catch = Detect(event.mousePos); } if (event.type == EVENT_KEY_DOWN && m_catch) { m_catch = false; - unsigned int key = GetVirtualKey(event.key.key); + unsigned int key = GetVirtualKey(event.GetData()->key); if (TestKey(key)) // impossible ? { @@ -95,9 +95,7 @@ bool CKey::EventProcess(const Event &event) } m_sound->Play(SOUND_CLICK); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } return false; } diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 56ed23e6..0be6d857 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -270,10 +270,9 @@ bool CList::ClearState(int state) bool CList::EventProcess(const Event &event) { - int i; if (m_bBlink && event.type == EVENT_FRAME) { - i = m_selectLine-m_firstLine; + int i = m_selectLine-m_firstLine; if (i >= 0 && i < 4 && m_button[i] != nullptr) { @@ -296,19 +295,20 @@ bool CList::EventProcess(const Event &event) if ((m_state & STATE_ENABLE) == 0) return true; - if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_UP && Detect(event.mousePos)) + if (event.type == EVENT_MOUSE_WHEEL && Detect(event.mousePos)) { - if (m_firstLine > 0) - m_firstLine--; - UpdateScroll(); - UpdateButton(); - return true; - } + auto data = event.GetData(); + if (data->dir == WHEEL_UP) + { + if (m_firstLine > 0) + m_firstLine--; + } + else + { + if (m_firstLine < m_totalLine - m_displayLine) + m_firstLine++; + } - if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos)) - { - if (m_firstLine < m_totalLine - m_displayLine) - m_firstLine++; UpdateScroll(); UpdateButton(); return true; @@ -319,7 +319,7 @@ bool CList::EventProcess(const Event &event) if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos)) { m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); - for (i = 0; i < m_displayLine; i++) + for (int i = 0; i < m_displayLine; i++) { if (i + m_firstLine >= m_totalLine) break; @@ -330,7 +330,7 @@ bool CList::EventProcess(const Event &event) if (m_bSelectCap) { - for (i = 0; i < m_displayLine; i++) + for (int i = 0; i < m_displayLine; i++) { if (i + m_firstLine >= m_totalLine) break; @@ -344,9 +344,7 @@ bool CList::EventProcess(const Event &event) { SetSelect(m_firstLine + i); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); // selected line changes + m_event->AddEvent(Event(m_eventType)); // selected line changes } } } diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index f79c2cd2..968eab84 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -191,8 +191,6 @@ bool CMap::GetFixImage() bool CMap::EventProcess(const Event &event) { - bool bInMap; - if ( (m_state & STATE_VISIBLE) == 0 ) return true; @@ -204,11 +202,13 @@ bool CMap::EventProcess(const Event &event) if ( event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos) ) { m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM); - if ( DetectObject(event.mousePos, bInMap) != 0 ) + bool inMap = false; + if (DetectObject(event.mousePos, inMap) != nullptr) m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND); } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == MOUSE_BUTTON_LEFT ) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT) { if ( CControl::Detect(event.mousePos) ) { diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index b81fd56b..6da8d2e4 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -218,9 +218,7 @@ bool CScroll::EventProcess(const Event &event) if ( m_visibleValue < 0.0f ) m_visibleValue = 0.0f; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } if ( event.type == m_eventDown && m_step > 0.0f ) @@ -229,17 +227,15 @@ bool CScroll::EventProcess(const Event &event) if ( m_visibleValue > 1.0f ) m_visibleValue = 1.0f; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } hButton = m_buttonUp?m_dim.x/0.75f:0.0f; - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && - (m_state & STATE_VISIBLE) && - (m_state & STATE_ENABLE) ) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT && + (m_state & STATE_VISIBLE) && + (m_state & STATE_ENABLE) ) { if ( CControl::Detect(event.mousePos) ) { @@ -257,9 +253,7 @@ bool CScroll::EventProcess(const Event &event) m_visibleValue = value; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } m_bCapture = true; m_pressPos = event.mousePos; @@ -281,37 +275,31 @@ bool CScroll::EventProcess(const Event &event) m_visibleValue = value; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } } } - if ( event.type == EVENT_MOUSE_BUTTON_UP && - event.mouseButton.button == MOUSE_BUTTON_LEFT && - m_bCapture ) + if (event.type == EVENT_MOUSE_BUTTON_UP && + event.GetData()->button == MOUSE_BUTTON_LEFT && + m_bCapture) { m_bCapture = false; } if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_UP && + event.GetData()->dir == WHEEL_UP && Detect(event.mousePos) && - m_buttonUp != 0) + m_buttonUp != nullptr) { - Event newEvent = event; - newEvent.type = m_buttonUp->GetEventType(); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_buttonUp->GetEventType())); } if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_DOWN && + event.GetData()->dir == WHEEL_DOWN && Detect(event.mousePos) && - m_buttonDown != 0) + m_buttonDown != nullptr) { - Event newEvent = event; - newEvent.type = m_buttonDown->GetEventType(); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_buttonDown->GetEventType())); } return true; diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 39570498..d4a0c6cd 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -68,14 +68,12 @@ bool CShortcut::EventProcess(const Event &event) m_time += event.rTime; } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT) { if ( CControl::Detect(event.mousePos) ) { - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } } diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 22bb85af..8a46b537 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -270,9 +270,7 @@ bool CSlider::EventProcess(const Event &event) if ( m_visibleValue > 1.0f ) m_visibleValue = 1.0f; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } if ( event.type == m_eventDown && m_step > 0.0f ) @@ -282,15 +280,13 @@ bool CSlider::EventProcess(const Event &event) if ( m_visibleValue > 1.0f ) m_visibleValue = 1.0f; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - (event.mouseButton.button == MOUSE_BUTTON_LEFT ) && - (m_state & STATE_VISIBLE) && - (m_state & STATE_ENABLE) ) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT && + (m_state & STATE_VISIBLE) && + (m_state & STATE_ENABLE)) { if ( CControl::Detect(event.mousePos) ) { @@ -313,9 +309,7 @@ bool CSlider::EventProcess(const Event &event) m_visibleValue = value; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); m_bCapture = true; m_pressPos = event.mousePos; @@ -347,37 +341,31 @@ bool CSlider::EventProcess(const Event &event) m_visibleValue = value; AdjustGlint(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } } - if ( ( event.type == EVENT_MOUSE_BUTTON_UP ) && - ( event.mouseButton.button == MOUSE_BUTTON_LEFT ) && - m_bCapture ) + if (event.type == EVENT_MOUSE_BUTTON_UP && + event.GetData()->button == MOUSE_BUTTON_LEFT && + m_bCapture) { m_bCapture = false; } if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_UP && + event.GetData()->dir == WHEEL_UP && Detect(event.mousePos) && - m_buttonLeft != 0) + m_buttonLeft != nullptr) { - Event newEvent = event; - newEvent.type = m_buttonLeft->GetEventType(); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_buttonLeft->GetEventType())); } if (event.type == EVENT_MOUSE_WHEEL && - event.mouseWheel.dir == WHEEL_DOWN && + event.GetData()->dir == WHEEL_DOWN && Detect(event.mousePos) && - m_buttonRight != 0) + m_buttonRight != nullptr) { - Event newEvent = event; - newEvent.type = m_buttonRight->GetEventType(); - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_buttonRight->GetEventType())); } return true; diff --git a/src/ui/controls/target.cpp b/src/ui/controls/target.cpp index 48a01079..d9032d0a 100644 --- a/src/ui/controls/target.cpp +++ b/src/ui/controls/target.cpp @@ -74,7 +74,7 @@ bool CTarget::EventProcess(const Event &event) } if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && + event.GetData()->button == MOUSE_BUTTON_LEFT && (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { @@ -107,9 +107,7 @@ bool CTarget::EventProcess(const Event &event) { m_engine->SetMouseType(Gfx::ENG_MOUSE_TARGET); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); return false; } else @@ -120,18 +118,16 @@ bool CTarget::EventProcess(const Event &event) } } - if ( event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT && - (m_state & STATE_VISIBLE) && - (m_state & STATE_ENABLE) ) + if (event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT && + (m_state & STATE_VISIBLE) && + (m_state & STATE_ENABLE)) { if ( CControl::Detect(event.mousePos) ) { if ( !m_main->GetFriendAim() ) { - Event newEvent = event; - newEvent.type = EVENT_OBJECT_FIRE; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(EVENT_OBJECT_FIRE)); return false; } } diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index ff3125c5..010fca9b 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -998,8 +998,9 @@ bool CWindow::EventProcess(const Event &event) } } - if ( m_bTrashEvent && event.type == EVENT_MOUSE_BUTTON_DOWN && - event.mouseButton.button == MOUSE_BUTTON_LEFT) + if (m_bTrashEvent && + event.type == EVENT_MOUSE_BUTTON_DOWN && + event.GetData()->button == MOUSE_BUTTON_LEFT) { if ( Detect(event.mousePos) ) { @@ -1064,12 +1065,12 @@ bool CWindow::EventProcess(const Event &event) m_pressPos = pos; AdjustButtons(); - Event newEvent = event; - newEvent.type = m_eventType; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(m_eventType)); } - if ( event.type == EVENT_MOUSE_BUTTON_UP && event.mouseButton.button == MOUSE_BUTTON_LEFT && m_bCapture ) + if (event.type == EVENT_MOUSE_BUTTON_UP && + event.GetData()->button == MOUSE_BUTTON_LEFT && + m_bCapture ) { m_bCapture = false; } diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 35f2030a..9ca98619 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -116,9 +116,7 @@ bool CDisplayInfo::EventProcess(const Event &event) { if ( event.type == pw->GetEventTypeClose() ) { - Event newEvent = event; - newEvent.type = EVENT_OBJECT_INFOOK; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(EVENT_OBJECT_INFOOK)); } if ( event.type == EVENT_SATCOM_HUSTON ) @@ -204,8 +202,8 @@ bool CDisplayInfo::EventProcess(const Event &event) } } - if ( ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == MOUSE_BUTTON_LEFT )|| - ( event.type == EVENT_MOUSE_BUTTON_UP && event.mouseButton.button == MOUSE_BUTTON_LEFT )) + if ((event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) && + event.GetData()->button == MOUSE_BUTTON_LEFT) { UpdateCopyButton(); } diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 7797a089..f814b199 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -77,11 +77,11 @@ bool CMainDialog::EventProcess(const Event &event) } EventType pressedButton = event.type; - if (event.type == EVENT_KEY_DOWN && event.key.key == KEY(RETURN) ) + if (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(RETURN) ) { pressedButton = EVENT_DIALOG_OK; } - if (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE) ) + if (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE) ) { pressedButton = EVENT_DIALOG_CANCEL; } diff --git a/src/ui/screen/screen_apperance.cpp b/src/ui/screen/screen_apperance.cpp index 400f2216..8ba1e3a1 100644 --- a/src/ui/screen/screen_apperance.cpp +++ b/src/ui/screen/screen_apperance.cpp @@ -315,15 +315,19 @@ bool CScreenApperance::EventProcess(const Event &event) switch( event.type ) { case EVENT_KEY_DOWN: - if ( event.key.key == KEY(RETURN) ) + { + auto data = event.GetData(); + + if (data->key == KEY(RETURN)) { m_main->ChangePhase(PHASE_MAIN_MENU); } - if ( event.key.key == KEY(ESCAPE) ) + if (data->key == KEY(ESCAPE)) { m_main->ChangePhase(PHASE_PLAYER_SELECT); } break; + } case EVENT_INTERFACE_PHEAD: m_apperanceTab = 0; diff --git a/src/ui/screen/screen_io_read.cpp b/src/ui/screen/screen_io_read.cpp index 79a68ab7..641d42a9 100644 --- a/src/ui/screen/screen_io_read.cpp +++ b/src/ui/screen/screen_io_read.cpp @@ -126,7 +126,7 @@ bool CScreenIORead::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_main->ChangePhase(PHASE_LEVEL_LIST); return false; @@ -139,7 +139,7 @@ bool CScreenIORead::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_interface->DeleteControl(EVENT_WINDOW5); m_main->ChangePhase(PHASE_SIMUL); diff --git a/src/ui/screen/screen_io_write.cpp b/src/ui/screen/screen_io_write.cpp index 7aeda22f..b920546e 100644 --- a/src/ui/screen/screen_io_write.cpp +++ b/src/ui/screen/screen_io_write.cpp @@ -127,7 +127,7 @@ bool CScreenIOWrite::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_interface->DeleteControl(EVENT_WINDOW5); m_main->ChangePhase(PHASE_SIMUL); diff --git a/src/ui/screen/screen_level_list.cpp b/src/ui/screen/screen_level_list.cpp index 64822884..f2f0502f 100644 --- a/src/ui/screen/screen_level_list.cpp +++ b/src/ui/screen/screen_level_list.cpp @@ -245,7 +245,7 @@ bool CScreenLevelList::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_main->ChangePhase(PHASE_MAIN_MENU); return false; diff --git a/src/ui/screen/screen_main_menu.cpp b/src/ui/screen/screen_main_menu.cpp index ccdc83ad..1e5b43ab 100644 --- a/src/ui/screen/screen_main_menu.cpp +++ b/src/ui/screen/screen_main_menu.cpp @@ -167,7 +167,7 @@ bool CScreenMainMenu::EventProcess(const Event &event) switch (event.type) { case EVENT_KEY_DOWN: - if ( event.key.key == KEY(ESCAPE) ) + if ( event.GetData()->key == KEY(ESCAPE) ) { m_sound->Play(SOUND_TZOING); m_main->ChangePhase(PHASE_QUIT_SCREEN); diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 05340a60..e36269cc 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -158,11 +158,13 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) switch( event.type ) { case EVENT_KEY_DOWN: - if ( event.key.key == KEY(RETURN) ) + { + auto data = event.GetData(); + if (data->key == KEY(RETURN)) { NameSelect(); } - if ( event.key.key == KEY(ESCAPE) ) + if (data->key == KEY(ESCAPE)) { pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); if ( pw == 0 ) break; @@ -174,6 +176,7 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) } } break; + } case EVENT_INTERFACE_NEDIT: UpdateNameList(); diff --git a/src/ui/screen/screen_quit.cpp b/src/ui/screen/screen_quit.cpp index a28f1d91..74b2bedd 100644 --- a/src/ui/screen/screen_quit.cpp +++ b/src/ui/screen/screen_quit.cpp @@ -111,7 +111,7 @@ bool CScreenQuit::EventProcess(const Event &event) if ( event.type == EVENT_KEY_DOWN ) { - if ( event.key.key == KEY(ESCAPE) ) + if ( event.GetData()->key == KEY(ESCAPE) ) { m_main->ChangePhase(PHASE_MAIN_MENU); return false; diff --git a/src/ui/screen/screen_setup.cpp b/src/ui/screen/screen_setup.cpp index 201abd89..34043c21 100644 --- a/src/ui/screen/screen_setup.cpp +++ b/src/ui/screen/screen_setup.cpp @@ -151,7 +151,7 @@ bool CScreenSetup::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_settings->SaveSettings(); m_engine->ApplyChange(); @@ -192,7 +192,7 @@ bool CScreenSetup::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() || event.type == EVENT_INTERFACE_BACK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) ) { m_settings->SaveSettings(); m_engine->ApplyChange(); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 7b620dcc..e65ffcf8 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -124,9 +124,7 @@ bool CStudio::EventProcess(const Event &event) if ( event.type == pw->GetEventTypeClose() ) { - Event newEvent = event; - newEvent.type = EVENT_STUDIO_OK; - m_event->AddEvent(newEvent); + m_event->AddEvent(Event(EVENT_STUDIO_OK)); } if ( event.type == EVENT_STUDIO_EDIT ) // text modifief? @@ -209,9 +207,7 @@ bool CStudio::EventProcess(const Event &event) { if ( m_script->IsRunning() ) { - Event newEvent = event; - newEvent.type = EVENT_OBJECT_PROGSTOP; - m_event->AddEvent(newEvent); // stop + m_event->AddEvent(Event(EVENT_OBJECT_PROGSTOP)); } else { @@ -219,9 +215,7 @@ bool CStudio::EventProcess(const Event &event) { SetInfoText("", false); - Event newEvent = event; - newEvent.type = EVENT_OBJECT_PROGSTART; - m_event->AddEvent(newEvent); // start + m_event->AddEvent(Event(EVENT_OBJECT_PROGSTART)); } else { @@ -361,9 +355,7 @@ bool CStudio::EventFrame(const Event &event) GetResource(RES_TEXT, RT_STUDIO_PROGSTOP, res); SetInfoText(res, false); - Event newEvent = event; - newEvent.type = EVENT_OBJECT_PROGSTOP; - m_event->AddEvent(newEvent); // stop + m_event->AddEvent(Event(EVENT_OBJECT_PROGSTOP)); } if ( m_script->IsRunning() && !m_bRunning ) // starting? @@ -1393,7 +1385,7 @@ bool CStudio::EventDialog(const Event &event) } if ( event.type == EVENT_DIALOG_OK || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(RETURN)) ) + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(RETURN)) ) { if ( m_dialog == SD_OPEN ) { @@ -1409,7 +1401,7 @@ bool CStudio::EventDialog(const Event &event) } if ( event.type == EVENT_DIALOG_CANCEL || - (event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) || + (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(ESCAPE)) || event.type == pw->GetEventTypeClose() ) { StopDialog();