80 wiersze
1.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #include <cstdlib> /* free() */
  15. #include <cstring> /* strdup() */
  16. #include "core.h"
  17. /*
  18. * Text implementation class
  19. */
  20. class TextData
  21. {
  22. friend class Text;
  23. private:
  24. int font;
  25. char *text;
  26. int3 pos;
  27. };
  28. /*
  29. * Public Text class
  30. */
  31. Text::Text(char const *text, char const *font)
  32. : data(new TextData())
  33. {
  34. data->font = Forge::Register(font);
  35. data->text = text ? strdup(text) : NULL;
  36. data->pos = int3(0, 0, 0);
  37. drawgroup = DRAWGROUP_HUD;
  38. }
  39. void Text::SetText(char const *text)
  40. {
  41. if (data->text)
  42. free(data->text);
  43. data->text = text ? strdup(text) : NULL;
  44. }
  45. void Text::SetPos(int3 pos)
  46. {
  47. data->pos = pos;
  48. }
  49. void Text::TickDraw(float deltams)
  50. {
  51. Entity::TickDraw(deltams);
  52. if (data->text)
  53. {
  54. Font *font = Forge::GetFont(data->font);
  55. font->PrintBold(data->pos.x, data->pos.y, data->text);
  56. }
  57. }
  58. Text::~Text()
  59. {
  60. if (data->text)
  61. free(data->text);
  62. Forge::Deregister(data->font);
  63. delete data;
  64. }