1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

added draw alpha to all components

This commit is contained in:
Ellpeck 2019-08-10 13:42:18 +02:00
parent 88da47bc00
commit 3f7f06f98f
7 changed files with 27 additions and 25 deletions

View file

@ -37,10 +37,10 @@ namespace MLEM.Ui.Elements {
} while (measure.X <= this.DisplayArea.Size.X && measure.Y <= this.DisplayArea.Size.Y);
}
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
var pos = this.DisplayArea.Location.ToVector2() + this.DisplayArea.Size.ToVector2() / 2;
this.font.DrawCenteredString(batch, this.Text, pos, this.scale, this.Color.CopyAlpha(color), true, true);
base.Draw(time, batch, color);
this.font.DrawCenteredString(batch, this.Text, pos, this.scale, this.Color * alpha, true, true);
base.Draw(time, batch, alpha);
}
}

View file

@ -28,15 +28,16 @@ namespace MLEM.Ui.Elements {
}
}
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
var tex = this.Texture;
var color = Color.White * alpha;
if (this.IsMouseOver) {
if (this.HoveredTexture != null)
tex = this.HoveredTexture;
color = this.HoveredColor.CopyAlpha(color);
color = this.HoveredColor * alpha;
}
batch.Draw(tex, this.DisplayArea, color);
base.Draw(time, batch, color);
base.Draw(time, batch, alpha);
}
}

View file

@ -67,6 +67,7 @@ namespace MLEM.Ui.Elements {
}
}
public bool IgnoresMouse;
public float DrawAlpha = 1;
private Rectangle area;
public Rectangle Area {
@ -260,17 +261,17 @@ namespace MLEM.Ui.Elements {
child.Update(time);
}
public virtual void Draw(GameTime time, SpriteBatch batch, Color color) {
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha) {
foreach (var child in this.children) {
if (!child.IsHidden)
child.Draw(time, batch, color);
child.Draw(time, batch, alpha * child.DrawAlpha);
}
}
public virtual void DrawUnbound(GameTime time, SpriteBatch batch, Color color, BlendState blendState = null, SamplerState samplerState = null) {
public virtual void DrawUnbound(GameTime time, SpriteBatch batch, float alpha, BlendState blendState = null, SamplerState samplerState = null) {
foreach (var child in this.children) {
if (!child.IsHidden)
child.DrawUnbound(time, batch, color, blendState, samplerState);
child.DrawUnbound(time, batch, alpha * child.DrawAlpha, blendState, samplerState);
}
}

View file

@ -20,9 +20,9 @@ namespace MLEM.Ui.Elements {
return this.scaleToImage ? this.texture.Size : base.CalcActualSize(parentArea);
}
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
batch.Draw(this.texture, this.DisplayArea, this.Color.CopyAlpha(color));
base.Draw(time, batch, color);
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
batch.Draw(this.texture, this.DisplayArea, this.Color * alpha);
base.Draw(time, batch, alpha);
}
}

View file

@ -6,7 +6,7 @@ namespace MLEM.Ui.Elements {
public class Panel : Element {
public static NinePatch DefaultTexture;
private readonly NinePatch texture;
public Panel(Anchor anchor, Vector2 size, Point positionOffset, NinePatch texture = null) : base(anchor, size) {
@ -15,9 +15,9 @@ namespace MLEM.Ui.Elements {
this.ChildPadding = new Point(5);
}
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
batch.Draw(this.texture, this.DisplayArea, color);
base.Draw(time, batch, color);
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
batch.Draw(this.texture, this.DisplayArea, Color.White * alpha);
base.Draw(time, batch, alpha);
}
}

View file

@ -10,7 +10,7 @@ namespace MLEM.Ui.Elements {
public class Paragraph : Element {
public static IGenericFont DefaultFont;
private string text;
private float lineHeight;
private string[] splitText;
@ -49,16 +49,16 @@ namespace MLEM.Ui.Elements {
return new Point(size.X, height.Ceil());
}
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
base.Draw(time, batch, color);
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
base.Draw(time, batch, alpha);
var pos = this.DisplayArea.Location.ToVector2();
var offset = new Vector2();
foreach (var line in this.splitText) {
if (this.centerText) {
this.font.DrawCenteredString(batch, line, pos + offset + new Vector2(this.DisplayArea.Width / 2, 0), this.TextScale, color);
this.font.DrawCenteredString(batch, line, pos + offset + new Vector2(this.DisplayArea.Width / 2, 0), this.TextScale, Color.White * alpha);
} else {
this.font.DrawString(batch, line, pos + offset, color, 0, Vector2.Zero, this.TextScale, SpriteEffects.None, 0);
this.font.DrawString(batch, line, pos + offset, Color.White * alpha, 0, Vector2.Zero, this.TextScale, SpriteEffects.None, 0);
}
offset.Y += this.lineHeight + 1;
}

View file

@ -32,7 +32,7 @@ namespace MLEM.Ui {
}
public Vector2 MousePos => this.inputHandler.MousePosition.ToVector2() / this.globalScale;
public Element MousedElement { get; private set; }
public Color DrawColor = Color.White;
public float DrawAlpha = 1;
public BlendState BlendState;
public SamplerState SamplerState = SamplerState.PointClamp;
@ -77,13 +77,13 @@ namespace MLEM.Ui {
batch.Begin(SpriteSortMode.Deferred, this.BlendState, this.SamplerState, transformMatrix: Matrix.CreateScale(this.globalScale));
foreach (var root in this.rootElements) {
if (!root.Element.IsHidden)
root.Element.Draw(time, batch, this.DrawColor);
root.Element.Draw(time, batch, this.DrawAlpha * root.Element.DrawAlpha);
}
batch.End();
foreach (var root in this.rootElements) {
if (!root.Element.IsHidden)
root.Element.DrawUnbound(time, batch, this.DrawColor, this.BlendState, this.SamplerState);
root.Element.DrawUnbound(time, batch, this.DrawAlpha * root.Element.DrawAlpha, this.BlendState, this.SamplerState);
}
}