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

#include <CUProgressBar.h>

Inheritance diagram for cugl::ProgressBar:
cugl::Node

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)
 
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::Node
 Node ()
 
virtual ~Node ()
 
virtual bool initWithPosition (const Vec2 &pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size &size)
 
bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect &rect)
 
bool initWithBounds (float x, float y, float width, float height)
 
virtual Nodecopy (Node *dst)
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Vec2getPosition () 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 SizegetContentSize () 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)
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
virtual void setAnchor (const Vec2 &anchor)
 
void setAnchor (float x, float y)
 
const Vec2getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor ()
 
void setRelativeColor (bool flag)
 
const Vec2getScale () 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 Mat4getAlternateTransform ()
 
void setAlternateTransform (const Mat4 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Mat4getNodeToParentTransform () const
 
Mat4 getParentToNodeTransform () const
 
Mat4 getNodeToWorldTransform () const
 
Mat4 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
 
void setZOrder (int z)
 
int getZOrder () const
 
bool isZDirty () const
 
void sortZOrder ()
 
size_t getChildCount () const
 
std::shared_ptr< NodegetChild (unsigned int pos)
 
const std::shared_ptr< Node > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< TgetChild (unsigned int pos) const
 
std::shared_ptr< NodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< TgetChildByTag (unsigned int tag) const
 
std::shared_ptr< NodegetChildByName (const std::string &name) const
 
template<typename T >
std::shared_ptr< TgetChildByName (const std::string &name) const
 
std::vector< std::shared_ptr< Node > > getChildren ()
 
const std::vector< std::shared_ptr< Node > > & getChildren () const
 
void addChild (std::shared_ptr< Node > child)
 
virtual void addChild (const std::shared_ptr< Node > &child, int zval)
 
void addChildWithTag (const std::shared_ptr< Node > &child, unsigned int tag)
 
void addChildWithTag (const std::shared_ptr< Node > &child, unsigned int tag, int zval)
 
void addChildWithName (const std::shared_ptr< Node > &child, const std::string &name)
 
void addChildWithName (const std::shared_ptr< Node > &child, const std::string &name, int zval)
 
void swapChild (const std::shared_ptr< Node > &child1, const std::shared_ptr< Node > &child2, bool inherit=false)
 
NodegetParent ()
 
const NodegetParent () const
 
ScenegetScene ()
 
const ScenegetScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< Node > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string &name)
 
virtual void removeAllChildren ()
 
void render (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint)
 
void render (const std::shared_ptr< SpriteBatch > &batch)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint)
 

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 Public Member Functions inherited from cugl::Node
static std::shared_ptr< Nodealloc ()
 
static std::shared_ptr< NodeallocWithPosition (const Vec2 &pos)
 
static std::shared_ptr< NodeallocWithPosition (float x, float y)
 
static std::shared_ptr< NodeallocWithBounds (const Size &size)
 
static std::shared_ptr< NodeallocWithBounds (float width, float height)
 
static std::shared_ptr< NodeallocWithBounds (const Rect &rect)
 
static std::shared_ptr< NodeallocWithBounds (float x, float y, float width, float height)
 

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::Node
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
Vec2 _scale
 
float _angle
 
Mat4 _transform
 
bool _useTransform
 
Mat4 _combined
 
std::vector< std::shared_ptr< Node > > _children
 
Node_parent
 
Scene_graph
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
int _zOrder
 
bool _zDirty
 

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

cugl::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.

cugl::ProgressBar::~ProgressBar ( )
inline

Deletes this progress bar, disposing all resources

Member Function Documentation

static std::shared_ptr<ProgressBar> cugl::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.

Parameters
sizeThe progress bar size
Returns
a newly allocated texture-less progress bar of the given size.
static std::shared_ptr<ProgressBar> cugl::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.

Parameters
backgroundThe progress bar texture
Returns
a newly allocated progress bar with the given texture.
static std::shared_ptr<ProgressBar> cugl::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.

Parameters
backgroundThe progress bar texture
sizeThe progress bar size
Returns
a newly allocated progress bar with the given texture and size
static std::shared_ptr<ProgressBar> cugl::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.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
Returns
a newly allocated progress bar with the given background and foreground.
static std::shared_ptr<ProgressBar> cugl::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.

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.
static std::shared_ptr<ProgressBar> cugl::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.

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.
static std::shared_ptr<ProgressBar> cugl::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.

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.
virtual void cugl::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::Node.

Color4 cugl::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
Color4 cugl::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
float cugl::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
virtual bool cugl::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::Node.

bool cugl::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.

Parameters
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.
bool cugl::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.

Parameters
backgroundThe progress bar texture
Returns
true if the progress bar is initialized properly, false otherwise.
bool cugl::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.

Parameters
backgroundThe progress bar texture
sizeThe progress bar size
Returns
true if the progress bar is initialized properly, false otherwise.
bool cugl::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.

Parameters
backgroundThe texture for the background
foregroundThe texture for the animated foreground
Returns
true if the progress bar is initialized properly, false otherwise.
bool cugl::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.

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.
bool cugl::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.

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.
bool cugl::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.

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.
void cugl::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
void cugl::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
void cugl::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

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

The background image or rectangle (representing total time)

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

The starting endcap image

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

The finishing endcap image

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

The foreground image or rectangle (representing progress)

Size cugl::ProgressBar::_foresize
protected

The (maximum) size of the foreground texture or node

float cugl::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: