Overhaul cursor double setting.

This commit is contained in:
Paul Chote
2019-12-08 11:08:06 +00:00
committed by teinarss
parent 010fafc6d3
commit b0c65c5eb9
8 changed files with 48 additions and 34 deletions

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Graphics
{ {
public readonly IReadOnlyDictionary<string, CursorSequence> Cursors; public readonly IReadOnlyDictionary<string, CursorSequence> Cursors;
public readonly IReadOnlyDictionary<string, ImmutablePalette> Palettes; public readonly IReadOnlyDictionary<string, ImmutablePalette> Palettes;
public readonly bool DoubleCursorSize;
public CursorProvider(ModData modData) public CursorProvider(ModData modData)
{ {
@@ -47,9 +48,10 @@ namespace OpenRA.Graphics
cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value)); cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value));
Cursors = cursors.AsReadOnly(); Cursors = cursors.AsReadOnly();
}
public static bool CursorViewportZoomed { get { return Game.Settings.Graphics.CursorDouble && Game.Settings.Graphics.PixelDouble; } } // Cursor size changes are applied on game start
DoubleCursorSize = Game.Settings.Graphics.CursorDouble;
}
public bool HasCursorSequence(string cursor) public bool HasCursorSequence(string cursor)
{ {

View File

@@ -81,11 +81,12 @@ namespace OpenRA.Graphics
if (cursorName == null) if (cursorName == null)
return; return;
var doubleCursor = cursorProvider.DoubleCursorSize && cursorName != "default";
var cursorSequence = cursorProvider.GetCursorSequence(cursorName); var cursorSequence = cursorProvider.GetCursorSequence(cursorName);
var cursorSprite = sprites[cursorName][(int)cursorFrame % cursorSequence.Length]; var cursorSprite = sprites[cursorName][(int)cursorFrame % cursorSequence.Length];
var cursorSize = CursorProvider.CursorViewportZoomed ? 2.0f * cursorSprite.Size : cursorSprite.Size; var cursorSize = doubleCursor ? 2.0f * cursorSprite.Size : cursorSprite.Size;
var cursorOffset = CursorProvider.CursorViewportZoomed ? var cursorOffset = doubleCursor ?
(2 * cursorSequence.Hotspot) + cursorSprite.Size.XY.ToInt2() : (2 * cursorSequence.Hotspot) + cursorSprite.Size.XY.ToInt2() :
cursorSequence.Hotspot + (0.5f * cursorSprite.Size.XY).ToInt2(); cursorSequence.Hotspot + (0.5f * cursorSprite.Size.XY).ToInt2();

View File

@@ -26,6 +26,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
static readonly WindowMode OriginalGraphicsMode; static readonly WindowMode OriginalGraphicsMode;
static readonly int2 OriginalGraphicsWindowedSize; static readonly int2 OriginalGraphicsWindowedSize;
static readonly int2 OriginalGraphicsFullscreenSize; static readonly int2 OriginalGraphicsFullscreenSize;
static readonly bool OriginalGraphicsHardwareCursors;
static readonly bool OriginalGraphicsCursorDouble;
static readonly bool OriginalServerDiscoverNatDevices; static readonly bool OriginalServerDiscoverNatDevices;
readonly Dictionary<PanelType, Action> leavePanelActions = new Dictionary<PanelType, Action>(); readonly Dictionary<PanelType, Action> leavePanelActions = new Dictionary<PanelType, Action>();
@@ -52,6 +54,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
OriginalGraphicsMode = original.Graphics.Mode; OriginalGraphicsMode = original.Graphics.Mode;
OriginalGraphicsWindowedSize = original.Graphics.WindowedSize; OriginalGraphicsWindowedSize = original.Graphics.WindowedSize;
OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize; OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize;
OriginalGraphicsHardwareCursors = original.Graphics.HardwareCursors;
OriginalGraphicsCursorDouble = original.Graphics.CursorDouble;
OriginalServerDiscoverNatDevices = original.Server.DiscoverNatDevices; OriginalServerDiscoverNatDevices = original.Server.DiscoverNatDevices;
} }
@@ -82,7 +86,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
current.Graphics.Mode != OriginalGraphicsMode || current.Graphics.Mode != OriginalGraphicsMode ||
current.Graphics.WindowedSize != OriginalGraphicsWindowedSize || current.Graphics.WindowedSize != OriginalGraphicsWindowedSize ||
current.Graphics.FullscreenSize != OriginalGraphicsFullscreenSize || current.Graphics.FullscreenSize != OriginalGraphicsFullscreenSize ||
current.Server.DiscoverNatDevices != OriginalServerDiscoverNatDevices) current.Server.DiscoverNatDevices != OriginalServerDiscoverNatDevices ||
current.Graphics.HardwareCursors != OriginalGraphicsHardwareCursors ||
current.Graphics.CursorDouble != OriginalGraphicsCursorDouble)
{ {
Action restart = () => Action restart = () =>
{ {
@@ -223,13 +229,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
worldRenderer.Viewport.Zoom = ds.PixelDouble ? 2 : 1; worldRenderer.Viewport.Zoom = ds.PixelDouble ? 2 : 1;
}; };
// Cursor doubling is only supported with software cursors and when pixel doubling is enabled
var cursorDoubleCheckbox = panel.Get<CheckboxWidget>("CURSORDOUBLE_CHECKBOX");
cursorDoubleCheckbox.IsDisabled = () => !ds.PixelDouble || Game.Cursor is HardwareCursor;
var cursorDoubleIsChecked = cursorDoubleCheckbox.IsChecked;
cursorDoubleCheckbox.IsChecked = () => !cursorDoubleCheckbox.IsDisabled() && cursorDoubleIsChecked();
panel.Get("WINDOW_RESOLUTION").IsVisible = () => ds.Mode == WindowMode.Windowed; panel.Get("WINDOW_RESOLUTION").IsVisible = () => ds.Mode == WindowMode.Windowed;
var windowWidth = panel.Get<TextFieldWidget>("WINDOW_WIDTH"); var windowWidth = panel.Get<TextFieldWidget>("WINDOW_WIDTH");
windowWidth.Text = ds.WindowedSize.X.ToString(); windowWidth.Text = ds.WindowedSize.X.ToString();

View File

@@ -20,12 +20,14 @@ namespace OpenRA.Mods.Common.Widgets
Sprite sprite; Sprite sprite;
readonly WorldRenderer worldRenderer; readonly WorldRenderer worldRenderer;
readonly CursorProvider cursorProvider;
string palette; string palette;
int2 location; int2 location;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public MouseAttachmentWidget(WorldRenderer worldRenderer) public MouseAttachmentWidget(ModData modData, WorldRenderer worldRenderer)
{ {
cursorProvider = modData.CursorProvider;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
} }
@@ -33,7 +35,7 @@ namespace OpenRA.Mods.Common.Widgets
{ {
if (sprite != null && palette != null) if (sprite != null && palette != null)
{ {
var scale = Game.Cursor is SoftwareCursor && CursorProvider.CursorViewportZoomed ? 2 : 1; var scale = Game.Cursor is SoftwareCursor && cursorProvider.DoubleCursorSize ? 2 : 1;
var directionPalette = worldRenderer.Palette(palette); var directionPalette = worldRenderer.Palette(palette);
WidgetUtils.DrawSHPCentered(sprite, ChildOrigin, directionPalette, scale); WidgetUtils.DrawSHPCentered(sprite, ChildOrigin, directionPalette, scale);
} }

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Mods.Common.Widgets
public class TooltipContainerWidget : Widget public class TooltipContainerWidget : Widget
{ {
static readonly Action Nothing = () => { }; static readonly Action Nothing = () => { };
readonly CursorProvider cursorProvider;
public int2 CursorOffset = new int2(0, 20); public int2 CursorOffset = new int2(0, 20);
public int BottomEdgeYOffset = -5; public int BottomEdgeYOffset = -5;
@@ -29,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets
public TooltipContainerWidget() public TooltipContainerWidget()
{ {
cursorProvider = Game.ModData.CursorProvider;
IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds; IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds;
} }
@@ -52,7 +54,7 @@ namespace OpenRA.Mods.Common.Widgets
{ {
get get
{ {
var pos = Viewport.LastMousePos + (CursorProvider.CursorViewportZoomed ? CursorOffset * 2 : CursorOffset); var pos = Viewport.LastMousePos + (cursorProvider.DoubleCursorSize ? CursorOffset * 2 : CursorOffset);
if (tooltip != null) if (tooltip != null)
{ {
// If the tooltip overlaps the right edge of the screen, move it left until it fits // If the tooltip overlaps the right edge of the screen, move it left until it fits
@@ -61,7 +63,7 @@ namespace OpenRA.Mods.Common.Widgets
// If the tooltip overlaps the bottom edge of the screen, switch tooltip above cursor // If the tooltip overlaps the bottom edge of the screen, switch tooltip above cursor
if (pos.Y + tooltip.Bounds.Bottom > Game.Renderer.Resolution.Height) if (pos.Y + tooltip.Bounds.Bottom > Game.Renderer.Resolution.Height)
pos = pos.WithY(Viewport.LastMousePos.Y + (CursorProvider.CursorViewportZoomed ? 2 : 1) * BottomEdgeYOffset - tooltip.Bounds.Height); pos = pos.WithY(Viewport.LastMousePos.Y + (cursorProvider.DoubleCursorSize ? 2 : 1) * BottomEdgeYOffset - tooltip.Bounds.Height);
} }
return pos; return pos;

View File

@@ -277,6 +277,14 @@ namespace OpenRA.Platforms.Default
hotspot *= 2; hotspot *= 2;
} }
// Scale all but the "default" cursor if requested by the player
if (Game.Settings.Graphics.CursorDouble && name != "default")
{
data = DoublePixelData(data, size);
size = new Size(2 * size.Width, 2 * size.Height);
hotspot *= 2;
}
return new Sdl2HardwareCursor(size, data, hotspot); return new Sdl2HardwareCursor(size, data, hotspot);
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -125,14 +125,21 @@ Container@SETTINGS_PANEL:
MaxLength: 5 MaxLength: 5
Type: Integer Type: Integer
Checkbox@HARDWARECURSORS_CHECKBOX: Checkbox@HARDWARECURSORS_CHECKBOX:
X: 310 X: 80
Y: 75 Y: 75
Width: 200 Width: 200
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Use Hardware Cursors Text: Use Hardware Cursors
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 300
Y: 75
Width: 200
Height: 20
Font: Regular
Text: Increase Command Cursor Size
Label@VIDEO_DESC: Label@VIDEO_DESC:
Y: 92 Y: 97
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 25 Height: 25
Font: Tiny Font: Tiny
@@ -152,13 +159,6 @@ Container@SETTINGS_PANEL:
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Enable Pixel Doubling Text: Enable Pixel Doubling
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 340
Y: 155
Width: 200
Height: 20
Font: Regular
Text: Also Double Cursor
Label@FRAME_LIMIT_DESC_A: Label@FRAME_LIMIT_DESC_A:
X: 45 X: 45
Y: 153 Y: 153

View File

@@ -139,14 +139,21 @@ Background@SETTINGS_PANEL:
MaxLength: 5 MaxLength: 5
Type: Integer Type: Integer
Checkbox@HARDWARECURSORS_CHECKBOX: Checkbox@HARDWARECURSORS_CHECKBOX:
X: 310 X: 80
Y: 75 Y: 75
Width: 200 Width: 200
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Use Hardware Cursors Text: Use Hardware Cursors
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 300
Y: 75
Width: 200
Height: 20
Font: Regular
Text: Increase Command Cursor Size
Label@VIDEO_DESC: Label@VIDEO_DESC:
Y: 93 Y: 97
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 25 Height: 25
Font: Tiny Font: Tiny
@@ -166,13 +173,6 @@ Background@SETTINGS_PANEL:
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Enable Pixel Doubling Text: Enable Pixel Doubling
Checkbox@CURSORDOUBLE_CHECKBOX:
X: 340
Y: 160
Width: 200
Height: 20
Font: Regular
Text: Also Double Cursor
Label@FRAME_LIMIT_DESC_A: Label@FRAME_LIMIT_DESC_A:
X: 45 X: 45
Y: 159 Y: 159