CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::ProgressBar Class Reference

#include <CUProgressBar.h>

Inheritance diagram for cugl::scene2::ProgressBar:
cugl::scene2::SceneNode

Public Member Functions

 ProgressBar ()
 
 ~ProgressBar ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool init (const Size size)
 
bool init (const std::shared_ptr< Texture > &background)
 
bool init (const std::shared_ptr< Texture > &background, const Size size)
 
bool init (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground)
 
bool init (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const Size size)
 
bool initWithCaps (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const std::shared_ptr< Texture > &beginCap, const std::shared_ptr< Texture > &finalCap)
 
bool initWithCaps (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const std::shared_ptr< Texture > &beginCap, const std::shared_ptr< Texture > &finalCap, const Size size)
 
bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
float getProgress () const
 
void setProgress (float progress)
 
Color4 getBackgroundColor () const
 
void setBackgroundColor (Color4 color)
 
Color4 getForegroundColor () const
 
void setForegroundColor (Color4 color)
 
- Public Member Functions inherited from cugl::scene2::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual bool initWithPosition (const Vec2 pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size size)
 
virtual bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect rect)
 
virtual bool initWithBounds (float x, float y, float width, float height)
 
virtual std::shared_ptr< SceneNodecopy (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
 
virtual void setContentSize (const Size size)
 
virtual void setContentSize (float width, float height)
 
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< ScissorgetScissor () 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 Affine2getTransform () const
 
const Affine2getAlternateTransform () const
 
void setAlternateTransform (const Affine2 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Affine2getNodeToParentTransform () 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< SceneNodegetChild (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< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (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)
 
SceneNodegetParent ()
 
const SceneNodegetParent () const
 
Scene2getScene ()
 
const Scene2getScene () 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)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint)
 
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< ProgressBaralloc (const Size size)
 
static std::shared_ptr< ProgressBaralloc (const std::shared_ptr< Texture > &background)
 
static std::shared_ptr< ProgressBaralloc (const std::shared_ptr< Texture > &background, const Size size)
 
static std::shared_ptr< ProgressBaralloc (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground)
 
static std::shared_ptr< ProgressBaralloc (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const Size size)
 
static std::shared_ptr< ProgressBarallocWithCaps (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const std::shared_ptr< Texture > &beginCap, const std::shared_ptr< Texture > &finalCap)
 
static std::shared_ptr< ProgressBarallocWithCaps (const std::shared_ptr< Texture > &background, const std::shared_ptr< Texture > &foreground, const std::shared_ptr< Texture > &beginCap, const std::shared_ptr< Texture > &finalCap, const Size size)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::scene2::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec2 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Size size)
 
static std::shared_ptr< SceneNodeallocWithBounds (float width, float height)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 

Protected Attributes

float _progress
 
Size _foresize
 
std::shared_ptr< PolygonNode_background
 
std::shared_ptr< PolygonNode_foreground
 
std::shared_ptr< PolygonNode_begincap
 
std::shared_ptr< PolygonNode_finalcap
 
- 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
 

Detailed Description

This class is a node the represents an (animating) project bar.

The progress bar may either be represented via a texture or a simple colored rectangle. If it is a texture, the foreground texture will be sampled left to right and the maximum horizontal texture coordinate will be the percentage of the progress bar. So if the progress bar is at 50%, the progress bar will draw the left side of the foreground texture.

When using textures it is also possible to specify endcap textures. This allows for progress bars that are not completely rectangular.

Constructor & Destructor Documentation

◆ ProgressBar()

cugl::scene2::ProgressBar::ProgressBar ( )
inline

Creates an uninitialized progress bar with no size or texture information.

You must initialize this progress bar 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.

◆ ~ProgressBar()

cugl::scene2::ProgressBar::~ProgressBar ( )
inline

Deletes this progress bar, disposing all resources

Member Function Documentation

◆ alloc() [1/5]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::alloc ( const Size  size)
inlinestatic

Returns a newly allocated texture-less progress bar of the given size.

The background will be a white rectangle, while the foreground (measuring progess) will be a red rectangle. You can change these colors with the setBackgroundColor and setForegroundColor methods.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
sizeThe progress bar size
Returns
a newly allocated texture-less progress bar of the given size.

◆ alloc() [2/5]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::alloc ( const std::shared_ptr< Texture > &  background)
inlinestatic

Returns a newly allocated progress bar with the given texture.

The progress bar will be the size of the texture. It will use the same texture for the background and foreground. However, the foreground (measuring progress) will be tinted red. You can change this color with the setForegroundColor method.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe progress bar texture
Returns
a newly allocated progress bar with the given texture.

