diff options
| -rw-r--r-- | src/font.cpp | 26 | ||||
| -rw-r--r-- | src/game.cpp | 9 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/font.cpp b/src/font.cpp index e905da3..6357a1d 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -89,12 +89,27 @@ uint32_t utf8_to_unicode(const char* str, uint32_t &out) { return i; } +float FontType_Inner_LookAheadWordLength(const FontType *const ft, const FontRender *const fr, uint32_t index, float font_glyph_spacing) { + uint32_t i; + float ret = 0; + FontGlyphChar *fgc; + for (i = index; i < fr->n_glyphs; ++i) { + fgc = &ft->glyphs[fr->glyph_indices[i]]; + if (fgc->is_whitespace == true) { + break; + } + ret += fgc->advance * font_glyph_spacing; + } + return ret; +} + void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInstanceBufferItem *ptr_dst) { assert(ft != nullptr); assert(fr != nullptr); assert(ptr_dst != nullptr); FontGlyphChar *fgc; FontInstanceBufferItem *buf_item; + bool new_word = true; uint32_t i; float font_glyph_spacing; float cursor_head, line_index, line_height; @@ -119,8 +134,17 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta if (fgc->is_whitespace == true) { cursor_head += fgc->advance * font_glyph_spacing; + new_word = true; continue; } + if (new_word == true) { + float word_width = FontType_Inner_LookAheadWordLength(ft, fr, i, font_glyph_spacing); + if (cursor_head + word_width > fr->settings.surface_area_size.x) { + line_index += 1; + cursor_head = 0; + } + new_word = false; + } // left, bottom, right, top // x, y, z, w @@ -151,7 +175,7 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta // box position translate.y = fr->settings.surface_area_pos.y; // baseline - current line (+1 to not draw above the box) - translate.y -= ((line_index + 1) * line_height); + translate.y += ((line_index + 1) * line_height); // places the top line of the glyph on the baseline translate.y += (font_glyph_spacing / 2.0) + (glyph_size.y / 2.0); // move glyph to the height relative to the baseline (cursor) diff --git a/src/game.cpp b/src/game.cpp index f34edca..6714910 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -619,16 +619,17 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { fr_set.char_scale = 9 * 7.0; fr_set.line_height_scale = 1.0; fr_set.char_spacing_scale = 1.0; - fr_set.surface_area_size.x = 1; - fr_set.surface_area_size.y = 1; - fr_set.surface_area_pos.x = 1920 / 2.0; - fr_set.surface_area_pos.y = 1080 / 2.0; + fr_set.surface_area_size.x = 1920 - (1920 / 4.0); + fr_set.surface_area_size.y = 1080 - (1080 / 3.0); + fr_set.surface_area_pos.x = 1920 / 4.0; + fr_set.surface_area_pos.y = 1080 / 3.0; fr_set.surface_area_type_flags = FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_NONE; if ((FontType_GetFonts(font_type_count)); font_type_count != FontTypeIndex{0}) { FontType_AddStringRender(FontTypeIndex{0}, pk_cstr_to_pk_str(&test_text), &fr_set); } if ((FontType_GetFonts(font_type_count)); font_type_count > FontTypeIndex{1}) { fr_set.surface_area_pos.y *= 2; + fr_set.surface_area_size.y = 1080 - fr_set.surface_area_pos.y; FontType_AddStringRender(FontTypeIndex{1}, pk_cstr_to_pk_str(&test_text2), &fr_set); } |
