Improve edge-scroll behavior

This commit is contained in:
Paul Chote
2011-07-05 21:03:04 +12:00
parent ca8605d3ee
commit 5f3483ed17
7 changed files with 261 additions and 137 deletions

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -16,6 +17,16 @@ using OpenRA.Support;
namespace OpenRA.Graphics
{
[Flags]
public enum ScrollDirection
{
None = 0,
Up = 1,
Left = 2,
Down = 4,
Right = 8
}
public class Viewport
{
readonly int2 screenSize;
@@ -164,4 +175,17 @@ namespace OpenRA.Graphics
return (b.HasValue) ? Rectangle.Intersect(cachedRect, b.Value) : cachedRect;
}
}
public static class ViewportExts
{
public static bool Includes(this ScrollDirection d, ScrollDirection s)
{
return (d & s) == s;
}
public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val)
{
return (d.Includes(s) != val) ? d ^ s : d;
}
}
}

View File

@@ -15,16 +15,6 @@ using OpenRA.Graphics;
namespace OpenRA.Widgets
{
[Flags]
public enum ScrollDirection
{
None = 0,
Up = 1,
Left = 2,
Down = 4,
Right = 8
}
public class ViewportScrollControllerWidget : Widget
{
public int EdgeScrollThreshold = 15;
@@ -32,8 +22,9 @@ namespace OpenRA.Widgets
ScrollDirection Keyboard;
ScrollDirection Edge;
public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
public ViewportScrollControllerWidget() : base() {}
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget)
: base(widget) {}
public override bool HandleMouseInput(MouseInput mi)
{
@@ -136,17 +127,4 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
}
public static class ViewportExts
{
public static bool Includes(this ScrollDirection d, ScrollDirection s)
{
return (d & s) == s;
}
public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val)
{
return (d.Includes(s) != val) ? d ^ s : d;
}
}
}