From 19b2b1dde25885ada99deefe79266c2e22376e85 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 22 Sep 2017 08:47:14 -0400 Subject: new font; dialog box word wrap... finally --- src/engine.cpp | 2 +- src/font.cpp | 5 +++-- src/render.cpp | 2 +- src/ui.cpp | 57 +++++++++++++++++++++++++++++++++------------------------ src/ui_menu.cpp | 6 +++--- 5 files changed, 41 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index b596c6e..bf0bca9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -47,7 +47,7 @@ void Engine::init(void) { // init ui FontSystem::init(game::config::fontFamily); - FontSystem::setFontSize(16); + FontSystem::setFontSize(FontSystem::SizeSmall); FontSystem::setFontColor(1, 1, 1); FontSystem::setFontZ(-6.0f); diff --git a/src/font.cpp b/src/font.cpp index af49d2a..0b425f7 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -41,9 +41,10 @@ void FontSystem::setFontSize(int size) // convert red-on-black to RGBA auto& g = ftFace->glyph; - std::vector buf (g->bitmap.width * g->bitmap.rows, 0xFFFFFFFF); + std::vector buf (g->bitmap.width * g->bitmap.rows, 0x00FFFFFF); for (auto j = buf.size(); j--;) - buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0; + buf[j] |= g->bitmap.buffer[j] << 24; +// buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0; d.wh.x = g->bitmap.width; d.wh.y = g->bitmap.rows; diff --git a/src/render.cpp b/src/render.cpp index baa08ee..b9a9770 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -187,7 +187,7 @@ void render(const int& fps) auto pos = PlayerSystem::getPosition(); UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()), "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s\nmem: %llukb (%d)", - pos.toString().c_str(), offset.toString().c_str(), fps, + pos.toString(2).c_str(), offset.toString(2).c_str(), fps, game::time::getTickCount(), ParticleSystem::getCount(), WorldSystem::getXMLFile().c_str(), getUsedMem() / 1024, balance ); diff --git a/src/ui.cpp b/src/ui.cpp index e8fd78a..dea2f8e 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -779,34 +780,42 @@ void UISystem::putString(const vec2& p, const std::string& s, float wrap) { vec2 offset = p, add; - for (auto c : s) { - switch (c) { - case '\n': + int sum; + for (auto word : tokens(s, ' ')) { + sum = 0; + for (auto c : word) + sum += FontSystem::getCharWidth(c); + if (wrap > 0 && offset.x + sum > wrap) { offset.y -= FontSystem::getSize() * 1.05f; offset.x = p.x; - break; - case '\b': - offset.x -= add.x; - break; - case '\r': - case '\t': - break; - case ' ': - offset.x += FontSystem::getSize() / 2.0f; - break; - default: - add = FontSystem::putChar(floor(offset.x), floor(offset.y), c); - offset += add; - break; } + + for (auto c : word) { + switch (c) { + case '\n': + //offset.y -= FontSystem::getSize() * 1.05f; + //offset.x = p.x; + break; + case '\b': + //offset.x -= add.x; + break; + case '\r': + case '\t': + break; + default: + add = FontSystem::putChar(floor(offset.x), floor(offset.y), c); + offset.x += add.x; + break; + } - if (wrap != 0.12345f && offset.x >= (wrap - 10)) { - offset.y -= FontSystem::getSize() * 1.05f; - offset.x = p.x; + /*if (wrap != 0.12345f && offset.x >= (wrap - 10)) { + offset.y -= FontSystem::getSize() * 1.05f; + offset.x = p.x; + }*/ } - } - //return offset.x; + offset.x += FontSystem::getSize() / 2.0f; + } } float UISystem::putStringCentered(const vec2& p, const std::string& s, bool print) @@ -972,10 +981,10 @@ void UISystem::render(void) } if (!importantText.empty()) { - FontSystem::setFontSize(24); + FontSystem::setFontSize(FontSystem::SizeLarge); FontSystem::setFontZ(-9.0f); putStringCentered(vec2(offset.x, 400), ui::typeOut(importantText)); FontSystem::setFontZ(-6.0f); - FontSystem::setFontSize(16); + FontSystem::setFontSize(FontSystem::SizeSmall); } } diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index fd316ce..3afe0dc 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -55,7 +55,7 @@ void Menu::gotoParent(void) { if (parent == nullptr) { game::config::update(); - FontSystem::setFontSize(16); + FontSystem::setFontSize(FontSystem::SizeSmall); } currentMenu = parent; @@ -253,7 +253,7 @@ namespace ui { Render::useShader(&Render::textShader); game::config::update(); - FontSystem::setFontSize(24); + FontSystem::setFontSize(FontSystem::SizeLarge); FontSystem::setFontZ(-9.0); mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2); @@ -370,7 +370,7 @@ namespace ui { } SDLReceiver::clicked = false; - FontSystem::setFontSize(16); + FontSystem::setFontSize(FontSystem::SizeSmall); FontSystem::setFontZ(-8.0); } -- cgit v1.2.3