Smoothly scrolling listboxes, items in the boxes can be partially visible
This commit is contained in:
@@ -207,31 +207,7 @@ namespace Barotrauma
|
||||
{
|
||||
y += child.Rect.Height + spacing;
|
||||
}
|
||||
|
||||
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
if (child.Rect.Right < rect.X) continue;
|
||||
if (child.Rect.Right > rect.Right) break;
|
||||
|
||||
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
|
||||
{
|
||||
x = rect.X;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (child.Rect.Y + child.Rect.Height < rect.Y) continue;
|
||||
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) break;
|
||||
|
||||
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
|
||||
{
|
||||
y = rect.Y;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (deltaTime>0.0f) child.Update(deltaTime);
|
||||
if (enabled && child.CanBeFocused &&
|
||||
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
|
||||
@@ -415,6 +391,8 @@ namespace Barotrauma
|
||||
|
||||
if (!scrollBarHidden) scrollBar.Draw(spriteBatch);
|
||||
|
||||
GameMain.CurrGraphicsDevice.ScissorRectangle = frame.Rect;
|
||||
|
||||
int lastVisible = 0;
|
||||
for (int i = 0; i < children.Count; i++)
|
||||
{
|
||||
@@ -430,6 +408,8 @@ namespace Barotrauma
|
||||
lastVisible = i;
|
||||
child.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
}
|
||||
|
||||
private bool IsChildVisible(GUIComponent child)
|
||||
@@ -439,22 +419,12 @@ namespace Barotrauma
|
||||
if (scrollBar.IsHorizontal)
|
||||
{
|
||||
if (child.Rect.Right < rect.X) return false;
|
||||
if (child.Rect.Right > rect.Right) return false;
|
||||
|
||||
if (child.Rect.X < rect.X && child.Rect.Right >= rect.X)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (child.Rect.X > rect.Right) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (child.Rect.Y + child.Rect.Height < rect.Y) return false;
|
||||
if (child.Rect.Y + child.Rect.Height > rect.Y + rect.Height) return false;
|
||||
|
||||
if (child.Rect.Y < rect.Y && child.Rect.Y + child.Rect.Height >= rect.Y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (child.Rect.Bottom < rect.Y) return false;
|
||||
if (child.Rect.Y > rect.Bottom) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace Barotrauma
|
||||
|
||||
public bool Wrap;
|
||||
|
||||
private bool overflowScrollActive;
|
||||
public bool OverflowScroll;
|
||||
|
||||
private float textDepth;
|
||||
|
||||
public override Vector4 Padding
|
||||
@@ -84,13 +87,7 @@ namespace Barotrauma
|
||||
get { return textDepth; }
|
||||
set { textDepth = MathHelper.Clamp(value, 0.0f, 1.0f); }
|
||||
}
|
||||
|
||||
public bool LimitText
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 TextPos
|
||||
{
|
||||
get { return textPos; }
|
||||
@@ -157,8 +154,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false)
|
||||
: this (rect, text, style, alignment, textAlignment, parent, wrap, null)
|
||||
public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment alignment, Alignment textAlignment = Alignment.Left, string style = null, GUIComponent parent = null, bool wrap = false, ScalableFont font = null)
|
||||
: this (rect, text, style, alignment, textAlignment, parent, wrap, font)
|
||||
{
|
||||
if (color != null) this.color = (Color)color;
|
||||
if (textColor != null) this.textColor = (Color)textColor;
|
||||
@@ -198,32 +195,29 @@ namespace Barotrauma
|
||||
{
|
||||
if (text == null) return;
|
||||
|
||||
overflowScrollActive = false;
|
||||
|
||||
wrappedText = text;
|
||||
|
||||
Vector2 size = MeasureText(text);
|
||||
Vector2 size = MeasureText(text);
|
||||
|
||||
if (Wrap && rect.Width > 0)
|
||||
{
|
||||
wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font, textScale);
|
||||
|
||||
Vector2 newSize = MeasureText(wrappedText);
|
||||
|
||||
size = newSize;
|
||||
size = MeasureText(wrappedText);
|
||||
}
|
||||
|
||||
if (LimitText && text.Length>1 && size.Y > rect.Height)
|
||||
else if (OverflowScroll)
|
||||
{
|
||||
string[] lines = text.Split('\n');
|
||||
text = string.Join("\n", lines, 0, lines.Length-1);
|
||||
overflowScrollActive = size.X > rect.Width;
|
||||
}
|
||||
|
||||
|
||||
textPos = new Vector2(rect.Width / 2.0f, rect.Height / 2.0f);
|
||||
origin = size * 0.5f;
|
||||
|
||||
if (textAlignment.HasFlag(Alignment.Left))
|
||||
if (textAlignment.HasFlag(Alignment.Left) && !overflowScrollActive)
|
||||
origin.X += (rect.Width / 2.0f - padding.X) - size.X / 2;
|
||||
|
||||
if (textAlignment.HasFlag(Alignment.Right))
|
||||
if (textAlignment.HasFlag(Alignment.Right) || overflowScrollActive)
|
||||
origin.X -= (rect.Width / 2.0f - padding.Z) - size.X / 2;
|
||||
|
||||
if (textAlignment.HasFlag(Alignment.Top))
|
||||
@@ -253,7 +247,7 @@ namespace Barotrauma
|
||||
|
||||
private Vector2 MeasureText(string text)
|
||||
{
|
||||
if (Font==null) return Vector2.Zero;
|
||||
if (Font == null) return Vector2.Zero;
|
||||
|
||||
Vector2 size = Vector2.Zero;
|
||||
while (size == Vector2.Zero)
|
||||
@@ -280,13 +274,13 @@ namespace Barotrauma
|
||||
|
||||
Rectangle drawRect = rect;
|
||||
if (offset != Vector2.Zero) drawRect.Location += offset.ToPoint();
|
||||
|
||||
//if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
|
||||
|
||||
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (TextGetter != null) text = TextGetter();
|
||||
|
||||
if (overflowScrollActive) GameMain.CurrGraphicsDevice.ScissorRectangle = rect;
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
Font.DrawString(spriteBatch,
|
||||
@@ -297,6 +291,8 @@ namespace Barotrauma
|
||||
SpriteEffects.None, textDepth);
|
||||
}
|
||||
|
||||
if (overflowScrollActive) GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
|
||||
DrawChildren(spriteBatch);
|
||||
|
||||
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
|
||||
|
||||
@@ -105,6 +105,12 @@ namespace Barotrauma
|
||||
get { return NetworkMember as GameClient; }
|
||||
}
|
||||
|
||||
public static RasterizerState ScissorTestEnable
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Total seconds elapsed after startup
|
||||
/// </summary>
|
||||
@@ -179,6 +185,8 @@ namespace Barotrauma
|
||||
|
||||
CurrGraphicsDevice = GraphicsDevice;
|
||||
|
||||
ScissorTestEnable = new RasterizerState() { ScissorTestEnable = true };
|
||||
|
||||
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Character));
|
||||
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Item));
|
||||
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Items.Components.ItemComponent));
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace Barotrauma
|
||||
|
||||
//-------------------- HUD -----------------------------
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
GUIpanel.Draw(spriteBatch);
|
||||
|
||||
|
||||
@@ -1103,7 +1103,7 @@ namespace Barotrauma
|
||||
|
||||
//-------------------- HUD -----------------------------
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace Barotrauma
|
||||
|
||||
DrawMap(graphics, spriteBatch);
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
|
||||
{
|
||||
|
||||
@@ -369,10 +369,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
graphics.Clear(Color.Black);
|
||||
|
||||
//GameMain.GameScreen.DrawMap(graphics, spriteBatch);
|
||||
|
||||
spriteBatch.Begin();
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
Sprite backGround = GameMain.GameSession.Map.CurrentLocation.Type.Background;
|
||||
spriteBatch.Draw(backGround.Texture, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero,
|
||||
|
||||
@@ -499,8 +499,8 @@ namespace Barotrauma
|
||||
GameMain.TitleScreen.Draw(spriteBatch, graphics, (float)deltaTime);
|
||||
|
||||
//Game1.GameScreen.DrawMap(graphics, spriteBatch);
|
||||
|
||||
spriteBatch.Begin(0, BlendState.AlphaBlend);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
buttonsTab.Draw(spriteBatch);
|
||||
if (selectedTab>0) menuTabs[(int)selectedTab].Draw(spriteBatch);
|
||||
|
||||
@@ -1005,7 +1005,7 @@ namespace Barotrauma
|
||||
{
|
||||
graphics.Clear(Color.Black);
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
if (backgroundSprite!=null)
|
||||
{
|
||||
|
||||
@@ -353,12 +353,10 @@ namespace Barotrauma
|
||||
GameMain.TitleScreen.DrawLoadingText = false;
|
||||
GameMain.TitleScreen.Draw(spriteBatch, graphics, (float)deltaTime);
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable);
|
||||
|
||||
menu.Draw(spriteBatch);
|
||||
|
||||
//if (previewPlayer!=null) previewPlayer.Draw(spriteBatch);
|
||||
|
||||
|
||||
GUI.Draw((float)deltaTime, spriteBatch, null);
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
Reference in New Issue
Block a user