Label.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "Base.h"
  2. #include "Label.h"
  3. namespace gameplay
  4. {
  5. Label::Label() : _text("")
  6. {
  7. }
  8. Label::Label(const Label& copy)
  9. {
  10. }
  11. Label::~Label()
  12. {
  13. }
  14. Label* Label::create(Theme::Style* style, Properties* properties)
  15. {
  16. Label* label = new Label();
  17. label->init(style, properties);
  18. return label;
  19. }
  20. void Label::init(Theme::Style* style, Properties* properties)
  21. {
  22. Control::init(style, properties);
  23. const char* text = properties->getString("text");
  24. if (text)
  25. {
  26. _text = text;
  27. }
  28. }
  29. void Label::setText(const char* text)
  30. {
  31. if (text)
  32. {
  33. _text = text;
  34. }
  35. }
  36. const char* Label::getText()
  37. {
  38. return _text.c_str();
  39. }
  40. void Label::drawText(const Rectangle& clip)
  41. {
  42. if (_text.size() <= 0)
  43. return;
  44. // TODO: Batch all labels that use the same font.
  45. Theme::Style::Overlay* overlay = _style->getOverlay(getOverlayType());
  46. Font* font = overlay->getFont();
  47. // Draw the text.
  48. font->begin();
  49. font->drawText(_text.c_str(), _clip, overlay->getTextColor(), overlay->getFontSize(), overlay->getTextAlignment(), true, overlay->getTextRightToLeft());
  50. font->end();
  51. _dirty = false;
  52. }
  53. }