Update keyboard scrolling at render rate.
This commit is contained in:
@@ -122,6 +122,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
tooltipContainer.Value.RemoveTooltip();
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lastScrollTime = 0;
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
if (IsJoystickScrolling)
|
if (IsJoystickScrolling)
|
||||||
@@ -132,6 +133,30 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var scroll = (joystickScrollEnd.Value - joystickScrollStart.Value).ToFloat2() * rate;
|
var scroll = (joystickScrollEnd.Value - joystickScrollStart.Value).ToFloat2() * rate;
|
||||||
worldRenderer.Viewport.Scroll(scroll, false);
|
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();
|
UpdateMouseover();
|
||||||
base.Draw();
|
base.Draw();
|
||||||
@@ -405,27 +430,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return false;
|
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()
|
ScrollDirection CheckForDirections()
|
||||||
{
|
{
|
||||||
var directions = ScrollDirection.None;
|
var directions = ScrollDirection.None;
|
||||||
|
|||||||
Reference in New Issue
Block a user