Jamba C++ API  5.1.1
ToggleButtonView Class Reference

A toggle button is a button that lets you toggle the value of a parameter between an "on" value and an "off" value. More...

#include <ToggleButtonView.h>

Inherits CustomDiscreteControlView.

Classes

class  Creator
 

Public Member Functions

void draw (CDrawContext *iContext) override
 
int32 getComputedOffStep () const
 Actual value that the code should use for the underlying parameter. More...
 
int32 getComputedOnStep () const
 Actual value that the code should use for the underlying parameter. More...
 
int getFrames () const
 The number of frames the image contains. More...
 
BitmapPtr getImage () const
 The image to use to draw the button. More...
 
bool getInverse () const
 Inverses the meaning of "on" and "off" in regards to drawing the view/image. More...
 
int32 getOffStep () const
 Maps to the "off" value unless it is set to its default (-1) value in which case it maps to 0 (should be -1 or a value in [0, stepCount]). More...
 
CColor const & getOnColor () const
 When no image is provided, back-color is used for the "off" state and on-color for the "on" state (draws a rectangle with this color). More...
 
int32 getOnStep () const
 Maps to the "on" value unless it is set to its default (-1) value in which case it maps to getStepCount() (should be -1 or a value in [0, stepCount]). More...
 
bool isOff () const
 Returns true if the toggle is in the "off" state (meaning the control value is equal to the off step) More...
 
bool isOn () const
 Returns true if the toggle is not in the "off" state. More...
 
int32_t onKeyDown (VstKeyCode &keyCode) override
 
int32_t onKeyUp (VstKeyCode &keyCode) override
 
CMouseEventResult onMouseCancel () override
 
CMouseEventResult onMouseDown (CPoint &where, const CButtonState &buttons) override
 
CMouseEventResult onMouseUp (CPoint &where, const CButtonState &buttons) override
 
void setFrames (int iFrames)
 
void setImage (BitmapPtr iImage)
 Attribute button-image. More...
 
void setInverse (bool iInverse)
 
void setOff ()
 Shortcut to set the toggle to its "off" state. More...
 
void setOffStep (int32 iStep)
 
void setOn ()
 Shortcut to set the toggle to its "on" state. More...
 
void setOnColor (CColor const &iColor)
 
void setOnOrOff (bool iOnOrOff)
 Shortcut to set the toggle to the boolean state provided (true means "on", false means off) More...
 
void setOnStep (int32 iStep)
 
bool sizeToFit () override
 
 ToggleButtonView (const CRect &iSize)
 
int32 toggleControlValue ()
 Toggles between on and off control value. More...
 
- Public Member Functions inherited from CustomDiscreteControlView
 CustomDiscreteControlView (const CRect &iSize)
 
int32 getStepCount () const
 The number of steps of the managed discrete parameter as specified by this view. More...
 
void registerParameters () override
 Registers the optional parameter using getControlTag() as its id. More...
 
void setStepCount (int32 iStepCount)
 
- Public Member Functions inherited from TCustomControlView< int32 >
int32 getControlValue () const
 Returns the value of the managed parameter (properly typed) More...
 
void registerParameters () override
 Registers the optional parameter using getControlTag() as its id. More...
 
virtual void setControlValue (int32 const &iControlValue)
 Sets the value of the managed parameter to the provided value. More...
 
 TCustomControlView (const CRect &iSize)
 
- Public Member Functions inherited from CustomControlView
 CustomControlView (const CRect &iSize)
 
ParamID getControlTag () const
 Id of the parameter that this view manages. More...
 
virtual void setControlTag (ParamID iTag)
 
- Public Member Functions inherited from CustomView
void afterApplyAttributes () override
 Handles the lifecycle behavior getting triggered once all the attributes have been set (which usually happens after the XML file (uidesc) has been read/processed, or when you modify attributes in the VSTGUI Editor). More...
 
 CustomView (const CRect &iSize)
 
 CustomView (const CustomView &c)=delete
 
