[add] Added Font and FontSet.

This commit is contained in:
falsycat 2019-10-12 00:00:00 +00:00
parent 957f9724db
commit ac37fbf3e5
6 changed files with 67 additions and 3 deletions

Binary file not shown.

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.dub
.bin
!/.bin
dub.selections.json
*.swp

View File

@ -2,6 +2,7 @@
import std;
import derelict.sfml2.audio,
derelict.sfml2.graphics,
derelict.sfml2.system,
derelict.sfml2.window;
@ -61,9 +62,10 @@ private KeyInput GetKeyInput() {
}
private auto CreateWindow(ref in Args args) {
DerelictSFML2Audio .load();
DerelictSFML2Graphics.load();
DerelictSFML2System .load();
DerelictSFML2Window .load();
DerelictSFML2Audio .load();
sfContextSettings specs;
specs.depthBits = 24;

31
src/sj/Font.d Normal file
View File

@ -0,0 +1,31 @@
/// License: MIT
module sj.Font;
import std.exception,
std.format,
std.string;
import derelict.sfml2.graphics;
import gl4d;
///
class Font {
public:
///
this(string path) {
font_ = sfFont_createFromFile(path.toStringz).
enforce("failed creating font from %s".format(path));
}
~this() {
sfFont_destroy(font_);
}
///
Texture2DRef Render(string text, size_t px) {
assert(false);
}
private:
sfFont* font_;
}

26
src/sj/FontSet.d Normal file
View File

@ -0,0 +1,26 @@
/// License: MIT
module sj.FontSet;
import std.file,
std.path;
import sj.Font;
///
class FontSet {
public:
///
this() {
const dir = thisExePath.dirName;
gothic_heavy_ = new Font(dir~"/fonts/SourceHanSansJP-Heavy.otf");
}
///
@property Font gothicHeavy() {
return gothic_heavy_;
}
private:
Font gothic_heavy_;
}

View File

@ -2,6 +2,7 @@
module sj.Game;
import sj.AbstractGame,
sj.FontSet,
sj.LobbyWorld,
sj.ProgramSet,
sj.TitleScene;
@ -12,6 +13,7 @@ class Game : AbstractGame {
///
this() {
programs_ = new ProgramSet;
fonts_ = new FontSet;
lobby_ = new LobbyWorld(programs_);
@ -32,6 +34,8 @@ class Game : AbstractGame {
private:
ProgramSet programs_;
FontSet fonts_;
LobbyWorld lobby_;
TitleScene title_;