mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
Compare commits
No commits in common. "b0bf55842b9612cfefa9dc4a287fa166a2a22d1a" and "2e1d52944a8e559cb7100b4c22083ff0fe54c053" have entirely different histories.
b0bf55842b
...
2e1d52944a
5 changed files with 47 additions and 87 deletions
|
@ -19,17 +19,9 @@ Jump to version:
|
||||||
## 8.0.0 (In Development)
|
## 8.0.0 (In Development)
|
||||||
|
|
||||||
### MLEM
|
### MLEM
|
||||||
Improvements
|
|
||||||
- Allow getting and setting TextureData by index
|
|
||||||
- Improved TextureExtensions.PremultipliedCopy memory performance
|
|
||||||
- Improved the naming of SpriteBatchExtensions texture generation methods
|
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed formatting codes at the start of strings not being added to the AllCodes collection
|
- Fixed formatting codes at the start of strings not being added to the AllCodes collection
|
||||||
|
|
||||||
Removals
|
|
||||||
- Marked SpriteBatchExtensions GenerateTexture and GenerateSquareTexture as obsolete in favor of their more clearly named replacements
|
|
||||||
|
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Additions
|
Additions
|
||||||
- Added Panel.IsVisible method to check if a child element is visible
|
- Added Panel.IsVisible method to check if a child element is visible
|
||||||
|
|
|
@ -5,7 +5,7 @@ using MLEM.Graphics;
|
||||||
namespace MLEM.Ui.Style {
|
namespace MLEM.Ui.Style {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default, untextured <see cref="UiStyle"/>.
|
/// The default, untextured <see cref="UiStyle"/>.
|
||||||
/// Note that, as MLEM does not provide any texture or font assets, this default style is made up of single-color textures that were generated using <see cref="SpriteBatchExtensions.GenerateNinePatch"/>.
|
/// Note that, as MLEM does not provide any texture or font assets, this default style is made up of single-color textures that were generated using <see cref="SpriteBatchExtensions.GenerateTexture"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UntexturedStyle : UiStyle {
|
public class UntexturedStyle : UiStyle {
|
||||||
|
|
||||||
|
@ -14,18 +14,18 @@ namespace MLEM.Ui.Style {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">The sprite batch to generate the textures with</param>
|
/// <param name="batch">The sprite batch to generate the textures with</param>
|
||||||
public UntexturedStyle(SpriteBatch batch) {
|
public UntexturedStyle(SpriteBatch batch) {
|
||||||
this.SelectionIndicator = batch.GenerateNinePatch(Color.Transparent, Color.Red);
|
this.SelectionIndicator = batch.GenerateTexture(Color.Transparent, Color.Red);
|
||||||
this.ButtonTexture = batch.GenerateNinePatch(Color.CadetBlue, Color.Black);
|
this.ButtonTexture = batch.GenerateTexture(Color.CadetBlue);
|
||||||
this.PanelTexture = batch.GenerateNinePatch(Color.Gray, Color.Black);
|
this.PanelTexture = batch.GenerateTexture(Color.Gray);
|
||||||
this.TextFieldTexture = batch.GenerateNinePatch(Color.MediumBlue, Color.Black);
|
this.TextFieldTexture = batch.GenerateTexture(Color.MediumBlue);
|
||||||
this.ScrollBarBackground = batch.GenerateNinePatch(Color.LightBlue, Color.Black);
|
this.ScrollBarBackground = batch.GenerateTexture(Color.LightBlue);
|
||||||
this.ScrollBarScrollerTexture = batch.GenerateNinePatch(Color.Blue, Color.Black);
|
this.ScrollBarScrollerTexture = batch.GenerateTexture(Color.Blue);
|
||||||
this.CheckboxTexture = batch.GenerateNinePatch(Color.LightBlue, Color.Black);
|
this.CheckboxTexture = batch.GenerateTexture(Color.LightBlue);
|
||||||
this.CheckboxCheckmark = batch.GenerateNinePatch(Color.Blue, Color.Black).Region;
|
this.CheckboxCheckmark = batch.GenerateTexture(Color.Blue).Region;
|
||||||
this.RadioTexture = batch.GenerateNinePatch(Color.AliceBlue, Color.Black);
|
this.RadioTexture = batch.GenerateTexture(Color.AliceBlue);
|
||||||
this.RadioCheckmark = batch.GenerateNinePatch(Color.CornflowerBlue, Color.Black).Region;
|
this.RadioCheckmark = batch.GenerateTexture(Color.CornflowerBlue).Region;
|
||||||
this.TooltipBackground = batch.GenerateNinePatch(Color.Black * 0.65F, Color.Black * 0.65F);
|
this.TooltipBackground = batch.GenerateTexture(Color.Black * 0.65F, Color.Black * 0.65F);
|
||||||
this.ProgressBarTexture = batch.GenerateNinePatch(Color.RoyalBlue, Color.Black);
|
this.ProgressBarTexture = batch.GenerateTexture(Color.RoyalBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Maths;
|
using MLEM.Maths;
|
||||||
|
@ -19,8 +18,11 @@ namespace MLEM.Graphics {
|
||||||
/// <param name="batch">The sprite batch</param>
|
/// <param name="batch">The sprite batch</param>
|
||||||
/// <returns>A 1x1 pixel white texture</returns>
|
/// <returns>A 1x1 pixel white texture</returns>
|
||||||
public static Texture2D GetBlankTexture(this SpriteBatch batch) {
|
public static Texture2D GetBlankTexture(this SpriteBatch batch) {
|
||||||
if (SpriteBatchExtensions.blankTexture == null)
|
if (SpriteBatchExtensions.blankTexture == null) {
|
||||||
SpriteBatchExtensions.blankTexture = batch.GenerateTexture(Color.White, 1, 1);
|
SpriteBatchExtensions.blankTexture = new Texture2D(batch.GraphicsDevice, 1, 1);
|
||||||
|
SpriteBatchExtensions.blankTexture.SetData(new[] {Color.White});
|
||||||
|
SpriteBatchExtensions.AutoDispose(batch, SpriteBatchExtensions.blankTexture);
|
||||||
|
}
|
||||||
return SpriteBatchExtensions.blankTexture;
|
return SpriteBatchExtensions.blankTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,25 +34,13 @@ namespace MLEM.Graphics {
|
||||||
/// <param name="color">The fill color of the texture</param>
|
/// <param name="color">The fill color of the texture</param>
|
||||||
/// <param name="outlineColor">The outline color of the texture</param>
|
/// <param name="outlineColor">The outline color of the texture</param>
|
||||||
/// <returns>A <see cref="NinePatch"/> containing a 3x3 texture with an outline</returns>
|
/// <returns>A <see cref="NinePatch"/> containing a 3x3 texture with an outline</returns>
|
||||||
[Obsolete("Use the new GenerateNinePatch instead")]
|
|
||||||
public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null) {
|
public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null) {
|
||||||
return batch.GenerateNinePatch(color, outlineColor ?? Color.Black);
|
var outli = outlineColor ?? Color.Black;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a <see cref="NinePatch"/> that has a texture with a given color and outline color.
|
|
||||||
/// This texture is automatically disposed of when the batch is disposed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="batch">The sprite batch</param>
|
|
||||||
/// <param name="color">The fill color of the texture</param>
|
|
||||||
/// <param name="outlineColor">The outline color of the texture</param>
|
|
||||||
/// <returns>A <see cref="NinePatch"/> containing a 3x3 texture with an outline</returns>
|
|
||||||
public static NinePatch GenerateNinePatch(this SpriteBatch batch, Color color, Color outlineColor) {
|
|
||||||
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
|
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
|
||||||
tex.SetData(new[] {
|
tex.SetData(new[] {
|
||||||
outlineColor, outlineColor, outlineColor,
|
outli, outli, outli,
|
||||||
outlineColor, color, outlineColor,
|
outli, color, outli,
|
||||||
outlineColor, outlineColor, outlineColor
|
outli, outli, outli
|
||||||
});
|
});
|
||||||
SpriteBatchExtensions.AutoDispose(batch, tex);
|
SpriteBatchExtensions.AutoDispose(batch, tex);
|
||||||
return new NinePatch(tex, 1);
|
return new NinePatch(tex, 1);
|
||||||
|
@ -63,26 +53,9 @@ namespace MLEM.Graphics {
|
||||||
/// <param name="batch">The sprite batch</param>
|
/// <param name="batch">The sprite batch</param>
|
||||||
/// <param name="color">The color of the texture</param>
|
/// <param name="color">The color of the texture</param>
|
||||||
/// <returns>A new texture with the given data</returns>
|
/// <returns>A new texture with the given data</returns>
|
||||||
[Obsolete("Use the new GenerateTexture instead")]
|
|
||||||
public static Texture2D GenerateSquareTexture(this SpriteBatch batch, Color color) {
|
public static Texture2D GenerateSquareTexture(this SpriteBatch batch, Color color) {
|
||||||
return batch.GenerateTexture(color, 1, 1);
|
var tex = new Texture2D(batch.GraphicsDevice, 1, 1);
|
||||||
}
|
tex.SetData(new[] {color});
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a texture with the given <paramref name="width"/> and <paramref name="height"/>, which will be filled with the given <paramref name="color"/>.
|
|
||||||
/// This texture is automatically disposed of when the batch is disposed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="batch">The sprite batch</param>
|
|
||||||
/// <param name="color">The color of the texture</param>
|
|
||||||
/// <param name="width">The width of the resulting texture</param>
|
|
||||||
/// <param name="height">The height of the resulting texture</param>
|
|
||||||
/// <returns>A new texture with the given data</returns>
|
|
||||||
public static Texture2D GenerateTexture(this SpriteBatch batch, Color color, int width, int height) {
|
|
||||||
var tex = new Texture2D(batch.GraphicsDevice, width, height);
|
|
||||||
using (var data = tex.GetTextureData()) {
|
|
||||||
for (var i = 0; i < data.Length; i++)
|
|
||||||
data[i] = color;
|
|
||||||
}
|
|
||||||
SpriteBatchExtensions.AutoDispose(batch, tex);
|
SpriteBatchExtensions.AutoDispose(batch, tex);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,15 @@ namespace MLEM.Textures {
|
||||||
/// <param name="texture">The texture of which to create a premultiplied copy.</param>
|
/// <param name="texture">The texture of which to create a premultiplied copy.</param>
|
||||||
/// <returns>The premultiplied copy of the <paramref name="texture"/>.</returns>
|
/// <returns>The premultiplied copy of the <paramref name="texture"/>.</returns>
|
||||||
public static Texture2D PremultipliedCopy(this Texture2D texture) {
|
public static Texture2D PremultipliedCopy(this Texture2D texture) {
|
||||||
var data = new Color[texture.Width * texture.Height];
|
|
||||||
texture.GetData(data);
|
|
||||||
for (var i = 0; i < data.Length; i++)
|
|
||||||
data[i] = Color.FromNonPremultiplied(data[i].ToVector4());
|
|
||||||
var ret = new Texture2D(texture.GraphicsDevice, texture.Width, texture.Height);
|
var ret = new Texture2D(texture.GraphicsDevice, texture.Width, texture.Height);
|
||||||
ret.SetData(data);
|
using (var textureData = texture.GetTextureData()) {
|
||||||
|
using (var retData = ret.GetTextureData()) {
|
||||||
|
for (var x = 0; x < ret.Width; x++) {
|
||||||
|
for (var y = 0; y < ret.Height; y++)
|
||||||
|
retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,34 +51,20 @@ namespace MLEM.Textures {
|
||||||
/// <param name="x">The x coordinate of the texture location</param>
|
/// <param name="x">The x coordinate of the texture location</param>
|
||||||
/// <param name="y">The y coordinate of the texture location</param>
|
/// <param name="y">The y coordinate of the texture location</param>
|
||||||
public Color this[int x, int y] {
|
public Color this[int x, int y] {
|
||||||
get => this[this.ToIndex(x, y)];
|
get => this.data[this.ToIndex(x, y)];
|
||||||
set => this[this.ToIndex(x, y)] = value;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the color at the given x,y position of the texture, where 0,0 represents the bottom left.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="point">The x and y coordinates of the texture location</param>
|
|
||||||
public Color this[Point point] {
|
|
||||||
get => this[point.X, point.Y];
|
|
||||||
set => this[point.X, point.Y] = value;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the color at the given index of the texture data, which is the index in the <see cref="Texture2D.GetData{T}(T[])"/> array.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="index">The index.</param>
|
|
||||||
public Color this[int index] {
|
|
||||||
get => this.data[index];
|
|
||||||
set {
|
set {
|
||||||
|
var index = this.ToIndex(x, y);
|
||||||
if (this.data[index] != value) {
|
if (this.data[index] != value) {
|
||||||
this.data[index] = value;
|
this.data[index] = value;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <inheritdoc cref="this[int,int]"/>
|
||||||
/// The length of the underlying texture data array, which is the texture's width multiplied by its height.
|
public Color this[Point point] {
|
||||||
/// </summary>
|
get => this[point.X, point.Y];
|
||||||
public int Length => this.data.Length;
|
set => this[point.X, point.Y] = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new texture data instance for the given texture.
|
/// Creates a new texture data instance for the given texture.
|
||||||
|
@ -118,7 +107,7 @@ namespace MLEM.Textures {
|
||||||
/// <returns>The corresponding texture coordinate</returns>
|
/// <returns>The corresponding texture coordinate</returns>
|
||||||
/// <exception cref="ArgumentException">If the given index is out of bounds</exception>
|
/// <exception cref="ArgumentException">If the given index is out of bounds</exception>
|
||||||
public Point FromIndex(int index) {
|
public Point FromIndex(int index) {
|
||||||
if (index < 0 || index >= this.Length)
|
if (index < 0 || index >= this.data.Length)
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
return new Point(index % this.texture.Width, index / this.texture.Width);
|
return new Point(index % this.texture.Width, index / this.texture.Width);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,13 @@ public class TexturePackerTests : GameTestFixture {
|
||||||
|
|
||||||
private TextureRegion MakeTextureRegion(int width, int height) {
|
private TextureRegion MakeTextureRegion(int width, int height) {
|
||||||
var color = ColorHelper.FromHexRgb(SingleRandom.Int(this.generatedTextures.Count));
|
var color = ColorHelper.FromHexRgb(SingleRandom.Int(this.generatedTextures.Count));
|
||||||
var texture = this.Game.SpriteBatch.GenerateTexture(color, Math.Max(width, 1), Math.Max(height, 1));
|
var texture = new Texture2D(this.Game.GraphicsDevice, Math.Max(width, 1), Math.Max(height, 1));
|
||||||
|
using (var data = texture.GetTextureData()) {
|
||||||
|
for (var x = 0; x < texture.Width; x++) {
|
||||||
|
for (var y = 0; y < texture.Height; y++)
|
||||||
|
data[x, y] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
var region = new TextureRegion(texture, 0, 0, width, height);
|
var region = new TextureRegion(texture, 0, 0, width, height);
|
||||||
this.generatedTextures.Add(region);
|
this.generatedTextures.Add(region);
|
||||||
return region;
|
return region;
|
||||||
|
|
Loading…
Reference in a new issue