Bitmap font wrapping so far
This commit is contained in:
@ -42,12 +42,14 @@ void BitmapFont::buffer(
|
||||
float_t y = 0;
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
size_t wordStart = 0;
|
||||
glm::vec2 xy0(0, 0);
|
||||
glm::vec2 tileSize = glm::vec2(tileset->getTileWidth(), tileset->getTileHeight());
|
||||
|
||||
// Buffer quads
|
||||
while(c = text[i++]) {
|
||||
if(c == FONT_SPACE) {
|
||||
wordStart = i;
|
||||
|
||||
// Did this space cause a newline?
|
||||
if(maxWidth != -1 && xy0.x > maxWidth) {
|
||||
@ -68,15 +70,35 @@ void BitmapFont::buffer(
|
||||
info->width = mathMax<float_t>(info->width, xy0.x);
|
||||
xy0.x = 0;
|
||||
xy0.y += tileSize.y;
|
||||
info->height = mathMax<float_t>(info->height, xy0.y);
|
||||
info->height = mathMax<float_t>(info->height, xy0.y);
|
||||
wordStart = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for wrapping, todo.
|
||||
if(maxWidth != -1 && (xy0.x+tileSize.x) > maxWidth) {
|
||||
// We've exceeded the edge, go back to the start of the word and newline.
|
||||
// We've exceeded the edge on THIS character. We first need to go back to
|
||||
// the start of the word and push it to the new line
|
||||
|
||||
// Go back to the previous (still current) line and remove the chars
|
||||
size_t charsToBeRewound = ((i - 1) - wordStart);
|
||||
|
||||
info->width = mathMax<float_t>(info->width, xy0.x - (tileSize.x * charsToBeRewound));
|
||||
|
||||
xy0.x = 0;
|
||||
xy0.y += tileSize.y;
|
||||
|
||||
j -= charsToBeRewound;// Rewind j back to wordStart.
|
||||
for(auto k = wordStart; k < (i-1); k++) {
|
||||
char c2 = text[k];
|
||||
tile = this->tileset->getTile(c2);
|
||||
QuadMesh::bufferQuadMesh(mesh,
|
||||
xy0, tile.uv0,
|
||||
xy0+tileSize, tile.uv1,
|
||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||
);
|
||||
xy0.x += tileSize.x;
|
||||
j++;
|
||||
}
|
||||
|
||||
// Next line begins with this word
|
||||
}
|
||||
@ -87,7 +109,7 @@ void BitmapFont::buffer(
|
||||
xy0+tileSize, tile.uv1,
|
||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||
);
|
||||
xy0.x += tileSize.x;//TODO: Spacing?
|
||||
xy0.x += tileSize.x;
|
||||
j++;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace Dawn {
|
||||
|
||||
label->text = "Hello World, how are you today? I hope you are doing well. I really like the fact I can ramble in my text for once.";
|
||||
label->font = &font;
|
||||
label->maxWidth = 275;
|
||||
label->maxWidth = 220;
|
||||
|
||||
image->alignment = glm::vec4(0, 0, label->getContentWidth(), label->getContentHeight());
|
||||
}
|
||||
|
Reference in New Issue
Block a user