Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Font.cpp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*!
  2. * \file src/Font.cpp
  3. * \brief Font implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9. #include "global.h"
  10. #include "utils/strings.h"
  11. #include "Window.h"
  12. #include "Font.h"
  13. Font::~Font() {
  14. delete [] mFontName;
  15. mFontName = NULL;
  16. }
  17. void Font::setFont(const char *font) {
  18. assert(font != NULL);
  19. assert(font[0] != '\0');
  20. assert(mFontInit == false);
  21. mFontName = fullPath(font, 0);
  22. }
  23. void Font::drawText(unsigned int x, unsigned int y, float scale,
  24. const unsigned char color[4], const char *s, ...) {
  25. FontString tempText;
  26. va_list args;
  27. va_start(args, s);
  28. tempText.text = new char[256];
  29. tempText.scale = scale;
  30. tempText.w = 0;
  31. tempText.h = 0;
  32. tempText.x = x;
  33. tempText.y = y;
  34. tempText.color[0] = color[0];
  35. tempText.color[1] = color[1];
  36. tempText.color[2] = color[2];
  37. tempText.color[3] = color[3];
  38. vsnprintf(tempText.text, 256, s, args);
  39. tempText.text[255] = '\0';
  40. writeString(tempText);
  41. delete [] tempText.text;
  42. va_end(args);
  43. }
  44. void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
  45. const unsigned char color[4], unsigned int width, const char *s, ...) {
  46. FontString tempText;
  47. va_list args;
  48. va_start(args, s);
  49. tempText.text = new char[256];
  50. tempText.scale = scale;
  51. tempText.w = 0;
  52. tempText.h = 0;
  53. tempText.x = x;
  54. tempText.y = y + getWindow().getHeight(); //! \fixme Ugly hack to hide first draw
  55. tempText.color[0] = color[0];
  56. tempText.color[1] = color[1];
  57. tempText.color[2] = color[2];
  58. tempText.color[3] = color[3];
  59. vsnprintf(tempText.text, 256, s, args);
  60. tempText.text[255] = '\0';
  61. writeString(tempText);
  62. tempText.x = (width / 2) - ((unsigned int)(tempText.w / 2));
  63. tempText.y = y;
  64. writeString(tempText);
  65. delete [] tempText.text;
  66. va_end(args);
  67. }