Merge pull request #6266 from huwpascoe/uiscaling

Cursor Doubling
This commit is contained in:
Matthias Mailänder
2014-08-23 16:14:13 +02:00
8 changed files with 41 additions and 11 deletions

View File

@@ -22,6 +22,8 @@ namespace OpenRA.Graphics
Dictionary<string, CursorSequence> cursors;
Cache<string, PaletteReference> palettes;
public static bool CursorViewportZoomed { get { return Game.Settings.Graphics.CursorDouble && Game.Settings.Graphics.PixelDouble; } }
public CursorProvider(ModData modData)
{
var sequenceFiles = modData.Manifest.Cursors;
@@ -72,12 +74,17 @@ namespace OpenRA.Graphics
{
var cursorSequence = GetCursorSequence(cursorName);
var cursorSprite = cursorSequence.GetSprite(cursorFrame);
var cursorSize = CursorViewportZoomed ? 2.0f * cursorSprite.size : cursorSprite.size;
var cursorOffset = CursorViewportZoomed ?
(2 * cursorSequence.Hotspot) + cursorSprite.size.ToInt2() :
cursorSequence.Hotspot + (0.5f * cursorSprite.size).ToInt2();
renderer.SetPalette(palette);
renderer.SpriteRenderer.DrawSprite(cursorSprite,
lastMousePos - cursorSequence.Hotspot - (0.5f * cursorSprite.size).ToInt2(),
palettes[cursorSequence.Palette],
cursorSprite.size);
lastMousePos - cursorOffset,
palettes[cursorSequence.Palette],
cursorSize);
}
public CursorSequence GetCursorSequence(string cursor)

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Graphics
public readonly TextureChannel channel;
public readonly float2 size;
public readonly float2 offset;
public readonly float2 fractionalOffset;
readonly float2[] textureCoords;
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
@@ -37,6 +38,8 @@ namespace OpenRA.Graphics
this.size = new float2(bounds.Size);
this.blendMode = blendMode;
this.fractionalOffset = offset / this.size;
var left = (float)(bounds.Left) / sheet.Size.Width;
var top = (float)(bounds.Top) / sheet.Size.Height;
var right = (float)(bounds.Right) / sheet.Size.Width;

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Graphics
currentBlend = s.blendMode;
currentSheet = s.sheet;
Util.FastCreateQuad(vertices, location + s.offset, s, paletteIndex, nv, size);
Util.FastCreateQuad(vertices, location + s.fractionalOffset * size, s, paletteIndex, nv, size);
nv += 4;
}

View File

@@ -86,6 +86,7 @@ namespace OpenRA
public int2 FullscreenSize = new int2(0, 0);
public int2 WindowedSize = new int2(1024, 768);
public bool PixelDouble = false;
public bool CursorDouble = false;
public bool CapFramerate = true;
public int MaxFramerate = 60;

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Widgets
{
get
{
var pos = Viewport.LastMousePos + CursorOffset;
var pos = Viewport.LastMousePos + (CursorProvider.CursorViewportZoomed ? CursorOffset * 2 : CursorOffset);
if (tooltip != null)
{
if (pos.X + tooltip.Bounds.Right > Game.Renderer.Resolution.Width)

View File

@@ -149,6 +149,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var gs = Game.Settings.Game;
BindCheckboxPref(panel, "PIXELDOUBLE_CHECKBOX", ds, "PixelDouble");
BindCheckboxPref(panel, "CURSORDOUBLE_CHECKBOX", ds, "CursorDouble");
BindCheckboxPref(panel, "FRAME_LIMIT_CHECKBOX", ds, "CapFramerate");
BindCheckboxPref(panel, "SHOW_SHELLMAP", gs, "ShowShellmap");
BindCheckboxPref(panel, "ALWAYS_SHOW_STATUS_BARS_CHECKBOX", gs, "AlwaysShowStatusBars");
@@ -165,13 +166,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic
// Update zoom immediately
var pixelDoubleCheckbox = panel.Get<CheckboxWidget>("PIXELDOUBLE_CHECKBOX");
var oldOnClick = pixelDoubleCheckbox.OnClick;
var pixelDoubleOnClick = pixelDoubleCheckbox.OnClick;
pixelDoubleCheckbox.OnClick = () =>
{
oldOnClick();
pixelDoubleOnClick();
worldRenderer.Viewport.Zoom = ds.PixelDouble ? 2 : 1;
};
var cursorDoubleCheckbox = panel.Get<CheckboxWidget>("CURSORDOUBLE_CHECKBOX");
cursorDoubleCheckbox.IsDisabled = () => !ds.PixelDouble;
panel.Get("WINDOW_RESOLUTION").IsVisible = () => ds.Mode == WindowMode.Windowed;
var windowWidth = panel.Get<TextFieldWidget>("WINDOW_WIDTH");
windowWidth.Text = ds.WindowedSize.X.ToString();
@@ -218,6 +222,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ds.WindowedSize = dds.WindowedSize;
ds.PixelDouble = dds.PixelDouble;
ds.CursorDouble = dds.CursorDouble;
worldRenderer.Viewport.Zoom = ds.PixelDouble ? 2 : 1;
};
}

View File

@@ -113,6 +113,13 @@ Container@SETTINGS_PANEL:
Height: 20
Font: Regular
Text: Enable Pixel Doubling
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 355
Y: 135
Width: 200
Height: 20
Font: Regular
Text: Also Double Cursor
Label@FRAME_LIMIT_DESC_A:
X: 45
Y: 132
@@ -133,7 +140,7 @@ Container@SETTINGS_PANEL:
Text: FPS
Checkbox@TEAM_HEALTH_COLORS_CHECKBOX:
X: 310
Y: 135
Y: 170
Width: 200
Height: 20
Font: Regular
@@ -147,7 +154,7 @@ Container@SETTINGS_PANEL:
Text: Show Shellmap
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
X: 310
Y: 170
Y: 205
Width: 200
Height: 20
Font: Regular

View File

@@ -126,6 +126,13 @@ Background@SETTINGS_PANEL:
Height: 20
Font: Regular
Text: Enable Pixel Doubling
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 355
Y: 135
Width: 200
Height: 20
Font: Regular
Text: Also Double Cursor
Label@FRAME_LIMIT_DESC_A:
X: 45
Y: 132
@@ -146,7 +153,7 @@ Background@SETTINGS_PANEL:
Text: FPS
Checkbox@TEAM_HEALTH_COLORS_CHECKBOX:
X: 310
Y: 135
Y: 170
Width: 200
Height: 20
Font: Regular
@@ -160,7 +167,7 @@ Background@SETTINGS_PANEL:
Text: Show Shellmap
Checkbox@ALWAYS_SHOW_STATUS_BARS_CHECKBOX:
X: 310
Y: 170
Y: 205
Width: 200
Height: 20
Font: Regular