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

#include <CUSlider.h>

Inheritance diagram for cugl::Slider:
cugl::Node

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< Node > &path, const std::shared_ptr< Button > &knob)
 
bool initWithData (const SceneLoader *loader, const std::shared_ptr< JsonValue > &data) override
 
float getMinValue () const
 
void setMinValue (float value)
 
float getMaxValue () const
 
void setMaxValue (float value)
 
const Vec2getRange () 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< Node > & getPath () const
 
void setPath (const std::shared_ptr< Node > &path)
 
const RectgetBounds () 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 () const
 
void setListener (Listener listener)
 
bool removeListener ()
 
bool activate (Uint32 key)
 
bool deactivate ()
 
bool isActive () const
 
- Public Member Functions inherited from cugl::Node
 Node ()
 
 ~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
 
virtual 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< T > getChild (unsigned int pos) const
 
std::shared_ptr< NodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< NodegetChildByName (const std::string &name) const
 
template<typename T >
std::shared_ptr< T > getChildByName (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 ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint)
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &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< Node > &path, const std::shared_ptr< Button > &knob)
 
static std::shared_ptr< SliderallocWithData (const SceneLoader *loader, const std::shared_ptr< JsonValue > &data)
 
- 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)
 
static std::shared_ptr< NodeallocWithData (const SceneLoader *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< Node > &path)
 

Protected Attributes

float _value
 
Vec2 _range
 
std::shared_ptr< Button_knob
 
std::shared_ptr< Node_path
 
Rect _bounds
 
Rect _adjust
 
float _tick
 
bool _snap
 
bool _active
 
bool _mouse
 
Vec2 _dragpos
 
Uint32 _inputkey
 
Listener _listener
 
- 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
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
int _zOrder
 
bool _zDirty
 

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(Uint32) 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::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::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::Slider::activate ( Uint32  key)

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.

Parameters
keyThe listener key for the input device
Returns
true if the slider was successfully activated

◆ alloc() [1/2]

static std::shared_ptr<Slider> cugl::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::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<Slider> cugl::Slider::allocWithData ( const SceneLoader 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 SceneLoader. 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::Slider::allocWithUI ( const Vec2 range,
const Rect bounds,
const std::shared_ptr< Node > &  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.

◆ deactivate()

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

◆ dragKnob()

void cugl::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::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::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::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::Slider::getListener ( ) const
inline

Returns the listener (if any) for this slider

This listener is invoked when value changes, whether active or not.

A slider may only have one listener at a time. If there is no listener, this method returns nullptr.

Returns
the listener (if any) for this slider.

◆ getMaxValue()

float cugl::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::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<Node>& cugl::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::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::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::Slider::getValue ( ) const
inline

Returns the current slider value.

Returns
the current slider value.

◆ hasListener()

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

Returns true if this slider has a listener

This listener is invoked when value changes, whether active or not.

A slider may only have one listener at a time.

Returns
true if this slider has a listener

◆ hasSnap()

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

◆ init() [2/2]

bool cugl::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::Slider::initWithData ( const SceneLoader 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 SceneLoader. 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::Node.

◆ initWithUI()

bool cugl::Slider::initWithUI ( const Vec2 range,
const Rect bounds,
const std::shared_ptr< Node > &  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::Slider::isActive ( ) const
inline

Returns true if this slider has been activated.

Returns
true if this slider has been activated.

◆ placeKnob()

void cugl::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::Slider::placePath ( const std::shared_ptr< Node > &  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::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::Slider::removeListener ( )

Removes the listener for this slider.

This listener is invoked when value changes, whether active or not.

A slider may only have one listener at a time. If slider does not have a listener, this method will fail.

Returns
true if the listener was successfully removed

◆ reposition()

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

◆ setListener()

void cugl::Slider::setListener ( Listener  listener)
inline

Sets the listener for this slider.

This listener is invoked when value changes, whether active or not.

A slider may only have one listener at a time. If this slider already has a listener, this method will replace it.

Parameters
listenerThe listener to use

◆ setMaxValue()

void cugl::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::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::Slider::setPath ( const std::shared_ptr< Node > &  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::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::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::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::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::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::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::Slider::_active
protected

Whether the slider is actively checking input

◆ _adjust

Rect cugl::Slider::_adjust
protected

The adjusted slider path, if padding is necessary

◆ _bounds

Rect cugl::Slider::_bounds
protected

The slider path, defined relative to the background widget

◆ _dragpos

Vec2 cugl::Slider::_dragpos
protected

The anchoring touch or mouse position in a drag

◆ _inputkey

Uint32 cugl::Slider::_inputkey
protected

The listener key when the text field is checking for events

◆ _knob

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

The knob widget for this slider

◆ _listener

Listener cugl::Slider::_listener
protected

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

◆ _mouse

bool cugl::Slider::_mouse
protected

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

◆ _path

std::shared_ptr<Node> cugl::Slider::_path
protected

The background widget for this slider

◆ _range

Vec2 cugl::Slider::_range
protected

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

◆ _snap

bool cugl::Slider::_snap
protected

Whether to snap the slider to a tick value

◆ _tick

float cugl::Slider::_tick
protected

The (optional) )tick period for this slider

◆ _value

float cugl::Slider::_value
protected

The current value of the slider


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