[Mac] Add horizontal scrolling

This commit is contained in:
thefiddler 2014-05-04 15:24:02 +02:00
parent 30c73e8ead
commit 4b115c443b

View file

@ -78,6 +78,7 @@ namespace OpenTK.Platform.MacOS
static readonly IntPtr selLocationInWindowOwner = Selector.Get("locationInWindow"); static readonly IntPtr selLocationInWindowOwner = Selector.Get("locationInWindow");
static readonly IntPtr selHide = Selector.Get("hide"); static readonly IntPtr selHide = Selector.Get("hide");
static readonly IntPtr selUnhide = Selector.Get("unhide"); static readonly IntPtr selUnhide = Selector.Get("unhide");
static readonly IntPtr selScrollingDeltaX = Selector.Get("scrollingDeltaX");
static readonly IntPtr selScrollingDeltaY = Selector.Get("scrollingDeltaY"); static readonly IntPtr selScrollingDeltaY = Selector.Get("scrollingDeltaY");
static readonly IntPtr selDeltaX = Selector.Get("deltaX"); static readonly IntPtr selDeltaX = Selector.Get("deltaX");
static readonly IntPtr selDeltaY = Selector.Get("deltaY"); static readonly IntPtr selDeltaY = Selector.Get("deltaY");
@ -145,7 +146,7 @@ namespace OpenTK.Platform.MacOS
private bool cursorInsideWindow = true; private bool cursorInsideWindow = true;
private MouseCursor selectedCursor = MouseCursor.Default; // user-selected cursor private MouseCursor selectedCursor = MouseCursor.Default; // user-selected cursor
private const float scrollFactor = 120.0f; private const float scrollFactor = 10.0f;
private const bool exclusiveFullscreen = false; private const bool exclusiveFullscreen = false;
public CocoaNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) public CocoaNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
@ -517,10 +518,14 @@ namespace OpenTK.Platform.MacOS
MathHelper.Clamp((int)Math.Round(p.Y + dy), 0, Height)); MathHelper.Clamp((int)Math.Round(p.Y + dy), 0, Height));
} }
// Only raise events when the mouse has actually moved
if (MouseState.X != p.X || MouseState.Y != p.Y)
{
MouseState.X = p.X; MouseState.X = p.X;
MouseState.Y = p.Y; MouseState.Y = p.Y;
OnMouseMove(); OnMouseMove();
} }
}
break; break;
case NSEventType.CursorUpdate: case NSEventType.CursorUpdate:
@ -528,17 +533,25 @@ namespace OpenTK.Platform.MacOS
case NSEventType.ScrollWheel: case NSEventType.ScrollWheel:
{ {
var scrollingDelta = Cocoa.SendFloat(e, selScrollingDeltaY); float dx, dy;
var factor = 1.0f;
if (Cocoa.SendBool(e, selHasPreciseScrollingDeltas)) if (Cocoa.SendBool(e, selHasPreciseScrollingDeltas))
{ {
factor = 1.0f / scrollFactor; // Problem: Don't know what factor to use here, but this seems to work. dx = Cocoa.SendFloat(e, selScrollingDeltaX) / scrollFactor;
dy = Cocoa.SendFloat(e, selScrollingDeltaY) / scrollFactor;
}
else
{
dx = Cocoa.SendFloat(e, selDeltaX);
dy = Cocoa.SendFloat(e, selDeltaY);
} }
MouseState.SetScrollRelative(0, scrollingDelta * factor); // Only raise wheel events when the user has actually scrolled
if (dx != 0 || dy != 0)
{
MouseState.SetScrollRelative(dx, dy);
OnMouseWheel(); OnMouseWheel();
} }
}
break; break;
case NSEventType.LeftMouseDown: case NSEventType.LeftMouseDown: