41 #ifndef __CU_LABEL_H__
42 #define __CU_LABEL_H__
45 #include <cugl/2d/CUNode.h>
46 #include <cugl/2d/CUFont.h>
224 std::shared_ptr<Texture> _texture;
228 #pragma mark Constructors
253 virtual void dispose()
override;
263 CUAssertLog(
false,
"This node does not support the empty initializer");
277 bool init(
const Size& size,
const std::shared_ptr<Font>& font);
296 bool initWithText(
const char* text,
const std::shared_ptr<Font>& font) {
317 bool initWithText(
const std::string& text,
const std::shared_ptr<Font>& font);
352 #pragma mark Static Constructors
363 static std::shared_ptr<Label>
alloc(
const Size& size,
const std::shared_ptr<Font>& font) {
364 std::shared_ptr<Label> result = std::make_shared<Label>();
365 return (result->init(size,font) ? result :
nullptr);
385 static std::shared_ptr<Label>
alloc(
const std::string& text,
const std::shared_ptr<Font>& font) {
386 std::shared_ptr<Label> result = std::make_shared<Label>();
387 return (result->initWithText(text,font) ? result :
nullptr);
410 static std::shared_ptr<Label>
alloc(
const char* text,
const std::shared_ptr<Font>& font) {
411 std::shared_ptr<Label> result = std::make_shared<Label>();
412 return (result->initWithText(text,font) ? result :
nullptr);
446 const std::shared_ptr<JsonValue> data) {
447 std::shared_ptr<Label> result = std::make_shared<Label>();
448 if (!result->initWithData(loader,data)) { result =
nullptr; }
449 return std::dynamic_pointer_cast<
Node>(result);
453 #pragma mark Text Attributes
486 virtual void setText(
const std::string& text,
bool resize=
false);
736 #pragma mark Other Attributes
794 void setFont(
const std::shared_ptr<Font>& font,
bool resize=
false);
797 #pragma mark Rendering
816 void setBlendFunc(GLenum srcFactor, GLenum dstFactor) { _srcFactor = srcFactor; _dstFactor = dstFactor; }
900 virtual void draw(
const std::shared_ptr<SpriteBatch>& batch,
const Mat4& transform,
Color4 tint)
override;
904 #pragma mark Internal Helpers
920 void generateRenderData();
925 void clearRenderData();
virtual void setContentSize(const Size &size) override
float x
Definition: CUVec2.h:66
GLenum _srcFactor
Definition: CULabel.h:214
float y
Definition: CUVec2.h:68
virtual bool initWithData(const SceneLoader *loader, const std::shared_ptr< JsonValue > data) override
static std::shared_ptr< Node > allocWithData(const SceneLoader *loader, const std::shared_ptr< JsonValue > data)
Definition: CULabel.h:445
const Rect & getTextBounds() const
Definition: CULabel.h:666
bool _rendered
Definition: CULabel.h:219
Rect _textbounds
Definition: CULabel.h:195
bool initWithText(const char *text, const std::shared_ptr< Font > &font)
Definition: CULabel.h:296
void setPaddingX(float padx)
Definition: CULabel.h:588
virtual void draw(const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint) override
const std::string & getText() const
Definition: CULabel.h:465
VAlign _valign
Definition: CULabel.h:204
~Label()
Definition: CULabel.h:242
VAlign getVerticalAlignment() const
Definition: CULabel.h:637
GLenum _blendEquation
Definition: CULabel.h:212
GLenum getDestinationBlendFactor() const
Definition: CULabel.h:844
static std::shared_ptr< Label > alloc(const std::string &text, const std::shared_ptr< Font > &font)
Definition: CULabel.h:385
Vec2 _padding
Definition: CULabel.h:200
GLenum getSourceBlendFactor() const
Definition: CULabel.h:830
HAlign _halign
Definition: CULabel.h:202
std::vector< Vertex2 > _vertices
Definition: CULabel.h:221
virtual void setText(const std::string &text, bool resize=false)
std::shared_ptr< Font > getFont() const
Definition: CULabel.h:784
Color4 getBackground() const
Definition: CULabel.h:766
Color4 getForeground() const
Definition: CULabel.h:745
const Vec2 & getPadding() const
Definition: CULabel.h:504
float getBaseLine() const
Color4 _foreground
Definition: CULabel.h:207
static std::shared_ptr< Label > alloc(const char *text, const std::shared_ptr< Font > &font)
Definition: CULabel.h:410
void setPaddingY(float pady)
Definition: CULabel.h:605
HAlign
Definition: CULabel.h:85
void setBackground(Color4 color)
void setForeground(Color4 color)
Definition: CULabel.h:755
Color4 _background
Definition: CULabel.h:209
virtual bool init() override
Definition: CULabel.h:262
void setBlendEquation(GLenum equation)
Definition: CULabel.h:861
GLenum getBlendEquation() const
Definition: CULabel.h:875
Rect _truebounds
Definition: CULabel.h:197
virtual void dispose() override
GLenum _dstFactor
Definition: CULabel.h:216
void setPadding(const Vec2 &padding)
Definition: CULabel.h:552
Vec2 origin
Definition: CURect.h:49
void setFont(const std::shared_ptr< Font > &font, bool resize=false)
std::vector< unsigned short > _indices
Definition: CULabel.h:223
float getPaddingX() const
Definition: CULabel.h:519
Definition: CUSceneLoader.h:77
std::string _text
Definition: CULabel.h:193
std::shared_ptr< Font > _font
Definition: CULabel.h:190
Size size
Definition: CURect.h:51
void setBlendFunc(GLenum srcFactor, GLenum dstFactor)
Definition: CULabel.h:816
Definition: CUColor4.h:1084
float getPaddingY() const
Definition: CULabel.h:534
Definition: CUAction.h:51
static std::shared_ptr< Label > alloc(const Size &size, const std::shared_ptr< Font > &font)
Definition: CULabel.h:363
VAlign
Definition: CULabel.h:137
void setVerticalAlignment(VAlign valign)
virtual void setContentSize(float width, float height) override
Definition: CULabel.h:731
const Rect getTrueBounds() const
Definition: CULabel.h:685
void setHorizontalAlignment(HAlign halign)
HAlign getHorizontalAlignment() const
Definition: CULabel.h:617