CmGUILabel.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "CmGUILabel.h"
  2. #include "CmGUIElementStyle.h"
  3. #include "CmTextSprite.h"
  4. #include "CmGUISkin.h"
  5. namespace CamelotEngine
  6. {
  7. GUILabel::GUILabel(GUIWidget* parent, const String& text, const GUISkin* skin, UINT32 fixedWidth, UINT32 fixedHeight,
  8. bool wordWrap, TextHorzAlign horzAlign, TextVertAlign vertAlign)
  9. :GUIElement(parent, skin), mText(text), mFixedWidth(fixedWidth), mFixedHeight(fixedHeight), mWordWrap(wordWrap),
  10. mHorzAlign(horzAlign), mVertAlign(vertAlign)
  11. {
  12. // This is calling a virtual method but it's okay because we always want the one
  13. // existing on this class.
  14. mStyle = skin->getStyle(getGUITypeName());
  15. mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite(text, mStyle->font, mStyle->fontSize);
  16. mTextSprite->setSize(fixedWidth, fixedHeight);
  17. mTextSprite->setWordWrap(wordWrap);
  18. mTextSprite->setClipRect(Rect(0, 0, fixedWidth, fixedHeight));
  19. mTextSprite->setAlignment(horzAlign, vertAlign);
  20. mBounds = mTextSprite->getBounds();
  21. }
  22. GUILabel::~GUILabel()
  23. {
  24. CM_DELETE(mTextSprite, TextSprite, PoolAlloc);
  25. }
  26. UINT32 GUILabel::getNumRenderElements() const
  27. {
  28. return mTextSprite->getNumRenderElements();
  29. }
  30. const HMaterial& GUILabel::getMaterial(UINT32 renderElementIdx) const
  31. {
  32. return mTextSprite->getMaterial(renderElementIdx);
  33. }
  34. UINT32 GUILabel::getNumQuads(UINT32 renderElementIdx) const
  35. {
  36. return mTextSprite->getNumQuads(renderElementIdx);
  37. }
  38. void GUILabel::fillBuffer(Vector2* vertices, Vector2* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, UINT32 renderElementIdx) const
  39. {
  40. mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, renderElementIdx);
  41. }
  42. const String& GUILabel::getGUITypeName()
  43. {
  44. static String typeName = "Label";
  45. return typeName;
  46. }
  47. }