Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FontImGui.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*!
  2. * \file src/FontImGui.cpp
  3. * \brief Default Font implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "UI.h"
  9. #include "FontImGui.h"
  10. #define SCALE_CALC 1.0f
  11. #define SCALE_DRAW 20.0f
  12. unsigned int FontImGui::widthText(float scale, std::string s) {
  13. ImGuiIO& io = ImGui::GetIO();
  14. ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, io.DisplaySize.y, s.c_str(), s.c_str() + s.length());
  15. return size.y;
  16. }
  17. void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
  18. const unsigned char color[4], std::string s) {
  19. ImGuiIO& io = ImGui::GetIO();
  20. ImVec2 pos = ImVec2(x, y);
  21. ImU32 col = color[0] | (color[1] << 8) | (color[2] << 16) | (color[3] << 24);
  22. ImDrawList dl;
  23. dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
  24. dl.AddText(io.Font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length());
  25. ImDrawList* dlp = &dl;
  26. UI::renderImGui(&dlp, 1);
  27. }
  28. unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::string s) {
  29. ImGuiIO& io = ImGui::GetIO();
  30. ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, maxWidth, s.c_str(), s.c_str() + s.length());
  31. return size.x;
  32. }
  33. void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
  34. const unsigned char color[4], unsigned int maxWidth, std::string s) {
  35. drawText(x, y, scale, color, s);
  36. }