From: Côme Chilliet Date: Wed, 14 Dec 2016 15:45:35 +0000 (+0700) Subject: Cleaned up a bit Text class. Using glPrintOutlined everywhere. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=8d1e44bf4f8448b2d9f0add10a1207c3f81ac5c7;p=lugaru.git Cleaned up a bit Text class. Using glPrintOutlined everywhere. --- diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 6119816..3374fbd 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -567,16 +567,11 @@ int Game::DrawGLScene(StereoSide side) else bonus_name = "Excellent!"; // When does this happen? - glColor4f(0, 0, 0, 1 - bonustime); - text->glPrintOutline(1024 / 2 - 10 * strlen(bonus_name) - 4, 768 / 16 - 4 + 768 * 4 / 5, bonus_name, 1, 2.5, 1024, 768); - glColor4f(1, 0, 0, 1 - bonustime); - text->glPrint(1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768); + text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768); string = to_string((int)bonusvalue); - glColor4f(0, 0, 0, 1 - bonustime); - text->glPrintOutline(1024 / 2 - 10 * string.size() - 4, 768 / 16 - 4 - 20 + 768 * 4 / 5, string, 1, 2.5 * .8, 1024, 768); - glColor4f(1, 0, 0, 1 - bonustime); - text->glPrint(1024 / 2 - 10 * string.size(), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768); + text->glPrintOutlined(1, 0, 0, 1 - bonustime, 1024 / 2 - 10 * string.size(), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768); + glColor4f(.5, .5, .5, 1); } @@ -870,27 +865,17 @@ int Game::DrawGLScene(StereoSide side) string3 = " "; } - glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); - text->glPrintOutline(screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); - text->glPrintOutline(screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); - glColor4f(1, 1, 1, tutorialopac); - text->glPrint(screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); - text->glPrint(screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); - text->glPrint(screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(1, 1, 1, tutorialopac, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(1, 1, 1, tutorialopac, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(1, 1, 1, tutorialopac, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); string = "Press 'tab' to skip to the next item."; string2 = "Press escape at any time to"; string3 = "pause or exit the tutorial."; - glColor4f(0, 0, 0, 1); - text->glPrintOutline(screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10, string, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight); - text->glPrintOutline(screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight); - text->glPrintOutline(screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight); - glColor4f(0.5, 0.5, 0.5, 1); - text->glPrint(screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); - text->glPrint(screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); - text->glPrint(screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); + text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight); } //Hot spots @@ -927,10 +912,7 @@ int Game::DrawGLScene(StereoSide side) int i = 0; while (!done) { if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') { - glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i); - glColor4f(1, 1, 1, tutorialopac); - text->glPrint(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); + text->glPrintOutlined(1, 1, 1, tutorialopac, screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); lastline = i + 1; line++; if (string[i] == '\0') @@ -1014,10 +996,7 @@ int Game::DrawGLScene(StereoSide side) string = std::string(tempname) + ": "; if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) { - glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(startx - 2 * 7.6 * string.size()*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); - glColor4f(0.7, 0.7, 0.7, tutorialopac); - text->glPrint(startx - 2 * 7.6 * string.size()*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); + text->glPrintOutlined(0.7, 0.7, 0.7, tutorialopac, startx - 2 * 7.6 * string.size()*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight); } else { glColor4f(0, 0, 0, tutorialopac); text->glPrintOutline(startx - 2 * 7.6 * string.size()*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); @@ -1039,13 +1018,10 @@ int Game::DrawGLScene(StereoSide side) while (!done) { if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') { if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) { - glColor4f(0, 0, 0, tutorialopac); - text->glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/ - 4, starty - 4 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i); - glColor4f(1, 1, 1, tutorialopac); - text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); + text->glPrintOutlined(1, 1, 1, tutorialopac, startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); } else { glColor4f(0, 0, 0, tutorialopac); - text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); + text->glPrint(startx, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i); } lastline = i + 1; line++; @@ -1068,10 +1044,7 @@ int Game::DrawGLScene(StereoSide side) } else { string = "Score: " + to_string(int(bonustotal)); } - glColor4f(0, 0, 0, 1); - text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16, string, 1, 1.5 * 1.25, 1024, 768); - glColor4f(1, 0, 0, 1); - text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768); + text->glPrintOutlined(1, 0, 0, 1, 1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768); if (showdamagebar) { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); @@ -1151,10 +1124,7 @@ int Game::DrawGLScene(StereoSide side) // writing the numbers : string = "Damages : " + to_string(int(Person::players[0]->damage)) + "/" + to_string(int(Person::players[0]->damagetolerance)) + " (" + to_string(int(Person::players[0]->bloodloss)) + ")"; - glColor4f(0, 0, 0, 1); - text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16 - 40, string, 1, 1.5 * 1.25, 1024, 768); - glColor4f(1, 0, 0, 1); - text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768); + text->glPrintOutlined(1, 0, 0, 1, 1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768); } } diff --git a/Source/Graphic/Text.cpp b/Source/Graphic/Text.cpp index ffc8b0a..2cf73aa 100644 --- a/Source/Graphic/Text.cpp +++ b/Source/Graphic/Text.cpp @@ -77,11 +77,6 @@ void Text::BuildFont() // Build Our Font Display List } // Loop Until All 256 Are Built } -void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens -{ - glPrint(x, y, string, set, size, width, height, 0, string.size()); -} - void Text::_glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end, int offset) // Where The Printing Happens { if (set > 1) { @@ -112,37 +107,40 @@ void Text::_glPrint(float x, float y, const std::string& string, int set, float glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); } -void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) // Where The Printing Happens +void Text::glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { + if (end < 0) { + end = string.size(); + } _glPrint(x, y, string, set, size, width, height, start, end, 0); } -void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens -{ - glPrintOutline(x, y, string, set, size, width, height, 0, string.size()); -} - -void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) // Where The Printing Happens +void Text::glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { + if (end < 0) { + end = string.size(); + } _glPrint(x, y, string, set, size, width, height, start, end, 256); } -void Text::glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens + +void Text::glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { - glPrintOutlined(1, 1, 1, x, y, string, set, size, width, height); + glPrintOutlined(1, 1, 1, 1, x, y, string, set, size, width, height, start, end); } -void Text::glPrintOutlined(float r, float g, float b, float x, float y, const std::string& string, int set, float size, float width, float height) // Where The Printing Happens +void Text::glPrintOutlined(float r, float g, float b, float a, float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end) { - glColor4f(0, 0, 0, 1); - glPrintOutline( x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height); - glColor4f(r, g, b, 1); - glPrint( x, y, string, set, size, width, height); + glColor4f(0, 0, 0, a); + glPrintOutline( x - 2 * size, y - 2 * size, string, set, size * 2.5 / 2, width, height, start, end); + glColor4f(r, g, b, a); + glPrint( x, y, string, set, size, width, height, start, end); } Text::Text() { base = 0; } + Text::~Text() { if (base) { diff --git a/Source/Graphic/Text.hpp b/Source/Graphic/Text.hpp index 73dc621..ea23c6f 100644 --- a/Source/Graphic/Text.hpp +++ b/Source/Graphic/Text.hpp @@ -36,12 +36,10 @@ public: void LoadFontTexture(const std::string& fileName); void BuildFont(); - void glPrint(float x, float y, const std::string& string, int set, float size, float width, float height); - void glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height); - void glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end); - void glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start, int end); - void glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height); - void glPrintOutlined(float r, float g, float b, float x, float y, const std::string& string, int set, float size, float width, float height); + void glPrint(float x, float y, const std::string& string, int set, float size, float width, float height, int start = 0, int end = -1); + void glPrintOutline(float x, float y, const std::string& string, int set, float size, float width, float height, int start = 0, int end = -1); + void glPrintOutlined(float x, float y, const std::string& string, int set, float size, float width, float height, int start = 0, int end = -1); + void glPrintOutlined(float r, float g, float b, float a, float x, float y, const std::string& string, int set, float size, float width, float height, int start = 0, int end = -1); Text(); ~Text(); diff --git a/Source/Menu/Menu.cpp b/Source/Menu/Menu.cpp index 1ce2960..08fffb0 100644 --- a/Source/Menu/Menu.cpp +++ b/Source/Menu/Menu.cpp @@ -239,7 +239,7 @@ void Menu::drawItems() } break; case MenuItem::MAPLABEL: - Game::text->glPrintOutlined(0.9, 0, 0, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480); + Game::text->glPrintOutlined(0.9, 0, 0, 1, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480); break; case MenuItem::MAPLINE: { XYZ linestart;