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

#include <CUSlider.h>

Inheritance diagram for cugl::scene2::Slider:
cugl::scene2::SceneNode

Public Types

typedef std::function< void(const std::string &name, float value)> Listener
 

Public Member Functions

 Slider ()
 
 ~Slider ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool init (const Vec2 range, const Rect bounds)
 
bool initWithUI (const Vec2 range, const Rect bounds, const std::shared_ptr< SceneNode > &path, const std::shared_ptr< Button > &knob)
 
bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
float getMinValue () const
 
void setMinValue (float value)
 
float getMaxValue () const
 
void setMaxValue (float value)
 
const Vec2 getRange () const
 
void setRange (const Vec2 range)
 
void setRange (float min, float max)
 
float getValue () const
 
void setValue (float value)
 
const std::shared_ptr< Button > & getKnob () const
 
void setKnob (const std::shared_ptr< Button > &knob)
 
const std::shared_ptr< SceneNode > & getPath () const
 
void setPath (const std::shared_ptr< SceneNode > &path)
 
const Rect getBounds () const
 
void getBounds (const Rect value)
 
float getTick () const
 
void setTick (float value)
 
bool hasSnap () const
 
void snapTick (bool value)
 
bool hasListener () const
 
const Listener getListener (Uint32 key) const
 
const std::vector< ListenergetListeners () const
 
Uint32 addListener (Listener listener)
 
bool removeListener (Uint32 key)
 
void clearListeners ()
 
bool activate ()
 
bool deactivate ()
 
bool isActive () const
 
- 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< Slideralloc ()
 
static std::shared_ptr< Slideralloc (const Vec2 range, const Rect bounds)
 
static std::shared_ptr< SliderallocWithUI (const Vec2 range, const Rect bounds, const std::shared_ptr< SceneNode > &path, const std::shared_ptr< Button > &knob)
 
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 Member Functions

float validate (float value) const
 
void reconfigure ()
 
void reposition ()
 
void dragKnob (const Vec2 pos)
 
void placeKnob (const std::shared_ptr< Button > &knob)
 
void placePath (const std::shared_ptr< SceneNode > &path)
 

Protected Attributes

float _value
 
Vec2 _range
 
std::shared_ptr< Button_knob
 
std::shared_ptr< SceneNode_path
 
Rect _bounds
 
Rect _adjust
 
float _tick
 
bool _snap
 
bool _active
 
bool _mouse
 
Vec2 _dragpos
 
Uint32 _inputkey
 
Uint32 _nextKey
 
std::unordered_map< Uint32, Listener_listeners
 
- 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 represents a slider, allowing the user to drag a knob to select a value.

A slider is defined by a knob and path. Each of these are a distinct scene graph node. If these are not specified, the class constructs a simple slider with a circle on a line.

The most important attribute for a slider is the bounds attribute. This rectangle defines the slideable region inside of the path node. This allows us to have complex path nodes with tick marks and other features that prevent ths slider from being centered in the node. It also allows us to define sliders with any orientation. The bottom left corner of the bounds rectangle is the minimum value while the top right is the maximum.

The user can also specify a tick interval that allows the slider to snap to predefined values. This is useful in preventing the slider values from being resolution dependent. However, the class will not automatically disolay tick marks. If you wish to display tick marks, you must add them to the path node.

The slider can track its own state, via the activate() method, relieving you of having to manually check presses and drags. However, the appropriate input device must be active before you can activate the slider, as it needs to attach internal listeners.

Member Typedef Documentation

◆ Listener

This type represents a listener for a value change in Slider.

In CUGL, listeners are implemented as a set of callback functions, not as objects. This allows each listener to implement as much or as little functionality as it wants. For simplicity, Slider nodes only support a single listener. If you wish for more than one listener, then your listener should handle its own dispatch.

The function type is equivalent to

 std::function<void (const std::string& name, float value)>
Parameters
nameThe alider name
valueChanged value of slider

Constructor & Destructor Documentation

◆ Slider()

cugl::scene2::Slider::Slider ( )

Creates an uninitialized slider. You must initialize it 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.

◆ ~Slider()

cugl::scene2::Slider::~Slider ( )
inline

Deletes this slider, disposing all resources

It is unsafe to call this on a slider that is still currently inside of a scene graph.

Member Function Documentation

◆ activate()

bool cugl::scene2::Slider::activate ( )

