Update keyboard scrolling at render rate.

This commit is contained in:
Paul Chote
2016-07-09 01:29:09 +01:00
parent 196dd04b5d
commit 8ef38fc060

View File

@@ -122,6 +122,7 @@ namespace OpenRA.Mods.Common.Widgets
tooltipContainer.Value.RemoveTooltip();
}
int lastScrollTime = 0;
public override void Draw()
{
if (IsJoystickScrolling)
@@ -132,6 +133,30 @@ namespace OpenRA.Mods.Common.Widgets
var scroll = (joystickScrollEnd.Value - joystickScrollStart.Value).ToFloat2() * rate;
worldRenderer.Viewport.Scroll(scroll, false);
}
else
{
edgeDirections = ScrollDirection.None;
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
edgeDirections = CheckForDirections();
if (keyboardDirections != ScrollDirection.None || edgeDirections != ScrollDirection.None)
{
var scroll = float2.Zero;
foreach (var kv in ScrollOffsets)
if (keyboardDirections.Includes(kv.Key) || edgeDirections.Includes(kv.Key))
scroll += kv.Value;
// Scroll rate is defined for a 40ms interval
var deltaScale = Math.Min(Game.RunTime - lastScrollTime, 25f);
var length = Math.Max(1, scroll.Length);
scroll *= (deltaScale / (25 * length)) * Game.Settings.Game.ViewportEdgeScrollStep;
worldRenderer.Viewport.Scroll(scroll, false);
lastScrollTime = Game.RunTime;
}
}
UpdateMouseover();
base.Draw();
@@ -405,27 +430,6 @@ namespace OpenRA.Mods.Common.Widgets
return false;
}
public override void Tick()
{
edgeDirections = ScrollDirection.None;
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
edgeDirections = CheckForDirections();
if (keyboardDirections != ScrollDirection.None || edgeDirections != ScrollDirection.None)
{
var scroll = float2.Zero;
foreach (var kv in ScrollOffsets)
if (keyboardDirections.Includes(kv.Key) || edgeDirections.Includes(kv.Key))
scroll += kv.Value;
var length = Math.Max(1, scroll.Length);
scroll *= (1f / length) * Game.Settings.Game.ViewportEdgeScrollStep;
worldRenderer.Viewport.Scroll(scroll, false);
}
}
ScrollDirection CheckForDirections()
{
var directions = ScrollDirection.None;