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 Dictionary<string, Cursor> cursors = new Dictionary<string, Cursor>();
|
||||||
readonly SheetBuilder sheetBuilder;
|
readonly SheetBuilder sheetBuilder;
|
||||||
|
readonly GraphicSettings graphicSettings;
|
||||||
|
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
bool isLocked = false;
|
bool isLocked = false;
|
||||||
int2 lockedPosition;
|
int2 lockedPosition;
|
||||||
bool hardwareCursorsDisabled = false;
|
bool hardwareCursorsDisabled = false;
|
||||||
|
bool hardwareCursorsDoubled = false;
|
||||||
public readonly bool DoubleCursorSize;
|
|
||||||
|
|
||||||
public CursorManager(CursorProvider cursorProvider)
|
public CursorManager(CursorProvider cursorProvider)
|
||||||
{
|
{
|
||||||
// Cursor settings are applied on game start
|
// Cursor settings are applied on game start
|
||||||
DoubleCursorSize = Game.Settings.Graphics.CursorDouble;
|
|
||||||
hardwareCursorsDisabled = !Game.Settings.Graphics.HardwareCursors;
|
hardwareCursorsDisabled = !Game.Settings.Graphics.HardwareCursors;
|
||||||
|
|
||||||
|
graphicSettings = Game.Settings.Graphics;
|
||||||
sheetBuilder = new SheetBuilder(SheetType.BGRA);
|
sheetBuilder = new SheetBuilder(SheetType.BGRA);
|
||||||
foreach (var kv in cursorProvider.Cursors)
|
foreach (var kv in cursorProvider.Cursors)
|
||||||
{
|
{
|
||||||
@@ -128,6 +128,8 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
ClearHardwareCursors();
|
ClearHardwareCursors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hardwareCursorsDoubled = graphicSettings.CursorDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCursor(string cursorName)
|
public void SetCursor(string cursorName)
|
||||||
@@ -146,6 +148,12 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
|
if (hardwareCursorsDoubled != graphicSettings.CursorDouble)
|
||||||
|
{
|
||||||
|
CreateOrUpdateHardwareCursors();
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
if (cursor == null || cursor.Cursors.Length == 1)
|
if (cursor == null || cursor.Cursors.Length == 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -180,7 +188,7 @@ namespace OpenRA.Graphics
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Render cursor in software
|
// 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 cursorSprite = cursor.Sprites[frame % cursor.Length];
|
||||||
var cursorSize = doubleCursor ? 2.0f * cursorSprite.Size : cursorSprite.Size;
|
var cursorSize = doubleCursor ? 2.0f * cursorSprite.Size : cursorSprite.Size;
|
||||||
var mousePos = isLocked ? lockedPosition : Viewport.LastMousePos;
|
var mousePos = isLocked ? lockedPosition : Viewport.LastMousePos;
|
||||||
@@ -247,6 +255,7 @@ namespace OpenRA.Graphics
|
|||||||
var newWidth = paddingTL.X + size.Width + paddingBR.X;
|
var newWidth = paddingTL.X + size.Width + paddingBR.X;
|
||||||
var newHeight = paddingTL.Y + size.Height + paddingBR.Y;
|
var newHeight = paddingTL.Y + size.Height + paddingBR.Y;
|
||||||
var rgbaData = new byte[4 * newWidth * newHeight];
|
var rgbaData = new byte[4 * newWidth * newHeight];
|
||||||
|
|
||||||
for (var j = 0; j < size.Height; j++)
|
for (var j = 0; j < size.Height; j++)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < size.Width; i++)
|
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()
|
void ClearHardwareCursors()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace OpenRA
|
|||||||
void GrabWindowMouseFocus();
|
void GrabWindowMouseFocus();
|
||||||
void ReleaseWindowMouseFocus();
|
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 SetHardwareCursor(IHardwareCursor cursor);
|
||||||
void SetRelativeMouseMode(bool mode);
|
void SetRelativeMouseMode(bool mode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
static readonly int2 OriginalGraphicsWindowedSize;
|
static readonly int2 OriginalGraphicsWindowedSize;
|
||||||
static readonly int2 OriginalGraphicsFullscreenSize;
|
static readonly int2 OriginalGraphicsFullscreenSize;
|
||||||
static readonly bool OriginalGraphicsHardwareCursors;
|
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>();
|
||||||
@@ -55,7 +54,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
OriginalGraphicsWindowedSize = original.Graphics.WindowedSize;
|
OriginalGraphicsWindowedSize = original.Graphics.WindowedSize;
|
||||||
OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize;
|
OriginalGraphicsFullscreenSize = original.Graphics.FullscreenSize;
|
||||||
OriginalGraphicsHardwareCursors = original.Graphics.HardwareCursors;
|
OriginalGraphicsHardwareCursors = original.Graphics.HardwareCursors;
|
||||||
OriginalGraphicsCursorDouble = original.Graphics.CursorDouble;
|
|
||||||
OriginalServerDiscoverNatDevices = original.Server.DiscoverNatDevices;
|
OriginalServerDiscoverNatDevices = original.Server.DiscoverNatDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,8 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
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.HardwareCursors != OriginalGraphicsHardwareCursors)
|
||||||
current.Graphics.CursorDouble != OriginalGraphicsCursorDouble)
|
|
||||||
{
|
{
|
||||||
Action restart = () =>
|
Action restart = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
|
readonly GraphicSettings graphicSettings;
|
||||||
string palette;
|
string palette;
|
||||||
int2 location;
|
int2 location;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public MouseAttachmentWidget(ModData modData, WorldRenderer worldRenderer)
|
public MouseAttachmentWidget(ModData modData, WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
|
graphicSettings = Game.Settings.Graphics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@@ -34,7 +36,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (sprite != null && palette != null)
|
if (sprite != null && palette != null)
|
||||||
{
|
{
|
||||||
var directionPalette = worldRenderer.Palette(palette);
|
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
|
public class TooltipContainerWidget : Widget
|
||||||
{
|
{
|
||||||
static readonly Action Nothing = () => { };
|
static readonly Action Nothing = () => { };
|
||||||
|
readonly GraphicSettings graphicSettings;
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
|
graphicSettings = Game.Settings.Graphics;
|
||||||
IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds;
|
IsVisible = () => Game.RunTime > Viewport.LastMoveRunTime + TooltipDelayMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +54,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
get
|
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 (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 +64,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 + (Game.Cursor.DoubleCursorSize ? 2 : 1) * BottomEdgeYOffset - tooltip.Bounds.Height);
|
pos = pos.WithY(Viewport.LastMousePos.Y + scale * BottomEdgeYOffset - tooltip.Bounds.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
return scaledData;
|
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();
|
VerifyThreadAffinity();
|
||||||
try
|
try
|
||||||
@@ -280,7 +280,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scale all but the "default" cursor if requested by the player
|
// Scale all but the "default" cursor if requested by the player
|
||||||
if (Game.Settings.Graphics.CursorDouble && name != "default")
|
if (pixelDouble)
|
||||||
{
|
{
|
||||||
data = DoublePixelData(data, size);
|
data = DoublePixelData(data, size);
|
||||||
size = new Size(2 * size.Width, 2 * size.Height);
|
size = new Size(2 * size.Width, 2 * size.Height);
|
||||||
|
|||||||
Reference in New Issue
Block a user