mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 21:48:35 +01:00
Compare commits
No commits in common. "e53d30e5ca14c2ec597da9a73de566f522215f7b" and "a76c14b243ae848d1487b333752c2e73aea2de32" have entirely different histories.
e53d30e5ca
...
a76c14b243
10 changed files with 33 additions and 39 deletions
|
@ -14,7 +14,7 @@ Improvements
|
||||||
- Improved NinePatch memory performance
|
- Improved NinePatch memory performance
|
||||||
- Moved sound-related classes into Sound namespace
|
- Moved sound-related classes into Sound namespace
|
||||||
- Added customizable overloads for Keybind, Combination and GenericInput ToString methods
|
- Added customizable overloads for Keybind, Combination and GenericInput ToString methods
|
||||||
- Moved ColorHelper.Invert to ColorExtensions.Invert
|
- Added ColorExtensions.Invert and made ColorHelper.Invert obsolete
|
||||||
- Removed LINQ Any and All usage in various methods to improve memory usage
|
- Removed LINQ Any and All usage in various methods to improve memory usage
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
|
@ -32,7 +32,7 @@ Fixes
|
||||||
|
|
||||||
### MLEM.Extended
|
### MLEM.Extended
|
||||||
Improvements
|
Improvements
|
||||||
- Adjusted GenericStashFont line height calculations to result in values closer to GenericSpriteFont and added a constructor parameter to set a custom line height
|
- Adjusted GenericStashFont line height calculations to result in the same values as GenericSpriteFont
|
||||||
|
|
||||||
### MLEM.Data
|
### MLEM.Data
|
||||||
Additions
|
Additions
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FontStashSharp;
|
using FontStashSharp;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
@ -25,21 +24,14 @@ namespace MLEM.Extended.Font {
|
||||||
/// Creates a new generic font using <see cref="SpriteFontBase"/>.
|
/// Creates a new generic font using <see cref="SpriteFontBase"/>.
|
||||||
/// Optionally, a bold and italic version of the font can be supplied.
|
/// Optionally, a bold and italic version of the font can be supplied.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
|
||||||
/// <see cref="DynamicSpriteFont"/> doesn't expose a text-independent line height (https://github.com/rds1983/FontStashSharp/blob/main/src/FontStashSharp/DynamicSpriteFont.cs#L130).
|
|
||||||
/// Since <see cref="GenericFont"/> exposes <see cref="LineHeight"/>, there is somewhat of an incompatibility between the two.
|
|
||||||
/// Because of this, <see cref="GenericStashFont"/> uses a heuristic to determine a text-independent line height based on the tallest character out of a set of predetermined characters (spaces, numbers and uppercase and lowercase A through Z).
|
|
||||||
/// Because this heuristic is just that, and because it excludes non-latin characters, the desired line height can be specified using <paramref name="lineHeight"/>, overriding the default heuristic.
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="font">The font to wrap</param>
|
/// <param name="font">The font to wrap</param>
|
||||||
/// <param name="bold">A bold version of the font</param>
|
/// <param name="bold">A bold version of the font</param>
|
||||||
/// <param name="italic">An italic version of the font</param>
|
/// <param name="italic">An italic version of the font</param>
|
||||||
/// <param name="lineHeight">The line height that should be used for <see cref="LineHeight"/> instead of the heuristic described in the remarks</param>
|
public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteFontBase italic = null) {
|
||||||
public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteFontBase italic = null, float? lineHeight = null) {
|
|
||||||
this.Font = font;
|
this.Font = font;
|
||||||
this.LineHeight = lineHeight ?? CalculateLineHeight(font);
|
this.LineHeight = CalculateLineHeight(font);
|
||||||
this.Bold = bold != null ? new GenericStashFont(bold, null, null, lineHeight) : this;
|
this.Bold = bold != null ? new GenericStashFont(bold) : this;
|
||||||
this.Italic = italic != null ? new GenericStashFont(italic, null, null, lineHeight) : this;
|
this.Italic = italic != null ? new GenericStashFont(italic) : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -62,11 +54,11 @@ namespace MLEM.Extended.Font {
|
||||||
// this is the same calculation used internally by StaticSpriteFont
|
// this is the same calculation used internally by StaticSpriteFont
|
||||||
return s.FontSize + s.LineSpacing;
|
return s.FontSize + s.LineSpacing;
|
||||||
} else {
|
} else {
|
||||||
// use a heuristic to determine the text-independent line heights as described in the constructor remarks
|
// Y (min y) just stores the glyph's Y offset, whereas Y2 (max y) stores the glyph's height
|
||||||
return new[] {' ', '\n', OneEmSpace, Zwsp, Nbsp}
|
// since we technically want line spacing rather than line height, we calculate it like this
|
||||||
.Concat(Enumerable.Range('a', 'z' - 'a' + 1).SelectMany(c => new[] {(char) c, char.ToUpper((char) c)}))
|
var bounds = new Bounds();
|
||||||
.Concat(Enumerable.Range('0', '9' - '0' + 1).Select(c => (char) c))
|
font.TextBounds(" ", Vector2.Zero, ref bounds);
|
||||||
.Select(c => font.MeasureString(c.ToString()).Y).Max();
|
return bounds.Y2 + (bounds.Y2 - bounds.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0">
|
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.5">
|
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.2">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
@ -183,8 +184,12 @@ namespace MLEM.Ui.Elements {
|
||||||
this.SetText(text, true);
|
this.SetText(text, true);
|
||||||
|
|
||||||
MlemPlatform.EnsureExists();
|
MlemPlatform.EnsureExists();
|
||||||
|
this.OnPressed += async e => {
|
||||||
this.OnPressed += OnPressed;
|
var title = this.MobileTitle ?? this.PlaceholderText;
|
||||||
|
var result = await MlemPlatform.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
||||||
|
if (result != null)
|
||||||
|
this.SetText(result.Replace('\n', ' '), true);
|
||||||
|
};
|
||||||
this.OnTextInput += (element, key, character) => {
|
this.OnTextInput += (element, key, character) => {
|
||||||
if (!this.IsSelected || this.IsHidden)
|
if (!this.IsSelected || this.IsHidden)
|
||||||
return;
|
return;
|
||||||
|
@ -201,13 +206,6 @@ namespace MLEM.Ui.Elements {
|
||||||
};
|
};
|
||||||
this.OnDeselected += e => this.CaretPos = 0;
|
this.OnDeselected += e => this.CaretPos = 0;
|
||||||
this.OnSelected += e => this.CaretPos = this.text.Length;
|
this.OnSelected += e => this.CaretPos = this.text.Length;
|
||||||
|
|
||||||
async void OnPressed(Element e) {
|
|
||||||
var title = this.MobileTitle ?? this.PlaceholderText;
|
|
||||||
var result = await MlemPlatform.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
|
||||||
if (result != null)
|
|
||||||
this.SetText(result.Replace('\n', ' '), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleTextChange(bool textChanged = true) {
|
private void HandleTextChange(bool textChanged = true) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Ui.Style;
|
using MLEM.Ui.Style;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TextCopy" Version="4.3.1" />
|
<PackageReference Include="TextCopy" Version="4.3.0" />
|
||||||
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
||||||
|
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
||||||
|
|
|
@ -34,6 +34,12 @@ namespace MLEM.Extensions {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ColorHelper {
|
public static class ColorHelper {
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ColorExtensions.Invert"/>
|
||||||
|
[Obsolete("This method has been moved to ColorExtensions.Invert in 5.1.0")]
|
||||||
|
public static Color Invert(this Color color) {
|
||||||
|
return ColorExtensions.Invert(color);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a hexadecimal number into an rgba color.
|
/// Parses a hexadecimal number into an rgba color.
|
||||||
/// The number should be in the format <c>0xaarrggbb</c>.
|
/// The number should be in the format <c>0xaarrggbb</c>.
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace Sandbox {
|
||||||
textureData[textureData.FromIndex(textureData.ToIndex(25, 9))] = Color.Yellow;
|
textureData[textureData.FromIndex(textureData.ToIndex(25, 9))] = Color.Yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
var system = new FontSystem();
|
var system = new FontSystem(this.GraphicsDevice, 1024, 1024);
|
||||||
system.AddFont(File.ReadAllBytes("Content/Fonts/Cadman_Roman.otf"));
|
system.AddFont(File.ReadAllBytes("Content/Fonts/Cadman_Roman.otf"));
|
||||||
//var font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont"));
|
//var font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont"));
|
||||||
//var font = new GenericBitmapFont(LoadContent<BitmapFont>("Fonts/Regular"));
|
//var font = new GenericBitmapFont(LoadContent<BitmapFont>("Fonts/Regular"));
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
|
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
|
||||||
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
|
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||||
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.5" />
|
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -13,13 +13,10 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||||
<PackageReference Include="NunitXml.TestLogger" Version="3.0.107" />
|
<PackageReference Include="NunitXml.TestLogger" Version="3.0.107" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue