Add Graphics.UIScale setting to modify UI size.
This commit is contained in:
@@ -16,9 +16,9 @@ namespace OpenRA.Platforms.Default
|
||||
{
|
||||
public class DefaultPlatform : IPlatform
|
||||
{
|
||||
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, int batchSize)
|
||||
public IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int batchSize)
|
||||
{
|
||||
return new Sdl2PlatformWindow(size, windowMode, batchSize);
|
||||
return new Sdl2PlatformWindow(size, windowMode, scaleModifier, batchSize);
|
||||
}
|
||||
|
||||
public ISoundEngine CreateSound(string device)
|
||||
|
||||
@@ -98,8 +98,8 @@ namespace OpenRA.Platforms.Default
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
|
||||
var windowSize = window.WindowSize;
|
||||
var windowScale = window.WindowScale;
|
||||
var windowSize = window.EffectiveWindowSize;
|
||||
var windowScale = window.EffectiveWindowScale;
|
||||
var surfaceSize = window.SurfaceSize;
|
||||
|
||||
if (windowSize != surfaceSize)
|
||||
|
||||
@@ -44,8 +44,19 @@ namespace OpenRA.Platforms.Default
|
||||
{
|
||||
// On Windows and Linux (X11) events are given in surface coordinates
|
||||
// These must be scaled to our effective window coordinates
|
||||
if (Platform.CurrentPlatform != PlatformType.OSX && device.WindowSize != device.SurfaceSize)
|
||||
return new int2((int)(x / device.WindowScale), (int)(y / device.WindowScale));
|
||||
// Round fractional components up to avoid rounding small deltas to 0
|
||||
if (Platform.CurrentPlatform != PlatformType.OSX && device.EffectiveWindowSize != device.SurfaceSize)
|
||||
{
|
||||
var s = 1 / device.EffectiveWindowScale;
|
||||
return new int2((int)(Math.Sign(x) / 2f + x * s), (int)(Math.Sign(x) / 2f + y * s));
|
||||
}
|
||||
|
||||
// On macOS we must still account for the user-requested scale modifier
|
||||
if (Platform.CurrentPlatform == PlatformType.OSX && device.EffectiveWindowScale != device.NativeWindowScale)
|
||||
{
|
||||
var s = device.NativeWindowScale / device.EffectiveWindowScale;
|
||||
return new int2((int)(Math.Sign(x) / 2f + x * s), (int)(Math.Sign(x) / 2f + y * s));
|
||||
}
|
||||
|
||||
return new int2(x, y);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OpenRA.Platforms.Default
|
||||
Size surfaceSize;
|
||||
float windowScale = 1f;
|
||||
int2? lockedMousePosition;
|
||||
float scaleModifier;
|
||||
|
||||
internal IntPtr Window
|
||||
{
|
||||
@@ -41,7 +42,7 @@ namespace OpenRA.Platforms.Default
|
||||
}
|
||||
}
|
||||
|
||||
public Size WindowSize
|
||||
public Size NativeWindowSize
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -50,7 +51,16 @@ namespace OpenRA.Platforms.Default
|
||||
}
|
||||
}
|
||||
|
||||
public float WindowScale
|
||||
public Size EffectiveWindowSize
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (syncObject)
|
||||
return new Size((int)(windowSize.Width / scaleModifier), (int)(windowSize.Height / scaleModifier));
|
||||
}
|
||||
}
|
||||
|
||||
public float NativeWindowScale
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -59,6 +69,15 @@ namespace OpenRA.Platforms.Default
|
||||
}
|
||||
}
|
||||
|
||||
public float EffectiveWindowScale
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (syncObject)
|
||||
return windowScale * scaleModifier;
|
||||
}
|
||||
}
|
||||
|
||||
public Size SurfaceSize
|
||||
{
|
||||
get
|
||||
@@ -68,16 +87,18 @@ namespace OpenRA.Platforms.Default
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<float, float> OnWindowScaleChanged = (before, after) => { };
|
||||
public event Action<float, float, float, float> OnWindowScaleChanged = (oldNative, oldEffective, newNative, newEffective) => { };
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
static extern bool SetProcessDPIAware();
|
||||
|
||||
public Sdl2PlatformWindow(Size requestEffectiveWindowSize, WindowMode windowMode, int batchSize)
|
||||
public Sdl2PlatformWindow(Size requestEffectiveWindowSize, WindowMode windowMode, float scaleModifier, int batchSize)
|
||||
{
|
||||
// Lock the Window/Surface properties until initialization is complete
|
||||
lock (syncObject)
|
||||
{
|
||||
this.scaleModifier = scaleModifier;
|
||||
|
||||
// Disable legacy scaling on Windows
|
||||
if (Platform.CurrentPlatform == PlatformType.Windows)
|
||||
SetProcessDPIAware();
|
||||
@@ -269,7 +290,7 @@ namespace OpenRA.Platforms.Default
|
||||
{
|
||||
// Pixel double the cursor on non-OSX if the window scale is large enough
|
||||
// OSX does this for us automatically
|
||||
if (Platform.CurrentPlatform != PlatformType.OSX && WindowScale > 1.5)
|
||||
if (Platform.CurrentPlatform != PlatformType.OSX && NativeWindowScale > 1.5f)
|
||||
{
|
||||
data = DoublePixelData(data, size);
|
||||
size = new Size(2 * size.Width, 2 * size.Height);
|
||||
@@ -341,7 +362,7 @@ namespace OpenRA.Platforms.Default
|
||||
windowScale = width * 1f / windowSize.Width;
|
||||
}
|
||||
|
||||
OnWindowScaleChanged(oldScale, windowScale);
|
||||
OnWindowScaleChanged(oldScale, oldScale * scaleModifier, windowScale, windowScale * scaleModifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user