Fix #2720 - Diagonal scrolling area in viewport corners are too small

I added two options, one is for EdgeScrollThreshold and the other one is
EdgeCornerScrollThreshold. You can modify these threshold as much as you
want.

[Squashed down into one commit -- chrisf]
This commit is contained in:
Bugra Cuhadaroglu
2013-03-10 22:26:00 -04:00
committed by Chris Forbes
parent 9db06ca222
commit 7cbc4a29bf

View File

@@ -18,13 +18,14 @@ namespace OpenRA.Widgets
public class ViewportScrollControllerWidget : Widget
{
public int EdgeScrollThreshold = 15;
public int EdgeCornerScrollThreshold = 35;
ScrollDirection Keyboard;
ScrollDirection Edge;
public ViewportScrollControllerWidget() : base() {}
public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget)
: base(widget) {}
: base(widget) { }
public override bool HandleMouseInput(MouseInput mi)
{
@@ -62,16 +63,16 @@ namespace OpenRA.Widgets
var blockedDirections = Game.viewport.GetBlockedDirections();
foreach( var dir in directions )
if (edge.Includes( dir.Key ))
return dir.Value + (blockedDirections.Includes( dir.Key ) ? "-blocked" : "");
foreach (var dir in directions)
if (edge.Includes(dir.Key))
return dir.Value + (blockedDirections.Includes(dir.Key) ? "-blocked" : "");
return null;
}
public override string GetCursor(int2 pos) { return GetScrollCursor(this, Edge, pos); }
public override bool LoseFocus (MouseInput mi)
public override bool LoseFocus(MouseInput mi)
{
Keyboard = ScrollDirection.None;
return base.LoseFocus(mi);
@@ -94,18 +95,60 @@ namespace OpenRA.Widgets
Edge = ScrollDirection.None;
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
{
// Check for edge-scroll
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Left, true);
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Up, true);
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Right, true);
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Down, true);
Edge = CheckForDirections();
Scroll();
}
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
}
ScrollDirection CheckForDirections()
{
// First let's check if the mouse is on the corners:
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeCornerScrollThreshold &&
Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeCornerScrollThreshold) //Bottom Right
{
return ScrollDirection.Right | ScrollDirection.Down;
}
else if (Viewport.LastMousePos.X < EdgeCornerScrollThreshold &&
Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeCornerScrollThreshold) //Bottom Left
{
return ScrollDirection.Down | ScrollDirection.Left;
}
else if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeCornerScrollThreshold &&
Viewport.LastMousePos.Y < EdgeCornerScrollThreshold) //Top Right
{
return ScrollDirection.Right | ScrollDirection.Up;
}
else if (Viewport.LastMousePos.X < EdgeCornerScrollThreshold &&
Viewport.LastMousePos.Y < EdgeCornerScrollThreshold) //Top Left
{
return ScrollDirection.Left | ScrollDirection.Up;
}
//Check for corner ends here now let's check the edges:
// Check for edge-scroll
if (Viewport.LastMousePos.X < EdgeScrollThreshold)
return ScrollDirection.Left;
if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
return ScrollDirection.Up;
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
return ScrollDirection.Right;
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
return ScrollDirection.Down;
//Check for edge-scroll ends here.If none of above then return none.
return ScrollDirection.None;
}
void Scroll()
{
if (Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
{
var scroll = new float2(0, 0);