Rework relative mouse events.
This commit is contained in:
@@ -26,17 +26,17 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public MouseInputEvent Event;
|
public MouseInputEvent Event;
|
||||||
public MouseButton Button;
|
public MouseButton Button;
|
||||||
public int ScrollDelta;
|
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
|
public int2 Delta;
|
||||||
public Modifiers Modifiers;
|
public Modifiers Modifiers;
|
||||||
public int MultiTapCount;
|
public int MultiTapCount;
|
||||||
|
|
||||||
public MouseInput(MouseInputEvent ev, MouseButton button, int scrollDelta, int2 location, Modifiers mods, int multiTapCount)
|
public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, int2 delta, Modifiers mods, int multiTapCount)
|
||||||
{
|
{
|
||||||
Event = ev;
|
Event = ev;
|
||||||
Button = button;
|
Button = button;
|
||||||
ScrollDelta = scrollDelta;
|
|
||||||
Location = location;
|
Location = location;
|
||||||
|
Delta = delta;
|
||||||
Modifiers = mods;
|
Modifiers = mods;
|
||||||
MultiTapCount = multiTapCount;
|
MultiTapCount = multiTapCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ namespace OpenRA.Widgets
|
|||||||
public static void ResetTooltips()
|
public static void ResetTooltips()
|
||||||
{
|
{
|
||||||
// Issue a no-op mouse move to force any tooltips to be recalculated
|
// Issue a no-op mouse move to force any tooltips to be recalculated
|
||||||
HandleInput(new MouseInput(MouseInputEvent.Move, MouseButton.None, 0,
|
HandleInput(new MouseInput(MouseInputEvent.Move, MouseButton.None,
|
||||||
Viewport.LastMousePos, Modifiers.None, 0));
|
Viewport.LastMousePos, int2.Zero, Modifiers.None, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public class SelectDirectionalTarget : IOrderGenerator
|
public class SelectDirectionalTarget : IOrderGenerator
|
||||||
{
|
{
|
||||||
|
const int MinDragThreshold = 20;
|
||||||
|
const int MaxDragThreshold = 75;
|
||||||
|
|
||||||
readonly string order;
|
readonly string order;
|
||||||
readonly SupportPowerManager manager;
|
readonly SupportPowerManager manager;
|
||||||
readonly string cursor;
|
readonly string cursor;
|
||||||
@@ -29,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
CPos targetCell;
|
CPos targetCell;
|
||||||
int2 targetLocation;
|
int2 targetLocation;
|
||||||
int2 dragLocation;
|
float2 dragDirection;
|
||||||
bool activated;
|
bool activated;
|
||||||
bool dragStarted;
|
bool dragStarted;
|
||||||
Arrow currentArrow;
|
Arrow currentArrow;
|
||||||
@@ -72,9 +75,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
{
|
{
|
||||||
dragLocation = mi.Location;
|
dragDirection += mi.Delta;
|
||||||
|
|
||||||
|
var angle = AngleOf(dragDirection);
|
||||||
|
if (dragDirection.Length > MaxDragThreshold)
|
||||||
|
dragDirection = -MaxDragThreshold * float2.FromAngle((float)(angle * (Math.PI / 180)));
|
||||||
|
|
||||||
var angle = AngleBetween(targetLocation, dragLocation);
|
|
||||||
currentArrow = GetArrow(angle);
|
currentArrow = GetArrow(angle);
|
||||||
dragStarted = true;
|
dragStarted = true;
|
||||||
}
|
}
|
||||||
@@ -100,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool IsOutsideDragZone
|
bool IsOutsideDragZone
|
||||||
{
|
{
|
||||||
get { return dragStarted && (dragLocation - targetLocation).Length > 20; }
|
get { return dragStarted && dragDirection.Length > MinDragThreshold; }
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
|
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
|
||||||
@@ -130,9 +136,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Starting at (0, -1) and rotating in CCW
|
// Starting at (0, -1) and rotating in CCW
|
||||||
static double AngleBetween(int2 p1, int2 p2)
|
static double AngleOf(float2 delta)
|
||||||
{
|
{
|
||||||
var radian = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
|
var radian = Math.Atan2(delta.Y, delta.X);
|
||||||
var d = radian * (180 / Math.PI);
|
var d = radian * (180 / Math.PI);
|
||||||
if (d < 0.0)
|
if (d < 0.0)
|
||||||
d += 360.0;
|
d += 360.0;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (mi.Event == MouseInputEvent.Scroll &&
|
if (mi.Event == MouseInputEvent.Scroll &&
|
||||||
Game.Settings.Game.AllowZoom && mi.Modifiers.HasModifier(Game.Settings.Game.ZoomModifier))
|
Game.Settings.Game.AllowZoom && mi.Modifiers.HasModifier(Game.Settings.Game.ZoomModifier))
|
||||||
{
|
{
|
||||||
Zoom(mi.ScrollDelta);
|
Zoom(mi.Delta.Y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Scroll)
|
if (mi.Event == MouseInputEvent.Scroll)
|
||||||
{
|
{
|
||||||
Scroll(mi.ScrollDelta);
|
Scroll(mi.Delta.Y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Scroll)
|
if (mi.Event == MouseInputEvent.Scroll)
|
||||||
{
|
{
|
||||||
Scroll(mi.ScrollDelta, true);
|
Scroll(mi.Delta.Y, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (mi.Event == MouseInputEvent.Scroll &&
|
if (mi.Event == MouseInputEvent.Scroll &&
|
||||||
Game.Settings.Game.AllowZoom && mi.Modifiers.HasModifier(Game.Settings.Game.ZoomModifier))
|
Game.Settings.Game.AllowZoom && mi.Modifiers.HasModifier(Game.Settings.Game.ZoomModifier))
|
||||||
{
|
{
|
||||||
Zoom(mi.ScrollDelta);
|
Zoom(mi.Delta.Y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
return new int2(x, y);
|
return new int2(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PumpInput(Sdl2PlatformWindow device, IInputHandler inputHandler)
|
public void PumpInput(Sdl2PlatformWindow device, IInputHandler inputHandler, int2? lockedMousePosition)
|
||||||
{
|
{
|
||||||
var mods = MakeModifiers((int)SDL.SDL_GetModState());
|
var mods = MakeModifiers((int)SDL.SDL_GetModState());
|
||||||
var scrollDelta = 0;
|
|
||||||
inputHandler.ModifierKeys(mods);
|
inputHandler.ModifierKeys(mods);
|
||||||
MouseInput? pendingMotion = null;
|
MouseInput? pendingMotion = null;
|
||||||
|
|
||||||
@@ -98,9 +97,11 @@ namespace OpenRA.Platforms.Default
|
|||||||
var button = MakeButton(e.button.button);
|
var button = MakeButton(e.button.button);
|
||||||
lastButtonBits |= button;
|
lastButtonBits |= button;
|
||||||
|
|
||||||
var pos = EventPosition(device, e.button.x, e.button.y);
|
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
|
||||||
|
var pos = EventPosition(device, input.X, input.Y);
|
||||||
|
|
||||||
inputHandler.OnMouseInput(new MouseInput(
|
inputHandler.OnMouseInput(new MouseInput(
|
||||||
MouseInputEvent.Down, button, scrollDelta, pos, mods,
|
MouseInputEvent.Down, button, pos, int2.Zero, mods,
|
||||||
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
|
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -117,9 +118,11 @@ namespace OpenRA.Platforms.Default
|
|||||||
var button = MakeButton(e.button.button);
|
var button = MakeButton(e.button.button);
|
||||||
lastButtonBits &= ~button;
|
lastButtonBits &= ~button;
|
||||||
|
|
||||||
var pos = EventPosition(device, e.button.x, e.button.y);
|
var input = lockedMousePosition ?? new int2(e.button.x, e.button.y);
|
||||||
|
var pos = EventPosition(device, input.X, input.Y);
|
||||||
|
|
||||||
inputHandler.OnMouseInput(new MouseInput(
|
inputHandler.OnMouseInput(new MouseInput(
|
||||||
MouseInputEvent.Up, button, scrollDelta, pos, mods,
|
MouseInputEvent.Up, button, pos, int2.Zero, mods,
|
||||||
MultiTapDetection.InfoFromMouse(e.button.button)));
|
MultiTapDetection.InfoFromMouse(e.button.button)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -127,10 +130,11 @@ namespace OpenRA.Platforms.Default
|
|||||||
|
|
||||||
case SDL.SDL_EventType.SDL_MOUSEMOTION:
|
case SDL.SDL_EventType.SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
var pos = EventPosition(device, e.motion.x, e.motion.y);
|
var input = lockedMousePosition ?? new int2(e.motion.x, e.motion.y);
|
||||||
|
var pos = EventPosition(device, input.X, input.Y);
|
||||||
|
var delta = EventPosition(device, e.motion.xrel, e.motion.yrel);
|
||||||
pendingMotion = new MouseInput(
|
pendingMotion = new MouseInput(
|
||||||
MouseInputEvent.Move, lastButtonBits, scrollDelta,
|
MouseInputEvent.Move, lastButtonBits, pos, delta, mods, 0);
|
||||||
pos, mods, 0);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -139,8 +143,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
SDL.SDL_GetMouseState(out x, out y);
|
SDL.SDL_GetMouseState(out x, out y);
|
||||||
scrollDelta = e.wheel.y;
|
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, new int2(x, y), new int2(0, e.wheel.y), mods, 0));
|
||||||
inputHandler.OnMouseInput(new MouseInput(MouseInputEvent.Scroll, MouseButton.None, scrollDelta, new int2(x, y), mods, 0));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
Size windowSize;
|
Size windowSize;
|
||||||
Size surfaceSize;
|
Size surfaceSize;
|
||||||
float windowScale;
|
float windowScale;
|
||||||
int2 mousePosition;
|
int2? lockedMousePosition;
|
||||||
|
|
||||||
internal IntPtr Window
|
internal IntPtr Window
|
||||||
{
|
{
|
||||||
@@ -283,13 +283,16 @@ namespace OpenRA.Platforms.Default
|
|||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
SDL.SDL_GetMouseState(out x, out y);
|
SDL.SDL_GetMouseState(out x, out y);
|
||||||
mousePosition = new int2(x, y);
|
lockedMousePosition = new int2(x, y);
|
||||||
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE);
|
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE);
|
SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE);
|
||||||
SDL.SDL_WarpMouseInWindow(window, mousePosition.X, mousePosition.Y);
|
if (lockedMousePosition.HasValue)
|
||||||
|
SDL.SDL_WarpMouseInWindow(window, lockedMousePosition.Value.X, lockedMousePosition.Value.Y);
|
||||||
|
|
||||||
|
lockedMousePosition = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +351,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
public void PumpInput(IInputHandler inputHandler)
|
public void PumpInput(IInputHandler inputHandler)
|
||||||
{
|
{
|
||||||
VerifyThreadAffinity();
|
VerifyThreadAffinity();
|
||||||
input.PumpInput(this, inputHandler);
|
input.PumpInput(this, inputHandler, lockedMousePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetClipboardText()
|
public string GetClipboardText()
|
||||||
|
|||||||
Reference in New Issue
Block a user