Separate sprites for horizontal and vertical scrollbars, style tweaking

This commit is contained in:
Regalis
2017-04-18 19:24:13 +03:00
parent dc6ed7daf1
commit 9a5777183f
11 changed files with 88 additions and 86 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ namespace Barotrauma
public void AddItem(string text, object userData = null)
{
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "", listBox);
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "ListBoxElement", listBox);
textBlock.UserData = userData;
}
+45 -28
View File
@@ -45,20 +45,21 @@ namespace Barotrauma
set
{
barScroll = MathHelper.Clamp(value, 0.0f, 1.0f);
int newX = bar.Rect.X - frame.Rect.X, newY = bar.Rect.Y - frame.Rect.Y;
int newX = bar.Rect.X - frame.Rect.X;
int newY = bar.Rect.Y - frame.Rect.Y;
float newScroll = step == 0.0f ? barScroll : MathUtils.RoundTowardsClosest(barScroll, step);
if (isHorizontal)
{
newX = (int)(newScroll * (frame.Rect.Width - bar.Rect.Width));
newX = MathHelper.Clamp(newX, 0, frame.Rect.Width - bar.Rect.Width);
newX = (int)(frame.Padding.X + newScroll * (frame.Rect.Width - bar.Rect.Width - frame.Padding.X - frame.Padding.Z));
newX = MathHelper.Clamp(newX, (int)frame.Padding.X, frame.Rect.Width - bar.Rect.Width - (int)frame.Padding.Z);
}
else
{
newY = (int)(newScroll * (frame.Rect.Height - bar.Rect.Height));
newY = MathHelper.Clamp(newY, 0, frame.Rect.Height - bar.Rect.Height);
newY = (int)(frame.Padding.Y + newScroll * (frame.Rect.Height - bar.Rect.Height - frame.Padding.Y - frame.Padding.W));
newY = MathHelper.Clamp(newY, (int)frame.Padding.Y, frame.Rect.Height - bar.Rect.Height - (int)frame.Padding.W);
}
bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);
@@ -111,18 +112,15 @@ namespace Barotrauma
parent.AddChild(this);
isHorizontal = (rect.Width > rect.Height);
frame = new GUIFrame(new Rectangle(0,0,0,0), Color.Black*0.8f, style, this);
GUI.Style.Apply(frame, "", this);
//AddChild(frame);
//System.Diagnostics.Debug.WriteLine(frame.rect);
frame = new GUIFrame(new Rectangle(0,0,0,0), style, this);
GUI.Style.Apply(frame, isHorizontal ? "GUIFrameHorizontal" : "GUIFrameVertical", this);
this.barSize = barSize;
bar = new GUIButton(new Rectangle(0, 0, 0, 0), "", color, "", this);
GUI.Style.Apply(bar, isHorizontal ? "GUIButtonHorizontal" : "GUIButtoneVertical", this);
bar.OnPressed = SelectBar;
//AddChild(bar);
enabled = true;
@@ -131,12 +129,16 @@ namespace Barotrauma
private void UpdateRect()
{
float width = frame.Rect.Width - frame.Padding.X - frame.Padding.Z;
float height = frame.Rect.Height - frame.Padding.Y - frame.Padding.W;
bar.Rect = new Rectangle(
bar.Rect.X,
bar.Rect.Y,
isHorizontal ? (int)(frame.Rect.Width * barSize) : frame.Rect.Width,
isHorizontal ? frame.Rect.Height : (int)(frame.Rect.Height * barSize));
isHorizontal ? (int)(width * barSize) : (int)width,
isHorizontal ? (int)height : (int)(height * barSize));
ClampRect();
foreach (GUIComponent child in bar.children)
{
@@ -144,16 +146,36 @@ namespace Barotrauma
}
}
private void ClampRect()
{
bar.Rect = new Rectangle(
(int)MathHelper.Clamp(bar.Rect.X, frame.Rect.X + frame.Padding.X, frame.Rect.Right - bar.Rect.Width - frame.Padding.X - frame.Padding.Z),
(int)MathHelper.Clamp(bar.Rect.Y, frame.Rect.Y + frame.Padding.Y, frame.Rect.Bottom - bar.Rect.Height - frame.Padding.Y - frame.Padding.W),
bar.Rect.Width,
bar.Rect.Height);
}
public override void Update(float deltaTime)
{
if (!Visible) return;
base.Update(deltaTime);
if (draggingBar != this) return;
if (!PlayerInput.LeftButtonHeld()) draggingBar = null;
if (MouseOn == frame)
{
if (PlayerInput.LeftButtonClicked())
{
MoveButton(new Vector2(
Math.Sign(PlayerInput.MousePosition.X - bar.Rect.Center.X) * bar.Rect.Width,
Math.Sign(PlayerInput.MousePosition.Y - bar.Rect.Center.Y) * bar.Rect.Height));
}
}
MoveButton();
if (draggingBar == this)
{
if (!PlayerInput.LeftButtonHeld()) draggingBar = null;
MoveButton(PlayerInput.MouseSpeed);
}
}
public override void Draw(SpriteBatch spriteBatch)
@@ -174,27 +196,22 @@ namespace Barotrauma
}
private void MoveButton()
private void MoveButton(Vector2 moveAmount)
{
float moveAmount;
if (isHorizontal)
{
moveAmount = PlayerInput.MouseSpeed.X;
barScroll += moveAmount / (frame.Rect.Width - bar.Rect.Width);
moveAmount.Y = 0.0f;
barScroll += moveAmount.X / (frame.Rect.Width - bar.Rect.Width - frame.Padding.X - frame.Padding.Z);
}
else
{
moveAmount = PlayerInput.MouseSpeed.Y;
barScroll += moveAmount / (frame.Rect.Height - bar.Rect.Height);
moveAmount.X = 0.0f;
barScroll += moveAmount.Y / (frame.Rect.Height - bar.Rect.Height - frame.Padding.Y - frame.Padding.W);
}
BarScroll = barScroll;
if (moveAmount != 0 && OnMoved != null) OnMoved(this, BarScroll);
//bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);
if (moveAmount != Vector2.Zero && OnMoved != null) OnMoved(this, BarScroll);
}
}
+2 -7
View File
@@ -164,7 +164,7 @@ namespace Barotrauma
}
public GUITextBox(Rectangle rect, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null)
public GUITextBox(Rectangle rect, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.CenterLeft, string style = null, GUIComponent parent = null)
: base(style)
{
Enabled = true;
@@ -174,8 +174,6 @@ namespace Barotrauma
if (color != null) this.color = (Color)color;
this.alignment = alignment;
//this.textAlignment = textAlignment;
if (parent != null)
parent.AddChild(this);
@@ -186,11 +184,8 @@ namespace Barotrauma
GUI.Style.Apply(textBlock, style == "" ? "GUITextBox" : style);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
//previousMouse = PlayerInput.GetMouseState;
CaretEnabled = true;
//SetTextPos();
}
public void Select()