Activates this slider to enable dragging.

This method attaches a listener to either the Mouse or Touchscreen inputs to monitor when the slider is dragged. The slider will favor the mouse, but will use the touch screen if no mouse input is active. If neither input is active, this method will fail.

When active, the slider will change its value on its own, without requiring the user to use setValue(float). If there is a Listener attached, it will call that function upon any state changes.

Returns
true if the slider was successfully activated

◆ addListener()

Uint32 cugl::scene2::Slider::addListener ( Listener  listener)

Returns a key for a listener after adding it to this button.

This listener is invoked when the slider value changes.

C++ cannot hash functions types. Therefore, the listener will be identified by a unique key, returned by this function. You should remember this key to remove the listener if necessary.

Parameters
listenerThe listener to add
Returns
the key for the listener

◆ alloc() [1/2]

static std::shared_ptr<Slider> cugl::scene2::Slider::alloc ( )
inlinestatic

Returns a newly allocated slider with the default values.

This initializer will create a horizontal slider from 0 to 100. It will assign one pixel to each value. The knob radius will be 20.

Returns
a newly allocated slider with the default values.

◆ alloc() [2/2]

static std::shared_ptr<Slider> cugl::scene2::Slider::alloc ( const Vec2  range,
const Rect  bounds 
)
inlinestatic

Returns a newly allocated slider with given bounds.

The slider visuals will be interpretted from bounds. The knob will be a circle whose radius is the maximum of x and y, where (x,y) is the bounds origin. The path will be a simple line, but it will be surrounded by a transparent "track" which tightly fits the knob.

The range is the slider value range. The x value is the minimum value (corresponding to the bottom left corner of bounds) and the y value is the maximum value (corresponding to the top right corner of bounds). The slider will start at the middle value.

Parameters
rangeThe slider value range
boundsThe slider path
Returns
a newly allocated slider with given bounds.

◆ allocWithData()

static std::shared_ptr<SceneNode> cugl::scene2::Slider::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:

 "bounds":   A 4-element array of numbers (x,y,width,height)
 "range":    A 2-element array of numbers (min,max)
 "value':    A number representing the initial value
 "tick':     A number greater than 0, representing the tick period
 "snap":     A boolean indicating whether to snap to a nearest tick
 "knob":     A JSON object defining a scene graph node
 "path":     A JSON object defining a scene graph node OR

The attribute 'bounds' is REQUIRED. All other attributes are optional.

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

◆ allocWithUI()

static std::shared_ptr<Slider> cugl::scene2::Slider::allocWithUI ( const Vec2  range,
const Rect  bounds,
const std::shared_ptr< SceneNode > &  path,
const std::shared_ptr< Button > &  knob 
)
inlinestatic

Returns a newly allocated slider with given scene graph nodes.

The slider visuals will be taken from the scene graph nodes knob and path. The rectangle bounds should define an interior region of path. The knob graph node can be slid from the origing of bounds to the top right corner.

The range is the slider value range. The x value is the minimum value (corresponding to the bottom left corner of bounds) and the y value is the maximum value (corresponding to the top right corner of bounds). The slider will start at the middle value.

Parameters
rangeThe slider value range
boundsThe slider path
pathThe scene graph node for the path
knobThe scene graph node for the knob
Returns
a newly allocated slider with given scene graph nodes.

◆ clearListeners()

void cugl::scene2::Slider::clearListeners ( )

Clears all listeners for this slider.

These listeners are invoked when the slider value changes. This method does not require you to remember the keys assigned to the individual listeners.

Returns
true if the listener was succesfully removed

◆ deactivate()

bool cugl::scene2::Slider::deactivate ( )

Deactivates this slider, unable to drag from then on.

This method removes its internal listener from either the Mouse or Touchscreen.

When deactivated, the slider will no longer change value on its own. However, the user can still change manually with the setValue(float) method. In addition, any Listener attached will still respond to manual state changes.

Returns
true if the slider was successfully deactivated

◆ dispose()

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

Disposes all of the resources used.

A disposed slider can be safely reinitialized. Any child will be released. They will be deleted if no other object owns them.

It is unsafe to call this on a slider that is still currently inside of a scene graph.

Reimplemented from cugl::scene2::SceneNode.

◆ dragKnob()

void cugl::scene2::Slider::dragKnob ( const Vec2  pos)
protected

