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