1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

added generic font wrapper

This commit is contained in:
Ellpeck 2019-08-09 14:26:20 +02:00
parent 369b4bf672
commit 82747e1331
7 changed files with 160 additions and 3 deletions

View file

@ -0,0 +1,53 @@
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Font {
public class GenericBitmapFont : IGenericFont {
public readonly BitmapFont Font;
public GenericBitmapFont(BitmapFont font) {
this.Font = font;
}
public static implicit operator GenericBitmapFont(BitmapFont font) {
return new GenericBitmapFont(font);
}
public Vector2 MeasureString(string text) {
return this.Font.MeasureString(text);
}
public Vector2 MeasureString(StringBuilder text) {
return this.Font.MeasureString(text);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
batch.DrawString(this.Font, text, position, color);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
batch.DrawString(this.Font, text, position, color);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
}
}

View file

@ -14,7 +14,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Extended" Version="3.6.0-beta0001"/>
<PackageReference Include="MonoGame.Extended" Version="3.6.0-beta0001">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

21
MLEM.Ui/Anchor.cs Normal file
View file

@ -0,0 +1,21 @@
namespace MLEM.Ui {
public enum Anchor {
TopLeft,
TopCenter,
TopRight,
CenterLeft,
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
AutoLeft, // below older sibling, aligned to the left
AutoCenter, // below older sibling, aligned to the center
AutoRight, //below older sibling, aligned to the right
AutoInline, // right of older sibling or below if overflows
AutoInlineIgnoreOverflow // right of older sibling at all time
}
}

View file

@ -14,7 +14,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Extended" Version="3.6.0-beta0001" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -10,6 +10,12 @@ namespace MLEM.Extensions {
if (blankTexture == null) {
blankTexture = new Texture2D(batch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
blankTexture.SetData(new[] {Color.White});
batch.Disposing += (sender, args) => {
if (blankTexture != null) {
blankTexture.Dispose();
blankTexture = null;
}
};
}
return blankTexture;
}

View file

@ -0,0 +1,51 @@
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MLEM.Font {
public class GenericSpriteFont : IGenericFont {
public readonly SpriteFont Font;
public GenericSpriteFont(SpriteFont font) {
this.Font = font;
}
public static implicit operator GenericSpriteFont(SpriteFont font) {
return new GenericSpriteFont(font);
}
public Vector2 MeasureString(string text) {
return this.Font.MeasureString(text);
}
public Vector2 MeasureString(StringBuilder text) {
return this.Font.MeasureString(text);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color) {
batch.DrawString(this.Font, text, position, color);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color) {
batch.DrawString(this.Font, text, position, color);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
public void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) {
batch.DrawString(this.Font, text, position, color, rotation, origin, scale, effects, layerDepth);
}
}
}

25
MLEM/Font/IGenericFont.cs Normal file
View file

@ -0,0 +1,25 @@
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MLEM.Font {
public interface IGenericFont {
Vector2 MeasureString(string text);
Vector2 MeasureString(StringBuilder text);
void DrawString(SpriteBatch batch, string text, Vector2 position, Color color);
void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth);
void DrawString(SpriteBatch batch, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color);
void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth);
void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
}
}