Drags the knob to the given position.

This method is called by the touch listeners and assumes that an initial drag anchor has been set. The position defines a drag vector that is projected on to the sliding bounds.

Parameters
posThe position to drag to (if in the sliding bounds)

◆ getBounds() [1/2]

const Rect cugl::scene2::Slider::getBounds ( ) const
inline

Returns the sliding bounds

This rectangle defines the slideable region inside of the path node. The bottom left corner of the bounds rectangle is the minimum value while the top right is the maximum. While the origin should have positive values either the width or height may be negative.

The bounds should be inside of the bounding box of the path node. However, this is not enforced.

Returns
the sliding bounds

◆ getBounds() [2/2]

void cugl::scene2::Slider::getBounds ( const Rect  value)
inline

Sets the sliding bounds

This rectangle defines the slideable region inside of the path node. The bottom left corner of the bounds rectangle is the minimum value while the top right is the maximum. While the origin should have positive values either the width or height may be negative.

The bounds should be inside of the bounding box of the path node. However, this is not enforced.

Parameters
valueThe new sliding bounds

◆ getKnob()

const std::shared_ptr<Button>& cugl::scene2::Slider::getKnob ( ) const
inline

Returns the scene graph node for the knob.

It is safe to make changes to the knob so long as you do not resize it it or scale it. Doing so will mess up the slider visuals.

Returns
the scene graph node for the knob.

◆ getListener()

const Listener cugl::scene2::Slider::getListener ( Uint32  key) const

Returns the listener for the given key

This listener is invoked when the slider value changes.

If there is no listener for the given key, it returns nullptr.

Parameters
keyThe identifier for the listener
Returns
the listener for the given key

◆ getListeners()

const std::vector<Listener> cugl::scene2::Slider::getListeners ( ) const

Returns all listeners for this slider

These listeners are invoked when the slider value changes.

Returns
the listeners for this slider

◆ getMaxValue()

float cugl::scene2::Slider::getMaxValue ( ) const
inline

Returns the maximum possible slider value.

This is the value when the slider is at the top right corner of the bounds.

Returns
the maximum possible slider value.

◆ getMinValue()

float cugl::scene2::Slider::getMinValue ( ) const
inline

Returns the minimum possible slider value.

This is the value when the slider is at the bottom left corner of the bounds.

Returns
the minimum possible slider value.

◆ getPath()

const std::shared_ptr<SceneNode>& cugl::scene2::Slider::getPath ( ) const
inline

Returns the scene graph node for the path.

It is safe to make changes to the path so long as you do not resize it it or scale it. Doing so will mess up the slider visuals.

Returns
the scene graph node for the path.

◆ getRange()

const Vec2 cugl::scene2::Slider::getRange ( ) const
inline

Returns the range of possible slider values.

The x coordinate is the minimum value while the y coordinate is the maximum value.

Returns
the range of possible slider values.

◆ getTick()

float cugl::scene2::Slider::getTick ( ) const
inline

Returns the tick period of this slider.

The tick period is used to set a course granularity on the slider. Without it, each pixel is essentially its own value. However, the tick period is irrelevant unless the slider is set to snap to a tick.

When the slider does snap to a tick, it snaps to the nearest value min + k * tick where k is an non-negative integer. If this value is greater than max, then it will snap to the max.

The tick period should be nonnegative, but this is not enforced. A negative tick value will always snap to the minimum value.

Returns
the tick period of this slider.

◆ getValue()

float cugl::scene2::Slider::getValue ( ) const
inline

Returns the current slider value.

Returns
the current slider value.

◆ hasListener()

bool cugl::scene2::Slider::hasListener ( ) const
inline

Returns true if this slider has a listener

This listener is invoked when the slider value changes.

Returns
true if this slider has a listener

◆ hasSnap()

bool cugl::scene2::Slider::hasSnap ( ) const
inline

Returns whether the slider will snap to a tick mark.

When the slider does snap to a tick, it snaps to the nearest value min + k * tick where k is an non-negative integer. If this value is greater than max, then it will snap to the max.

Returns
true if the slider will snap to a tick mark; false otherwise

◆ init() [1/2]

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

Initializes a slider with the default values.

This initializer will create a horizontal slider from 0 to 100. It will assign one pixel to each value. The knob radius will be 20.

Returns
true if the button is initialized properly, false otherwise.

