Text.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #define UTILS WalrusRPG::Utils
  10. void TEXT::print_char(char c, unsigned x, unsigned y)
  11. {
  12. draw_sprite_sheet(font, x, y, UTILS::Rect((c % 16) * 8, (c / 16) * 8, 8, 8));
  13. }
  14. void TEXT::print_string(const char *str, unsigned x, unsigned y)
  15. {
  16. UTILS::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. draw_sprite_sheet(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. "";
  36. va_list args;
  37. va_start(args, format);
  38. vsnprintf(buffer, 256, format, args);
  39. print_string(buffer, x, y);
  40. }
  41. void TEXT::print_format(unsigned x, unsigned y, const std::string &format, ...)
  42. {
  43. TEXT::print_format(x, y, format.c_str());
  44. }