diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index 23ed06d21e..16e68d53b0 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -30,20 +30,20 @@ namespace OpenRA.Graphics readonly Dictionary cursors = new Dictionary(); readonly SheetBuilder sheetBuilder; + readonly GraphicSettings graphicSettings; Cursor cursor; bool isLocked = false; int2 lockedPosition; bool hardwareCursorsDisabled = false; - - public readonly bool DoubleCursorSize; + bool hardwareCursorsDoubled = false; public CursorManager(CursorProvider cursorProvider) { // Cursor settings are applied on game start - DoubleCursorSize = Game.Settings.Graphics.CursorDouble; hardwareCursorsDisabled = !Game.Settings.Graphics.HardwareCursors; + graphicSettings = Game.Settings.Graphics; sheetBuilder = new SheetBuilder(SheetType.BGRA); foreach (var kv in cursorProvider.Cursors) { @@ -128,6 +128,8 @@ namespace OpenRA.Graphics ClearHardwareCursors(); } + + hardwareCursorsDoubled = graphicSettings.CursorDouble; } public void SetCursor(string cursorName) @@ -146,6 +148,12 @@ namespace OpenRA.Graphics public void Tick() { + if (hardwareCursorsDoubled != graphicSettings.CursorDouble) + { + CreateOrUpdateHardwareCursors(); + Update(); + } + if (cursor == null || cursor.Cursors.Length == 1) return; @@ -180,7 +188,7 @@ namespace OpenRA.Graphics return; // Render cursor in software - var doubleCursor = DoubleCursorSize && cursor.Name != "default"; + var doubleCursor = graphicSettings.CursorDouble && cursor.Name != "default"; var cursorSprite = cursor.Sprites[frame % cursor.Length]; var cursorSize = doubleCursor ? 2.0f * cursorSprite.Size : cursorSprite.Size; var mousePos = isLocked ? lockedPosition : Viewport.LastMousePos; @@ -247,6 +255,7 @@ namespace OpenRA.Graphics var newWidth = paddingTL.X + size.Width + paddingBR.X; var newHeight = paddingTL.Y + size.Height + paddingBR.Y; var rgbaData = new byte[4 * newWidth * newHeight]; + for (var j = 0; j < size.Height; j++) { for (var i = 0; i < size.Width; i++) @@ -257,7 +266,7 @@ namespace OpenRA.Graphics } } - return Game.Renderer.Window.CreateHardwareCursor(name, new Size(newWidth, newHeight), rgbaData, hotspot); + return Game.Renderer.Window.CreateHardwareCursor(name, new Size(newWidth, newHeight), rgbaData, hotspot, graphicSettings.CursorDouble && cursor.Name != "default"); } void ClearHardwareCursors() diff --git a/OpenRA.Game/Graphics/PlatformInterfaces.cs b/OpenRA.Game/Graphics/PlatformInterfaces.cs index e4046c3f61..3e8b7d22b0 100644 --- a/OpenRA.Game/Graphics/PlatformInterfaces.cs +++ b/OpenRA.Game/Graphics/PlatformInterfaces.cs @@ -52,7 +52,7 @@ namespace OpenRA void GrabWindowMouseFocus(); void ReleaseWindowMouseFocus(); - IHardwareCursor CreateHardwareCursor(string name, Size size, byte[] data, int2 hotspot); + IHardwareCursor CreateHardwareCursor(string name, Size size, byte[] data, int2 hotspot, bool pixelDouble); void SetHardwareCursor(IHardwareCursor cursor); void SetRelativeMouseMode(bool mode); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 651d4d6345..c7779a2b93 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -27,7 +27,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic static readonly int2 OriginalGraphicsWindowedSize; static readonly int2 OriginalGraphicsFullscreenSize; static readonly bool OriginalGraphicsHardwareCursors; - static readonly bool OriginalGraphicsCursorDouble; static readonly bool OriginalServerDiscoverNatDevices; readonly Dictionary leavePanelActions = new Dictionary(); @@ -55,7 +54,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic OriginalGraphicsWindowedSize = original.Graphics.WindowedSize; OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize; OriginalGraphicsHardwareCursors = original.Graphics.HardwareCursors; - OriginalGraphicsCursorDouble = original.Graphics.CursorDouble; OriginalServerDiscoverNatDevices = original.Server.DiscoverNatDevices; } @@ -87,8 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic current.Graphics.WindowedSize != OriginalGraphicsWindowedSize || current.Graphics.FullscreenSize != OriginalGraphicsFullscreenSize || current.Server.DiscoverNatDevices != OriginalServerDiscoverNatDevices || - current.Graphics.HardwareCursors != OriginalGraphicsHardwareCursors || - current.Graphics.CursorDouble != OriginalGraphicsCursorDouble) + current.Graphics.HardwareCursors != OriginalGraphicsHardwareCursors) { Action restart = () => { diff --git a/OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs b/OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs index 29e827dc57..c499da979c 100644 --- a/OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs +++ b/OpenRA.Mods.Common/Widgets/MouseAttachmentWidget.cs @@ -20,6 +20,7 @@ namespace OpenRA.Mods.Common.Widgets Sprite sprite; readonly WorldRenderer worldRenderer; + readonly GraphicSettings graphicSettings; string palette; int2 location; @@ -27,6 +28,7 @@ namespace OpenRA.Mods.Common.Widgets public MouseAttachmentWidget(ModData modData, WorldRenderer worldRenderer) { this.worldRenderer = worldRenderer; + graphicSettings = Game.Settings.Graphics; } public override void Draw() @@ -34,7 +36,7 @@ namespace OpenRA.Mods.Common.Widgets if (sprite != null && palette != null) { var directionPalette = worldRenderer.Palette(palette); - WidgetUtils.DrawSHPCentered(sprite, ChildOrigin, directionPalette, Game.Cursor.DoubleCursorSize ? 2 : 1); + WidgetUtils.DrawSHPCentered(sprite, ChildOrigin, directionPalette, graphicSettings.CursorDouble ? 2 : 1); } } diff --git a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs index b9a08cb1d6..fd07742524 100644 --- a/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TooltipContainerWidget.cs @@ -19,6 +19,7 @@ namespace OpenRA.Mods.Common.Widgets public class TooltipContainerWidget : Widget { static readonly Action Nothing = () => { }; + readonly GraphicSettings graphicSettings; public int2 CursorOffset = new int2(0, 20); public int BottomEdgeYOffset = -5; @@ -29,6 +30,7 @@ namespace OpenRA.Mods.Common.Widgets public TooltipContainerWidget() { + graphicSettings = Game.Settings.Graphics; IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds; } @@ -52,7 +54,8 @@ namespace OpenRA.Mods.Common.Widgets { get { - var pos = Viewport.LastMousePos + (Game.Cursor.DoubleCursorSize ? CursorOffset * 2 : CursorOffset); + var scale = graphicSettings.CursorDouble ? 2 : 1; + var pos = Viewport.LastMousePos + scale * CursorOffset; if (tooltip != null) { // If the tooltip overlaps the right edge of the screen, move it left until it fits @@ -61,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets // If the tooltip overlaps the bottom edge of the screen, switch tooltip above cursor if (pos.Y + tooltip.Bounds.Bottom > Game.Renderer.Resolution.Height) - pos = pos.WithY(Viewport.LastMousePos.Y + (Game.Cursor.DoubleCursorSize ? 2 : 1) * BottomEdgeYOffset - tooltip.Bounds.Height); + pos = pos.WithY(Viewport.LastMousePos.Y + scale * BottomEdgeYOffset - tooltip.Bounds.Height); } return pos; diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index 23f0345de0..51100432c9 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -265,7 +265,7 @@ namespace OpenRA.Platforms.Default return scaledData; } - public IHardwareCursor CreateHardwareCursor(string name, Size size, byte[] data, int2 hotspot) + public IHardwareCursor CreateHardwareCursor(string name, Size size, byte[] data, int2 hotspot, bool pixelDouble) { VerifyThreadAffinity(); try @@ -280,7 +280,7 @@ namespace OpenRA.Platforms.Default } // Scale all but the "default" cursor if requested by the player - if (Game.Settings.Graphics.CursorDouble && name != "default") + if (pixelDouble) { data = DoublePixelData(data, size); size = new Size(2 * size.Width, 2 * size.Height);