void draw (CDrawContext *iContext) override
 The basic draw method which will erase the background with the back color. More...
 
virtual void drawBackColor (CDrawContext *iContext)
 Draws the back color (if not set to transparent) More...
 
void drawStyleChanged ()
 Called when the draw style is changed (simply marks the view dirty) More...
 
CColor const & getBackColor () const
 The back color (background) for the view. More...
 
TagID getCustomViewTag () const
 The tag associated to this custom view. More...
 
bool getEditorMode () const
 A flag whose purpose is to render/log information during development when the flag is set to true. More...
 
void markDirty ()
 Marks this view dirty which will (at the appropriate time in the rendering lifecycle) trigger a call to draw() More...
 
void onParameterChange (ParamID iParamID) override
 Callback when a parameter changes. More...
 
void setBackColor (CColor const &iColor)
 
void setCustomViewTag (TagID iTag)
 
void setEditorMode (bool iEditorMode)
 
- Public Member Functions inherited from ParamAware
virtual void initState (GUIState *iGUIState)
 Called during initialization. More...
 
void invokeAll ()
 Invoke all (currently) registered callbacks and onParameterChange() (if registered). More...
 
IGUIParam registerBaseCallback (ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
 Registers a callback for the "base" param for the most generic use case. More...
 
IGUIParam registerBaseCallback (ParamID iParamID, Parameters::ChangeCallback1< IGUIParam > iChangeCallback, bool iInvokeCallback)
 Registers a callback for the "base" param for the most generic use case. More...
 
IGUIParam registerBaseParam (ParamID iParamID, bool iSubscribeToChanges=true)
 Registers the "base" param for the most generic use case but as a result is fairly limited and mainly gives access to the string representation of the param. More...
 
GUIRawVstParam registerCallback (RawVstParam const &iParamDef, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Registers a raw parameter (no conversion). More...
 
GUIRawVstParam registerCallback (RawVstParam const &iParamDef, Parameters::ChangeCallback1< GUIRawVstParam > iChangeCallback, bool iInvokeCallback=false)
 Registers a raw parameter (no conversion). More...
 
template<typename T >
GUIVstParam< T > registerCallback (VstParam< T > const &iParamDef, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Vst param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIVstParam< T > registerCallback (VstParam< T > const &iParamDef, Parameters::ChangeCallback1< GUIVstParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Vst param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerCallback (JmbParam< T > const &iParamDef, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Jmb param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerCallback (JmbParam< T > const &iParamDef, Parameters::ChangeCallback1< GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Jmb param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerCallback (GUIJmbParam< T > &iParam, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Jmb param simply by using the param from the state (accessible in state-aware views via fState->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerCallback (GUIJmbParam< T > &iParam, Parameters::ChangeCallback1< GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Convenient call to register a callback for the Jmb param simply by using the param from the state (accessible in state-aware views via fState->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerJmbCallback (ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Registers a callback for the Jmb param by its id and return the wrapper to the param. More...
 
template<typename T >
GUIJmbParam< T > registerJmbCallback (ParamID iParamID, Parameters::ChangeCallback1< GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Registers a callback for the Jmb param by its id and return the wrapper to the param. More...
 
template<typename T >
GUIJmbParam< T > registerJmbParam (ParamID iParamID, bool iSubscribeToChanges=true)
 Registers the Jmb param by its id and return the wrapper to the param. More...
 
template<typename T >
GUIOptionalParam< T > registerOptionalCallback (ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Registers an optional parameter which handles Vst, Jmb or no parameter at all. More...
 
template<typename T >
GUIOptionalParam< T > registerOptionalCallback (ParamID iParamID, Parameters::ChangeCallback1< GUIOptionalParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Registers an optional parameter which handles Vst, Jmb or no parameter at all. More...
 
GUIOptionalParam< int32 > registerOptionalDiscreteCallback (ParamID iParamID, int32 iStepCount, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Registers an optional discrete parameter which handles Vst, Jmb or no parameter at all. More...
 
GUIOptionalParam< int32 > registerOptionalDiscreteCallback (ParamID iParamID, int32 iStepCount, Parameters::ChangeCallback1< GUIOptionalParam< int32 >> iChangeCallback, bool iInvokeCallback=false)
 Registers an optional discrete parameter which handles Vst, Jmb or no parameter at all. More...
 
GUIOptionalParam< int32 > registerOptionalDiscreteParam (ParamID iParamID, int32 iStepCount, bool iSubscribeToChanges=true)
 Registers an optional discrete parameter which handles Vst, Jmb or no parameter at all. More...
 
template<typename T >
GUIOptionalParam< T > registerOptionalParam (ParamID iParamID, bool iSubscribeToChanges=true)
 Registers an optional parameter which handles Vst, Jmb or no parameter at all. More...
 
GUIRawVstParam registerParam (RawVstParam const &iParamDef, bool iSubscribeToChanges=true)
 Registers a raw parameter (no conversion). More...
 
template<typename T >
GUIVstParam< T > registerParam (VstParam< T > const &iParamDef, bool iSubscribeToChanges=true)
 Convenient call to register a Vst param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerParam (JmbParam< T > const &iParamDef, bool iSubscribeToChanges=true)
 Convenient call to register a Jmb param simply by using its description (accessible in state-aware views via fParams->fMyParam). More...
 
template<typename T >
GUIJmbParam< T > registerParam (GUIJmbParam< T > &iParam, bool iSubscribeToChanges=true)
 Convenient call to register a Jmb param simply by using the param from the state (accessible in state-aware views via fState->fMyParam). More...
 
GUIRawVstParam registerRawVstCallback (ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Registers a raw parameter (no conversion) The callback will be invoked when the parameter changes. More...
 
GUIRawVstParam registerRawVstCallback (ParamID iParamID, Parameters::ChangeCallback1< GUIRawVstParam > iChangeCallback, bool iInvokeCallback=false)
 Registers a raw parameter (no conversion) The callback will be invoked when the parameter changes. More...
 
GUIRawVstParam registerRawVstParam (ParamID iParamID, bool iSubscribeToChanges=true)
 Registers a raw parameter (no conversion) onParameterChange() will be called on changes (if iSubscribeToChanges is set to true). More...
 
GUIVstParam< bool > registerVstBooleanParam (ParamID iParamID, bool iSubscribeToChanges=true)
 
template<typename T >
GUIVstParam< T > registerVstCallback (ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
 Register a callback for a Vst parameter simply given its id The callback will be invoked when the parameter changes. More...
 
template<typename T >
GUIVstParam< T > registerVstCallback (ParamID iParamID, Parameters::ChangeCallback1< GUIVstParam< T >> iChangeCallback, bool iInvokeCallback=false)
 Register a callback for a Vst parameter simply given its id The callback will be invoked when the parameter changes. More...
 
template<typename T >
GUIVstParam< T > registerVstParam (ParamID iParamID, bool iSubscribeToChanges=true)
 Register a Vst parameter simply given its id onParameterChange() will be called on changes (if iSubscribeToChanges is set to true). More...
 
GUIVstParam< PercentregisterVstPercentParam (ParamID iParamID, bool iSubscribeToChanges=true)
 
void unregisterAll ()
 Unregisters all parameters. More...
 
bool unregisterParam (ParamID iParamID)
 Removes the registration of the provided param (closing the connection/stopping to listen) More...
 
GUIRawVstParam unregisterParam (GUIRawVstParam const &iParam)
 Removes the registration of the provided param (closing the connection/stopping to listen) More...
 
template<typename T >
GUIVstParam< T > unregisterParam (GUIVstParam< T > const &iParam)
 Removes the registration of the provided param (closing the connection/stopping to listen) More...
 
template<typename T >
GUIJmbParam< T > unregisterParam (GUIJmbParam< T > const &iParam)
 Removes the registration of the provided param (closing the connection/stopping to listen) More...
 
virtual ~ParamAware ()
 

Protected Attributes

int fFrames {4}
 
BitmapSPtr fImage {nullptr}
 
bool fInverse {false}
 
int32 fOffStep {-1}
 
CColor fOnColor {kRedCColor}
 
int32 fOnStep {-1}
 
bool fPressed {false}
 
- Protected Attributes inherited from CustomDiscreteControlView
int32 fStepCount {-1}
 
- Protected Attributes inherited from TCustomControlView< int32 >
GUIOptionalParam< int32 > fControlParameter
 
- Protected Attributes inherited from CustomControlView
ParamID fControlTag {UNDEFINED_PARAM_ID}
 
- Protected Attributes inherited from CustomView
CColor fBackColor
 
ParamID fTag
 
- Protected Attributes inherited from ParamAware
std::unique_ptr< GUIParamCxMgrfParamCxMgr {}
 

Additional Inherited Members

- Public Types inherited from TCustomControlView< int32 >
using Creator = CustomViewCreator< TCustomControlView< int32 >, CustomControlView >
 
- Protected Member Functions inherited from CustomView
void sizeToFit (CCoord iWidth, CCoord iHeight)
 Convenient call to size to fit this view according to the and height provided. More...
 
bool sizeToFit (BitmapPtr iBitmap, int iFrameCount=1)
 Convenient call to size to fit this view to match the bitmap. More...
 

Detailed Description

A toggle button is a button that lets you toggle the value of a parameter between an "on" value and an "off" value.

This view is designed to handle parameters which are backed by a bool representation but it works for any parameter (both Vst and Jmb) that is (or can be interpreted as) a discrete parameter.

Note
This view defines the "on" state as being the opposite of the "off" state and so the "off" state is the one being checked against the off value (otherwise we could end up in a situation where both isOn and isOff are true...). The consequence is that the underlying parameter might have a value that is neither the "off" value nor the "on" value, but for the sake of this view it will be treated as "on" (similarly to C/C++ where 0 is false and any non-zero is true).

In addition to the attributes exposed by CustomDiscreteControlView, this class exposes the following attributes:

Attribute Description
on-step Maps to the "on" value unless it is set to its default (-1) value in which case it maps to getStepCount() (should be -1 or a value in [0, stepCount]).
off-step Maps to the "off" value unless it is set to its default (-1) value in which case it maps to 0 (should be -1 or a value in [0, stepCount]).
on-color When no image is provided, back-color is used for the "off" state and on-color for the "on" state (draws a rectangle with this color).
frames

The number of frames the image contains. Should be either 2 or 4 (4 includes the pressed state).

See also
getImage() for more details on the content of the image based on this value
button-image

The image to use to draw the button. The content of the image depends on the attribute frames (getFrames()) with the following convention:

  • for 2 frames each is of size image height / 2:

    y frame
    0 the button in its "off" state
    image height / 2 the button in its "on" state

    Example: 2 frames example

  • for 4 frames each is of size image height / 4:

    y frame
    0 the button in its "off" state
    image height * 1/4 the button in its "off" state depressed
    image height * 2/4 the button in its "on" state
    image height * 3/4 the button in its "on" state depressed

    Example: 4 frames example

inverse Inverses the meaning of "on" and "off" in regards to drawing the view/image.
See also
CustomDiscreteControlView for details on discrete parameters and the usage of step-count

Constructor & Destructor Documentation

◆ ToggleButtonView()

ToggleButtonView ( const CRect &  iSize)
inlineexplicit

Member Function Documentation

◆ draw()

void draw ( CDrawContext *  iContext)
override

◆ getComputedOffStep()

int32 getComputedOffStep ( ) const
inline

Actual value that the code should use for the underlying parameter.

getOffStep() represents the raw attribute value which can be set to -1. This call returns the actual value representing the "off" step.

◆ getComputedOnStep()

int32 getComputedOnStep ( ) const

Actual value that the code should use for the underlying parameter.

getOnStep() represents the raw attribute value which can be set to -1. This call returns the actual value representing the "on" step.

◆ getFrames()

int getFrames ( ) const
inline

The number of frames the image contains.

Should be either 2 or 4 (4 includes the pressed state).

See also
getImage() for more details on the content of the image based on this value

◆ getImage()

BitmapPtr getImage ( ) const
inline

The image to use to draw the button.

The content of the image depends on the attribute frames (getFrames()) with the following convention:

  • for 2 frames each is of size image height / 2:

    y frame
    0 the button in its "off" state
    image height / 2 the button in its "on" state

    Example: 2 frames example

  • for 4 frames each is of size image height / 4:

    y frame
    0 the button in its "off" state
    image height * 1/4 the button in its "off" state depressed
    image height * 2/4 the button in its "on" state
    image height * 3/4 the button in its "on" state depressed

    Example: 4 frames example

◆ getInverse()

bool getInverse ( ) const
inline

Inverses the meaning of "on" and "off" in regards to drawing the view/image.

◆ getOffStep()

int32 getOffStep ( ) const
inline

Maps to the "off" value unless it is set to its default (-1) value in which case it maps to 0 (should be -1 or a value in [0, stepCount]).

◆ getOnColor()

CColor const& getOnColor ( ) const
inline

When no image is provided, back-color is used for the "off" state and on-color for the "on" state (draws a rectangle with this color).

◆ getOnStep()

int32 getOnStep ( ) const
inline

Maps to the "on" value unless it is set to its default (-1) value in which case it maps to getStepCount() (should be -1 or a value in [0, stepCount]).

◆ isOff()

bool isOff ( ) const
inline

Returns true if the toggle is in the "off" state (meaning the control value is equal to the off step)

◆ isOn()

bool isOn ( ) const
inline

Returns true if the toggle is not in the "off" state.

Note
This view defines the "on" state as being the opposite of the "off" state and so the "off" state is the one being checked against the off value (otherwise we could end up in a situation where both isOn and isOff are true...). The consequence is that the underlying parameter might have a value that is neither the "off" value nor the "on" value, but for the sake of this view it will be treated as "on" (similarly to C/C++ where 0 is false and any non-zero is true).

◆ onKeyDown()

int32_t onKeyDown ( VstKeyCode &  keyCode)
override

◆ onKeyUp()

int32_t onKeyUp ( VstKeyCode &  keyCode)
override

◆ onMouseCancel()

CMouseEventResult onMouseCancel ( )
override

◆ onMouseDown()

CMouseEventResult onMouseDown ( CPoint &  where,
const CButtonState &  buttons 
)
override

◆ onMouseUp()

CMouseEventResult onMouseUp ( CPoint &  where,
const CButtonState &  buttons 
)
override

◆ setFrames()

void setFrames ( int  iFrames)

◆ setImage()

void setImage ( BitmapPtr  iImage)
inline

Attribute button-image.

◆ setInverse()

void setInverse ( bool  iInverse)
inline

◆ setOff()

void setOff ( )
inline

Shortcut to set the toggle to its "off" state.

◆ setOffStep()

void setOffStep ( int32  iStep)
inline

◆ setOn()

void setOn ( )
inline

Shortcut to set the toggle to its "on" state.

◆ setOnColor()

void setOnColor ( CColor const &  iColor)
inline

◆ setOnOrOff()

void setOnOrOff ( bool  iOnOrOff)
inline

Shortcut to set the toggle to the boolean state provided (true means "on", false means off)

◆ setOnStep()

void setOnStep ( int32  iStep)
inline

◆ sizeToFit()

bool sizeToFit ( )
override

◆ toggleControlValue()

int32 toggleControlValue ( )

Toggles between on and off control value.

Returns
the new control value

Member Data Documentation

◆ fFrames

int fFrames {4}
protected

◆ fImage

BitmapSPtr fImage {nullptr}
protected

◆ fInverse

bool fInverse {false}
protected

◆ fOffStep

int32 fOffStep {-1}
protected

◆ fOnColor

CColor fOnColor {kRedCColor}
protected

◆ fOnStep

int32 fOnStep {-1}
protected

◆ fPressed

bool fPressed {false}
protected

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