1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 01:09:23 +01:00

added stuff for monogame.extended

This commit is contained in:
Ellpeck 2019-08-06 14:26:51 +02:00
parent 2e29a114f3
commit 63a6cf493f
4 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Extensions {
public static class BitmapFontExtensions {
public static IEnumerable<string> SplitString(this BitmapFont font, string text, float width, float scale) {
var builder = new StringBuilder();
foreach (var word in text.Split(' ')) {
builder.Append(word).Append(' ');
if (font.MeasureString(builder).Width * scale >= width) {
var len = builder.Length - word.Length - 1;
yield return builder.ToString(0, len);
builder.Remove(0, len);
}
}
yield return builder.ToString();
}
}
}

View file

@ -0,0 +1,20 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Extensions {
public static class SpriteBatchExtensions {
public static void DrawCenteredString(this SpriteBatch batch, BitmapFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) {
var size = font.MeasureString(text);
var center = new Vector2(
horizontal ? size.Width * scale / 2F : 0,
vertical ? size.Height * scale / 2F : 0);
batch.DrawString(font, text,
position + (Vector2) size * scale / 2 - center,
color, 0, size / 2, scale + addedScale, SpriteEffects.None, 0);
}
}
}

View file

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<Authors>Ellpeck</Authors>
<Description>(M)LEM (L)ibrary by (E)llpeck for (M)onoGame for MonoGame.Extended</Description>
<PackageTags>monogame ellpeck mlem utility extensions monogame.extended extended</PackageTags>
<PackageProjectUrl>https://github.com/Ellpeck/MLEM</PackageProjectUrl>
<RepositoryUrl>https://github.com/Ellpeck/MLEM</RepositoryUrl>
<PackageLicenseUrl>https://github.com/Ellpeck/MLEM/blob/master/LICENSE</PackageLicenseUrl>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Extended" Version="3.6.0-beta0001" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.0.1708" />
</ItemGroup>
</Project>

View file

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM", "MLEM\MLEM.csproj", "{1D6AB762-43C4-4775-8924-707C7EC3F142}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MLEM.Extended", "MLEM.Extended\MLEM.Extended.csproj", "{232A6513-A28C-4D7F-BA5A-89281BFC1538}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{1D6AB762-43C4-4775-8924-707C7EC3F142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D6AB762-43C4-4775-8924-707C7EC3F142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D6AB762-43C4-4775-8924-707C7EC3F142}.Release|Any CPU.Build.0 = Release|Any CPU
{232A6513-A28C-4D7F-BA5A-89281BFC1538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{232A6513-A28C-4D7F-BA5A-89281BFC1538}.Debug|Any CPU.Build.0 = Debug|Any CPU
{232A6513-A28C-4D7F-BA5A-89281BFC1538}.Release|Any CPU.ActiveCfg = Release|Any CPU
{232A6513-A28C-4D7F-BA5A-89281BFC1538}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal