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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(),
  15. // s.c_str() + s.length());
  16. //return size.y;
  17. return s.length() * 15;
  18. }
  19. void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
  20. const unsigned char color[4], std::string s) {
  21. ImGuiIO& io = ImGui::GetIO();
  22. ImVec2 pos = ImVec2(x, y);
  23. ImU32 col = color[0] | (color[1] << 8) | (color[2] << 16) | (color[3] << 24);
  24. ImDrawList dl;
  25. dl.PushClipRect(ImVec4(0.0f, 0.0f, io.DisplaySize.x, io.DisplaySize.y));
  26. dl.AddText(io.Font, scale * SCALE_DRAW, pos, col, s.c_str(), s.c_str() + s.length());
  27. ImDrawList* dlp = &dl;
  28. UI::renderImGui(&dlp, 1);
  29. }
  30. unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::string s) {
  31. //ImGuiIO& io = ImGui::GetIO();
  32. //ImVec2 size = io.Font->CalcTextSizeA(scale * SCALE_CALC, maxWidth, s.c_str(),
  33. // s.c_str() + s.length());
  34. //return size.x;
  35. return 15;
  36. }
  37. void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
  38. const unsigned char color[4], unsigned int maxWidth, std::string s) {
  39. drawText(x, y, scale, color, s);
  40. }