Hand scrolling moves scroll bars appropriately.
This commit is contained in:
parent
53000e6a6c
commit
1211cda508
@ -20,10 +20,13 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
Color scrollBarColor;
|
Color scrollBarColor;
|
||||||
float opacityOfBar = 1;
|
float opacityOfBar = 1;
|
||||||
bool showingBars;
|
bool showingBars;
|
||||||
int shiftX, shiftY;
|
private bool mouseWasPressed;
|
||||||
|
private bool horizontalSelected;
|
||||||
|
private Vector2 mouseRelativePosition;
|
||||||
|
float shiftX, shiftY;
|
||||||
int furthestX;
|
int furthestX;
|
||||||
int furthestY;
|
int furthestY;
|
||||||
UIModule furthestXMod, furthestYMod;
|
UIModule furthestXModule, furthestYMod;
|
||||||
|
|
||||||
bool horScrollAvailable, vertScrollAvailable;
|
bool horScrollAvailable, vertScrollAvailable;
|
||||||
|
|
||||||
@ -154,7 +157,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
{
|
{
|
||||||
if (hideScrollBars)
|
if (hideScrollBars)
|
||||||
{
|
{
|
||||||
if (!showingBars)
|
if (!showingBars && !mouseWasPressed)
|
||||||
{
|
{
|
||||||
if (opacityOfBar > 0f)
|
if (opacityOfBar > 0f)
|
||||||
{
|
{
|
||||||
@ -165,6 +168,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
opacityOfBar = 1f;
|
opacityOfBar = 1f;
|
||||||
|
scrollBarColor = color * opacityOfBar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +213,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
int mFurthestY = m.Boundaries.Y + m.Boundaries.Height;
|
int mFurthestY = m.Boundaries.Y + m.Boundaries.Height;
|
||||||
if (mFurthestX > furthestX)
|
if (mFurthestX > furthestX)
|
||||||
{
|
{
|
||||||
furthestXMod = m;
|
furthestXModule = m;
|
||||||
furthestX = mFurthestX;
|
furthestX = mFurthestX;
|
||||||
}
|
}
|
||||||
if (mFurthestY > furthestY)
|
if (mFurthestY > furthestY)
|
||||||
@ -227,7 +231,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
{
|
{
|
||||||
group.RemoveModule(module);
|
group.RemoveModule(module);
|
||||||
|
|
||||||
if (module == furthestXMod)
|
if (module == furthestXModule)
|
||||||
{
|
{
|
||||||
furthestX = 0;
|
furthestX = 0;
|
||||||
UIModule[] modules = group.GetCopyOfModules();
|
UIModule[] modules = group.GetCopyOfModules();
|
||||||
@ -237,7 +241,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
int mFurthestX = m.Boundaries.X + m.Boundaries.Width;
|
int mFurthestX = m.Boundaries.X + m.Boundaries.Width;
|
||||||
if (mFurthestX > furthestX)
|
if (mFurthestX > furthestX)
|
||||||
{
|
{
|
||||||
furthestXMod = m;
|
furthestXModule = m;
|
||||||
furthestX = mFurthestX;
|
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)
|
public override bool MouseStateChanged(MouseState state)
|
||||||
{
|
{
|
||||||
if (InputUtilities.MouseWithinBoundries(Boundaries))
|
if (InputUtilities.MouseWithinBoundries(Boundaries))
|
||||||
@ -341,7 +356,62 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
{
|
{
|
||||||
showingBars = false;
|
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);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using RecrownedAthenaeum.Input;
|
||||||
using RecrownedAthenaeum.Render;
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.ScreenSystem;
|
using RecrownedAthenaeum.ScreenSystem;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
@ -23,7 +24,7 @@ namespace TestGame
|
|||||||
Texture2D logo;
|
Texture2D logo;
|
||||||
Image logoImage;
|
Image logoImage;
|
||||||
Skin skin;
|
Skin skin;
|
||||||
|
|
||||||
public TestGame()
|
public TestGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
@ -67,6 +68,7 @@ namespace TestGame
|
|||||||
|
|
||||||
logoImage = new Image(logo);
|
logoImage = new Image(logo);
|
||||||
uIScrollable.AddModules(logoImage);
|
uIScrollable.AddModules(logoImage);
|
||||||
|
InputUtilities.InputListeners.Add(uIScrollable);
|
||||||
// TODO: use this.Content to load your game content here
|
// TODO: use this.Content to load your game content here
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ namespace TestGame
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
InputUtilities.Update();
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||||
Exit();
|
Exit();
|
||||||
uIScrollable.Update(gameTime);
|
uIScrollable.Update(gameTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user