Text.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <cstdio>
  2. #include <cstdarg>
  3. #include "Text.h"
  4. #include "sprites.h"
  5. #include "Graphics.h"
  6. #define TEXT WalrusRPG::Graphics::Text
  7. using namespace WalrusRPG::Graphics;
  8. using namespace WalrusRPG::Utils;
  9. Texture tex_font((char *) font);
  10. void TEXT::print_char(char c, unsigned x, unsigned y)
  11. {
  12. put_sprite(tex_font, x, y, Rect((c % 16) * 8, (c / 16) * 8, 8, 8));
  13. }
  14. void TEXT::print_string(const char *str, unsigned x, unsigned y)
  15. {
  16. Rect rect;
  17. rect.width = 8;
  18. rect.height = 8;
  19. for (unsigned index = 0; str[index]; index++)
  20. {
  21. char c = str[index];
  22. rect.x = (c % 16) * 8;
  23. rect.y = (c / 16) * 8;
  24. put_sprite(tex_font, x, y, rect);
  25. x += 8;
  26. }
  27. }
  28. void TEXT::print_string(const std::string &str, unsigned x, unsigned y)
  29. {
  30. TEXT::print_string(str.c_str(), x, y);
  31. }
  32. void TEXT::print_format(unsigned x, unsigned y, const char *format, ...)
  33. {
  34. char buffer[256] = "";
  35. va_list args;
  36. va_start(args, format);
  37. vsnprintf(buffer, 256, format, args);
  38. print_string(buffer, x, y);
  39. }
  40. void TEXT::print_format(unsigned x, unsigned y, const std::string &format, ...)
  41. {
  42. TEXT::print_format(x, y, format.c_str());
  43. }