public bool TestScroll(UpdateState state)
{
var mouse = state.MouseState;
if (State == null) { return false; }
var screenWidth = State.WorldSpace.WorldPxWidth;
var screenHeight = State.WorldSpace.WorldPxHeight;
/** Corners **/
var xBound = screenWidth - ScrollBounds;
var yBound = screenHeight - ScrollBounds;
var cursor = CursorType.Normal;
var scrollVector = new Vector2(0, 0);
if (mouse.X > 0 && mouse.Y > 0 && mouse.X < screenWidth && mouse.Y < screenHeight)
{
if (mouse.Y <= ScrollBounds)
{
if (mouse.X <= ScrollBounds)
{
/** Scroll top left **/
cursor = CursorType.ArrowUpLeft;
scrollVector = new Vector2(-1, -1);
}
else if (mouse.X >= xBound)
{
/** Scroll top right **/
cursor = CursorType.ArrowUpRight;
scrollVector = new Vector2(1, -1);
}
else
{
/** Scroll up **/
cursor = CursorType.ArrowUp;
scrollVector = new Vector2(0, -1);
}
}
else if (mouse.Y <= yBound)
{
if (mouse.X <= ScrollBounds)
{
/** Left **/
cursor = CursorType.ArrowLeft;
scrollVector = new Vector2(-1, 0);
}
else if (mouse.X >= xBound)
{
/** Right **/
cursor = CursorType.ArrowRight;
scrollVector = new Vector2(1, -1);
}
}
else
{
if (mouse.X <= ScrollBounds)
{
/** Scroll bottom left **/
cursor = CursorType.ArrowDownLeft;
scrollVector = new Vector2(-1, 1);
}
else if (mouse.X >= xBound)
{
/** Scroll bottom right **/
cursor = CursorType.ArrowDownRight;
scrollVector = new Vector2(1, 1);
}
else
{
/** Scroll down **/
cursor = CursorType.ArrowDown;
scrollVector = new Vector2(0, 1);
}
}
}
if (cursor != CursorType.Normal)
{
/**
* Calculate scroll vector based on rotation & scroll type
*/
scrollVector = new Vector2();
var basis = GetScrollBasis();
switch (cursor)
{
case CursorType.ArrowDown:
scrollVector = basis[1];
break;
case CursorType.ArrowUp:
scrollVector = -basis[1];
break;
case CursorType.ArrowLeft:
scrollVector = -basis[0];
break;
case CursorType.ArrowRight:
scrollVector = basis[0];
break;
}
/** We need to scroll **/
if (scrollVector != Vector2.Zero)
{
State.CenterTile += scrollVector * new Vector2(0.0625f, 0.0625f);
State.ScrollAnchor = null;
}
}
if (cursor != CursorType.Normal)
{
CursorManager.INSTANCE.SetCursor(cursor);
return true; //we scrolled, return true and set cursor
}
return false;
}