Reimplemented from cugl::scene2::SceneNode.

◆ init() [2/2]

bool cugl::scene2::Slider::init ( const Vec2  range,
const Rect  bounds 
)

Initializes a slider with given bounds.

The slider visuals will be interpretted from bounds. The knob will be a circle whose radius is the maximum of x and y, where (x,y) is the bounds origin. The path will be a simple line, but it will be surrounded by a transparent "track" which tightly fits the knob.

The range is the slider value range. The x value is the minimum value (corresponding to the bottom left corner of bounds) and the y value is the maximum value (corresponding to the top right corner of bounds). The slider will start at the middle value.

Parameters
rangeThe slider value range
boundsThe slider path
Returns
true if the slider is initialized properly, false otherwise.

◆ initWithData()

bool cugl::scene2::Slider::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:

 "bounds":   A 4-element array of numbers (x,y,width,height)
 "range":    A 2-element array of numbers (min,max)
 "value':    A number representing the initial value
 "tick':     A number greater than 0, representing the tick period
 "snap":     A boolean indicating whether to snap to a nearest tick
 "knob":     A JSON object defining a scene graph node
 "path":     A JSON object defining a scene graph node OR

The attribute 'bounds' is REQUIRED. All other attributes are optional.

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.

◆ initWithUI()

bool cugl::scene2::Slider::initWithUI ( const Vec2  range,
const Rect  bounds,
const std::shared_ptr< SceneNode > &  path,
const std::shared_ptr< Button > &  knob 
)

Initializes a slider with given scene graph nodes.

The slider visuals will be taken from the scene graph nodes knob and path. The rectangle bounds should define an interior region of path. The knob graph node can be slid from the origing of bounds to the top right corner.

The range is the slider value range. The x value is the minimum value (corresponding to the bottom left corner of bounds) and the y value is the maximum value (corresponding to the top right corner of bounds). The slider will start at the middle value.

Parameters
rangeThe slider value range
boundsThe slider path
pathThe scene graph node for the path
knobThe scene graph node for the knob
Returns
true if the slider is initialized properly, false otherwise.

◆ isActive()

bool cugl::scene2::Slider::isActive ( ) const
inline

Returns true if this slider has been activated.

Returns
true if this slider has been activated.

◆ placeKnob()

void cugl::scene2::Slider::placeKnob ( const std::shared_ptr< Button > &  knob)
protected

Sets the scene graph node for the knob.

If this value is nullptr, the method will construct a default knob scene graph consisting of a simple circle.

Unlike setKnob(), this does not resize the bounding box.

Parameters
knobThe new scene graph node for the knob.

◆ placePath()

void cugl::scene2::Slider::placePath ( const std::shared_ptr< SceneNode > &  path)
protected

Sets the scene graph node for the path.

If this value is nullptr, the method will construct a default path scene graph consisting of a simple line and a semi-transparent track.

Unlike setPath(), this does not resize the bounding box.

Parameters
pathThe new scene graph node for the path.

◆ reconfigure()

void cugl::scene2::Slider::reconfigure ( )
protected

Resizes the node and arranges the position of the knob and path.

This method is called whenever the bounds or scene graph changes.

◆ removeListener()

bool cugl::scene2::Slider::removeListener ( Uint32  key)

Removes a listener from this slider.

This listener is invoked when the button state changes (up or down).

Listeners must be identified by the key returned by the addListener method. If this slider does not have a listener for the given key, this method will fail.

Parameters
keyThe key of the listener to remove
Returns
true if the listener was succesfully removed

◆ reposition()

void cugl::scene2::Slider::reposition ( )
protected

Repositions the knob to reflect a change in value.

This method is called whenever the value or its range changes.

◆ setKnob()

void cugl::scene2::Slider::setKnob ( const std::shared_ptr< Button > &  knob)
inline

Sets the scene graph node for the knob.

If this value is nullptr, the method will construct a default knob scene graph consisting of a simple circle.

Changing the knob may resize the bounding box of the slider. The slider tries to ensure that the knob remains inside of the bounding box no matter its position.

Parameters
knobThe new scene graph node for the knob.

◆ setMaxValue()

void cugl::scene2::Slider::setMaxValue ( float  value)
inline

Sets the maximum possible slider value.

This is the value when the slider is at the top right corner of the bounds.

Parameters
valueThe maximum possible slider value.

◆ setMinValue()

