FT_Done_FreeType(ftLibrary);
}
+ constexpr static inline int SizeSmall = 16;
+ constexpr static inline int SizeLarge = 24;
+
static void init(const std::string& ttf);
static void setFontSize(int size);
static void setFontColor(float r, float g, float b);
static inline auto& getFont(void)
{ return fontData.at(currentSize); }
+
+ static inline auto getCharWidth(char c)
+ { return fontData.at(currentSize)[c - 33].wh.x; }
};
#endif // FONT_HPP_
*/
static void putText(const vec2& p, const std::string& s, ...);
- static void putString(const vec2& p, const std::string& s, float wrap = 0.12345f);
+ static void putString(const vec2& p, const std::string& s, float wrap = 0);
static float putStringCentered(const vec2& p, const std::string& s, bool print = true);
static void dialogBox(const std::string& n, const std::string& s, ...);
#include <string>
#include <type_traits>
+#include <sstream>
+#include <iomanip>
+
template<typename T>
struct vector2 {
static_assert(std::is_arithmetic<T>::value, "vector2 members must be an arithmetic type (i.e. numbers)");
}
// other functions
- std::string toString(void) const {
- return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
+ std::string toString(int precision = -1) const {
+ std::stringstream ss;
+ std::string sx, sy;
+ ss << std::fixed;
+ if (precision > -1)
+ ss << std::setprecision(precision);
+ ss << x;
+ sx = ss.str();
+ ss.str(std::string());
+ ss << y;
+ sy = ss.str();
+ return "(" + sx + ", " + sy + ")";
}
};
// init ui
FontSystem::init(game::config::fontFamily);
- FontSystem::setFontSize(16);
+ FontSystem::setFontSize(FontSystem::SizeSmall);
FontSystem::setFontColor(1, 1, 1);
FontSystem::setFontZ(-6.0f);
// convert red-on-black to RGBA
auto& g = ftFace->glyph;
- std::vector<uint32_t> buf (g->bitmap.width * g->bitmap.rows, 0xFFFFFFFF);
+ std::vector<uint32_t> 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;
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
);
#include <events.hpp>
#include <window.hpp>
#include <player.hpp>
+#include <tokens.hpp>
#include <chrono>
{
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)
}
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);
}
}
{
if (parent == nullptr) {
game::config::update();
- FontSystem::setFontSize(16);
+ FontSystem::setFontSize(FontSystem::SizeSmall);
}
currentMenu = parent;
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);
}
SDLReceiver::clicked = false;
- FontSystem::setFontSize(16);
+ FontSystem::setFontSize(FontSystem::SizeSmall);
FontSystem::setFontZ(-8.0);
}