From 843cc42ed1a36bd4bf48b6e7ef05620672dfcbf9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 31 Dec 2013 13:15:20 +0000 Subject: [PATCH] font: support \b (backspace) in text rendering. --- src/font.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/font.cpp b/src/font.cpp index 71a890f4..ae4e9e2c 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -2,6 +2,7 @@ // Lol Engine // // Copyright: (c) 2010-2013 Sam Hocevar +// 2013 Jean-Yves Lamoureux // 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 // 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) { - int origin_x = pos.x; + float origin_x = pos.x; while (*str) { uint32_t ch = (uint8_t)*str++; - if (ch == '\n') + switch (ch) { + case '\r': /* carriage return */ 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; } }