diff options
Diffstat (limited to 'src/Text.cpp')
-rw-r--r-- | src/Text.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/Text.cpp b/src/Text.cpp index 53118b8..383256a 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -9,10 +9,17 @@ #include <mglpp/graphics/Font.hpp> #include <mglpp/graphics/Texture.hpp> #include <mglpp/system/Utf8.hpp> -#include <cmath> namespace QuickMedia { + static float floor(float v) { + return (int)v; + } + + static float fabs(float v) { + return v >= 0.0 ? v : -v; + } + static const float TAB_WIDTH = 4.0f; static const float WORD_WRAP_MIN_SIZE = 80.0f; @@ -381,7 +388,7 @@ namespace QuickMedia } float Text::font_get_real_height(mgl::Font *font) { - return font->get_glyph('|').size.y + std::floor(4.0f * ((float)characterSize / (float)14.0f)); + return font->get_glyph('|').size.y + floor(4.0f * ((float)characterSize / (float)14.0f)); } float Text::get_text_quad_left_side(const VertexRef &vertex_ref) const { @@ -510,11 +517,11 @@ namespace QuickMedia int vertexStart = vertices[vertices_index].size(); EmojiRectangle emoji_rec = emoji_get_extents(codepoint); - const float font_height_offset = std::floor(-vspace * 0.2f); - mgl::vec2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - std::floor(emoji_rec.height * emoji_scale) * 0.5f); - mgl::vec2f vertexTopRight(glyphPos.x + std::floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset - std::floor(emoji_rec.height * emoji_scale) * 0.5f); + const float font_height_offset = floor(-vspace * 0.2f); + mgl::vec2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - floor(emoji_rec.height * emoji_scale) * 0.5f); + mgl::vec2f vertexTopRight(glyphPos.x + floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset - floor(emoji_rec.height * emoji_scale) * 0.5f); mgl::vec2f vertexBottomLeft(glyphPos.x, glyphPos.y + font_height_offset + emoji_rec.height * emoji_scale * 0.5f); - mgl::vec2f vertexBottomRight(glyphPos.x + std::floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset + std::floor(emoji_rec.height * emoji_scale) * 0.5f); + mgl::vec2f vertexBottomRight(glyphPos.x + floor(emoji_rec.width * emoji_scale), glyphPos.y + font_height_offset + floor(emoji_rec.height * emoji_scale) * 0.5f); vertexTopLeft = vec2f_floor(vertexTopLeft); vertexTopRight = vec2f_floor(vertexTopRight); @@ -533,7 +540,7 @@ namespace QuickMedia vertices[vertices_index].emplace_back(vertexBottomRight, textureBottomRight, emoji_color); vertices[vertices_index].emplace_back(vertexTopRight, textureTopRight, emoji_color); - glyphPos.x += std::floor(emoji_rec.width * emoji_scale) + characterSpacing; + glyphPos.x += floor(emoji_rec.width * emoji_scale) + characterSpacing; vertices_linear.push_back({vertices_index, vertexStart, 0, codepoint}); i += clen; @@ -1133,12 +1140,12 @@ namespace QuickMedia if(!editable) return true; pos.y -= floor(vspace * 2.0f); - const float caret_margin = std::floor(2.0f * get_config().scale); + const float caret_margin = floor(2.0f * get_config().scale); - mgl::Rectangle caretRect(mgl::vec2f(0.0f, 0.0f), mgl::vec2f(std::floor(2.0f * get_config().scale), floor(vspace - caret_margin * 2.0f))); + mgl::Rectangle caretRect(mgl::vec2f(0.0f, 0.0f), mgl::vec2f(floor(2.0f * get_config().scale), floor(vspace - caret_margin * 2.0f))); caretRect.set_position(mgl::vec2f( floor(pos.x + caretPosition.x), - floor(pos.y + caretPosition.y + caret_margin + std::floor(4.0f * get_config().scale)) + floor(pos.y + caretPosition.y + caret_margin + floor(4.0f * get_config().scale)) )); target.draw(caretRect); return true; |