◆ alloc() [3/5]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::alloc ( const std::shared_ptr< Texture > &  background,
const Size  size 
)
inlinestatic

Returns a newly allocated progress bar with the given texture and size

The progress bar texture will scale to the given size. It will use the same texture for the background and foreground. However, the foreground (measuring progress) will be tinted red. You can change this color with the setForegroundColor method.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe progress bar texture
sizeThe progress bar size
Returns
a newly allocated progress bar with the given texture and size

◆ alloc() [4/5]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::alloc ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground 
)
inlinestatic

Returns a newly allocated progress bar with the given background and foreground.

The progress bar will be the size of the background texture. The foreground texture will be scaled to this size. Neither the background nor the foreground texture will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
Returns
a newly allocated progress bar with the given background and foreground.

◆ alloc() [5/5]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::alloc ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const Size  size 
)
inlinestatic

Returns a newly allocated progress bar with the given textures and size.

The progress bar will scale both the background and foreground texture. to the given size. Neither the background nor the foreground texture will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
sizeThe progress bar size
Returns
a newly allocated progress bar with the given textures and size.

◆ allocWithCaps() [1/2]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::allocWithCaps ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const std::shared_ptr< Texture > &  beginCap,
const std::shared_ptr< Texture > &  finalCap 
)
inlinestatic

Returns a newly allocated progress bar with the given textures and size.

The progress bar will be the size of the background texture. The foreground texture and end caps will be scaled so that they are this size when combined together. None of the textures will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
beginCapThe left end cap of the foreground
finalCapThe right end cap of the foreground
Returns
a newly allocated progress bar with the given textures and size.

◆ allocWithCaps() [2/2]

static std::shared_ptr<ProgressBar> cugl::scene2::ProgressBar::allocWithCaps ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const std::shared_ptr< Texture > &  beginCap,
const std::shared_ptr< Texture > &  finalCap,
const Size  size 
)
inlinestatic

Returns a newly allocated progress bar with the given textures and size.

The progress bar will scale the background texture to the given size. The foreground texture and end caps will be scaled so that they are this size when combined together. None of the textures will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
beginCapThe left end cap of the foreground
finalCapThe right end cap of the foreground
sizeThe progress bar size
Returns
a newly allocated progress bar with the given textures and size.

◆ allocWithData()

static std::shared_ptr<SceneNode> cugl::scene2::ProgressBar::allocWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
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:

 "foreground":   The name of a previously loaded texture asset
 "background":   The name of a previously loaded texture asset
 "left_cap":     The name of a previously loaded texture asset
 "right_cap":    The name of a previously loaded texture asset

All attributes are optional. There are no required attributes.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
a newly allocated node with the given JSON specificaton.

◆ dispose()

virtual void cugl::scene2::ProgressBar::dispose ( )
overridevirtual

Disposes all of the resources used by this node.

A disposed progress bar 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 progress bar that is still currently inside of a scene graph.

Reimplemented from cugl::scene2::SceneNode.

◆ getBackgroundColor()

Color4 cugl::scene2::ProgressBar::getBackgroundColor ( ) const
inline

Returns the background color or tint of the progress bar

This is the color applied to the background texture if it exists, or the color of the background rectangle. It is white by default.

Returns
the background color or tint of the progress bar

◆ getForegroundColor()

Color4 cugl::scene2::ProgressBar::getForegroundColor ( ) const
inline

Returns the foreground color or tint of the progress bar

This is the color applied to the foreground texture (and end caps) if it exists, or the color of the foreground rectangle. If there is a texture it is white by default. Otherwise it is red by default.

Returns
the foreground color or tint of the progress bar

◆ getProgress()

float cugl::scene2::ProgressBar::getProgress ( ) const
inline

Returns the percentage progress of this progress bar

This value is a float between 0 and 1. Changing this value will alter the size of the progress bar foreground.

Returns
the percentage progress of this progress bar

◆ init() [1/6]

virtual bool cugl::scene2::ProgressBar::init ( )
inlineoverridevirtual

Deactivates the default initializer.

This initializer may not be used for a progress bar. A progress bar either needs a texture or a size

Returns
false

Reimplemented from cugl::scene2::SceneNode.

◆ init() [2/6]

bool cugl::scene2::ProgressBar::init ( const Size  size)
inline

Initializes a texture-less progress bar of the given size.

The background will be a white rectangle, while the foreground (measuring progess) will be a red rectangle. You can change these colors with the setBackgroundColor and setForegroundColor methods.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.

◆ init() [3/6]

bool cugl::scene2::ProgressBar::init ( const std::shared_ptr< Texture > &  background)
inline

Initializes a progress bar with the given texture.

