| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include "BsGUILabel.h"
- #include "BsGUIElementStyle.h"
- #include "BsTextSprite.h"
- #include "BsGUISkin.h"
- #include "BsGUIWidget.h"
- #include "BsGUILayoutOptions.h"
- #include "BsGUIHelper.h"
- #include "CmTextUtility.h"
- using namespace CamelotFramework;
- namespace BansheeEngine
- {
- GUILabel::GUILabel(GUIWidget& parent, const GUIElementStyle* style, const GUIContent& content, const GUILayoutOptions& layoutOptions)
- :GUIElement(parent, style, layoutOptions), mContent(content)
- {
- mTextSprite = cm_new<TextSprite, PoolAlloc>();
- mDesc.text = content.getText();
- mDesc.font = mStyle->font;
- mDesc.fontSize = mStyle->fontSize;
- mDesc.wordWrap = mStyle->wordWrap;
- mDesc.horzAlign = mStyle->textHorzAlign;
- mDesc.vertAlign = mStyle->textVertAlign;
- }
- GUILabel::~GUILabel()
- {
- cm_delete<PoolAlloc>(mTextSprite);
- }
- UINT32 GUILabel::getNumRenderElements() const
- {
- return mTextSprite->getNumRenderElements();
- }
- const HMaterial& GUILabel::getMaterial(UINT32 renderElementIdx) const
- {
- return mTextSprite->getMaterial(renderElementIdx);
- }
- UINT32 GUILabel::getNumQuads(UINT32 renderElementIdx) const
- {
- return mTextSprite->getNumQuads(renderElementIdx);
- }
- void GUILabel::updateRenderElementsInternal()
- {
- mDesc.width = mWidth;
- mDesc.height = mHeight;
- mTextSprite->update(mDesc);
- GUIElement::updateRenderElementsInternal();
- }
- void GUILabel::updateClippedBounds()
- {
- mClippedBounds = mTextSprite->getBounds(mOffset, mClipRect);
- }
- Int2 GUILabel::_getOptimalSize() const
- {
- return GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions());
- }
- void GUILabel::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads,
- UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
- {
- mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx, mOffset, mClipRect);
- }
- void GUILabel::setContent(const GUIContent& content)
- {
- mContent = content;
- mDesc.text = content.getText();
- markContentAsDirty();
- }
- GUILabel* GUILabel::create(GUIWidget& parent, const WString& text, const GUIElementStyle* style)
- {
- return create(parent, GUIContent(text), style);
- }
- GUILabel* GUILabel::create(GUIWidget& parent, const WString& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
- {
- return create(parent, GUIContent(text), layoutOptions, style);
- }
- GUILabel* GUILabel::create(GUIWidget& parent, const GUIContent& content, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUILabel, PoolAlloc>()) GUILabel(parent, style, content, getDefaultLayoutOptions(style));
- }
- GUILabel* GUILabel::create(GUIWidget& parent, const GUIContent& content, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUILabel, PoolAlloc>()) GUILabel(parent, style, content, layoutOptions);
- }
- const String& GUILabel::getGUITypeName()
- {
- static String typeName = "Label";
- return typeName;
- }
- }
|