Text.cpp 1.2 KB

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