Skip to content

Commit

Permalink
Plumb wheel events through the control map
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Jan 25, 2025
1 parent f0ea7b7 commit 1a7c064
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum
kControlFlagMiddleButtonEx = 0x08000000,
kControlFlagMiddleButtonRepeat = 0x10000000,
kControlFlagMiddleButtonUp = 0x20000000,
kControlFlagWheel = 0x40000000
};

// mouse button flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ enum ControlEventCode
S_SET_CURSOR_UPWARD,
S_SET_LADDER_CONTROL,
S_CLEAR_LADDER_CONTROL,
B_CAMERA_ADJUST_OFFSET,
END_CONTROLS
};

Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/NucleusLib/pnInputCore/plInputMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,4 +1098,5 @@ const std::map<ControlEventCode, ST::string> plInputMap::fCmdConvert =
{ B_CONTROL_OPEN_BOOK, ST_LITERAL("Open Player Book") },
{ B_CONTROL_EXIT_GUI_MODE, ST_LITERAL("Exit GUI Mode") },
{ B_CONTROL_MODIFIER_STRAFE, ST_LITERAL("Strafe Modifier") },
{ B_CAMERA_ADJUST_OFFSET, ST_LITERAL("Camera Offset") },
};
31 changes: 23 additions & 8 deletions Sources/Plasma/PubUtilLib/plInputCore/plAvatarInputInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,17 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg )
fInputMap->fButtonState &= ~kMiddleButtonDown;
fInputMap->fButtonState &= ~kMiddleButtonRepeat;
}

if( oldButtonState != fInputMap->fButtonState || pMouseMsg->GetDX() != 0.f || pMouseMsg->GetDY() != 0.f )
{
fCursorTimeout = 0.f; // Reset cursor opacity timeout thingy
if (pMouseMsg->GetButton() == kWheelPos) {
fInputMap->fButtonState &= ~kWheelNeg;
fInputMap->fButtonState |= kWheelPos;
}
if (pMouseMsg->GetButton() == kWheelNeg) {
fInputMap->fButtonState &= ~kWheelPos;
fInputMap->fButtonState |= kWheelNeg;
}

if (oldButtonState != fInputMap->fButtonState || pMouseMsg->GetDX() != 0.f || pMouseMsg->GetDY() != 0.f || pMouseMsg->GetWheelDelta() != 0.f)
fCursorTimeout = 0.f; // Reset cursor opacity timeout thingy

/* NOTE: I see that this interface always returns true for mouse
messages, even if it does nothing with them. It ends up working
Expand Down Expand Up @@ -801,6 +807,8 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg )
disable = true;
if (mouseInfo->fControlFlags & kControlFlagMiddleButtonRepeat && !(fInputMap->fButtonState & kMiddleButtonDown))
disable = true;
if (mouseInfo->fControlFlags & kControlFlagWheel && !(fInputMap->fButtonState & kWheelPos | kWheelNeg))
disable = true;

// can we disable this control based on the cursor position?
if (!CursorInBox(pMouseMsg, mouseInfo->fBox) && mouseInfo->fControlFlags & kControlFlagBoxDisable)
Expand Down Expand Up @@ -850,7 +858,9 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg )
pCmd->fControlCode = mouseInfo->fCode;
float pct = 0.0f;

if (mouseInfo->fControlFlags & kControlFlagXAxisEvent)
if (mouseInfo->fControlFlags & kControlFlagWheel)
pct = pMouseMsg->GetWheelDelta();
else if (mouseInfo->fControlFlags & kControlFlagXAxisEvent)
pct = pMouseMsg->GetDX();
else
pct = pMouseMsg->GetDY();
Expand Down Expand Up @@ -916,6 +926,8 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg )
continue;
if (mouseInfo->fControlFlags & kControlFlagMiddleButtonUp && !(pMouseMsg->GetButton() == kMiddleButtonUp))
continue;
if (mouseInfo->fControlFlags & kControlFlagWheel && !(pMouseMsg->GetButton() == kWheelPos | pMouseMsg->GetButton() == kWheelNeg))
continue;

// okay, we're in the box and either we don't require a button or our button is pressed.
// so set the command as 'enabled'
Expand Down Expand Up @@ -954,7 +966,9 @@ bool plAvatarInputInterface::InterpretInputEvent( plInputEventMsg *pMsg )

if (mouseInfo->fControlFlags & kControlFlagDelta)
{
if (mouseInfo->fControlFlags & kControlFlagXAxisEvent)
if (mouseInfo->fControlFlags & kControlFlagWheel)
pct = pMouseMsg->GetWheelDelta();
else if (mouseInfo->fControlFlags & kControlFlagXAxisEvent)
pct = pMouseMsg->GetDX();
else
pct = pMouseMsg->GetDY();
Expand Down Expand Up @@ -1056,7 +1070,8 @@ plLadderDismountMap::plLadderDismountMap() : plSuspendedMovementMap()

plBasicThirdPersonControlMap::plBasicThirdPersonControlMap() : plBasicControlMap()
{
fMouseMap->AddMapping(new plMouseInfo(S_SET_FREELOOK, kControlFlagRightButton, 0.0f, 1.0f, 0.0f, 1.0f));
fMouseMap->AddMapping(new plMouseInfo(S_SET_FREELOOK, kControlFlagRightButton, 0.0f, 1.0f, 0.0f, 1.0f));
fMouseMap->AddMapping(new plMouseInfo(B_CAMERA_ADJUST_OFFSET, kControlFlagWheel | kControlFlagDelta, 0.0f, 1.0f, 0.0f, 1.0f));
}

plBasicFirstPersonControlMap::plBasicFirstPersonControlMap() : plBasicControlMap()
Expand Down Expand Up @@ -1105,4 +1120,4 @@ pl3rdWalkBackwardLBMap::pl3rdWalkBackwardLBMap() : pl3rdWalkMap()
fMouseMap->AddMapping(new plMouseInfo(S_SET_BASIC_MODE, kControlFlagLeftButtonUp, 0.0f, 1.0f, 0.0f, 1.0f));
fMouseMap->AddMapping(new plMouseInfo(B_CONTROL_MOVE_BACKWARD, kControlFlagLeftButton, 0.0f, 1.0f, 0.0f, 1.0f));
fMouseMap->AddMapping(new plMouseInfo(B_CONTROL_CAMERA_WALK_PAN, kControlFlagLeftButton, 0.0f, 1.0f, 0.0f, 1.0f));
}
}

0 comments on commit 1a7c064

Please sign in to comment.