KumiScript/renderer/Glyph.cs

101 lines
2.5 KiB
C#
Raw Normal View History

using SDL2;
namespace KumiScript.Renderer
{
public class Glyph : IDisposable
{
readonly char _char;
readonly int _width;
readonly int _height;
SDLTexture _tex;
SDLRenderer _renderer;
public Glyph(char c, SDLFont font, SDL.SDL_Color clr, SDLRenderer renderer)
{
_char = c;
nint surface = SDL_ttf.TTF_RenderGlyph32_Blended(font.GetHandle(), c, clr);
_tex = new SDLTexture(surface, renderer);
SDL.SDL_FreeSurface(surface);
_tex.QueryTexture(out _, out _, out _width, out _height);
_renderer = renderer;
}
public void Dispose()
{
_tex.Dispose();
return;
}
public char GetCharacter()
{
return _char;
}
public SDLTexture GetTexture()
{
return _tex;
}
public int GetWidth()
{
return _width;
}
public void DrawAt(int x, int y)
{
SDL.SDL_Rect destRect;
destRect.x = x;
destRect.y = y;
destRect.w = _width;
destRect.h = _height;
SDL.SDL_Rect sourceRect;
sourceRect.x = 0;
sourceRect.y = 0;
sourceRect.w = _width;
sourceRect.h = _height;
_tex.Draw(_renderer, sourceRect, destRect);
}
public void DrawAdvancePen(int x, int y, out int pen)
{
SDL.SDL_Rect destRect;
destRect.x = x;
destRect.y = y;
destRect.w = _width;
destRect.h = _height;
SDL.SDL_Rect sourceRect;
sourceRect.x = 0;
sourceRect.y = 0;
sourceRect.w = _width;
sourceRect.h = _height;
_tex.Draw(_renderer, sourceRect, destRect);
pen = x + _width;
}
internal void DrawAdvancePenModAlpha(int x, int y, out int pen, byte v)
{
_tex.SetAlpha(v);
SDL.SDL_Rect destRect;
destRect.x = x;
destRect.y = y;
destRect.w = _width;
destRect.h = _height;
SDL.SDL_Rect sourceRect;
sourceRect.x = 0;
sourceRect.y = 0;
sourceRect.w = _width;
sourceRect.h = _height;
_tex.Draw(_renderer, sourceRect, destRect);
_tex.SetAlpha(255);
pen = x + _width;
return;
}
}
}