CUGL 2.1
Cornell University Game Library
|
#include <CULabel.h>
Public Member Functions | |
Label () | |
~Label () | |
virtual void | dispose () override |
virtual bool | initWithPosition (const Vec2 pos) override |
bool | initWithPosition (float x, float y) |
virtual bool | initWithBounds (const Size size) override |
virtual bool | initWithBounds (float width, float height) override |
virtual bool | initWithBounds (const Rect rect) override |
virtual bool | initWithBounds (float x, float y, float width, float height) override |
bool | initWithText (const std::string text, const std::shared_ptr< Font > &font) |
bool | initWithText (const Vec2 position, const std::string text, const std::shared_ptr< Font > &font) |
bool | initWithTextBox (const Size size, const std::string text, const std::shared_ptr< Font > &font) |
bool | initWithTextBox (const Rect rect, const std::string text, const std::shared_ptr< Font > &font) |
virtual bool | initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override |
const std::string & | getText () const |
virtual void | setText (const std::string &text, bool resize=false) |
std::shared_ptr< Font > | getFont () const |
void | setFont (const std::shared_ptr< Font > &font, bool resize=false) |
HorizontalAlign | getHorizontalAlignment () const |
void | setHorizontalAlignment (HorizontalAlign halign) |
VerticalAlign | getVerticalAlignment () const |
void | setVerticalAlignment (VerticalAlign valign) |
bool | getWrap () const |
void | setWrap (bool wrap) |
float | getSpacing () const |
void | setSpacing (float spacing) |
void | setPadding (float left, float bottom, float right, float top) |
void | setPadding (float pad) |
float | getPaddingLeft () const |
void | setPaddingLeft (float left) |
float | getPaddingBottom () const |
void | setPaddingBottom (float bot) |
float | getPaddingRight () const |
void | setPaddingRight (float right) |
float | getPaddingTop () const |
void | setPaddingTop (float top) |
const Rect | getInterior () const |
void | setInterior (const Rect rect) |
const Rect | getTextBounds () const |
const Rect | getTrueBounds () const |
virtual void | setContentSize (const Size size) override |
virtual void | setContentSize (float width, float height) override |
Color4 | getForeground () const |
void | setForeground (Color4 color) |
Color4 | getBackground () const |
void | setBackground (Color4 color) |
const Vec2 & | getDropShadow () const |
void | setDropShadow (const Vec2 p) |
void | setDropShadow (float x, float y) |
float | getShadowBlur () const |
void | setShadowBlur (float blur) |
void | setBlendFunc (GLenum srcFactor, GLenum dstFactor) |
GLenum | getSourceBlendFactor () const |
GLenum | getDestinationBlendFactor () const |
void | setBlendEquation (GLenum equation) |
GLenum | getBlendEquation () const |
virtual void | draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override |
Public Member Functions inherited from cugl::scene2::SceneNode | |
SceneNode () | |
~SceneNode () | |
virtual bool | init () |
bool | initWithPosition (float x, float y) |
virtual std::shared_ptr< SceneNode > | copy (const std::shared_ptr< SceneNode > &dst) const |
unsigned int | getTag () const |
void | setTag (unsigned int tag) |
const std::string | getName () const |
void | setName (const std::string name) |
const std::string | getClassName () const |
virtual std::string | toString (bool verbose=false) const |
operator std::string () const | |
const Vec2 | getPosition () const |
void | setPosition (const Vec2 &position) |
void | setPosition (float x, float y) |
float | getPositionX (void) const |
void | setPositionX (float x) |
float | getPositionY (void) const |
void | setPositionY (float y) |
Vec2 | getWorldPosition () const |
const Size | getContentSize () const |
float | getContentWidth () const |
void | setContentWidth (float width) |
float | getContentHeight () const |
void | setContentHeight (float height) |
virtual Rect | getLayoutBounds () const |
Size | getSize () const |
float | getWidth () const |
float | getHeight () const |
Rect | getBoundingBox () const |
virtual void | setAnchor (const Vec2 anchor) |
virtual void | setAnchor (float x, float y) |
const Vec2 | getAnchor () const |
Vec2 | getAnchorInPixels () |
Color4 | getColor () const |
virtual void | setColor (Color4 color) |
Color4 | getAbsoluteColor () |
bool | isVisible () const |
void | setVisible (bool visible) |
bool | hasRelativeColor () const |
void | setRelativeColor (bool flag) |
std::shared_ptr< Scissor > | getScissor () const |
void | setScissor (const std::shared_ptr< Scissor > &scissor) |
void | setScissor () |
const Vec2 | getScale () const |
float | getScaleX () const |
float | getScaleY () const |
void | setScale (float scale) |
void | setScale (const Vec2 vec) |
void | setScale (float sx, float sy) |
float | getAngle () |
void | setAngle (float angle) |
const Affine2 & | getTransform () const |
const Affine2 & | getAlternateTransform () const |
void | setAlternateTransform (const Affine2 &transform) |
bool | withAlternateTransform () |
void | chooseAlternateTransform (bool active) |
const Affine2 & | getNodeToParentTransform () const |
Affine2 | getParentToNodeTransform () const |
Affine2 | getNodeToWorldTransform () const |
Affine2 | getWorldToNodeTransform () const |
Vec2 | screenToNodeCoords (const Vec2 screenPoint) const |
Vec2 | worldToNodeCoords (const Vec2 worldPoint) const |
Vec2 | nodeToScreenCoords (const Vec2 nodePoint) const |
Vec2 | nodeToWorldCoords (const Vec2 nodePoint) const |
Vec2 | parentToNodeCoords (const Vec2 parentPoint) const |
Vec2 | nodeToParentCoords (const Vec2 nodePoint) const |
size_t | getChildCount () const |
std::shared_ptr< SceneNode > | getChild (unsigned int pos) |
const std::shared_ptr< SceneNode > & | getChild (unsigned int pos) const |
template<typename T > | |
std::shared_ptr< T > | getChild (unsigned int pos) const |
std::shared_ptr< SceneNode > | getChildByTag (unsigned int tag) const |
template<typename T > | |
std::shared_ptr< T > | getChildByTag (unsigned int tag) const |
std::shared_ptr< SceneNode > | getChildByName (const std::string name) const |
template<typename T > | |
std::shared_ptr< T > | getChildByName (const std::string name) const |
std::vector< std::shared_ptr< SceneNode > > | getChildren () |
const std::vector< std::shared_ptr< SceneNode > > & | getChildren () const |
void | addChild (const std::shared_ptr< SceneNode > &child) |
void | addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag) |
void | addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string name) |
void | swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false) |
SceneNode * | getParent () |
const SceneNode * | getParent () const |
Scene2 * | getScene () |
const Scene2 * | getScene () const |
void | removeFromParent () |
virtual void | removeChild (unsigned int pos) |
void | removeChild (const std::shared_ptr< SceneNode > &child) |
void | removeChildByTag (unsigned int tag) |
void | removeChildByName (const std::string name) |
virtual void | removeAllChildren () |
void | setPriority (float priority) |
float | getPriority () |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) |
virtual void | render (const std::shared_ptr< SpriteBatch > &batch) |
const std::shared_ptr< Layout > & | getLayout () const |
void | setLayout (const std::shared_ptr< Layout > &layout) |
virtual void | doLayout () |
Static Public Member Functions | |
static std::shared_ptr< Label > | allocWithBounds (const Size size) |
static std::shared_ptr< Label > | allocWithBounds (float width, float height) |
static std::shared_ptr< Label > | allocWithBounds (const Rect rect) |
static std::shared_ptr< Label > | allocWithBounds (float x, float y, float width, float height) |
static std::shared_ptr< Label > | allocWithText (const std::string text, const std::shared_ptr< Font > &font) |
static std::shared_ptr< Label > | allocWithText (const Vec2 position, const std::string text, const std::shared_ptr< Font > &font) |
static std::shared_ptr< Label > | allocWithTextBox (const Size size, const std::string text, const std::shared_ptr< Font > &font) |
static std::shared_ptr< Label > | allocWithTextBox (const Rect rect, const std::string text, const std::shared_ptr< Font > &font) |
static std::shared_ptr< SceneNode > | allocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) |
Static Public Member Functions inherited from cugl::scene2::SceneNode | |
static std::shared_ptr< SceneNode > | alloc () |
static std::shared_ptr< SceneNode > | allocWithPosition (const Vec2 pos) |
static std::shared_ptr< SceneNode > | allocWithPosition (float x, float y) |
static std::shared_ptr< SceneNode > | allocWithBounds (const Size size) |
static std::shared_ptr< SceneNode > | allocWithBounds (float width, float height) |
static std::shared_ptr< SceneNode > | allocWithBounds (const Rect rect) |
static std::shared_ptr< SceneNode > | allocWithBounds (float x, float y, float width, float height) |
static std::shared_ptr< SceneNode > | allocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) |
Protected Member Functions | |
virtual void | generateRenderData () |
void | clearRenderData () |
void | updateColor () |
void | resize () |
void | reanchor () |
Protected Attributes | |
std::shared_ptr< Font > | _font |
std::shared_ptr< TextLayout > | _layout |
Vec2 | _offset |
float | _padbot |
float | _padleft |
float | _padtop |
float | _padrght |
bool | _dropShadow |
float | _dropBlur |
Vec2 | _dropOffset |
Color4 | _foreground |
Color4 | _background |
GLenum | _blendEquation |
GLenum | _srcFactor |
GLenum | _dstFactor |
bool | _rendered |
Rect | _bounds |
std::unordered_map< GLuint, std::shared_ptr< GlyphRun > > | _glyphrun |
Protected Attributes inherited from cugl::scene2::SceneNode | |
Vec2 | _position |
Vec2 | _anchor |
Size | _contentSize |
Color4 | _tintColor |
bool | _hasParentColor |
bool | _isVisible |
std::shared_ptr< Scissor > | _scissor |
Vec2 | _scale |
float | _angle |
Affine2 | _transform |
bool | _useTransform |
Affine2 | _combined |
std::vector< std::shared_ptr< SceneNode > > | _children |
SceneNode * | _parent |
Scene2 * | _graph |
std::shared_ptr< Layout > | _layout |
int | _childOffset |
unsigned int | _tag |
std::string | _name |
size_t | _hashOfName |
std::string | _classname |
float | _priority |
std::shared_ptr< JsonValue > | _json |
This class is a node the represents formatted text on rectangular background.
By default, the content size is just large enough to render the text given. If you reset the content size to larger than the what the text needs, the the text is placed in the label according to the text bounds. If you reset it to smaller, the text may be cut off in rendering.
If the background color is not clear, then the label will have a colored backing rectangle. The rectangle will extended from the origin to the content size in Node space.
The text itself is formatted using a TextLayout. This text layout breaks the text into multiple lines as needed, though by default, a label only breaks lines at explicit newlines. The text layout aligns the lines of text with each other. But it also positions the text against the background rectangle as well. See getHorizontalAlignment and getVerticalAlignment for more information.
To display the text, you need a Font. The label assumes that the font has an atlas, either through a pre-built atlas, or by setting the attribute Font#setAtlasFallback to true. If the font does not have an atlas, or characters are missing from the atlas, then those glyphs will not be displayed. It is generally recommended that you use a prebuilt atlas, as fallback atlases introduce significant time and memory overhead.
cugl::scene2::Label::Label | ( | ) |
Creates an uninitialized label with no text or font information.
You must initialize this Label before use.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a Node on the heap, use one of the static constructors instead.
|
inline |
Deletes this label, disposing all resources
Returns a newly allocated label with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The label will empty, as it has no font or text.
rect | The bounds of the label in parent space |
Returns a newly allocated label with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The label will empty, as it has no font or text.
size | The size of the label in parent space |
|
inlinestatic |
Returns a newly allocated label with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The label will empty, as it has no font or text.
width | The width of the label in parent space |
height | The height of the label in parent space |
|
inlinestatic |
Returns a newly allocated label with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The label will empty, as it has no font or text.
x | The x-coordinate of the label origin in parent space |
y | The y-coordinate of the label origin in parent space |
width | The width of the label in parent space |
height | The height of the label in parent space |
|
inlinestatic |
Returns a newly allocated node with the given JSON specificaton.
This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:
"font": The name of a previously loaded font asset "text": The initial label text "foreground": Either a four-element integer array (values 0..255) or a string. Any string should be a web color or a Tkinter color name. "background": Either a four-element integer array (values 0..255) or a string. Any string should be a web color or a Tkinter color name. "padding": A number or a 4-element float array. "dropshadow": A boolean indicating the presence of a drop shadow "wrap": A boolean indicating whether to break text into lines "spacing": A float indicating the spacing factor between lines "halign": One of 'left', 'center', 'right', 'justify', 'hard left', 'true center' and 'hard right'. "valign": One of 'top', 'middle', 'bottom', 'hard top', 'true middle' and 'hard bottom'.
All attributes are optional. There are no required attributes. However, a label without a font cannot display text.
loader | The scene loader passing this JSON file |
data | The JSON object specifying the node |
|
inlinestatic |
Returns a newly allocated label with the given text and font
The label will be sized to fit the rendered text exactly. That is, the height will be the maximum height of the font, and the width will be the sum of the advance of the rendered characters. That means that there may be some natural spacing around the characters.
By default, the text will formated so that the origin is on the left edge of the baseline (of the top line). The text will take up a single line unless there are newline characters in the string. If any glyphs are missing from the font atlas, they will not be rendered.
text | The text to display in the label |
font | The font for this label |
|
inlinestatic |
Returns a newly allocated label with the given text and font
The label will be sized to fit the rendered text exactly. That is, the height will be the maximum height of the font, and the width will be the sum of the advance of the rendered characters. That means that there may be some natural spacing around the characters.
By default, the text will formated so that the origin is on the left edge of the baseline (of the top line). The text will take up a single line unless there are newline characters in the string. If any glyphs are missing from the font atlas, they will not be rendered.
position | The label position |
text | The text to display in the label |
font | The font for this label |
|
inlinestatic |
Returns a newly allocated multiline label with the given dimensions
The label will use the size specified and attempt to fit the text in this region. Lines will be broken at white space locations to keep each line within the size width. However, this may result in so many lines that glyphs at the bottom are cut out. A label will never render text outside of its content bounds.
By default, a multiline label is aligned to the top and left. It has a line spacing of 1 (single-spaced).
The label will use the rectangle origin to position this label in its parent. It will be anchored in the bottom left.
rect | The bounds of the label to display |
text | The text to display in the label |
font | The font for this label |
|
inlinestatic |
Returns a newly allocated multiline label with the given dimensions
The label will use the size specified and attempt to fit the text in this region. Lines will be broken at white space locations to keep each line within the size width. However, this may result in so many lines that glyphs at the bottom are cut out. A label will never render text outside of its content bounds.
By default, a multiline label is aligned to the top and left. It has a line spacing of 1 (single-spaced).
The label will be placed at the origin of the parent and will be anchored in the bottom left.
size | The size of the label to display |
text | The text to display in the label |
font | The font for this label |
|
protected |
Clears the render data, releasing all vertices and indices.
|
overridevirtual |
Disposes all of the resources used by this label.
A disposed Label can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.
It is unsafe to call this on a Label that is still currently inside of a scene graph.
Reimplemented from cugl::scene2::SceneNode.
Reimplemented in cugl::scene2::TextField.
|
overridevirtual |
Draws this Node via the given SpriteBatch.
This method only worries about drawing the current node. It does not attempt to render the children.
This is the method that you should override to implement your custom drawing code. You are welcome to use any OpenGL commands that you wish. You can even skip use of the SpriteBatch. However, if you do so, you must flush the SpriteBatch by calling end() at the start of the method. in addition, you should remember to call begin() at the start of the method.
This method provides the correct transformation matrix and tint color. You do not need to worry about whether the node uses relative color. This method is called by render() and these values are guaranteed to be correct. In addition, this method does not need to check for visibility, as it is guaranteed to only be called when the node is visible.
batch | The SpriteBatch to draw with. |
transform | The global transformation matrix. |
tint | The tint to blend with the Node color. |
Reimplemented from cugl::scene2::SceneNode.
Reimplemented in cugl::scene2::TextField.
|
protectedvirtual |
Allocates the render data necessary to render this node.
Reimplemented in cugl::scene2::TextField.
|
inline |
Returns the background color of this label.
If this color is not CLEAR (the default color), then the label will have a colored backing rectangle. The rectangle will extended from the origin to the content size in Node space.
|
inline |
Returns the blending equation for this textured node
By default this value is GL_FUNC_ADD. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
This blending equation only affects the texture of the current node. It does not affect any children of the node.
|
inline |
Returns the destination blending factor
By default this value is GL_ONE_MINUS_SRC_ALPHA. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This blending factor only affects the texture of the current node. It does not affect any children of the node.
|
inline |
Returns the drop shadow offset of this label
A drop shadow is a blurred and/or slightly offset version of the label text, drawn behind the original text. The color of the drop shadow is always a slighlty transparent black. It is used to give a sense of depth to the text.
This property controls the offset of the drop shadow but does not control the blur. You must use the property getShadowBlur for that. A typical drop shadow is offset down and to the right with minor blurring.
|
inline |
Returns the font to use for this label
|
inline |
Returns the foreground color of this label.
This color will be applied to the characters themselves. This color is BLACK by default.
HorizontalAlign cugl::scene2::Label::getHorizontalAlignment | ( | ) | const |
Returns the horizontal alignment of the text.
Horizontal alignment serves two purposes in a label. First it is the alignment of multiple lines of text to each other, as specified in TextLayout. But it also represents the relationship between the text and the background region of this node. In particular, setting this value has the following effects:
LEFT, HARD_LEFT, and JUSTIFY all place the left edge of the text layout against the left edge of the label, after applying padding. Similarly, RIGHT places the right edge of the text layout against the right edge of the label, after applying padding.
Padding is unusual for the CENTER and TRUE_CENTER alignments. The center of the label is determined from the edges after applying padding. So if the left and right padding are not equal, then the text will not be placed at the true center. Even if they are equal, the left and right padding reduce the width of the label, which can affect word wrap.
This value is LEFT by default.
const Rect cugl::scene2::Label::getInterior | ( | ) | const |
Returns the non-padded interior of this label.
Padding can be added to the bottom, left, top, and right edges of the label. This padding detracts from the area in which text can appear, and can influence the word wrap. We call the area of the label in which the text can appear the interior of the label.
Normally the content bounds of a scene graph node has origin (0,0) and size SceneNode#getContentSize. This method shifts the origin and reduces the width and height to account for the padding on the edges.
|
inline |
Returns the bottom-edge padding of the label.
Adding bottom padding to a label does not effect word wrap, but it can affect the text position. If the text has alignment BOTTOM or BASELINE, the label will shift the text up by this amount. On the other hand, it will have no effect on TOP aligned text.
For MIDDLE aligned text, the label middle is computed after applying padding to the edges. So the top and bottom padding should be equal to ensure that the text is in the true middle of the label.
|
inline |
Returns the left-edge padding of the label.
Adding left padding to a label reduces the text width of the label, which can affect word wrap (if enabled). In addition, the padding can affect the position of the text. If the text has alignment LEFT or JUSTIFY, the label will shift the text right by this amount. On the other hand, it will have no effect on RIGHT aligned text (other than reducing the line width).
For CENTER aligned text, the label center is computed after applying padding to the edges. So the left and right padding should be equal to ensure that the text is in the true center of the label.
|
inline |
Returns the right-edge padding of the label.
Adding right padding to a label reduces the text width of the label, which can affect word wrap (if enabled). In addition, the padding can affect the position of the text. If the text has alignment RIGHT then the label will shift the text left by this amount. On the other hand, it will have no effect on LEFT or JUSTIFY aligned text (other than reducing the line width).
For CENTER aligned text, the label center is computed after applying padding to the edges. So the left and right padding should be equal to ensure that the text is in the true center of the label.
|
inline |
Returns the top-edge padding of the label.
Adding top padding to a label does not effect word wrap, but it can affect the position of the text. If the text has alignment TOP, the label will shift the text down by this amount. On the other hand, it will have no effect on BOTTOM or BASELINE aligned text.
For MIDDLE aligned text, the label middle is computed after applying padding to the edges. So the top and bottom padding should be equal to ensure that the text is in the true middle of the label.
|
inline |
Returns the drop shadow blur of this label
A drop shadow is a blurred and/or slightly offset version of the label text, drawn behind the original text. The color of the drop shadow is always a slighlty transparent black. It is used to give a sense of depth to the text.
This property controls the offset of the drop shadow but does not control the blur. You must use the property getShadowBlur for that. A typical drop shadow is offset down and to the right with minor blurring.
When blurring a drop shadow, remember to use a font with the same Font#getPadding as the blur size. This will prevent bleeding across characters in the atlas.
|
inline |
Returns the source blending factor
By default this value is GL_SRC_ALPHA. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This blending factor only affects the texture of the current node. It does not affect any children of the node.
float cugl::scene2::Label::getSpacing | ( | ) | const |
Returns the line spacing of this label.
This value is multiplied by the font size to determine the space between lines in the label. So a value of 1 is single-spaced text, while a value of 2 is double spaced. The value should be positive.
const std::string& cugl::scene2::Label::getText | ( | ) | const |
Returns the text for this label.
The string will be in either ASCII or UTF8 format. No other string encodings are supported. As all ASCII strings are also UTF8, you can this effectively means that the text must be UTF8.
If the font is missing glyphs in this string, the characters in the text may be different than those displayed. Furthermore, if this label has no font, then the text will not display at all.
const Rect cugl::scene2::Label::getTextBounds | ( | ) | const |
Returns the bounds of the rendered text.
This is the bounds of the rendered text with respect to the Node space. The size of the bounding box is the natural size to render the text. This corresponds to TextLayout#getBounds of the underlying text layout. In particular, this means there may be some natural spacing around the characters.
The origin of the bounds is determined by the padding and alignment. If this rectangle extends outside the bounding box of the label (e.g. the rectangle with origin (0,0) and the content size), then only the part of the rectangle inside the bounding box will be rendered.
const Rect cugl::scene2::Label::getTrueBounds | ( | ) | const |
Returns the tightest bounds of the rendered text.
This is the bounds of the rendered text, with respect to the Node space. The size of the bounding box ignores any nautural spacing around the characters. It also includes any tracking applied to each line. This corresponds to TextLayout#getTrueBounds of the underlying text layout.
The origin of the bounds is determined by the padding and alignment. If this rectangle extends outside the bounding box of the label (e.g. the rectangle with origin (0,0) and the content size), then only the part of the rectangle inside the bounding box will be rendered.
VerticalAlign cugl::scene2::Label::getVerticalAlignment | ( | ) | const |
Returns the vertical alignment of the text.
Vertical alignment is used to place the formatted text in against the background rectangle. The options are interpretted as follows:
TOP and HARD_TOP place the top edge of the text layout against the top edge of the label, after applying padding. Note that the meaning of "top edge" differs between TOP and HARD_TOP in TextLayout. Similarly, BOTTOM and HARD_BOTTOM place the bottom edge of the text layout against the bottom edge of the label, after applying padding.
Padding is unusual for the MIDDLE and TRUE_MIDDLE alignments. The middle of the label is determined from the edges after applying padding. So if the top and bottom padding are not equal, then the text will not be placed at the true middle.
Finally, for BASELINE, this will place the baseline of the bottom line (not the top, as the case with TextLayout) line at the bottom edge of the label, after adjusting for padding.
This value is TOP by default.
bool cugl::scene2::Label::getWrap | ( | ) | const |
Returns true if this label will wrap text to fit.
By default, label text will be displayed on one line (unless it has newline characters). This could cause the text to exceed the bounds of the content size and be cut off. If this option is true, the label will break up lines at white space locations (or mid-word if there are no white space locations) so that each line can fit in the width of the content region. This could still cause text to be cut off if the height of the content region is not large enough.
Not that even if this value is false, a label will still break lines at newline characters. If you do not want the label to break up a string with newlines, you should remove the newline characters from the string (as these are not renderable anyway).
|
overridevirtual |
Initializes a node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The label will be empty, as it has no font or text.
rect | The bounds of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Initializes a label with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The label will be empty, as it has no font or text.
size | The size of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
inlineoverridevirtual |
Initializes a node with the given size.
The size defines the content size. The bounding box of the node is (0,0,width,height) and is anchored in the bottom left corner (0,0). The node is positioned at the origin in parent space.
The label will be empty, as it has no font or text.
width | The width of the node in parent space |
height | The height of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
inlineoverridevirtual |
Initializes a node with the given bounds.
The rectangle origin is the bottom left corner of the node in parent space, and corresponds to the origin of the Node space. The size defines its content width and height in node space. The node anchor is placed in the bottom left corner.
The label will be empty, as it has no font or text.
x | The x-coordinate of the node origin in parent space |
y | The y-coordinate of the node origin in parent space |
width | The width of the node in parent space |
height | The height of the node in parent space |
Reimplemented from cugl::scene2::SceneNode.
|
overridevirtual |
Initializes a node with the given JSON specificaton.
This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:
"font": The name of a previously loaded font asset "text": The initial label text "foreground": Either a four-element integer array (values 0..255) or a string. Any string should be a web color or a Tkinter color name. "background": Either a four-element integer array (values 0..255) or a string. Any string should be a web color or a Tkinter color name. "padding": A number or a 4-element float array. "dropshadow": A boolean indicating the presence of a drop shadow "wrap": A boolean indicating whether to break text into lines "spacing": A float indicating the spacing factor between lines "halign": One of 'left', 'center', 'right', 'justify', 'hard left', 'true center' and 'hard right'. "valign": One of 'top', 'middle', 'bottom', 'hard top', 'true middle' and 'hard bottom'.
All attributes are optional. There are no required attributes. However, a label without a font cannot display text.
loader | The scene loader passing this JSON file |
data | The JSON object specifying the node |
Reimplemented from cugl::scene2::SceneNode.
Reimplemented in cugl::scene2::TextField.
|
inlineoverridevirtual |
Disables the inherited initializer.
This initializer is disabled and should not be used.
Reimplemented from cugl::scene2::SceneNode.
|
inline |
Disables the inherited initializer.
This initializer is disabled and should not be used.
bool cugl::scene2::Label::initWithText | ( | const std::string | text, |
const std::shared_ptr< Font > & | font | ||
) |
Initializes a label at (0,0) with the given text and font
The label will be sized to fit the rendered text exactly. That is, the height will be the maximum height of the font, and the width will be the sum of the advance of the rendered characters. That means that there may be some natural spacing around the characters.
By default, the text will formated so that the origin is on the left edge of the baseline (of the top line). The text will take up a single line unless there are newline characters in the string. If any glyphs are missing from the font atlas, they will not be rendered.
text | The text to display in the label |
font | The font for this label |
bool cugl::scene2::Label::initWithText | ( | const Vec2 | position, |
const std::string | text, | ||
const std::shared_ptr< Font > & | font | ||
) |
Initializes a label at the position with the given text and font
The label will be sized to fit the rendered text exactly. That is, the height will be the maximum height of the font, and the width will be the sum of the advance of the rendered characters. That means that there may be some natural spacing around the characters.
By default, the text will formated so that the origin is on the left edge of the baseline (of the top line). The text will take up a single line unless there are newline characters in the string. If any glyphs are missing from the font atlas, they will not be rendered.
position | The label position |
text | The text to display in the label |
font | The font for this label |
bool cugl::scene2::Label::initWithTextBox | ( | const Rect | rect, |
const std::string | text, | ||
const std::shared_ptr< Font > & | font | ||
) |
Initializes a multiline label with the given dimensions
The label will use the size specified and attempt to fit the text in this region. Lines will be broken at white space locations to keep each line within the size width. However, this may result in so many lines that glyphs at the bottom are cut out. A label will never render text outside of its content bounds.
By default, a multiline label is aligned to the top and left. It has a line spacing of 1 (single-spaced).
The label will use the rectangle origin to position this label in its parent. It will be anchored in the bottom left.
rect | The bounds of the label to display |
text | The text to display in the label |
font | The font for this label |
bool cugl::scene2::Label::initWithTextBox | ( | const Size | size, |
const std::string | text, | ||
const std::shared_ptr< Font > & | font | ||
) |
Initializes a multiline label with the given dimensions
The label will use the size specified and attempt to fit the text in this region. Lines will be broken at white space locations to keep each line within the size width. However, this may result in so many lines that glyphs at the bottom are cut out. A label will never render text outside of its content bounds.
By default, a multiline label is aligned to the top and left. It has a line spacing of 1 (single-spaced).
The label will be placed at the origin of the parent and will be anchored in the bottom left.
size | The size of the label to display |
text | The text to display in the label |
font | The font for this label |
|
protected |
Repositions the text inside of this label.
This method is called whenever there is a formatting or alignment change to the label.
|
protected |
Resizes the content bounds to fit the text.
void cugl::scene2::Label::setBackground | ( | Color4 | color | ) |
Sets the background color of this label.
If this color is not CLEAR (the default color), then the label will have a colored backing rectangle. The rectangle will extended from the origin to the content size in Node space.
color | The background color of this label. |
|
inline |
Sets the blending equation for this textured node
The enum must be a standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
However, this setter does not do any error checking to verify that the input is valid. By default, the equation is GL_FUNC_ADD.
This blending equation only affects the texture of the current node. It does not affect any children of the node.
equation | Specifies how source and destination colors are combined |
|
inline |
Sets the blending function for this texture node.
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid. By default, srcFactor is GL_SRC_ALPHA while dstFactor is GL_ONE_MINUS_SRC_ALPHA. This corresponds to non-premultiplied alpha blending.
This blending factor only affects the texture of the current node. It does not affect any children of the node.
srcFactor | Specifies how the source blending factors are computed |
dstFactor | Specifies how the destination blending factors are computed. |
|
overridevirtual |
Sets the untransformed size of the node.
The content size remains the same no matter how the node is scaled or rotated. All nodes must have a size, though it may be degenerate (0,0).
Changing the size of a rectangle will not change the position of the node. However, if the anchor is not the bottom-left corner, it will change the origin. The Node will grow out from an anchor on an edge, and equidistant from an anchor in the center.
In addition, if the rendered text is cannot fit in the content size, it may be cut off in rendering.
size | The untransformed size of the node. |
Reimplemented from cugl::scene2::SceneNode.
|
inlineoverridevirtual |
Sets the untransformed size of the node.
The content size remains the same no matter how the node is scaled or rotated. All nodes must have a size, though it may be degenerate (0,0).
Changing the size of a rectangle will not change the position of the node. However, if the anchor is not the bottom-left corner, it will change the origin. The Node will grow out from an anchor on an edge, and equidistant from an anchor in the center.
In addition, if the rendered text is cannot fit in the content size, it may be cut off in rendering.
width | The untransformed width of the node. |
height | The untransformed height of the node. |
Reimplemented from cugl::scene2::SceneNode.
|
inline |
Sets the drop shadow offset of this label
A drop shadow is a blurred and/or slightly offset version of the label text, drawn behind the original text. The color of the drop shadow is always a slighlty transparent black. It is used to give a sense of depth to the text.
This property controls the offset of the drop shadow but does not control the blur. You must use the property getShadowBlur for that. A typical drop shadow is offset down and to the right with minor blurring.
p | The drop shadow offset of this label |
void cugl::scene2::Label::setDropShadow | ( | float | x, |
float | y | ||
) |
Sets the drop shadow offset of this label
A drop shadow is a blurred and/or slightly offset version of the label text, drawn behind the original text. The color of the drop shadow is always a slighlty transparent black. It is used to give a sense of depth to the text.
This property controls the offset of the drop shadow but does not control the blur. You must use the property getShadowBlur for that. A typical drop shadow is offset down and to the right with minor blurring.
x | The x-offset of the drop shadow |
y | The x-offset of the drop shadow |
void cugl::scene2::Label::setFont | ( | const std::shared_ptr< Font > & | font, |
bool | resize = false |
||
) |
Sets the font to use this label
Changing this value will regenerate the render data, and is potentially expensive, particularly if the font does not have an atlas.
font | The font to use for this label |
resize | Whether to resize this label to fit the new font |
|
inline |
Sets the foreground color of this label.
This color will be applied to the characters themselves. This color is BLACK by default.
color | The foreground color of this label. |
void cugl::scene2::Label::setHorizontalAlignment | ( | HorizontalAlign | halign | ) |
Sets the horizontal alignment of the text.
Horizontal alignment serves two purposes in a label. First it is the alignment of multiple lines of text to each other, as specified in TextLayout. But it also represents the relationship between the text and the background region of this node. In particular, setting this value has the following effects:
LEFT, HARD_LEFT, and JUSTIFY all place the left edge of the text layout against the left edge of the label, after applying padding. Note that the meaning of the "left edge" differs between LEFT and HARD_LEFT in TextLayout. Similarly, RIGHT and HARD_RIGHT place the right edge of the text layout against the right edge of the label, after applying padding.
Padding is unusual for the CENTER and TRUE_CENTER alignments. The center of the label is determined from the edges after applying padding. So if the left and right padding are not equal, then the text will not be placed at the true center. Even if they are equal, the left and right padding reduce the width of the label, which can affect word wrap.
This value is LEFT by default.
halign | The horizontal alignment of the text. |
void cugl::scene2::Label::setInterior | ( | const Rect | rect | ) |
Sets the non-padded interior of this label.
Padding can be added to the bottom, left, top, and right edges of the label. This padding detracts from the area in which text can appear, and can influence the word wrap. We call the area of the label in which the text can appear the interior of the label.
This method is essentially an alternate way to set the padding. The method will add padding so that the interior appears in a region with origin (0,0) and size SceneNode#getContentSize. If the interior cannot fit in this region, then the interior will be the intersection. This method will never change the content size of the label.
rect | The non-padded interior of this label. |
void cugl::scene2::Label::setPadding | ( | float | left, |
float | bottom, | ||
float | right, | ||
float | top | ||
) |
Sets the padding of the label.
Padding can be added to the bottom, left, top, and right edges of the label. This padding detracts from the area in which text can appear, and can influence the word wrap. We call the area of the label in which the text can appear the interior of the label.
Padding can also have effect on the various text alignments. See both setHorizontalAlignment and setVerticalAlignment for the affect of padding on alignment.
left | The left edge padding of the label |
bottom | The bottom edge padding of the label |
right | The right edge padding of the label |
top | The top edge padding of the label |
|
inline |
Sets the padding of the label.
Padding can be added to the bottom, left, top, and right edges of the label. This padding detracts from the area in which text can appear, and can influence the word wrap. We call the area of the label in which the text can appear the interior of the label. In this method, the padding is applied to uniformly to all sides.
Padding can also have effect on the various text alignments. See both setHorizontalAlignment and setVerticalAlignment for the affect of padding on alignment.
pad | The uniform padding for each edge |
|
inline |
Sets the bottom-edge padding of the label.
Adding bottom padding to a label does not effect word wrap, but it can affect the text position. If the text has alignment BOTTOM or BASELINE, the label will shift the text up by this amount. On the other hand, it will have no effect on TOP aligned text.
For MIDDLE aligned text, the label middle is computed after applying padding to the edges. So the top and bottom padding should be equal to ensure that the text is in the true middle of the label.
bot | The bottom-edge padding of the label. |
|
inline |
Sets the left-edge padding of the label.
Adding left padding to a label reduces the text width of the label, which can affect word wrap (if enabled). In addition, the padding can affect the position of the text. If the text has alignment LEFT or JUSTIFY, the label will shift the text right by this amount. On the other hand, it will have no effect on RIGHT aligned text (other than reducing the line width).
For CENTER aligned text, the label center is computed after applying padding to the edges. So the left and right padding should be equal to ensure that the text is in the true center of the label.
left | The left-edge padding of the label. |
|
inline |
Sets the right-edge padding of the label.
Adding right padding to a label reduces the text width of the label, which can affect word wrap (if enabled). In addition, the padding can affect the position of the text. If the text has alignment RIGHT then the label will shift the text left by this amount. On the other hand, it will have no effect on LEFT or JUSTIFY aligned text (other than reducing the line width).
For CENTER aligned text, the label center is computed after applying padding to the edges. So the left and right padding should be equal to ensure that the text is in the true center of the label.
right | The right-edge padding of the label. |
|
inline |
Sets the top-edge padding of the label.
Adding top padding to a label does not effect word wrap, but it can affect the position of the text. If the text has alignment TOP, the label will shift the text down by this amount. On the other hand, it will have no effect on BOTTOM or BASELINE aligned text.
For MIDDLE aligned text, the label middle is computed after applying padding to the edges. So the top and bottom padding should be equal to ensure that the text is in the true middle of the label.
top | The top-edge padding of the label. |
void cugl::scene2::Label::setShadowBlur | ( | float | blur | ) |
Sets the drop shadow blur of this label
A drop shadow is a blurred and/or slightly offset version of the label text, drawn behind the original text. The color of the drop shadow is always a slighlty transparent black. It is used to give a sense of depth to the text.
This property controls the offset of the drop shadow but does not control the blur. You must use the property getShadowBlur for that. A typical drop shadow is offset down and to the right with minor blurring.
When blurring a drop shadow, remember to use a font with the same Font#getPadding as the blur size. This will prevent bleeding across characters in the atlas.
blur | The drop shadow blur of this label |
void cugl::scene2::Label::setSpacing | ( | float | spacing | ) |
Sets the line spacing of this label.
This value is multiplied by the font size to determine the space between lines in the label. So a value of 1 is single-spaced text, while a value of 2 is double spaced. The value should be positive.
spacing | The line spacing of this label. |
|
virtual |
Sets the text for this label.
The string must be in either ASCII or UTF8 format. No other string encodings are supported. As all ASCII strings are also UTF8, you can this effectively means that the text must be UTF8.
If the font is missing glyphs in this string, the characters in the text may be different than those displayed. Furthermore, if this label has no font, then the text will not display at all.
Changing this value will regenerate the render data, and is potentially expensive, particularly if the font is using a fallback atlas.
text | The text for this label. |
resize | Whether to resize the label to fit the new text. |
Reimplemented in cugl::scene2::TextField.
void cugl::scene2::Label::setVerticalAlignment | ( | VerticalAlign | valign | ) |
Sets the vertical alignment of the text.
Vertical alignment is used to place the formatted text in against the background rectangle. The options are interpretted as follows:
TOP and HARD_TOP place the top edge of the text layout against the top edge of the label, after applying padding. Note that the meaning of "top edge" differs between TOP and HARD_TOP in TextLayout. Similarly, BOTTOM and HARD_BOTTOM place the bottom edge of the text layout against the bottom edge of the label, after applying padding.
Padding is unusual for the MIDDLE and TRUE_MIDDLE alignments. The middle of the label is determined from the edges after applying padding. So if the top and bottom padding are not equal, then the text will not be placed at the true middle.
Finally, for BASELINE, this will place the baseline of the bottom line (not the top, as the case with TextLayout) line at the bottom edge of the label, after adjusting for padding.
This value is TOP by default.
valign | The horizontal alignment of the text. |
void cugl::scene2::Label::setWrap | ( | bool | wrap | ) |
Sets whether this label will wrap text to fit.
By default, label text will be displayed on one line (unless it has newline characters). This could cause the text to exceed the bounds of the content size and be cut off. If this option is true, the label will break up lines at white space locations (or mid-word if there are no white space locations) so that each line can fit in the width of the content region. This could still cause text to be cut off if the height of the content region is not large enough.
Not that even if this value is false, a label will still break lines at newline characters. If you do not want the label to break up a string with newlines, you should remove the newline characters from the string (as these are not renderable anyway).
wrap | Whether this label will wrap text to fit. |
|
protected |
Updates the color value for any other data that needs it.
This method is used to synchronize the background and foreground colors.
|
protected |
The color of the background panel (default is CLEAR)
|
protected |
The blending equation for this texture
|
protected |
The font bounds
|
protected |
The blurring effect for the drop shadow
|
protected |
The drop shadow offset
|
protected |
Whether to shadow the text
|
protected |
The destination factor for the blend function
|
protected |
The font (with or without an atlas)
|
protected |
The color of the text (default is BLACK)
|
protected |
The glyph runs to render
|
protected |
The underlying text layout (the text and font are accessed from here)
|
protected |
The position to place the origin of the layout (in Node coordinates)
|
protected |
The bottom padding offset
|
protected |
The left padding offset
|
protected |
The right padding offset
|
protected |
The top padding offset
|
protected |
Whether or not the glyphs have been rendered
|
protected |
The source factor for the blend function