Revised mousewheel handling (#294)
This commit is contained in:
parent
4206592804
commit
25fc20f7f3
@ -41,6 +41,7 @@ MA 02110-1301, USA.
|
||||
#define NUM_KEYS 320
|
||||
#define MOUSE_DOUBLE_CLICK_INTERVAL 0.40
|
||||
#define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL 0.05
|
||||
#define OOMOUSEWHEEL_DELTA 1.0
|
||||
|
||||
@class Entity, GameController;
|
||||
|
||||
@ -135,7 +136,7 @@ extern int debug;
|
||||
NSMutableString *typedString;
|
||||
|
||||
NSPoint virtualJoystickPosition;
|
||||
enum MouseWheelStatus _mouseWheelState;
|
||||
float _mouseWheelDelta;
|
||||
|
||||
NSSize viewSize;
|
||||
NSSize backingViewSize;
|
||||
@ -202,6 +203,8 @@ extern int debug;
|
||||
- (BOOL) isCapsLockOn;
|
||||
- (int) numKeys;
|
||||
- (int) mouseWheelState;
|
||||
- (float) mouseWheelDelta;
|
||||
- (void) setMouseWheelDelta: (float) newWheelDelta;
|
||||
|
||||
// Command-key combinations need special handling.
|
||||
- (BOOL) isCommandQDown;
|
||||
|
@ -264,7 +264,7 @@ static void UnapplyCursorState(OOMouseInteractionMode mode);
|
||||
- (void) pollControls
|
||||
{
|
||||
if ([NSDate timeIntervalSinceReferenceDate] > timeIntervalAtLastMouseWheel + OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL)
|
||||
_mouseWheelState = gvMouseWheelNeutral;
|
||||
_mouseWheelDelta = 0.0f;
|
||||
}
|
||||
|
||||
- (void) drawRect:(NSRect)rect
|
||||
@ -745,7 +745,6 @@ FAIL:
|
||||
CGPoint centerPoint = CGPointMake(viewSize.width / 2.0, viewSize.height / 2.0);
|
||||
CGWarpMouseCursorPosition(centerPoint);
|
||||
[self setVirtualJoystick:0.0 :0.0];
|
||||
_mouseWheelState = gvMouseWheelNeutral;
|
||||
}
|
||||
|
||||
|
||||
@ -782,10 +781,19 @@ FAIL:
|
||||
return;
|
||||
|
||||
if (dy > 0)
|
||||
_mouseWheelState = gvMouseWheelUp;
|
||||
{
|
||||
if (_mouseWheelDelta >= 0)
|
||||
_mouseWheelDelta += dy;
|
||||
else
|
||||
_mouseWheelState = gvMouseWheelDown;
|
||||
|
||||
_mouseWheelDelta = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_mouseWheelDelta <= 0)
|
||||
_mouseWheelDelta += dy;
|
||||
else
|
||||
_mouseWheelDelta = 0;
|
||||
}
|
||||
timeIntervalAtLastMouseWheel = [NSDate timeIntervalSinceReferenceDate];
|
||||
}
|
||||
|
||||
@ -1033,7 +1041,24 @@ FAIL:
|
||||
|
||||
- (int) mouseWheelState
|
||||
{
|
||||
return _mouseWheelState;
|
||||
if (_mouseWheelDelta > 0.0f)
|
||||
return gvMouseWheelUp;
|
||||
else if (_mouseWheelDelta < 0.0f)
|
||||
return gvMouseWheelDown;
|
||||
else
|
||||
return gvMouseWheelNeutral;
|
||||
}
|
||||
|
||||
|
||||
- (float) mouseWheelDelta
|
||||
{
|
||||
return _mouseWheelDelta / OOMOUSEWHEEL_DELTA;
|
||||
}
|
||||
|
||||
|
||||
- (void) setMouseWheelDelta: (float) newWheelDelta
|
||||
{
|
||||
_mouseWheelDelta = newWheelDelta * OOMOUSEWHEEL_DELTA;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3106,6 +3106,21 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
|
||||
DESTROY(lastShot);
|
||||
}
|
||||
|
||||
// update mousewheel status
|
||||
UPDATE_STAGE(@"updating mousewheel delta");
|
||||
MyOpenGLView *gView = [UNIVERSE gameView];
|
||||
float mouseWheelDelta = [gView mouseWheelDelta];
|
||||
if (mouseWheelDelta > 0.0f)
|
||||
{
|
||||
if (mouseWheelDelta < delta_t) [gView setMouseWheelDelta:0.0f];
|
||||
else [gView setMouseWheelDelta:mouseWheelDelta - delta_t];
|
||||
}
|
||||
else if (mouseWheelDelta < 0.0f)
|
||||
{
|
||||
if (mouseWheelDelta > -delta_t) [gView setMouseWheelDelta:0.0f];
|
||||
else [gView setMouseWheelDelta:mouseWheelDelta + delta_t];
|
||||
}
|
||||
|
||||
STAGE_TRACKING_END
|
||||
}
|
||||
|
||||
|
@ -911,13 +911,14 @@ static NSTimeInterval time_last_frame;
|
||||
exceptionContext = @"thrust";
|
||||
// DJS: Thrust can be an axis or a button. Axis takes precidence.
|
||||
double reqSpeed=[stickHandler getAxisState: AXIS_THRUST];
|
||||
float mouseWheelDeltaFactor = mouse_control_on ? fabs([gameView mouseWheelDelta]) : 1.0f;
|
||||
// Updated DJS original code to fix BUG #17482 - (Getafix 2010/09/13)
|
||||
if (([gameView isDown:key_increase_speed] ||
|
||||
joyButtonState[BUTTON_INCTHRUST] ||
|
||||
((mouse_control_on)&&([gameView mouseWheelState] == gvMouseWheelUp) && !([UNIVERSE viewDirection] && [gameView isCapsLockOn])))
|
||||
&& (flightSpeed < maxFlightSpeed) && (!afterburner_engaged))
|
||||
{
|
||||
flightSpeed += speed_delta * delta_t;
|
||||
flightSpeed += speed_delta * delta_t * mouseWheelDeltaFactor;
|
||||
}
|
||||
|
||||
if (([gameView isDown:key_decrease_speed] ||
|
||||
@ -925,7 +926,7 @@ static NSTimeInterval time_last_frame;
|
||||
((mouse_control_on)&&([gameView mouseWheelState] == gvMouseWheelDown) && !([UNIVERSE viewDirection] && [gameView isCapsLockOn])))
|
||||
&& (!afterburner_engaged))
|
||||
{
|
||||
flightSpeed -= speed_delta * delta_t;
|
||||
flightSpeed -= speed_delta * delta_t * mouseWheelDeltaFactor;
|
||||
// ** tgape ** - decrease obviously means no hyperspeed
|
||||
hyperspeed_engaged = NO;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ MA 02110-1301, USA.
|
||||
#define NUM_KEYS 320
|
||||
#define MOUSE_DOUBLE_CLICK_INTERVAL 0.40
|
||||
#define OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL 0.05
|
||||
#define OOMOUSEWHEEL_DELTA 120 // Same as Windows WHEEL_DELTA
|
||||
|
||||
#define SNAPSHOTS_PNG_FORMAT 1
|
||||
|
||||
@ -192,7 +193,7 @@ extern int debug;
|
||||
// Mouse mode indicator (for mouse movement model)
|
||||
BOOL mouseInDeltaMode;
|
||||
|
||||
int _mouseWheelState;
|
||||
float _mouseWheelDelta;
|
||||
}
|
||||
|
||||
- (void) initSplashScreen;
|
||||
@ -279,6 +280,8 @@ extern int debug;
|
||||
- (BOOL) isCapsLockOn;
|
||||
- (int) numKeys;
|
||||
- (int) mouseWheelState;
|
||||
- (float) mouseWheelDelta;
|
||||
- (void) setMouseWheelDelta: (float) newWheelDelta;
|
||||
|
||||
// Command-key combinations need special handling. SDL stubs for these mac functions.
|
||||
- (BOOL) isCommandQDown;
|
||||
|
@ -334,7 +334,7 @@ MA 02110-1301, USA.
|
||||
|
||||
timeIntervalAtLastClick = timeSinceLastMouseWheel = [NSDate timeIntervalSinceReferenceDate];
|
||||
|
||||
_mouseWheelState = gvMouseWheelNeutral;
|
||||
_mouseWheelDelta = 0.0f;
|
||||
|
||||
m_glContextInitialized = NO;
|
||||
|
||||
@ -1577,7 +1577,24 @@ MA 02110-1301, USA.
|
||||
|
||||
- (int) mouseWheelState
|
||||
{
|
||||
return _mouseWheelState;
|
||||
if (_mouseWheelDelta > 0.0f)
|
||||
return gvMouseWheelUp;
|
||||
else if (_mouseWheelDelta < 0.0f)
|
||||
return gvMouseWheelDown;
|
||||
else
|
||||
return gvMouseWheelNeutral;
|
||||
}
|
||||
|
||||
|
||||
- (float) mouseWheelDelta
|
||||
{
|
||||
return _mouseWheelDelta / OOMOUSEWHEEL_DELTA;
|
||||
}
|
||||
|
||||
|
||||
- (void) setMouseWheelDelta: (float) newWheelDelta
|
||||
{
|
||||
_mouseWheelDelta = newWheelDelta * OOMOUSEWHEEL_DELTA;
|
||||
}
|
||||
|
||||
|
||||
@ -1639,6 +1656,12 @@ MA 02110-1301, USA.
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mbtn_event = (SDL_MouseButtonEvent*)&event;
|
||||
#if OOLITE_LINUX
|
||||
short inDelta = 0;
|
||||
#else
|
||||
// specially built SDL.dll is required for this
|
||||
short inDelta = mbtn_event->wheelDelta;
|
||||
#endif
|
||||
switch(mbtn_event->button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
@ -1655,11 +1678,30 @@ MA 02110-1301, USA.
|
||||
[self resetMouse]; // Will set mouseWarped to YES
|
||||
break;
|
||||
// mousewheel stuff
|
||||
#if OOLITE_LINUX
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
_mouseWheelState = gvMouseWheelUp;
|
||||
break;
|
||||
inDelta = OOMOUSEWHEEL_DELTA;
|
||||
// allow fallthrough
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
_mouseWheelState = gvMouseWheelDown;
|
||||
if (inDelta == 0) inDelta = -OOMOUSEWHEEL_DELTA;
|
||||
#else
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
#endif
|
||||
if (inDelta > 0)
|
||||
{
|
||||
if (_mouseWheelDelta >= 0.0f)
|
||||
_mouseWheelDelta += inDelta;
|
||||
else
|
||||
_mouseWheelDelta = 0.0f;
|
||||
}
|
||||
else if (inDelta < 0)
|
||||
{
|
||||
if (_mouseWheelDelta <= 0.0f)
|
||||
_mouseWheelDelta += inDelta;
|
||||
else
|
||||
_mouseWheelDelta = 0.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -2296,7 +2338,7 @@ keys[a] = NO; keys[b] = NO; \
|
||||
// if needed
|
||||
if (timeNow >= timeSinceLastMouseWheel + OOMOUSEWHEEL_EVENTS_DELAY_INTERVAL)
|
||||
{
|
||||
_mouseWheelState = gvMouseWheelNeutral;
|
||||
_mouseWheelDelta = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user