Hand scrolling moves scroll bars appropriately.
This commit is contained in:
@@ -20,10 +20,13 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
Color scrollBarColor;
|
||||
float opacityOfBar = 1;
|
||||
bool showingBars;
|
||||
int shiftX, shiftY;
|
||||
private bool mouseWasPressed;
|
||||
private bool horizontalSelected;
|
||||
private Vector2 mouseRelativePosition;
|
||||
float shiftX, shiftY;
|
||||
int furthestX;
|
||||
int furthestY;
|
||||
UIModule furthestXMod, furthestYMod;
|
||||
UIModule furthestXModule, furthestYMod;
|
||||
|
||||
bool horScrollAvailable, vertScrollAvailable;
|
||||
|
||||
@@ -154,7 +157,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
if (hideScrollBars)
|
||||
{
|
||||
if (!showingBars)
|
||||
if (!showingBars && !mouseWasPressed)
|
||||
{
|
||||
if (opacityOfBar > 0f)
|
||||
{
|
||||
@@ -165,6 +168,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
else
|
||||
{
|
||||
opacityOfBar = 1f;
|
||||
scrollBarColor = color * opacityOfBar;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +213,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
int mFurthestY = m.Boundaries.Y + m.Boundaries.Height;
|
||||
if (mFurthestX > furthestX)
|
||||
{
|
||||
furthestXMod = m;
|
||||
furthestXModule = m;
|
||||
furthestX = mFurthestX;
|
||||
}
|
||||
if (mFurthestY > furthestY)
|
||||
@@ -227,7 +231,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
group.RemoveModule(module);
|
||||
|
||||
if (module == furthestXMod)
|
||||
if (module == furthestXModule)
|
||||
{
|
||||
furthestX = 0;
|
||||
UIModule[] modules = group.GetCopyOfModules();
|
||||
@@ -237,7 +241,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
int mFurthestX = m.Boundaries.X + m.Boundaries.Width;
|
||||
if (mFurthestX > furthestX)
|
||||
{
|
||||
furthestXMod = m;
|
||||
furthestXModule = m;
|
||||
furthestX = mFurthestX;
|
||||
}
|
||||
}
|
||||
@@ -331,6 +335,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override bool KeyboardStateChanged(KeyboardState state)
|
||||
{
|
||||
if (state.IsKeyDown(Keys.Right))
|
||||
{
|
||||
shiftX -= 20;
|
||||
}
|
||||
|
||||
return base.KeyboardStateChanged(state);
|
||||
}
|
||||
|
||||
public override bool MouseStateChanged(MouseState state)
|
||||
{
|
||||
if (InputUtilities.MouseWithinBoundries(Boundaries))
|
||||
@@ -341,7 +356,62 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
showingBars = false;
|
||||
}
|
||||
|
||||
if (InputUtilities.MouseWithinBoundries(horizontalScrollBarBounds))
|
||||
{
|
||||
if (state.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
mouseWasPressed = true;
|
||||
horizontalSelected = true;
|
||||
}
|
||||
if (!mouseWasPressed)
|
||||
{
|
||||
mouseRelativePosition.X = state.X - horizontalScrollBarBounds.X;
|
||||
}
|
||||
}
|
||||
|
||||
if (InputUtilities.MouseWithinBoundries(verticalScrollBarBounds))
|
||||
{
|
||||
if (state.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
mouseWasPressed = true;
|
||||
horizontalSelected = false;
|
||||
}
|
||||
if (!mouseWasPressed)
|
||||
{
|
||||
mouseRelativePosition.Y = state.Y - verticalScrollBarBounds.Y;
|
||||
}
|
||||
}
|
||||
|
||||
if (mouseWasPressed)
|
||||
{
|
||||
if (horizontalSelected)
|
||||
{
|
||||
float latestPosition = state.X - mouseRelativePosition.X;
|
||||
shiftX = -(latestPosition / (Width - horizontalScrollBarBounds.Width)) * furthestX;
|
||||
}
|
||||
else
|
||||
{
|
||||
float latestPosition = state.Y - mouseRelativePosition.Y;
|
||||
shiftY = -(latestPosition / (Height - verticalScrollBarBounds.Height)) * furthestY;
|
||||
}
|
||||
|
||||
if (state.LeftButton == ButtonState.Released)
|
||||
{
|
||||
mouseWasPressed = false;
|
||||
}
|
||||
}
|
||||
return base.MouseStateChanged(state);
|
||||
}
|
||||
|
||||
private void MoveHorizontalScrollBar(int position)
|
||||
{
|
||||
shiftX = -(int)(furthestX * ((float)position / Width));
|
||||
}
|
||||
|
||||
private void MoveVerticalScrollBar(int position)
|
||||
{
|
||||
shiftY = (int)(furthestY * ((float)position / Height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user