Browse Source

font: support \b (backspace) in text rendering.

undefined
Sam Hocevar 11 years ago
parent
commit
843cc42ed1
1 changed files with 17 additions and 9 deletions
  1. +17
    -9
      src/font.cpp

+ 17
- 9
src/font.cpp View File

@@ -2,6 +2,7 @@
// Lol Engine // Lol Engine
// //
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// 2013 Jean-Yves Lamoureux <jylam@lnxscene.org>
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To // modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See // Public License, Version 2, as published by Sam Hocevar. See
@@ -69,22 +70,29 @@ char const *Font::GetName()


void Font::Print(vec3 pos, char const *str, vec2 scale) void Font::Print(vec3 pos, char const *str, vec2 scale)
{ {
int origin_x = pos.x;
float origin_x = pos.x;
while (*str) while (*str)
{ {
uint32_t ch = (uint8_t)*str++; uint32_t ch = (uint8_t)*str++;


if (ch == '\n')
switch (ch)
{ {
case '\r': /* carriage return */
pos.x = origin_x; pos.x = origin_x;
pos.y-=data->size.y * scale.y;
continue;
}
else if (ch != ' ')
{
g_scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
break;
case '\b': /* backspace */
pos.x -= data->size.x * scale.x;
break;
case '\n': /* new line */
pos.x = origin_x;
pos.y -= data->size.y * scale.y;
break;
default:
if (ch != ' ')
g_scene->AddTile(data->tileset, ch & 255, pos, 0, scale);
pos.x += data->size.x * scale.x;
break;
} }
pos.x += data->size.x * scale.x;
} }
} }




Loading…
Cancel
Save