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:
parent
369b4bf672
commit
82747e1331
7 changed files with 160 additions and 3 deletions
53
MLEM.Extended/Font/GenericBitmapFont.cs
Normal file
53
MLEM.Extended/Font/GenericBitmapFont.cs
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,13 +14,15 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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">
|
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MLEM\MLEM.csproj"/>
|
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
21
MLEM.Ui/Anchor.cs
Normal file
21
MLEM.Ui/Anchor.cs
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MonoGame.Extended" Version="3.6.0-beta0001" />
|
|
||||||
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625">
|
<PackageReference Include="MonoGame.Framework.Portable" Version="3.6.0.1625">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|
|
@ -10,6 +10,12 @@ namespace MLEM.Extensions {
|
||||||
if (blankTexture == null) {
|
if (blankTexture == null) {
|
||||||
blankTexture = new Texture2D(batch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
blankTexture = new Texture2D(batch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
||||||
blankTexture.SetData(new[] {Color.White});
|
blankTexture.SetData(new[] {Color.White});
|
||||||
|
batch.Disposing += (sender, args) => {
|
||||||
|
if (blankTexture != null) {
|
||||||
|
blankTexture.Dispose();
|
||||||
|
blankTexture = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return blankTexture;
|
return blankTexture;
|
||||||
}
|
}
|
||||||
|
|
51
MLEM/Font/GenericSpriteFont.cs
Normal file
51
MLEM/Font/GenericSpriteFont.cs
Normal 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
25
MLEM/Font/IGenericFont.cs
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue