mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
made tooltips be panels and remove the weird paragraph background thing
This commit is contained in:
parent
e2682e866d
commit
43b665642d
5 changed files with 42 additions and 46 deletions
|
@ -22,8 +22,6 @@ namespace MLEM.Ui.Elements {
|
||||||
public StyleProp<IGenericFont> ItalicFont;
|
public StyleProp<IGenericFont> ItalicFont;
|
||||||
public StyleProp<FormatSettings> FormatSettings;
|
public StyleProp<FormatSettings> FormatSettings;
|
||||||
|
|
||||||
public StyleProp<NinePatch> Background;
|
|
||||||
public StyleProp<Color> BackgroundColor;
|
|
||||||
public StyleProp<Color> TextColor;
|
public StyleProp<Color> TextColor;
|
||||||
public StyleProp<float> TextScale;
|
public StyleProp<float> TextScale;
|
||||||
public string Text {
|
public string Text {
|
||||||
|
@ -82,9 +80,6 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
|
||||||
if (this.Background.Value != null)
|
|
||||||
batch.Draw(this.Background, this.Area, (Color) this.BackgroundColor * alpha);
|
|
||||||
|
|
||||||
var pos = this.DisplayArea.Location;
|
var pos = this.DisplayArea.Location;
|
||||||
var sc = this.TextScale * this.Scale;
|
var sc = this.TextScale * this.Scale;
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,20 @@ using MLEM.Font;
|
||||||
using MLEM.Ui.Style;
|
using MLEM.Ui.Style;
|
||||||
|
|
||||||
namespace MLEM.Ui.Elements {
|
namespace MLEM.Ui.Elements {
|
||||||
public class Tooltip : Group {
|
public class Tooltip : Panel {
|
||||||
|
|
||||||
public Vector2 MouseOffset = new Vector2(2, 3);
|
public StyleProp<Vector2> MouseOffset;
|
||||||
public Paragraph Paragraph;
|
public Paragraph Paragraph;
|
||||||
|
|
||||||
public Tooltip(float width, string text = null, Element elementToHover = null) :
|
public Tooltip(float width, string text = null, Element elementToHover = null) :
|
||||||
base(Anchor.TopLeft, Vector2.One) {
|
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text));
|
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text));
|
||||||
this.Paragraph.AutoAdjustWidth = true;
|
this.Paragraph.AutoAdjustWidth = true;
|
||||||
this.Paragraph.Padding = new Vector2(2);
|
|
||||||
this.SetWidthBasedOnChildren = true;
|
|
||||||
}
|
}
|
||||||
|
this.SetWidthBasedOnChildren = true;
|
||||||
|
this.SetHeightBasedOnChildren = true;
|
||||||
|
this.ChildPadding = new Vector2(2);
|
||||||
this.CanBeMoused = false;
|
this.CanBeMoused = false;
|
||||||
|
|
||||||
if (elementToHover != null) {
|
if (elementToHover != null) {
|
||||||
|
@ -27,7 +28,7 @@ namespace MLEM.Ui.Elements {
|
||||||
};
|
};
|
||||||
elementToHover.OnMouseExit += element => {
|
elementToHover.OnMouseExit += element => {
|
||||||
if (this.System != null)
|
if (this.System != null)
|
||||||
this.System.Remove(element.GetType().Name + "Tooltip");
|
this.System.Remove(this.Root.Name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,10 +46,8 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
protected override void InitStyle(UiStyle style) {
|
protected override void InitStyle(UiStyle style) {
|
||||||
base.InitStyle(style);
|
base.InitStyle(style);
|
||||||
if (this.Paragraph != null) {
|
this.Texture.SetFromStyle(style.TooltipBackground);
|
||||||
this.Paragraph.Background.SetFromStyle(style.TooltipBackground);
|
this.MouseOffset.SetFromStyle(style.TooltipOffset);
|
||||||
this.Paragraph.BackgroundColor.SetFromStyle(style.TooltipBackgroundColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SnapPositionToMouse() {
|
public void SnapPositionToMouse() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace MLEM.Ui.Style {
|
||||||
public Color RadioHoveredColor;
|
public Color RadioHoveredColor;
|
||||||
public TextureRegion RadioCheckmark;
|
public TextureRegion RadioCheckmark;
|
||||||
public NinePatch TooltipBackground;
|
public NinePatch TooltipBackground;
|
||||||
public Color TooltipBackgroundColor;
|
public Vector2 TooltipOffset;
|
||||||
public NinePatch ProgressBarTexture;
|
public NinePatch ProgressBarTexture;
|
||||||
public Color ProgressBarColor;
|
public Color ProgressBarColor;
|
||||||
public Vector2 ProgressBarProgressPadding;
|
public Vector2 ProgressBarProgressPadding;
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MLEM.Extensions;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
|
||||||
|
@ -9,46 +10,29 @@ namespace MLEM.Ui.Style {
|
||||||
public class UntexturedStyle : UiStyle {
|
public class UntexturedStyle : UiStyle {
|
||||||
|
|
||||||
public UntexturedStyle(SpriteBatch batch) {
|
public UntexturedStyle(SpriteBatch batch) {
|
||||||
this.SelectionIndicator = GenerateTexture(batch, Color.Transparent, Color.Red);
|
this.SelectionIndicator = batch.GenerateTexture(Color.Transparent, Color.Red);
|
||||||
this.ButtonTexture = GenerateTexture(batch, Color.CadetBlue);
|
this.ButtonTexture = batch.GenerateTexture(Color.CadetBlue);
|
||||||
this.ButtonHoveredColor = Color.LightGray;
|
this.ButtonHoveredColor = Color.LightGray;
|
||||||
this.PanelTexture = GenerateTexture(batch, Color.Gray);
|
this.PanelTexture = batch.GenerateTexture(Color.Gray);
|
||||||
this.TextFieldTexture = GenerateTexture(batch, Color.MediumBlue);
|
this.TextFieldTexture = batch.GenerateTexture(Color.MediumBlue);
|
||||||
this.TextFieldHoveredColor = Color.LightGray;
|
this.TextFieldHoveredColor = Color.LightGray;
|
||||||
this.ScrollBarBackground = GenerateTexture(batch, Color.LightBlue);
|
this.ScrollBarBackground = batch.GenerateTexture(Color.LightBlue);
|
||||||
this.ScrollBarScrollerTexture = GenerateTexture(batch, Color.Blue);
|
this.ScrollBarScrollerTexture = batch.GenerateTexture(Color.Blue);
|
||||||
this.CheckboxTexture = GenerateTexture(batch, Color.LightBlue);
|
this.CheckboxTexture = batch.GenerateTexture(Color.LightBlue);
|
||||||
this.CheckboxHoveredColor = Color.LightGray;
|
this.CheckboxHoveredColor = Color.LightGray;
|
||||||
this.CheckboxCheckmark = GenerateTexture(batch, Color.Blue).Region;
|
this.CheckboxCheckmark = batch.GenerateTexture(Color.Blue).Region;
|
||||||
this.RadioTexture = GenerateTexture(batch, Color.AliceBlue);
|
this.RadioTexture = batch.GenerateTexture(Color.AliceBlue);
|
||||||
this.RadioHoveredColor = Color.LightGray;
|
this.RadioHoveredColor = Color.LightGray;
|
||||||
this.RadioCheckmark = GenerateTexture(batch, Color.CornflowerBlue).Region;
|
this.RadioCheckmark = batch.GenerateTexture(Color.CornflowerBlue).Region;
|
||||||
this.TooltipBackground = GenerateTexture(batch, Color.DarkGray);
|
this.TooltipBackground = batch.GenerateTexture(Color.Black * 0.65F, Color.Black * 0.65F);
|
||||||
this.TooltipBackgroundColor = new Color(Color.Black, 0.65F);
|
this.TooltipOffset = new Vector2(2, 3);
|
||||||
this.ProgressBarTexture = GenerateTexture(batch, Color.RoyalBlue);
|
this.ProgressBarTexture = batch.GenerateTexture(Color.RoyalBlue);
|
||||||
this.ProgressBarColor = Color.White;
|
this.ProgressBarColor = Color.White;
|
||||||
this.ProgressBarProgressPadding = new Vector2(1);
|
this.ProgressBarProgressPadding = new Vector2(1);
|
||||||
this.ProgressBarProgressColor = Color.Red;
|
this.ProgressBarProgressColor = Color.Red;
|
||||||
this.Font = new EmptyFont();
|
this.Font = new EmptyFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NinePatch GenerateTexture(SpriteBatch batch, Color color, Color? outlineColor = null) {
|
|
||||||
var outli = outlineColor ?? Color.Black;
|
|
||||||
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
|
|
||||||
tex.SetData(new[] {
|
|
||||||
outli, outli, outli,
|
|
||||||
outli, color, outli,
|
|
||||||
outli, outli, outli
|
|
||||||
});
|
|
||||||
batch.Disposing += (sender, args) => {
|
|
||||||
if (tex != null) {
|
|
||||||
tex.Dispose();
|
|
||||||
tex = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return new NinePatch(tex, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EmptyFont : IGenericFont {
|
private class EmptyFont : IGenericFont {
|
||||||
|
|
||||||
public float LineHeight => 1;
|
public float LineHeight => 1;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
using MLEM.Textures;
|
||||||
|
|
||||||
namespace MLEM.Extensions {
|
namespace MLEM.Extensions {
|
||||||
public static class SpriteBatchExtensions {
|
public static class SpriteBatchExtensions {
|
||||||
|
@ -21,6 +22,23 @@ namespace MLEM.Extensions {
|
||||||
return blankTexture;
|
return blankTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null) {
|
||||||
|
var outli = outlineColor ?? Color.Black;
|
||||||
|
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
|
||||||
|
tex.SetData(new[] {
|
||||||
|
outli, outli, outli,
|
||||||
|
outli, color, outli,
|
||||||
|
outli, outli, outli
|
||||||
|
});
|
||||||
|
batch.Disposing += (sender, args) => {
|
||||||
|
if (tex != null) {
|
||||||
|
tex.Dispose();
|
||||||
|
tex = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new NinePatch(tex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
public static void DrawCenteredString(this SpriteBatch batch, SpriteFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) {
|
public static void DrawCenteredString(this SpriteBatch batch, SpriteFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) {
|
||||||
var size = font.MeasureString(text);
|
var size = font.MeasureString(text);
|
||||||
var center = new Vector2(
|
var center = new Vector2(
|
||||||
|
|
Loading…
Reference in a new issue