CmGUILabel.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  21. GUILabel::~GUILabel()
  22. {
  23. CM_DELETE(mTextSprite, TextSprite, PoolAlloc);
  24. }
  25. UINT32 GUILabel::getNumRenderElements() const
  26. {
  27. return mTextSprite->getNumRenderElements();
  28. }
  29. const HMaterial& GUILabel::getMaterial(UINT32 renderElementIdx) const
  30. {
  31. return mTextSprite->getMaterial(renderElementIdx);
  32. }
  33. UINT32 GUILabel::getNumQuads(UINT32 renderElementIdx) const
  34. {
  35. return mTextSprite->getNumQuads(renderElementIdx);
  36. }
  37. void GUILabel::fillBuffer(Vector2* vertices, Vector2* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, UINT32 renderElementIdx) const
  38. {
  39. mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, renderElementIdx);
  40. }
  41. const String& GUILabel::getGUITypeName()
  42. {
  43. static String typeName = "Label";
  44. return typeName;
  45. }
  46. }