From 08c14c7ca0398d792e3a2676b1afd66666674dae Mon Sep 17 00:00:00 2001 From: Kester Maddock Date: Sun, 2 May 2004 23:45:03 +0000 Subject: [PATCH] Mouse Wheel Support for the Game Engine. This adds "Wheel Up" and "Wheel Down" as choices to the Mouse sensor brick. --- source/blender/makesdna/DNA_sensor_types.h | 2 ++ source/blender/src/buttons_logic.c | 2 +- .../BlenderRoutines/KX_BlenderInputDevice.h | 12 +++++----- .../Converter/KX_ConvertSensors.cpp | 18 ++++++++++----- .../gameengine/GameLogic/SCA_IInputDevice.h | 3 +++ .../gameengine/GameLogic/SCA_MouseSensor.cpp | 8 +++++++ source/gameengine/GameLogic/SCA_MouseSensor.h | 2 ++ .../GamePlayer/common/GPC_MouseDevice.cpp | 6 +++++ .../GamePlayer/common/GPC_MouseDevice.h | 4 +++- .../GamePlayer/ghost/GPG_Application.cpp | 22 +++++++++++++++++++ .../GamePlayer/ghost/GPG_Application.h | 1 + 11 files changed, 68 insertions(+), 12 deletions(-) diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h index d6192242da4..9c4d3c1ca20 100644 --- a/source/blender/makesdna/DNA_sensor_types.h +++ b/source/blender/makesdna/DNA_sensor_types.h @@ -219,6 +219,8 @@ typedef struct bSensor { #define BL_SENS_MOUSE_LEFT_BUTTON 1 #define BL_SENS_MOUSE_MIDDLE_BUTTON 2 #define BL_SENS_MOUSE_RIGHT_BUTTON 4 +#define BL_SENS_MOUSE_WHEEL_UP 5 +#define BL_SENS_MOUSE_WHEEL_DOWN 6 #define BL_SENS_MOUSE_MOVEMENT 8 #define BL_SENS_MOUSE_MOUSEOVER 16 diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index 7fc2d2f9e57..ef3a0104983 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -1189,7 +1189,7 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short /* Line 2: type selection. The number are a bit mangled to get * proper compatibility with older .blend files. */ str= "Type %t|Left button %x1|Middle button %x2|" - "Right button %x4|Movement %x8|Mouse over %x16"; + "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16"; uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19, &ms->type, 0, 31, 0, 0, "Specify the type of event this mouse sensor should trigger on."); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h index 02bae96d840..ed4eb65a769 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h @@ -59,11 +59,13 @@ public: /* The reverse table. In order to not confuse ourselves, we */ /* immediately convert all events that come in to KX codes. */ - m_reverseKeyTranslateTable[LEFTMOUSE ] = KX_LEFTMOUSE ; - m_reverseKeyTranslateTable[MIDDLEMOUSE ] = KX_MIDDLEMOUSE ; - m_reverseKeyTranslateTable[RIGHTMOUSE ] = KX_RIGHTMOUSE ; - m_reverseKeyTranslateTable[MOUSEX ] = KX_MOUSEX ; - m_reverseKeyTranslateTable[MOUSEY ] = KX_MOUSEY ; + m_reverseKeyTranslateTable[LEFTMOUSE ] = KX_LEFTMOUSE ; + m_reverseKeyTranslateTable[MIDDLEMOUSE ] = KX_MIDDLEMOUSE ; + m_reverseKeyTranslateTable[RIGHTMOUSE ] = KX_RIGHTMOUSE ; + m_reverseKeyTranslateTable[WHEELUPMOUSE ] = KX_WHEELUPMOUSE ; + m_reverseKeyTranslateTable[WHEELDOWNMOUSE ] = KX_WHEELDOWNMOUSE ; + m_reverseKeyTranslateTable[MOUSEX ] = KX_MOUSEX ; + m_reverseKeyTranslateTable[MOUSEY ] = KX_MOUSEY ; // TIMERS diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 525674e1887..8818762bfab 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -104,11 +104,13 @@ void BL_ConvertSensors(struct Object* blenderobject, /* The reverse table. In order to not confuse ourselves, we */ /* immediately convert all events that come in to KX codes. */ - gReverseKeyTranslateTable[LEFTMOUSE ] = SCA_IInputDevice::KX_LEFTMOUSE; - gReverseKeyTranslateTable[MIDDLEMOUSE ] = SCA_IInputDevice::KX_MIDDLEMOUSE; - gReverseKeyTranslateTable[RIGHTMOUSE ] = SCA_IInputDevice::KX_RIGHTMOUSE; - gReverseKeyTranslateTable[MOUSEX ] = SCA_IInputDevice::KX_MOUSEX; - gReverseKeyTranslateTable[MOUSEY ] = SCA_IInputDevice::KX_MOUSEY; + gReverseKeyTranslateTable[LEFTMOUSE ] = SCA_IInputDevice::KX_LEFTMOUSE; + gReverseKeyTranslateTable[MIDDLEMOUSE ] = SCA_IInputDevice::KX_MIDDLEMOUSE; + gReverseKeyTranslateTable[RIGHTMOUSE ] = SCA_IInputDevice::KX_RIGHTMOUSE; + gReverseKeyTranslateTable[WHEELUPMOUSE ] = SCA_IInputDevice::KX_WHEELUPMOUSE; + gReverseKeyTranslateTable[WHEELDOWNMOUSE ] = SCA_IInputDevice::KX_WHEELDOWNMOUSE; + gReverseKeyTranslateTable[MOUSEX ] = SCA_IInputDevice::KX_MOUSEX; + gReverseKeyTranslateTable[MOUSEY ] = SCA_IInputDevice::KX_MOUSEY; // TIMERS @@ -430,6 +432,12 @@ void BL_ConvertSensors(struct Object* blenderobject, case BL_SENS_MOUSE_RIGHT_BUTTON: keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_RIGHTBUTTON; break; + case BL_SENS_MOUSE_WHEEL_UP: + keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELUP; + break; + case BL_SENS_MOUSE_WHEEL_DOWN: + keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELDOWN; + break; case BL_SENS_MOUSE_MOVEMENT: keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MOVEMENT; break; diff --git a/source/gameengine/GameLogic/SCA_IInputDevice.h b/source/gameengine/GameLogic/SCA_IInputDevice.h index ff74ac91b13..b2ed8686b43 100644 --- a/source/gameengine/GameLogic/SCA_IInputDevice.h +++ b/source/gameengine/GameLogic/SCA_IInputDevice.h @@ -248,6 +248,9 @@ public: KX_RIGHTMOUSE, KX_ENDMOUSEBUTTONS, + + KX_WHEELUPMOUSE, + KX_WHEELDOWNMOUSE, KX_MOUSEX, KX_MOUSEY, diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 2c4b7d87c30..08cf68ba332 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -73,6 +73,12 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, case KX_MOUSESENSORMODE_RIGHTBUTTON: m_hotkey = SCA_IInputDevice::KX_RIGHTMOUSE; break; + case KX_MOUSESENSORMODE_WHEELUP: + m_hotkey = SCA_IInputDevice::KX_WHEELUPMOUSE; + break; + case KX_MOUSESENSORMODE_WHEELDOWN: + m_hotkey = SCA_IInputDevice::KX_WHEELDOWNMOUSE; + break; default: ; /* ignore, no hotkey */ } @@ -141,6 +147,8 @@ bool SCA_MouseSensor::Evaluate(CValue* event) case KX_MOUSESENSORMODE_LEFTBUTTON: case KX_MOUSESENSORMODE_MIDDLEBUTTON: case KX_MOUSESENSORMODE_RIGHTBUTTON: + case KX_MOUSESENSORMODE_WHEELUP: + case KX_MOUSESENSORMODE_WHEELDOWN: { const SCA_InputEvent& event = mousedev->GetEventValue(m_hotkey); if (event.m_status == SCA_InputEvent::KX_JUSTACTIVATED) diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 5923b1e6b8c..9b8043a1f15 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -79,6 +79,8 @@ class SCA_MouseSensor : public SCA_ISensor KX_MOUSESENSORMODE_LEFTBUTTON, KX_MOUSESENSORMODE_MIDDLEBUTTON, KX_MOUSESENSORMODE_RIGHTBUTTON, + KX_MOUSESENSORMODE_WHEELUP, + KX_MOUSESENSORMODE_WHEELDOWN, KX_MOUSESENSORMODE_POSITION, KX_MOUSESENSORMODE_POSITIONX, KX_MOUSESENSORMODE_POSITIONY, diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp b/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp index bfd1acaf65d..7e57aa1ee40 100644 --- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp +++ b/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp @@ -107,6 +107,12 @@ bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown) case buttonRight: result = ConvertEvent(KX_RIGHTMOUSE, isDown); break; + case buttonWheelUp: + result = ConvertEvent(KX_WHEELUPMOUSE, isDown); + break; + case buttonWheelDown: + result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown); + break; default: // Should not happen! break; diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h b/source/gameengine/GamePlayer/common/GPC_MouseDevice.h index 150b7808e4b..da5098b06d6 100644 --- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h +++ b/source/gameengine/GamePlayer/common/GPC_MouseDevice.h @@ -53,7 +53,9 @@ public: typedef enum { buttonLeft, buttonMiddle, - buttonRight + buttonRight, + buttonWheelUp, + buttonWheelDown } TButtonId; GPC_MouseDevice(); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index c33114c423a..13848cecc62 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -228,6 +228,10 @@ bool GPG_Application::processEvent(GHOST_IEvent* event) case GHOST_kEventButtonUp: handled = handleButton(event, false); break; + + case GHOST_kEventWheel: + handled = handleWheel(event); + break; case GHOST_kEventCursorMove: handled = handleCursorMove(event); @@ -562,6 +566,24 @@ void GPG_Application::exitEngine() m_engineInitialized = false; } +bool GPG_Application::handleWheel(GHOST_IEvent* event) +{ + bool handled = false; + assert(event); + if (m_mouse) + { + GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData(); + GHOST_TEventWheelData* wheelData = static_cast(eventData); + GPC_MouseDevice::TButtonId button; + if (wheelData->z > 0) + button = GPC_MouseDevice::buttonWheelUp; + else + button = GPC_MouseDevice::buttonWheelDown; + m_mouse->ConvertButtonEvent(button, true); + handled = true; + } + return handled; +} bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown) { diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h index 010e976f83c..4fcd66e64e0 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h @@ -67,6 +67,7 @@ public: void StopGameEngine(); protected: + bool handleWheel(GHOST_IEvent* event); bool handleButton(GHOST_IEvent* event, bool isDown); bool handleCursorMove(GHOST_IEvent* event); bool handleKey(GHOST_IEvent* event, bool isDown);