Jamba C++ API  4.3.0
CustomView Class Reference

Class you should inherit from if you want to write a custom view. More...

#include <CustomView.h>

Inherits CView, ParamAware, and ICustomViewLifecycle.

Inherited by CustomControlView, ImageView, and ScrollbarView.

Classes

class  Creator
 Defines and registers the attributes exposed in the VSTGUI Editor and XML file (.uidesc) for CustomView. More...
 

Public Member Functions

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...
 
virtual void registerParameters ()
 Subclasses should override this method to register each parameter. 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 Member Functions

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

Protected Attributes

CColor fBackColor
 
ParamID fTag
 
- Protected Attributes inherited from ParamAware
std::unique_ptr< GUIParamCxMgrfParamCxMgr {}
 

Detailed Description

Class you should inherit from if you want to write a custom view.

It offers the following functionalities:

  • a back color that can be set (disabled by setting it to transparent)
  • a tag that can be associated with the view itself (can be used for example when writing custom controller)
  • an editor mode which can be used while developing the custom view (for example, draw debug info...)
  • gives access to parameter registration via Params::ParamAware
  • handle default parameter listener (mark the view dirty which triggers a redraw)

In general, when inheriting from this class you will typically override:

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

Attribute Description
custom-view-tag

The tag associated to this custom view. This tag (which is not related to a parameter), is optional and can be used to differentiate between views when implementing a custom controller.

// Example
CView *SampleEditController::verifyView(CView *iView,
const UIAttributes &iAttributes,
const IUIDescription *iDescription)
{
auto button = dynamic_cast<Views::TextButtonView *>(iView);
if(button) {
switch(button->getCustomViewTag()) {
case ESampleSplitterParamID::kNormalize0Action:
initButton(button, SampleDataAction::Type::kNormalize0, false);
break;
// ....
}
}
}
editor-mode

A flag whose purpose is to render/log information during development when the flag is set to true. It can be flipped directly in the VSTGUI Editor without having to recompile the code.

// Example
void SampleEditView::draw(CDrawContext *iContext) {
// ...
#if EDITOR_MODE
{
auto rdc = pongasoft::VST::GUI::RelativeDrawContext{this, iContext};
rdc.debug("SampleRange: [%.3f,%.3f] | PixelRange: [%.3f,%.3f] | Visible: [%.3f,%.3f] | BPM: %f",
fState->fWESelectedSampleRange->fFrom, fState->fWESelectedSampleRange->fTo,
fSelectedPixelRange.fFrom, fSelectedPixelRange.fTo,
fVisibleSampleRange.fFrom, fVisibleSampleRange.fTo,
fHostInfo->fTempo);
}
#endif
}
Note
Since getEditorMode() always returns false in release build mode, it is recommended to enclose such code in an #if / #endif block as shown in the example.
back-color The back color (background) for the view. The draw() method in this class simply delegates to drawBackColor() which paints the background of the view with this color (if not set to transparent).
See also
CustomViewCreator for details on how a custom view gets created

Constructor & Destructor Documentation

◆ CustomView() [1/2]

CustomView ( const CRect &  iSize)
explicit

◆ CustomView() [2/2]

CustomView ( const CustomView c)
delete

Member Function Documentation

◆ afterApplyAttributes()

void afterApplyAttributes ( )
inlineoverridevirtual

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).

Note
Subclasses are allowed to extend this behavior (if you want to do some extra setup when the view is initialized for example), but care should be taken in making sure that this method ends up being called, otherwise the view will most likely not behave as expected.

Reimplemented from ICustomViewLifecycle.

◆ draw()

void draw ( CDrawContext *  iContext)
override

The basic draw method which will erase the background with the back color.

You override this method to implement your additional own logic.

◆ drawBackColor()

void drawBackColor ( CDrawContext *  iContext)
virtual

Draws the back color (if not set to transparent)

◆ drawStyleChanged()

void drawStyleChanged ( )

Called when the draw style is changed (simply marks the view dirty)

◆ getBackColor()

CColor const& getBackColor ( ) const
inline

The back color (background) for the view.

The draw() method in this class simply delegates to drawBackColor() which paints the background of the view with this color (if not set to transparent).

◆ getCustomViewTag()

TagID getCustomViewTag ( ) const
inline

The tag associated to this custom view.

This tag (which is not related to a parameter), is optional and can be used to differentiate between views when implementing a custom controller.

// Example
CView *SampleEditController::verifyView(CView *iView,
const UIAttributes &iAttributes,
const IUIDescription *iDescription)
{
auto button = dynamic_cast<Views::TextButtonView *>(iView);
if(button) {
switch(button->getCustomViewTag()) {
case ESampleSplitterParamID::kNormalize0Action:
initButton(button, SampleDataAction::Type::kNormalize0, false);
break;
// ....
}
}
}

◆ getEditorMode()

bool getEditorMode ( ) const

A flag whose purpose is to render/log information during development when the flag is set to true.

It can be flipped directly in the VSTGUI Editor without having to recompile the code.

// Example
void SampleEditView::draw(CDrawContext *iContext) {
// ...
#if EDITOR_MODE
{
auto rdc = pongasoft::VST::GUI::RelativeDrawContext{this, iContext};
rdc.debug("SampleRange: [%.3f,%.3f] | PixelRange: [%.3f,%.3f] | Visible: [%.3f,%.3f] | BPM: %f",
fState->fWESelectedSampleRange->fFrom, fState->fWESelectedSampleRange->fTo,
fSelectedPixelRange.fFrom, fSelectedPixelRange.fTo,
fVisibleSampleRange.fFrom, fVisibleSampleRange.fTo,
fHostInfo->fTempo);
}
#endif
}
Note
Since getEditorMode() always returns false in release build mode, it is recommended to enclose such code in an #if / #endif block as shown in the example.

◆ markDirty()

void markDirty ( )
inline

Marks this view dirty which will (at the appropriate time in the rendering lifecycle) trigger a call to draw()

Warning
You should not call draw() yourself but instead call this method which will invoke draw() at the appropriate time (for example, calling markDirty() 3 times will not invoke draw() 3 times...).

◆ onParameterChange()

void onParameterChange ( ParamID  iParamID)
overridevirtual

Callback when a parameter changes.

By default simply marks the view as dirty. This method is intended to be overriden to implement specific behavior.

Reimplemented from ParamAware.

Reimplemented in ScrollbarView.

◆ setBackColor()

void setBackColor ( CColor const &  iColor)
See also
getBackColor()

◆ setCustomViewTag()

void setCustomViewTag ( TagID  iTag)
inline

◆ setEditorMode()

void setEditorMode ( bool  iEditorMode)
See also
getEditorMode()

◆ sizeToFit() [1/2]

void sizeToFit ( CCoord  iWidth,
CCoord  iHeight 
)
inlineprotected

Convenient call to size to fit this view according to the and height provided.

◆ sizeToFit() [2/2]

bool sizeToFit ( BitmapPtr  iBitmap,
int  iFrameCount = 1 
)
inlineprotected

Convenient call to size to fit this view to match the bitmap.

Member Data Documentation

◆ fBackColor

CColor fBackColor
protected

◆ fTag

ParamID fTag
protected

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