From 10c9d92cd2581448d76548efb20957a7a1c24478 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 19 Sep 2012 21:23:42 +0200 Subject: Mouse wheel events, motion vectors - added mouse wheel events - added motion vectors to CRobotMain - other minor changes in event.h --- src/app/app.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'src/app/app.cpp') diff --git a/src/app/app.cpp b/src/app/app.cpp index 0d34811..23e6d9f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -120,9 +120,6 @@ CApplication::CApplication() m_mouseButtonsState = 0; m_trackedKeys = 0; - m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_dataPath = "./data"; m_language = LANG_ENGLISH; @@ -439,6 +436,8 @@ bool CApplication::CreateVideoSurface() void CApplication::Destroy() { + m_joystickEnabled = false; + if (m_robotMain != nullptr) { delete m_robotMain; @@ -810,15 +809,32 @@ Event CApplication::ParseEvent() else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) || (m_private->currentEvent.type == SDL_MOUSEBUTTONUP) ) { - if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) - event.type = EVENT_MOUSE_BUTTON_DOWN; + 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; + if (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN) + event.mouseWheel.dir = WHEEL_DOWN; + else + event.mouseWheel.dir = WHEEL_UP; + event.mouseWheel.pos = m_engine->WindowToInterfaceCoords( + Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); + } + } else - event.type = EVENT_MOUSE_BUTTON_UP; + { + if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) + event.type = EVENT_MOUSE_BUTTON_DOWN; + else + event.type = EVENT_MOUSE_BUTTON_UP; - event.mouseButton.button = m_private->currentEvent.button.button; - event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state); - event.mouseButton.pos = m_engine->WindowToInterfaceCoords( - Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); + event.mouseButton.button = m_private->currentEvent.button.button; + event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state); + event.mouseButton.pos = m_engine->WindowToInterfaceCoords( + Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); + } } else if (m_private->currentEvent.type == SDL_MOUSEMOTION) { @@ -878,8 +894,6 @@ bool CApplication::ProcessEvent(Event &event) else event.mousePos = m_engine->GetMousePos(); - // TODO: mouse pos - if (event.type == EVENT_ACTIVE) { if (m_debugMode) @@ -980,6 +994,11 @@ bool CApplication::ProcessEvent(Event &event) l->Info(" state = %s\n", (event.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); l->Info(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y); break; + case EVENT_MOUSE_WHEEL: + l->Info("EVENT_MOUSE_WHEEL:\n"); + l->Info(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP"); + l->Info(" pos = (%f, %f)\n", event.mouseWheel.pos.x, event.mouseWheel.pos.y); + break; case EVENT_JOY_AXIS: l->Info("EVENT_JOY_AXIS:\n"); l->Info(" axis = %d\n", event.joyAxis.axis); @@ -1235,8 +1254,7 @@ void CApplication::ResetKeyStates() { m_trackedKeys = 0; m_kmodState = 0; - m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); - m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); + m_robotMain->ResetKeyStates(); } void CApplication::SetGrabInput(bool grab) -- cgit v1.2.3-1-g7c22