mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +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
|
||||
- Moved sound-related classes into Sound namespace
|
||||
- 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
|
||||
|
||||
Fixes
|
||||
|
@ -32,7 +32,7 @@ Fixes
|
|||
|
||||
### MLEM.Extended
|
||||
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
|
||||
Additions
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using FontStashSharp;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
@ -25,21 +24,14 @@ namespace MLEM.Extended.Font {
|
|||
/// Creates a new generic font using <see cref="SpriteFontBase"/>.
|
||||
/// Optionally, a bold and italic version of the font can be supplied.
|
||||
/// </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="bold">A bold 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, float? lineHeight = null) {
|
||||
public GenericStashFont(SpriteFontBase font, SpriteFontBase bold = null, SpriteFontBase italic = null) {
|
||||
this.Font = font;
|
||||
this.LineHeight = lineHeight ?? CalculateLineHeight(font);
|
||||
this.Bold = bold != null ? new GenericStashFont(bold, null, null, lineHeight) : this;
|
||||
this.Italic = italic != null ? new GenericStashFont(italic, null, null, lineHeight) : this;
|
||||
this.LineHeight = CalculateLineHeight(font);
|
||||
this.Bold = bold != null ? new GenericStashFont(bold) : this;
|
||||
this.Italic = italic != null ? new GenericStashFont(italic) : this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -62,11 +54,11 @@ namespace MLEM.Extended.Font {
|
|||
// this is the same calculation used internally by StaticSpriteFont
|
||||
return s.FontSize + s.LineSpacing;
|
||||
} else {
|
||||
// use a heuristic to determine the text-independent line heights as described in the constructor remarks
|
||||
return new[] {' ', '\n', OneEmSpace, Zwsp, Nbsp}
|
||||
.Concat(Enumerable.Range('a', 'z' - 'a' + 1).SelectMany(c => new[] {(char) c, char.ToUpper((char) c)}))
|
||||
.Concat(Enumerable.Range('0', '9' - '0' + 1).Select(c => (char) c))
|
||||
.Select(c => font.MeasureString(c.ToString()).Y).Max();
|
||||
// Y (min y) just stores the glyph's Y offset, whereas Y2 (max y) stores the glyph's height
|
||||
// since we technically want line spacing rather than line height, we calculate it like this
|
||||
var bounds = new Bounds();
|
||||
font.TextBounds(" ", Vector2.Zero, ref bounds);
|
||||
return bounds.Y2 + (bounds.Y2 - bounds.Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.5">
|
||||
<PackageReference Include="FontStashSharp.MonoGame" Version="0.9.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
||||
|
@ -33,6 +33,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../Media/Logo.png" Pack="true" PackagePath="" />
|
||||
<None Include="../Media/Logo.png" Pack="true" PackagePath=""/>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
@ -183,8 +184,12 @@ namespace MLEM.Ui.Elements {
|
|||
this.SetText(text, true);
|
||||
|
||||
MlemPlatform.EnsureExists();
|
||||
|
||||
this.OnPressed += OnPressed;
|
||||
this.OnPressed += async 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);
|
||||
};
|
||||
this.OnTextInput += (element, key, character) => {
|
||||
if (!this.IsSelected || this.IsHidden)
|
||||
return;
|
||||
|
@ -201,13 +206,6 @@ namespace MLEM.Ui.Elements {
|
|||
};
|
||||
this.OnDeselected += e => this.CaretPos = 0;
|
||||
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) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Ui.Style;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TextCopy" Version="4.3.1" />
|
||||
<PackageReference Include="TextCopy" Version="4.3.0" />
|
||||
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
||||
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
||||
|
@ -25,6 +25,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../Media/Logo.png" Pack="true" PackagePath="" />
|
||||
<None Include="../Media/Logo.png" Pack="true" PackagePath=""/>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -34,6 +34,12 @@ namespace MLEM.Extensions {
|
|||
/// </summary>
|
||||
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>
|
||||
/// Parses a hexadecimal number into an rgba color.
|
||||
/// 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;
|
||||
}
|
||||
|
||||
var system = new FontSystem();
|
||||
var system = new FontSystem(this.GraphicsDevice, 1024, 1024);
|
||||
system.AddFont(File.ReadAllBytes("Content/Fonts/Cadman_Roman.otf"));
|
||||
//var font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont"));
|
||||
//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.Tiled" Version="3.8.0" />
|
||||
<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>
|
||||
|
|
|
@ -13,13 +13,10 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in a new issue