Fix IDE0055

This rule no longer appears to be buggy, so enforce it. Some of the automated fixes are adjusted in order to improve the result. #pragma directives have no option to control indentation, so remove them where possible.
This commit is contained in:
RoosterDragon
2023-11-09 19:56:52 +00:00
committed by Pavel Penev
parent 60cbf79c9b
commit 360f24f609
58 changed files with 719 additions and 714 deletions

View File

@@ -79,147 +79,87 @@ namespace OpenRA.Platforms.Default
break;
case SDL.SDL_EventType.SDL_WINDOWEVENT:
{
switch (e.window.windowEvent)
{
switch (e.window.windowEvent)
{
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
device.HasInputFocus = false;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
device.HasInputFocus = false;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
device.HasInputFocus = true;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
device.HasInputFocus = true;
break;
// Triggered when moving between displays with different DPI settings
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
device.WindowSizeChanged();
break;
// Triggered when moving between displays with different DPI settings
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
device.WindowSizeChanged();
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
device.IsSuspended = true;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
device.IsSuspended = true;
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
device.IsSuspended = false;
break;
}
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
device.IsSuspended = false;
break;
}
break;
}
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
{
// Mouse 1, Mouse 2 and Mouse 3 are handled as mouse inputs
// Mouse 4 and Mouse 5 are treated as (pseudo) keyboard inputs
if (e.button.button == SDL.SDL_BUTTON_LEFT ||
e.button.button == SDL.SDL_BUTTON_MIDDLE ||
e.button.button == SDL.SDL_BUTTON_RIGHT)
{
// Mouse 1, Mouse 2 and Mouse 3 are handled as mouse inputs
// Mouse 4 and Mouse 5 are treated as (pseudo) keyboard inputs
if (e.button.button == SDL.SDL_BUTTON_LEFT ||
e.button.button == SDL.SDL_BUTTON_MIDDLE ||
e.button.button == SDL.SDL_BUTTON_RIGHT)
if (pendingMotion != null)
{
if (pendingMotion != null)
{
inputHandler.OnMouseInput(pendingMotion.Value);
pendingMotion = null;
}
var button = MakeButton(e.button.button);
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
lastButtonBits |= button;
else
lastButtonBits &= ~button;
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, int2.Zero, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
else
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, int2.Zero, mods,
MultiTapDetection.InfoFromMouse(e.button.button)));
inputHandler.OnMouseInput(pendingMotion.Value);
pendingMotion = null;
}
if (e.button.button == SDL.SDL_BUTTON_X1 ||
e.button.button == SDL.SDL_BUTTON_X2)
{
Keycode keyCode;
var button = MakeButton(e.button.button);
if (e.button.button == SDL.SDL_BUTTON_X1)
keyCode = Keycode.MOUSE4;
else
keyCode = Keycode.MOUSE5;
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
lastButtonBits |= button;
else
lastButtonBits &= ~button;
var type = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode, mods) :
MultiTapDetection.InfoFromKeyboard(keyCode, mods);
var keyEvent = new KeyInput
{
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = '?',
MultiTapCount = tapCount,
IsRepeat = e.key.repeat != 0
};
inputHandler.OnKeyInput(keyEvent);
}
break;
}
case SDL.SDL_EventType.SDL_MOUSEMOTION:
{
var mousePos = new int2(e.motion.x, e.motion.y);
var input = lockedMousePosition ?? mousePos;
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
var pos = EventPosition(device, input.X, input.Y);
var delta = lockedMousePosition == null
? EventPosition(device, e.motion.xrel, e.motion.yrel)
: mousePos - lockedMousePosition.Value;
pendingMotion = new MouseInput(
MouseInputEvent.Move, lastButtonBits, pos, delta, mods, 0);
break;
if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, int2.Zero, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
else
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, int2.Zero, mods,
MultiTapDetection.InfoFromMouse(e.button.button)));
}
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
if (e.button.button == SDL.SDL_BUTTON_X1 ||
e.button.button == SDL.SDL_BUTTON_X2)
{
SDL.SDL_GetMouseState(out var x, out var y);
Keycode keyCode;
var pos = EventPosition(device, x, y);
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, pos, new int2(0, e.wheel.y), mods, 0));
if (e.button.button == SDL.SDL_BUTTON_X1)
keyCode = Keycode.MOUSE4;
else
keyCode = Keycode.MOUSE5;
break;
}
case SDL.SDL_EventType.SDL_TEXTINPUT:
{
var rawBytes = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
unsafe { Marshal.Copy((IntPtr)e.text.text, rawBytes, 0, SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE); }
inputHandler.OnTextInput(Encoding.UTF8.GetString(rawBytes, 0, Array.IndexOf(rawBytes, (byte)0)));
break;
}
case SDL.SDL_EventType.SDL_KEYDOWN:
case SDL.SDL_EventType.SDL_KEYUP:
{
var keyCode = (Keycode)e.key.keysym.sym;
var type = e.type == SDL.SDL_EventType.SDL_KEYDOWN ?
var type = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == SDL.SDL_EventType.SDL_KEYDOWN ?
var tapCount = e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode, mods) :
MultiTapDetection.InfoFromKeyboard(keyCode, mods);
@@ -228,20 +168,80 @@ namespace OpenRA.Platforms.Default
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.sym,
UnicodeChar = '?',
MultiTapCount = tapCount,
IsRepeat = e.key.repeat != 0
};
// Special case workaround for windows users
if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_F4 && mods.HasModifier(Modifiers.Alt) &&
Platform.CurrentPlatform == PlatformType.Windows)
Game.Exit();
else
inputHandler.OnKeyInput(keyEvent);
break;
inputHandler.OnKeyInput(keyEvent);
}
break;
}
case SDL.SDL_EventType.SDL_MOUSEMOTION:
{
var mousePos = new int2(e.motion.x, e.motion.y);
var input = lockedMousePosition ?? mousePos;
var pos = EventPosition(device, input.X, input.Y);
var delta = lockedMousePosition == null
? EventPosition(device, e.motion.xrel, e.motion.yrel)
: mousePos - lockedMousePosition.Value;
pendingMotion = new MouseInput(
MouseInputEvent.Move, lastButtonBits, pos, delta, mods, 0);
break;
}
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
{
SDL.SDL_GetMouseState(out var x, out var y);
var pos = EventPosition(device, x, y);
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, pos, new int2(0, e.wheel.y), mods, 0));
break;
}
case SDL.SDL_EventType.SDL_TEXTINPUT:
{
var rawBytes = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
unsafe { Marshal.Copy((IntPtr)e.text.text, rawBytes, 0, SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE); }
inputHandler.OnTextInput(Encoding.UTF8.GetString(rawBytes, 0, Array.IndexOf(rawBytes, (byte)0)));
break;
}
case SDL.SDL_EventType.SDL_KEYDOWN:
case SDL.SDL_EventType.SDL_KEYUP:
{
var keyCode = (Keycode)e.key.keysym.sym;
var type = e.type == SDL.SDL_EventType.SDL_KEYDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == SDL.SDL_EventType.SDL_KEYDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode, mods) :
MultiTapDetection.InfoFromKeyboard(keyCode, mods);
var keyEvent = new KeyInput
{
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.sym,
MultiTapCount = tapCount,
IsRepeat = e.key.repeat != 0
};
// Special case workaround for windows users
if (e.key.keysym.sym == SDL.SDL_Keycode.SDLK_F4 && mods.HasModifier(Modifiers.Alt) &&
Platform.CurrentPlatform == PlatformType.Windows)
Game.Exit();
else
inputHandler.OnKeyInput(keyEvent);
break;
}
}
}

View File

@@ -99,7 +99,7 @@ namespace OpenRA.Platforms.Default
getCreateVertexBuffer =
tuple =>
{
(object t, var type) = ((int, Type))tuple;
(object t, var type) = ((int, Type))tuple;
var vertexBuffer = context.GetType().GetMethod(nameof(CreateVertexBuffer)).MakeGenericMethod(type).Invoke(context, new[] { t });
return typeof(ThreadedVertexBuffer<>).MakeGenericType(type).GetConstructors()[0].Invoke(new[] { this, vertexBuffer });
};