forked from MoonsideGames/MoonWorks
Packer.TextBounds
parent
d190df55b2
commit
db5ca97726
|
@ -1 +1 @@
|
||||||
Subproject commit ac63d6c9b2d773792f8c3e5dafe760dd8769a4bf
|
Subproject commit f8872bae59e394b0f8a35224bb39ab8fd041af97
|
|
@ -12,6 +12,8 @@ namespace MoonWorks.Graphics.Font
|
||||||
|
|
||||||
public Font Font { get; }
|
public Font Font { get; }
|
||||||
|
|
||||||
|
private byte[] StringBytes;
|
||||||
|
|
||||||
private bool IsDisposed;
|
private bool IsDisposed;
|
||||||
|
|
||||||
public unsafe Packer(GraphicsDevice graphicsDevice, Font font, float fontSize, uint textureWidth, uint textureHeight, uint padding = 1)
|
public unsafe Packer(GraphicsDevice graphicsDevice, Font font, float fontSize, uint textureWidth, uint textureHeight, uint padding = 1)
|
||||||
|
@ -19,6 +21,7 @@ namespace MoonWorks.Graphics.Font
|
||||||
Font = font;
|
Font = font;
|
||||||
Handle = Wellspring.Wellspring_CreatePacker(Font.Handle, fontSize, textureWidth, textureHeight, 0, padding);
|
Handle = Wellspring.Wellspring_CreatePacker(Font.Handle, fontSize, textureWidth, textureHeight, 0, padding);
|
||||||
Texture = Texture.CreateTexture2D(graphicsDevice, textureWidth, textureHeight, TextureFormat.R8, TextureUsageFlags.Sampler);
|
Texture = Texture.CreateTexture2D(graphicsDevice, textureWidth, textureHeight, TextureFormat.R8, TextureUsageFlags.Sampler);
|
||||||
|
StringBytes = new byte[128];
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe bool PackFontRanges(params FontRange[] fontRanges)
|
public unsafe bool PackFontRanges(params FontRange[] fontRanges)
|
||||||
|
@ -43,6 +46,38 @@ namespace MoonWorks.Graphics.Font
|
||||||
commandBuffer.SetTextureData(Texture, pixelDataPointer, Texture.Width * Texture.Height);
|
commandBuffer.SetTextureData(Texture, pixelDataPointer, Texture.Width * Texture.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public unsafe void TextBounds(
|
||||||
|
string text,
|
||||||
|
float x,
|
||||||
|
float y,
|
||||||
|
HorizontalAlignment horizontalAlignment,
|
||||||
|
VerticalAlignment verticalAlignment,
|
||||||
|
out Wellspring.Rectangle rectangle
|
||||||
|
) {
|
||||||
|
var byteCount = System.Text.Encoding.UTF8.GetByteCount(text);
|
||||||
|
|
||||||
|
if (StringBytes.Length < byteCount)
|
||||||
|
{
|
||||||
|
System.Array.Resize(ref StringBytes, byteCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
fixed (char* chars = text)
|
||||||
|
fixed (byte* bytes = StringBytes)
|
||||||
|
{
|
||||||
|
System.Text.Encoding.UTF8.GetBytes(chars, text.Length, bytes, byteCount);
|
||||||
|
Wellspring.Wellspring_TextBounds(
|
||||||
|
Handle,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
(Wellspring.HorizontalAlignment) horizontalAlignment,
|
||||||
|
(Wellspring.VerticalAlignment) verticalAlignment,
|
||||||
|
(IntPtr) bytes,
|
||||||
|
(uint) byteCount,
|
||||||
|
out rectangle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!IsDisposed)
|
if (!IsDisposed)
|
||||||
|
|
Loading…
Reference in New Issue