1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-24 21:48:35 +01:00

Compare commits

..

No commits in common. "642608a8a26a6d51ba27ebeda94cc07cf98a0fca" and "00d9ee99d877a17c111555c63822a7cb1914b5af" have entirely different histories.

3 changed files with 23 additions and 38 deletions

View file

@ -10,13 +10,6 @@ Jump to version:
Fixes Fixes
- Set default values for InputHandler held and pressed keys to avoid an exception if buttons are held in the very first frame - Set default values for InputHandler held and pressed keys to avoid an exception if buttons are held in the very first frame
Improvements
- Improved NinePatch memory performance
### MLEM.Ui
Fixes
- Fixed a crash if a paragraph has a link formatting code, but no font
## 5.0.0 ## 5.0.0
### MLEM ### MLEM
Additions Additions

View file

@ -236,9 +236,8 @@ namespace MLEM.Ui.Elements {
/// <inheritdoc /> /// <inheritdoc />
public override void ForceUpdateArea() { public override void ForceUpdateArea() {
// set the position offset and size to the token's first area // set the position offset and size to the token's first area
var area = this.Token.GetArea(Vector2.Zero, this.textScale).FirstOrDefault(); var area = this.Token.GetArea(Vector2.Zero, this.textScale).First();
this.PositionOffset = area.Location + new Vector2(((Paragraph) this.Parent).GetAlignmentOffset() / this.Parent.Scale, 0); this.PositionOffset = area.Location + new Vector2(((Paragraph) this.Parent).GetAlignmentOffset() / this.Parent.Scale, 0);
this.IsHidden = area.IsEmpty;
this.Size = area.Size; this.Size = area.Size;
base.ForceUpdateArea(); base.ForceUpdateArea();
} }

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions; using MLEM.Extensions;
@ -39,9 +41,7 @@ namespace MLEM.Textures {
this.Region = texture; this.Region = texture;
this.Padding = padding; this.Padding = padding;
this.Mode = mode; this.Mode = mode;
this.SourceRectangles = new Rectangle[9]; this.SourceRectangles = this.CreateRectangles(this.Region.Area).ToArray();
for (var i = 0; i < this.SourceRectangles.Length; i++)
this.SourceRectangles[i] = (Rectangle) this.GetRectangleForIndex((RectangleF) this.Region.Area, i);
} }
/// <summary> /// <summary>
@ -77,7 +77,7 @@ namespace MLEM.Textures {
this(texture, padding, padding, padding, padding, mode) { this(texture, padding, padding, padding, padding, mode) {
} }
internal RectangleF GetRectangleForIndex(RectangleF area, int index, float patchScale = 1) { internal IEnumerable<RectangleF> CreateRectangles(RectangleF area, float patchScale = 1) {
var pl = this.Padding.Left * patchScale; var pl = this.Padding.Left * patchScale;
var pr = this.Padding.Right * patchScale; var pr = this.Padding.Right * patchScale;
var pt = this.Padding.Top * patchScale; var pt = this.Padding.Top * patchScale;
@ -90,28 +90,19 @@ namespace MLEM.Textures {
var topY = area.Y + pt; var topY = area.Y + pt;
var bottomY = area.Y + area.Height - pb; var bottomY = area.Y + area.Height - pb;
switch (index) { yield return new RectangleF(area.X, area.Y, pl, pt);
case 0: yield return new RectangleF(leftX, area.Y, centerW, pt);
return new RectangleF(area.X, area.Y, pl, pt); yield return new RectangleF(rightX, area.Y, pr, pt);
case 1: yield return new RectangleF(area.X, topY, pl, centerH);
return new RectangleF(leftX, area.Y, centerW, pt); yield return new RectangleF(leftX, topY, centerW, centerH);
case 2: yield return new RectangleF(rightX, topY, pr, centerH);
return new RectangleF(rightX, area.Y, pr, pt); yield return new RectangleF(area.X, bottomY, pl, pb);
case 3: yield return new RectangleF(leftX, bottomY, centerW, pb);
return new RectangleF(area.X, topY, pl, centerH); yield return new RectangleF(rightX, bottomY, pr, pb);
case 4:
return new RectangleF(leftX, topY, centerW, centerH);
case 5:
return new RectangleF(rightX, topY, pr, centerH);
case 6:
return new RectangleF(area.X, bottomY, pl, pb);
case 7:
return new RectangleF(leftX, bottomY, centerW, pb);
case 8:
return new RectangleF(rightX, bottomY, pr, pb);
default:
throw new ArgumentOutOfRangeException(nameof(index));
} }
private IEnumerable<Rectangle> CreateRectangles(Rectangle area, float patchScale = 1) {
return this.CreateRectangles((RectangleF) area, patchScale).Select(r => (Rectangle) r);
} }
} }
@ -152,10 +143,11 @@ namespace MLEM.Textures {
/// <param name="layerDepth">The depth</param> /// <param name="layerDepth">The depth</param>
/// <param name="patchScale">The scale of each area of the nine patch</param> /// <param name="patchScale">The scale of each area of the nine patch</param>
public static void Draw(this SpriteBatch batch, NinePatch texture, RectangleF destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth, float patchScale = 1) { public static void Draw(this SpriteBatch batch, NinePatch texture, RectangleF destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth, float patchScale = 1) {
for (var i = 0; i < texture.SourceRectangles.Length; i++) { var destinations = texture.CreateRectangles(destinationRectangle, patchScale);
var rect = texture.GetRectangleForIndex(destinationRectangle, i, patchScale); var count = 0;
foreach (var rect in destinations) {
if (!rect.IsEmpty) { if (!rect.IsEmpty) {
var src = texture.SourceRectangles[i]; var src = texture.SourceRectangles[count];
switch (texture.Mode) { switch (texture.Mode) {
case NinePatchMode.Stretch: case NinePatchMode.Stretch:
batch.Draw(texture.Region.Texture, rect, src, color, rotation, origin, effects, layerDepth); batch.Draw(texture.Region.Texture, rect, src, color, rotation, origin, effects, layerDepth);
@ -172,6 +164,7 @@ namespace MLEM.Textures {
break; break;
} }
} }
count++;
} }
} }