Merge pull request #354 from mrhelmut/RetinaMouseFix2TK
Scaling mouse coordinate to match Retina scaling
This commit is contained in:
commit
dc54e9bc02
2 changed files with 17 additions and 2 deletions
|
@ -83,6 +83,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static float Scale = 1.0f;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Members
|
#region Public Members
|
||||||
|
@ -110,13 +112,19 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public MouseState GetState()
|
public MouseState GetState()
|
||||||
{
|
{
|
||||||
return state;
|
MouseState scaledState = state;
|
||||||
|
if (Configuration.RunningOnMacOS)
|
||||||
|
{
|
||||||
|
scaledState.X = (int)Math.Round(scaledState.X * Scale);
|
||||||
|
scaledState.Y = (int)Math.Round(scaledState.Y * Scale);
|
||||||
|
}
|
||||||
|
return scaledState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MouseState GetState(int index)
|
public MouseState GetState(int index)
|
||||||
{
|
{
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return state;
|
return GetState();
|
||||||
else
|
else
|
||||||
return new MouseState();
|
return new MouseState();
|
||||||
}
|
}
|
||||||
|
@ -126,6 +134,12 @@ namespace OpenTK.Platform.SDL2
|
||||||
int x, y;
|
int x, y;
|
||||||
var buttons = SDL.GetGlobalMouseState(out x, out y);
|
var buttons = SDL.GetGlobalMouseState(out x, out y);
|
||||||
|
|
||||||
|
if (Configuration.RunningOnMacOS)
|
||||||
|
{
|
||||||
|
x = (int)Math.Round(x * Scale);
|
||||||
|
y = (int)Math.Round(y * Scale);
|
||||||
|
}
|
||||||
|
|
||||||
var c = new MouseState();
|
var c = new MouseState();
|
||||||
c.SetIsConnected(true);
|
c.SetIsConnected(true);
|
||||||
c.X = x;
|
c.X = x;
|
||||||
|
|
|
@ -285,6 +285,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
window.OnMouseMove(
|
window.OnMouseMove(
|
||||||
(int)Math.Round(ev.X * scale),
|
(int)Math.Round(ev.X * scale),
|
||||||
(int)Math.Round(ev.Y * scale));
|
(int)Math.Round(ev.Y * scale));
|
||||||
|
Sdl2Mouse.Scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessMouseWheelEvent(Sdl2NativeWindow window, MouseWheelEvent ev)
|
static void ProcessMouseWheelEvent(Sdl2NativeWindow window, MouseWheelEvent ev)
|
||||||
|
|
Loading…
Reference in a new issue