Start on Font module.
This commit is contained in:
parent
45bbf230a5
commit
b3cb93612d
63
src/jes/gui/font.d
Normal file
63
src/jes/gui/font.d
Normal file
@ -0,0 +1,63 @@
|
||||
module jes.gui.font;
|
||||
import std.string;
|
||||
|
||||
struct CFont;
|
||||
|
||||
struct CGlyph
|
||||
{
|
||||
ubyte * bitmap;
|
||||
int width;
|
||||
int height;
|
||||
int left;
|
||||
int top;
|
||||
int advance;
|
||||
}
|
||||
|
||||
private extern(C) CGlyph * Font_LoadGlyph(CFont * font, uint char_code);
|
||||
private extern(C) void Font_FreeGlyph(CGlyph * glyph);
|
||||
private extern(C) CFont * Font_Load(const char * fname, int size);
|
||||
private extern(C) void Font_Free(CFont * font);
|
||||
|
||||
class Font
|
||||
{
|
||||
class Glyph
|
||||
{
|
||||
int advance;
|
||||
void render()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CFont * font;
|
||||
|
||||
this(const char * fname, int size)
|
||||
{
|
||||
font = Font_Load(fname, size);
|
||||
if (font == null)
|
||||
{
|
||||
throw new Exception("Could not load font");
|
||||
}
|
||||
}
|
||||
|
||||
this(string fname, int size)
|
||||
{
|
||||
this(fname.toStringz(), size);
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
Font_Free(font);
|
||||
}
|
||||
|
||||
uint next_power_of_2(uint n)
|
||||
{
|
||||
n--;
|
||||
n |= n >> 1u;
|
||||
n |= n >> 2u;
|
||||
n |= n >> 4u;
|
||||
n |= n >> 8u;
|
||||
n |= n >> 16u;
|
||||
n++;
|
||||
return n;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user