void cugl::scene2::Slider::setMinValue ( float  value)
inline

Sets the minimum possible slider value.

This is the value when the slider is at the bottom left corner of the bounds.

Parameters
valueThe minimum possible slider value.

◆ setPath()

void cugl::scene2::Slider::setPath ( const std::shared_ptr< SceneNode > &  path)
inline

Sets the scene graph node for the path.

If this value is nullptr, the method will construct a default path scene graph consisting of a simple line and a semi-transparent track.

Changing the knob may resize the bounding box of the slider. The slider tries to ensure that the entire path remains inside of the bounding box.

Parameters
pathThe new scene graph node for the path.

◆ setRange() [1/2]

void cugl::scene2::Slider::setRange ( const Vec2  range)
inline

Sets the range of possible slider values.

The x coordinate is the minimum value while the y coordinate is the maximum value.

Parameters
rangeThe range of possible slider values.

◆ setRange() [2/2]

void cugl::scene2::Slider::setRange ( float  min,
float  max 
)
inline

Sets the range of possible slider values.

The minimum is the value when the slider is at the bottom left corner of the bounds and the maximum is when the slider is in the top right corner.

Parameters
minThe minimum possible slider value.
maxThe maximum possible slider value.

◆ setTick()

void cugl::scene2::Slider::setTick ( float  value)
inline

Sets the tick period of this slider.

The tick period is used to set a course granularity on the slider. Without it, each pixel is essentially its own value. However, the tick period is irrelevant unless the slider is set to snap to a tick.

When the slider does snap to a tick, it snaps to the nearest value min + k * tick where k is an non-negative integer. If this value is greater than max, then it will snap to the max.

The tick period should be nonnegative, but this is not enforced. A negative tick value will always snap to the minimum value.

Parameters
valueThe tick period of this slider.

◆ setValue()

void cugl::scene2::Slider::setValue ( float  value)
inline

Sets the current slider value.

If the slider is set to snap to ticks, this will assign the value to the nearest tick. In addition, if the value is out of range, it will snap to the nearest value in range.

Parameters
valueThe slider value

◆ snapTick()

void cugl::scene2::Slider::snapTick ( bool  value)
inline

Sets whether the slider will snap to a tick mark.

When the slider does snap to a tick, it snaps to the nearest value min + k * tick where k is an non-negative integer. If this value is greater than max, then it will snap to the max.

Parameters
valueWhether the slider will snap to a tick mark.

◆ validate()

float cugl::scene2::Slider::validate ( float  value) const
protected

Returns the correct value nearest the given one.

This method is used to snap values to the grid of ticks, as well as keep the value in range.

Parameters
valueThe candidate value
Returns
the nearest correct value.

Member Data Documentation

◆ _active

bool cugl::scene2::Slider::_active
protected

Whether the slider is actively checking input

◆ _adjust

Rect cugl::scene2::Slider::_adjust
protected

The adjusted slider path, if padding is necessary

◆ _bounds

Rect cugl::scene2::Slider::_bounds
protected

The slider path, defined relative to the background widget

◆ _dragpos

Vec2 cugl::scene2::Slider::_dragpos
protected

The anchoring touch or mouse position in a drag

◆ _inputkey

Uint32 cugl::scene2::Slider::_inputkey
protected

The listener key when the text field is checking for events

◆ _knob

std::shared_ptr<Button> cugl::scene2::Slider::_knob
protected

The knob widget for this slider

◆ _listeners

std::unordered_map<Uint32,Listener> cugl::scene2::Slider::_listeners
protected

Listener for this slider, which will be called when value is changed

◆ _mouse

bool cugl::scene2::Slider::_mouse
protected

Whether we are using the mouse (as opposed to the touch screen)

◆ _nextKey

Uint32 cugl::scene2::Slider::_nextKey
protected

The next available key for a listener

◆ _path

std::shared_ptr<SceneNode> cugl::scene2::Slider::_path
protected

The background widget for this slider

◆ _range

Vec2 cugl::scene2::Slider::_range
protected

The value range of the slider (x is min and y is max)

◆ _snap

bool cugl::scene2::Slider::_snap
protected

Whether to snap the slider to a tick value

◆ _tick

float cugl::scene2::Slider::_tick
protected

The (optional) )tick period for this slider

◆ _value

float cugl::scene2::Slider::_value
protected

The current value of the slider


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