Basic framework for scaling text, unimplemented
This commit is contained in:
parent
0551f05e73
commit
12fbc1000e
Binary file not shown.
@ -266,7 +266,8 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
|||||||
|
|
||||||
i32 startingGlyphIndex = 0;
|
i32 startingGlyphIndex = 0;
|
||||||
i32 glyphsRemaining = numGlyphs;
|
i32 glyphsRemaining = numGlyphs;
|
||||||
i32 glyphsOnCurrRow = glyphsPerRow;
|
i32 glyphsOnCurrRow =
|
||||||
|
(glyphsPerRow < glyphsRemaining) ? glyphsPerRow : glyphsRemaining;
|
||||||
|
|
||||||
// TODO(doyle): We copy over the bitmap direct to the font sheet, should we
|
// TODO(doyle): We copy over the bitmap direct to the font sheet, should we
|
||||||
// align the baselines up so we don't need to do baseline adjusting at
|
// align the baselines up so we don't need to do baseline adjusting at
|
||||||
|
@ -23,12 +23,16 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
|
|||||||
f32 rotate, v4 color)
|
f32 rotate, v4 color)
|
||||||
{
|
{
|
||||||
i32 strLen = common_strlen(string);
|
i32 strLen = common_strlen(string);
|
||||||
|
// TODO(doyle): Scale, not too important .. but rudimentary infrastructure
|
||||||
|
// laid out here
|
||||||
|
f32 scale = 1.0f;
|
||||||
|
|
||||||
// TODO(doyle): Slightly incorrect string length in pixels calculation,
|
// TODO(doyle): Slightly incorrect string length in pixels calculation,
|
||||||
// because we use the advance metric of each character for length not
|
// because we use the advance metric of each character for length not
|
||||||
// maximum character size in rendering
|
// maximum character size in rendering
|
||||||
v2 rightAlignedP =
|
v2 rightAlignedP =
|
||||||
v2_add(pos, V2((CAST(f32) font->maxSize.w * CAST(f32) strLen),
|
v2_add(pos, V2(scale *(CAST(f32) font->maxSize.w * CAST(f32) strLen),
|
||||||
CAST(f32) font->maxSize.h));
|
scale * CAST(f32) font->maxSize.h));
|
||||||
v2 leftAlignedP = pos;
|
v2 leftAlignedP = pos;
|
||||||
if ((leftAlignedP.x < cameraBounds.z && rightAlignedP.x >= cameraBounds.x) &&
|
if ((leftAlignedP.x < cameraBounds.z && rightAlignedP.x >= cameraBounds.x) &&
|
||||||
(leftAlignedP.y < cameraBounds.y && rightAlignedP.y >= cameraBounds.w))
|
(leftAlignedP.y < cameraBounds.y && rightAlignedP.y >= cameraBounds.w))
|
||||||
@ -49,12 +53,12 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
|
|||||||
i32 codepoint = string[i];
|
i32 codepoint = string[i];
|
||||||
i32 relativeIndex = codepoint - font->codepointRange.x;
|
i32 relativeIndex = codepoint - font->codepointRange.x;
|
||||||
CharMetrics charMetric = font->charMetrics[relativeIndex];
|
CharMetrics charMetric = font->charMetrics[relativeIndex];
|
||||||
pos.y = baseline - charMetric.offset.y;
|
pos.y = baseline - (scale * charMetric.offset.y);
|
||||||
|
|
||||||
const v4 charRectOnScreen = getRect(
|
const v4 charRectOnScreen = getRect(
|
||||||
pos, V2(CAST(f32) font->maxSize.w, CAST(f32) font->maxSize.h));
|
pos, V2(scale * CAST(f32) font->maxSize.w, scale * CAST(f32) font->maxSize.h));
|
||||||
|
|
||||||
pos.x += charMetric.advance;
|
pos.x += scale * charMetric.advance;
|
||||||
|
|
||||||
/* Get texture out */
|
/* Get texture out */
|
||||||
v4 charTexRect = font->atlas->texRect[relativeIndex];
|
v4 charTexRect = font->atlas->texRect[relativeIndex];
|
||||||
|
Loading…
Reference in New Issue
Block a user