The progress bar will be the size of the texture. It will use the same texture for the background and foreground. However, the foreground (measuring progress) will be tinted red. You can change this color with the setForegroundColor method.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe progress bar texture
Returns
true if the progress bar is initialized properly, false otherwise.

◆ init() [4/6]

bool cugl::scene2::ProgressBar::init ( const std::shared_ptr< Texture > &  background,
const Size  size 
)
inline

Initializes a progress bar with the given texture and size

The progress bar texture will scale to the given size. It will use the same texture for the background and foreground. However, the foreground (measuring progress) will be tinted red. You can change this color with the setForegroundColor method.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe progress bar texture
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.

◆ init() [5/6]

bool cugl::scene2::ProgressBar::init ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground 
)
inline

Initializes a progress bar with the given background and foreground.

The progress bar will be the size of the background texture. The foreground texture will be scaled to this size. Neither the background nor the foreground texture will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
Returns
true if the progress bar is initialized properly, false otherwise.

◆ init() [6/6]

bool cugl::scene2::ProgressBar::init ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const Size  size 
)
inline

Initializes a progress bar with the given textures and size.

The progress bar will scale both the background and foreground texture. to the given size. Neither the background nor the foreground texture will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.

◆ initWithCaps() [1/2]

bool cugl::scene2::ProgressBar::initWithCaps ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const std::shared_ptr< Texture > &  beginCap,
const std::shared_ptr< Texture > &  finalCap 
)

Initializes a progress bar with the given textures and size.

The progress bar will be the size of the background texture. The foreground texture and end caps will be scaled so that they are this size when combined together. None of the textures will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
beginCapThe left end cap of the foreground
finalCapThe right end cap of the foreground
Returns
true if the progress bar is initialized properly, false otherwise.

◆ initWithCaps() [2/2]

bool cugl::scene2::ProgressBar::initWithCaps ( const std::shared_ptr< Texture > &  background,
const std::shared_ptr< Texture > &  foreground,
const std::shared_ptr< Texture > &  beginCap,
const std::shared_ptr< Texture > &  finalCap,
const Size  size 
)

Initializes a progress bar with the given textures and size.

The progress bar will scale the background texture to the given size.
The foreground texture and end caps will be scaled so that they are this size when combined together. None of the textures will be tinted.

The progress bar will be placed at the origin of the parent and by anchored at the bottom left.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
beginCapThe left end cap of the foreground
finalCapThe right end cap of the foreground
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.

◆ initWithData()

bool cugl::scene2::ProgressBar::initWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
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:

 "foreground":   The name of a previously loaded texture asset
 "background":   The name of a previously loaded texture asset
 "left_cap":     The name of a previously loaded texture asset
 "right_cap":    The name of a previously loaded texture asset

All attributes are optional. There are no required attributes.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::SceneNode.

◆ setBackgroundColor()

void cugl::scene2::ProgressBar::setBackgroundColor ( Color4  color)
inline

Sets the background color or tint of the progress bar

This is the color applied to the background texture if it exists, or the color of the background rectangle. It is white by default.

Parameters
colorThe background color or tint of the progress bar

◆ setForegroundColor()

void cugl::scene2::ProgressBar::setForegroundColor ( Color4  color)

Sets the foreground color or tint of the progress bar

This is the color applied to the foreground texture (and end caps) if it exists, or the color of the foreground rectangle. If there is a texture it is white by default. Otherwise it is red by default.

Parameters
colorThe foreground color or tint of the progress bar

◆ setProgress()

void cugl::scene2::ProgressBar::setProgress ( float  progress)

Sets the percentage progress of this progress bar

This value is a float between 0 and 1. Changing this value will alter the size of the progress bar foreground.

Parameters
progressThe percentage progress of this progress bar

Member Data Documentation

◆ _background

std::shared_ptr<PolygonNode> cugl::scene2::ProgressBar::_background
protected

The background image or rectangle (representing total time)

◆ _begincap

std::shared_ptr<PolygonNode> cugl::scene2::ProgressBar::_begincap
protected

The starting endcap image

◆ _finalcap

std::shared_ptr<PolygonNode> cugl::scene2::ProgressBar::_finalcap
protected

The finishing endcap image

◆ _foreground

std::shared_ptr<PolygonNode> cugl::scene2::ProgressBar::_foreground
protected

The foreground image or rectangle (representing progress)

◆ _foresize

Size cugl::scene2::ProgressBar::_foresize
protected

The (maximum) size of the foreground texture or node

◆ _progress

float cugl::scene2::ProgressBar::_progress
protected

The progress percentage of this progress bar (between 0 and 1)


The documentation for this class was generated from the following file: