Add Graphics.UIScale setting to modify UI size.

This commit is contained in:
Paul Chote
2019-12-25 18:00:04 +00:00
committed by teinarss
parent ce445f993c
commit 6388a6bff4
12 changed files with 78 additions and 42 deletions

View File

@@ -193,14 +193,13 @@ namespace OpenRA.Graphics
// Cursor is rendered in native window coordinates
// Apply same scaling rules as hardware cursors
var ws = Game.Renderer.WindowScale;
if (ws > 1.5f)
if (Game.Renderer.NativeWindowScale > 1.5f)
cursorSize = 2 * cursorSize;
var mousePos = isLocked ? lockedPosition : Viewport.LastMousePos;
renderer.RgbaSpriteRenderer.DrawSprite(cursorSprite,
mousePos,
cursorSize / ws);
cursorSize / Game.Renderer.WindowScale);
}
public void Lock()

View File

@@ -17,7 +17,7 @@ namespace OpenRA
{
public interface IPlatform
{
IPlatformWindow CreateWindow(Size size, WindowMode windowMode, int batchSize);
IPlatformWindow CreateWindow(Size size, WindowMode windowMode, float scaleModifier, int batchSize);
ISoundEngine CreateSound(string device);
IFont CreateFont(byte[] data);
}
@@ -39,11 +39,13 @@ namespace OpenRA
{
IGraphicsContext Context { get; }
Size WindowSize { get; }
float WindowScale { get; }
Size NativeWindowSize { get; }
Size EffectiveWindowSize { get; }
float NativeWindowScale { get; }
float EffectiveWindowScale { get; }
Size SurfaceSize { get; }
event Action<float, float> OnWindowScaleChanged;
event Action<float, float, float, float> OnWindowScaleChanged;
void PumpInput(IInputHandler inputHandler);
string GetClipboardText();

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Graphics
private set
{
zoom = value;
viewportSize = (1f / zoom * new float2(Game.Renderer.Resolution)).ToInt2();
viewportSize = (1f / zoom * new float2(Game.Renderer.NativeResolution)).ToInt2();
cellsDirty = true;
allCellsDirty = true;
}
@@ -181,7 +181,7 @@ namespace OpenRA.Graphics
float CalculateMinimumZoom(float minHeight, float maxHeight)
{
var h = Game.Renderer.Resolution.Height;
var h = Game.Renderer.NativeResolution.Height;
// Check the easy case: the native resolution is within the maximum limit
// Also catches the case where the user may force a resolution smaller than the minimum window size
@@ -222,7 +222,7 @@ namespace OpenRA.Graphics
minZoom = CalculateMinimumZoom(range.X, range.Y);
}
maxZoom = Math.Min(minZoom * viewportSizes.MaxZoomScale, Game.Renderer.Resolution.Height * 1f / viewportSizes.MaxZoomWindowHeight);
maxZoom = Math.Min(minZoom * viewportSizes.MaxZoomScale, Game.Renderer.NativeResolution.Height * 1f / viewportSizes.MaxZoomWindowHeight);
if (unlockMinZoom)
{
@@ -304,9 +304,9 @@ namespace OpenRA.Graphics
yield return new MPos(u, v);
}
public int2 ViewToWorldPx(int2 view) { return (1f / Zoom * view.ToFloat2()).ToInt2() + TopLeft; }
public int2 WorldToViewPx(int2 world) { return (Zoom * (world - TopLeft).ToFloat2()).ToInt2(); }
public int2 WorldToViewPx(float3 world) { return (Zoom * (world - TopLeft).XY).ToInt2(); }
public int2 ViewToWorldPx(int2 view) { return (graphicSettings.UIScale / Zoom * view.ToFloat2()).ToInt2() + TopLeft; }
public int2 WorldToViewPx(int2 world) { return ((Zoom / graphicSettings.UIScale) * (world - TopLeft).ToFloat2()).ToInt2(); }
public int2 WorldToViewPx(float3 world) { return ((Zoom / graphicSettings.UIScale) * (world - TopLeft).XY).ToInt2(); }
public void Center(IEnumerable<Actor> actors)
{

View File

@@ -66,7 +66,7 @@ namespace OpenRA
this.platform = platform;
var resolution = GetResolution(graphicSettings);
Window = platform.CreateWindow(new Size(resolution.Width, resolution.Height), graphicSettings.Mode, graphicSettings.BatchSize);
Window = platform.CreateWindow(new Size(resolution.Width, resolution.Height), graphicSettings.Mode, graphicSettings.UIScale, graphicSettings.BatchSize);
Context = Window.Context;
TempBufferSize = graphicSettings.BatchSize;
@@ -103,17 +103,17 @@ namespace OpenRA
fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512);
Fonts = modData.Manifest.Get<Fonts>().FontList.ToDictionary(x => x.Key,
x => new SpriteFont(x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(),
x.Value.Size, x.Value.Ascender, Window.WindowScale, fontSheetBuilder)).AsReadOnly();
x.Value.Size, x.Value.Ascender, Window.EffectiveWindowScale, fontSheetBuilder)).AsReadOnly();
}
Window.OnWindowScaleChanged += (before, after) =>
Window.OnWindowScaleChanged += (oldNative, oldEffective, newNative, newEffective) =>
{
Game.RunAfterTick(() =>
{
ChromeProvider.SetDPIScale(after);
ChromeProvider.SetDPIScale(newEffective);
foreach (var f in Fonts)
f.Value.SetScale(after);
f.Value.SetScale(newEffective);
});
};
}
@@ -159,7 +159,7 @@ namespace OpenRA
// but to have a higher resolution backing surface with more than 1 texture pixel per viewport pixel.
// We must convert the surface buffer size to a viewport size - in general this is NOT just the window size
// rounded to the next power of two, as the NextPowerOf2 calculation is done in the surface pixel coordinates
var scale = Window.WindowScale;
var scale = Window.EffectiveWindowScale;
var bufferSize = new Size((int)(surfaceBufferSize.Width / scale), (int)(surfaceBufferSize.Height / scale));
if (lastBufferSize != bufferSize)
{
@@ -220,7 +220,7 @@ namespace OpenRA
// Render the world buffer into the UI buffer
screenBuffer.Bind();
var scale = Window.WindowScale;
var scale = Window.EffectiveWindowScale;
var bufferSize = new Size((int)(screenSprite.Bounds.Width / scale), (int)(-screenSprite.Bounds.Height / scale));
SpriteRenderer.SetAntialiasingPixelsPerTexel(Window.SurfaceSize.Height * 1f / worldSprite.Bounds.Height);
@@ -292,8 +292,10 @@ namespace OpenRA
CurrentBatchRenderer = null;
}
public Size Resolution { get { return Window.WindowSize; } }
public float WindowScale { get { return Window.WindowScale; } }
public Size Resolution { get { return Window.EffectiveWindowSize; } }
public Size NativeResolution { get { return Window.NativeWindowSize; } }
public float WindowScale { get { return Window.EffectiveWindowScale; } }
public float NativeWindowScale { get { return Window.NativeWindowScale; } }
public interface IBatchRenderer { void Flush(); }
@@ -385,7 +387,7 @@ namespace OpenRA
throw new InvalidOperationException("EndFrame called with renderType = {0}, expected RenderType.UI.".F(renderType));
Flush();
SpriteRenderer.SetAntialiasingPixelsPerTexel(Window.WindowScale);
SpriteRenderer.SetAntialiasingPixelsPerTexel(Window.EffectiveWindowScale);
}
public void DisableAntialiasingFilter()

View File

@@ -156,6 +156,7 @@ namespace OpenRA
public bool CursorDouble = false;
public WorldViewport ViewportDistance = WorldViewport.Medium;
public float UIScale = 1;
[Desc("Add a frame rate limiter.")]
public bool CapFramerate = false;