Added 'style' font render argument
This commit is contained in:
+15
-34
@@ -43,34 +43,10 @@ bool Font::isPrintableChar(int c) {
|
||||
#define RES 16
|
||||
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y) {
|
||||
int page = 0;
|
||||
int next = 10000;
|
||||
int init_x = x;
|
||||
do {
|
||||
for (unsigned c : text){
|
||||
if (isPrintableChar(c)){
|
||||
int charpage = c >> 8;
|
||||
if (charpage == page){
|
||||
Texture* texture = pages[charpage];
|
||||
if (texture == nullptr){
|
||||
texture = pages[0];
|
||||
}
|
||||
batch->texture(pages[charpage]);
|
||||
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
|
||||
}
|
||||
else if (charpage > page && charpage < next){
|
||||
next = charpage;
|
||||
}
|
||||
}
|
||||
x += getGlyphWidth(c);
|
||||
}
|
||||
page = next;
|
||||
next = 10000;
|
||||
x = init_x;
|
||||
} while (page < 10000);
|
||||
draw(batch, text, x, y, STYLE_NONE);
|
||||
}
|
||||
|
||||
void Font::drawWithOutline(Batch2D* batch, std::wstring text, int x, int y) {
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y, int style) {
|
||||
int page = 0;
|
||||
int next = 10000;
|
||||
int init_x = x;
|
||||
@@ -84,15 +60,20 @@ void Font::drawWithOutline(Batch2D* batch, std::wstring text, int x, int y) {
|
||||
texture = pages[0];
|
||||
}
|
||||
batch->texture(pages[charpage]);
|
||||
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x-1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x+1, y, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
batch->sprite(x-1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x+1, y-1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
batch->sprite(x-1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
switch (style){
|
||||
case STYLE_SHADOW:
|
||||
batch->sprite(x+1, y+1, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
break;
|
||||
case STYLE_OUTLINE:
|
||||
for (int oy = -1; oy <= 1; oy++){
|
||||
for (int ox = -1; ox <= 1; ox++){
|
||||
if (ox || oy)
|
||||
batch->sprite(x+ox, y+oy, RES, RES, 16, c, vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
batch->sprite(x, y, RES, RES, 16, c, vec4(1.0f));
|
||||
}
|
||||
|
||||
+5
-1
@@ -7,6 +7,10 @@
|
||||
class Texture;
|
||||
class Batch2D;
|
||||
|
||||
#define STYLE_NONE 0
|
||||
#define STYLE_SHADOW 1
|
||||
#define STYLE_OUTLINE 2
|
||||
|
||||
class Font {
|
||||
public:
|
||||
std::vector<Texture*> pages;
|
||||
@@ -16,7 +20,7 @@ public:
|
||||
int getGlyphWidth(char c);
|
||||
bool isPrintableChar(int c);
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y);
|
||||
void drawWithOutline(Batch2D* batch, std::wstring text, int x, int y);
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y, int style);
|
||||
};
|
||||
|
||||
#endif /* GRAPHICS_FONT_H_ */
|
||||
|
||||
Reference in New Issue
Block a user