Apply cursor doubling setting without requiring a restart.
This commit is contained in:
committed by
Matthias Mailänder
parent
847db5e59b
commit
f7e5111123
@@ -30,20 +30,20 @@ namespace OpenRA.Graphics
|
||||
|
||||
readonly Dictionary<string, Cursor> cursors = new Dictionary<string, Cursor>();
|
||||
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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<PanelType, Action> leavePanelActions = new Dictionary<PanelType, Action>();
|
||||
@@ -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 = () =>
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user