1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +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); } 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; 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); this.font.DrawCenteredString(batch, this.Text, pos, this.scale, this.Color * alpha, true, true);
base.Draw(time, batch, color); 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 tex = this.Texture;
var color = Color.White * alpha;
if (this.IsMouseOver) { if (this.IsMouseOver) {
if (this.HoveredTexture != null) if (this.HoveredTexture != null)
tex = this.HoveredTexture; tex = this.HoveredTexture;
color = this.HoveredColor.CopyAlpha(color); color = this.HoveredColor * alpha;
} }
batch.Draw(tex, this.DisplayArea, color); 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 bool IgnoresMouse;
public float DrawAlpha = 1;
private Rectangle area; private Rectangle area;
public Rectangle Area { public Rectangle Area {
@ -260,17 +261,17 @@ namespace MLEM.Ui.Elements {
child.Update(time); 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) { foreach (var child in this.children) {
if (!child.IsHidden) 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) { foreach (var child in this.children) {
if (!child.IsHidden) 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); return this.scaleToImage ? this.texture.Size : base.CalcActualSize(parentArea);
} }
public override void Draw(GameTime time, SpriteBatch batch, Color color) { public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
batch.Draw(this.texture, this.DisplayArea, this.Color.CopyAlpha(color)); batch.Draw(this.texture, this.DisplayArea, this.Color * alpha);
base.Draw(time, batch, color); base.Draw(time, batch, alpha);
} }
} }

View file

@ -15,9 +15,9 @@ namespace MLEM.Ui.Elements {
this.ChildPadding = new Point(5); this.ChildPadding = new Point(5);
} }
public override void Draw(GameTime time, SpriteBatch batch, Color color) { public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
batch.Draw(this.texture, this.DisplayArea, color); batch.Draw(this.texture, this.DisplayArea, Color.White * alpha);
base.Draw(time, batch, color); base.Draw(time, batch, alpha);
} }
} }

View file

@ -49,16 +49,16 @@ namespace MLEM.Ui.Elements {
return new Point(size.X, height.Ceil()); return new Point(size.X, height.Ceil());
} }
public override void Draw(GameTime time, SpriteBatch batch, Color color) { public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
base.Draw(time, batch, color); base.Draw(time, batch, alpha);
var pos = this.DisplayArea.Location.ToVector2(); var pos = this.DisplayArea.Location.ToVector2();
var offset = new Vector2(); var offset = new Vector2();
foreach (var line in this.splitText) { foreach (var line in this.splitText) {
if (this.centerText) { 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 { } 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; offset.Y += this.lineHeight + 1;
} }

View file

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