VSTGUI 4.10
Graphical User Interface Framework not only for VST plugins
Loading...
Searching...
No Matches
CSegmentButton Class Reference

Control which draws a segmented button. More...

#include <csegmentbutton.h>

+ Inheritance diagram for CSegmentButton:

Classes

struct  Segment
 

Public Types

enum class  Style { kHorizontal , kVertical , kHorizontalInverse , kVerticalInverse }
 
enum class  SelectionMode { kSingle , kSingleToggle , kMultiple }
 
using Segments = std::vector<Segment>
 
using CheckDefaultValueEventFuncT = bool (*) (CControl*, MouseDownEvent&)
 
using CheckDefaultValueFuncT = bool (*) (CControl*, CButtonState)
 
enum class  MouseListenerCall { MouseDown , MouseMoved , MouseUp , MouseCancel }
 

Public Member Functions

 CSegmentButton (const CRect &size, IControlListener *listener=nullptr, int32_t tag=-1)
 
Segment Methods
bool addSegment (const Segment &segment, uint32_t index=kPushBack)
 
bool addSegment (Segment &&segment, uint32_t index=kPushBack)
 
void removeSegment (uint32_t index)
 
void removeAllSegments ()
 
const SegmentsgetSegments () const
 
void setSelectedSegment (uint32_t index)
 set the selected segment in single selection mode
 
uint32_t getSelectedSegment () const
 get the selected segment in single selection mode
 
void selectSegment (uint32_t index, bool state)
 set selection state for a segment in multiple selection mode
 
bool isSegmentSelected (uint32_t index) const
 get selection state for a segment in multiple selection mode
 
- Public Member Functions inherited from CControl
 CControl (const CRect &size, IControlListener *listener=nullptr, int32_t tag=0, CBitmap *pBackground=nullptr)
 
 CControl (const CControl &c)
 
virtual void setValue (float val)
 
virtual float getValue () const
 
virtual void setValueNormalized (float val)
 
virtual float getValueNormalized () const
 
virtual void setMin (float val)
 
virtual float getMin () const
 
virtual void setMax (float val)
 
virtual float getMax () const
 
float getRange () const
 
virtual void setOldValue (float val)
 
virtual float getOldValue () const
 
virtual void setDefaultValue (float val)
 
virtual float getDefaultValue () const
 
virtual void bounceValue ()
 
virtual void setTag (int32_t val)
 
virtual int32_t getTag () const
 
virtual void beginEdit ()
 
virtual void endEdit ()
 
bool isEditing () const
 
virtual IControlListenergetListener () const
 get main listener
 
virtual void setListener (IControlListener *l)
 set main listener
 
void registerControlListener (IControlListener *listener)
 register a sub listener
 
void unregisterControlListener (IControlListener *listener)
 unregister a sub listener
 
virtual void setWheelInc (float val)
 
virtual float getWheelInc () const
 
bool isDirty () const override
 check if view is dirty
 
void setDirty (bool val=true) override
 set the view to dirty so that it is redrawn in the next idle.
 
- Public Member Functions inherited from CView
 CView (const CRect &size)
 
 CView (const CView &view)
 
virtual void dispatchEvent (Event &event)
 dispatch an event
 
virtual void onMouseDownEvent (MouseDownEvent &event)
 called when a mouse down event occurs
 
virtual void onMouseMoveEvent (MouseMoveEvent &event)
 called when a mouse move event occurs
 
virtual void onMouseUpEvent (MouseUpEvent &event)
 called when a mouse up event occurs
 
virtual void onMouseCancelEvent (MouseCancelEvent &event)
 called when mouse tracking should be canceled
 
virtual void onMouseEnterEvent (MouseEnterEvent &event)
 called when the mouse enters this view
 
virtual void onMouseExitEvent (MouseExitEvent &event)
 called when the mouse leaves this view
 
virtual void onMouseWheelEvent (MouseWheelEvent &event)
 called when a mouse wheel event occurs
 
virtual void onZoomGestureEvent (ZoomGestureEvent &event)
 called when a zoom gesture event occurs
 
virtual void setMouseEnabled (bool bEnable=true)
 turn on/off mouse usage for this view
 
bool getMouseEnabled () const
 get the state of wheather this view uses the mouse or not
 
virtual void setMouseableArea (const CRect &rect)
 set the area in which the view reacts to the mouse
 
CRect getMouseableArea () const
 get the area in which the view reacts to the mouse
 
virtual CMouseEventResult onMouseUp (CPoint &where, const CButtonState &buttons)
 do not use any longer.
 
virtual CMouseEventResult onMouseMoved (CPoint &where, const CButtonState &buttons)
 do not use any longer.
 
virtual CMouseEventResult onMouseCancel ()
 do not use any longer.
 
virtual CMouseEventResult onMouseEntered (CPoint &where, const CButtonState &buttons)
 do not use any longer.
 
virtual CMouseEventResult onMouseExited (CPoint &where, const CButtonState &buttons)
 do not use any longer.
 
virtual bool onWheel (const CPoint &where, const float &distance, const CButtonState &buttons) final
 
virtual bool onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons)
 
CRectgetMouseableArea (CRect &rect) const
 get the area in which the view reacts to the mouse
 
void setHitTestPath (CGraphicsPath *path)
 
virtual bool hitTest (const CPoint &where, const Event &event=noEvent())
 check if where hits this view
 
virtual bool hitTest (const CPoint &where, const CButtonState &buttons)
 
bool doDrag (const DragDescription &dragDescription, const SharedPointer< IDragCallback > &callback={})
 start a drag operation
 
virtual SharedPointer< IDropTargetgetDropTarget ()
 get the drag target for drag and drop handling
 
void setDropTarget (const SharedPointer< IDropTarget > &dt)
 set a custom drop target
 
DragResult doDrag (IDataPackage *source, const CPoint &offset=CPoint(0, 0), CBitmap *dragBitmap=nullptr)
 a drag can only be started from within onMouseDown
 
virtual int32_t onKeyDown (VstKeyCode &keyCode)
 called if a key down event occurs and this view has focus
 
virtual int32_t onKeyUp (VstKeyCode &keyCode)
 called if a key up event occurs and this view has focus
 
CCoord getHeight () const
 get the height of the view
 
CCoord getWidth () const
 get the width of the view
 
const CRectgetViewSize () const
 read only access to view size
 
virtual CRect getVisibleViewSize () const
 returns the visible size of the view
 
virtual void parentSizeChanged ()
 notification that one of the views parent has changed its size
 
virtual CPointframeToLocal (CPoint &point) const
 conversion from frame coordinates to local view coordinates
 
virtual CPointlocalToFrame (CPoint &point) const
 conversion from local view coordinates to frame coordinates
 
virtual void setAutosizeFlags (int32_t flags)
 set autosize flags
 
int32_t getAutosizeFlags () const
 get autosize flags
 
virtual bool sizeToFit ()
 resize view to optimal size
 
virtual void looseFocus ()
 called if view should loose focus
 
virtual void takeFocus ()
 called if view should take focus
 
virtual bool wantsFocus () const
 check if view supports focus
 
virtual void setWantsFocus (bool state)
 set focus support on/off
 
bool getAttributeSize (const CViewAttributeID id, uint32_t &outSize) const
 get the size of an attribute
 
bool getAttribute (const CViewAttributeID id, const uint32_t inSize, void *outData, uint32_t &outSize) const
 get an attribute
 
bool setAttribute (const CViewAttributeID id, const uint32_t inSize, const void *inData)
 set an attribute
 
bool removeAttribute (const CViewAttributeID id)
 remove an attribute
 
template<typename T>
bool setAttribute (const CViewAttributeID id, const T &data)
 set an attribute
 
template<typename T>
bool getAttribute (const CViewAttributeID id, T &data) const
 get an attribute
 
virtual void setBackground (CBitmap *background)
 set the background image of this view
 
CBitmapgetBackground () const
 get the background image of this view
 
virtual void setDisabledBackground (CBitmap *background)
 set background image used when the mouse is not enabled
 
CBitmapgetDisabledBackground () const
 get background image used when the mouse is not enabled
 
CBitmapgetDrawBackground () const
 get the bitmap which is drawn depending on the enabled state.
 
virtual void setTransparency (bool val)
 set views transparent state
 
bool getTransparency () const
 get views transparent state
 
virtual void setAlphaValue (float alpha)
 set alpha value which will be applied when drawing this view
 
float getAlphaValue () const
 get alpha value
 
virtual bool removed (CView *parent)
 view is removed from parent view
 
bool isAttached () const
 is view attached to a parentView
 
void setSubviewState (bool state)
 
bool isSubview () const
 
CViewgetParentView () const
 get parent view
 
CFramegetFrame () const
 get frame
 
virtual VSTGUIEditorInterfacegetEditor () const
 get editor
 
void addAnimation (IdStringPtr name, Animation::IAnimationTarget *target, Animation::ITimingFunction *timingFunction, CBaseObject *notificationObject)
 
void addAnimation (IdStringPtr name, Animation::IAnimationTarget *target, Animation::ITimingFunction *timingFunction, const Animation::DoneFunction &doneFunc=nullptr, bool callDoneOnCancel=false)
 
void removeAnimation (IdStringPtr name)
 
void removeAllAnimations ()
 
void registerViewListener (IViewListener *listener)
 
void unregisterViewListener (IViewListener *listener)
 
void registerViewEventListener (IViewEventListener *listener)
 
void unregisterViewEventListener (IViewEventListener *listener)
 
void registerViewMouseListener (IViewMouseListener *listener)
 
void unregisterViewMouseListener (IViewMouseListener *listener)
 
CGraphicsTransform getGlobalTransform (bool ignoreFrame=false) const
 get the active global transform for this view
 
template<typename T>
T & translateToGlobal (T &t, bool ignoreFrame=false) const
 translates a local coordinate to a global one using parent transforms
 
template<typename T>
translateToGlobal (const T &t, bool ignoreFrame=false) const
 translates a local coordinate to a global one using parent transforms
 
template<typename T>
T & translateToLocal (T &t, bool ignoreFrame=false) const
 translates a global coordinate to a local one using parent transforms
 
template<typename T>
translateToLocal (const T &t, bool ignoreFrame=false) const
 translates a local coordinate to a global one using parent transforms
 
virtual CViewContainerasViewContainer ()
 
virtual const CViewContainerasViewContainer () const
 
CMouseEventResult callMouseListener (MouseListenerCall type, CPoint pos, CButtonState buttons)
 
void callMouseListenerEnteredExited (bool mouseEntered)
 
CMessageResult notify (CBaseObject *sender, IdStringPtr message) override
 
void beforeDelete () override
 
CBaseObjectnewCopy () const override
 
virtual bool checkUpdate (const CRect &updateRect) const
 
virtual void invalidRect (const CRect &rect)
 mark rect as invalid
 
virtual void invalid ()
 mark whole view as invalid
 
virtual void setVisible (bool state)
 set visibility state
 
bool isVisible () const
 get visibility state
 
virtual void onIdle ()
 called on idle when view wants idle
 
void setWantsIdle (bool state)
 enable/disable onIdle() callback
 
bool wantsIdle () const
 returns if the view wants idle callback or not
 
virtual bool wantsWindowActiveStateChangeNotification () const
 whether this view wants to be informed if the window's active state changes
 
virtual void onWindowActivate (bool state)
 called when the active state of the window changes
 
void setTooltipText (UTF8StringPtr text)
 
- Public Member Functions inherited from CBaseObject
 CBaseObject ()=default
 
 ~CBaseObject () noexcept override=default
 
 CBaseObject (const CBaseObject &)
 
CBaseObjectoperator= (const CBaseObject &)
 
- Public Member Functions inherited from ReferenceCounted< int32_t >
 ReferenceCounted ()=default
 
virtual ~ReferenceCounted () noexcept=default
 
 ReferenceCounted (const ReferenceCounted &)
 
ReferenceCountedoperator= (const ReferenceCounted &)
 
 ReferenceCounted ()=default
 
 ReferenceCounted (const ReferenceCounted &)
 
virtual ~ReferenceCounted () noexcept=default
 
ReferenceCountedoperator= (const ReferenceCounted &)
 
void forget () override
 decrease refcount and delete object if refcount == 0
 
void remember () override
 increase refcount
 
virtual int32_t getNbReference () const
 get refcount
 
void forget () override
 decrease refcount and delete object if refcount == 0
 
void remember () override
 increase refcount
 
virtual int32_t getNbReference () const
 get refcount
 
- Public Member Functions inherited from IFocusDrawing
virtual ~IFocusDrawing () noexcept=default
 

Static Public Attributes

static constexpr uint32_t kPushBack = (std::numeric_limits<uint32_t>::max) ()
 
static CheckDefaultValueEventFuncT CheckDefaultValueEventFunc
 Function to check if a mouse down event should reset the value to its default value for a control.
 
static int32_t kZoomModifier = kShift
 zoom modifier key, per default is the shift key
 
static int32_t kDefaultValueModifier = kControl
 
static CheckDefaultValueFuncT CheckDefaultValueFunc
 
static bool kDirtyCallAlwaysOnMainThread = false
 if this is true, setting a view dirty will call invalid() instead of checking it in idle.
 
static uint32_t idleRate = 30
 global idle rate in Hz, defaults to 30 Hz
 

CSegmentButton Style Methods

void setStyle (Style newStyle)
 
Style getStyle () const
 
void setSelectionMode (SelectionMode mode)
 
SelectionMode getSelectionMode () const
 
void setTextTruncateMode (CDrawMethods::TextTruncateMode mode)
 
CDrawMethods::TextTruncateMode getTextTruncateMode () const
 
void setGradient (CGradient *newGradient)
 
CGradientgetGradient () const
 
void setGradientHighlighted (CGradient *newGradient)
 
CGradientgetGradientHighlighted () const
 
void setRoundRadius (CCoord newRoundRadius)
 
CCoord getRoundRadius () const
 
void setFont (CFontRef font)
 
CFontRef getFont () const
 
void setTextAlignment (CHoriTxtAlign alignment)
 
CHoriTxtAlign getTextAlignment () const
 
void setTextMargin (CCoord newMargin)
 
CCoord getTextMargin () const
 
void setTextColor (CColor newColor)
 
CColor getTextColor () const
 
void setTextColorHighlighted (CColor newColor)
 
CColor getTextColorHighlighted () const
 
void setFrameColor (CColor newColor)
 
CColor getFrameColor () const
 
void setFrameWidth (CCoord newWidth)
 
CCoord getFrameWidth () const
 
bool attached (CView *parent) override
 view is attached to a parent view
 
void setViewSize (const CRect &rect, bool invalid=true) override
 set views size
 
CMouseEventResult onMouseDown (CPoint &where, const CButtonState &buttons) override
 do not use any longer.
 
void onKeyboardEvent (KeyboardEvent &event) override
 called when a keyboard event is dispatched to this view
 
void draw (CDrawContext *pContext) override
 called if the view should draw itself
 
void drawRect (CDrawContext *pContext, const CRect &dirtyRect) override
 called if the view should draw itself
 
bool drawFocusOnTop () override
 draw focus before view will be drawn or afterwards
 
bool getFocusPath (CGraphicsPath &outPath) override
 the graphics path will be drawn filled with the evenodd method and the color set in CFrame::setFocusColor()
 
void valueChanged () override
 notifies listener and dependent objects
 
CBaseObjectnewCopy () const override
 
static bool isHorizontalStyle (Style style)
 
static bool isVerticalStyle (Style style)
 
static bool isInverseStyle (Style style)
 

Additional Inherited Members

- Protected Types inherited from CView
enum  {
  kMouseEnabled = 1 << 0 , kTransparencyEnabled = 1 << 1 , kWantsFocus = 1 << 2 , kIsAttached = 1 << 3 ,
  kVisible = 1 << 4 , kDirty = 1 << 5 , kWantsIdle = 1 << 6 , kIsSubview = 1 << 7 ,
  kHasAlpha = 1 << 8 , kHasBackground = 1 << 9 , kHasDisabledBackground = 1 << 10 , kHasMouseableArea = 1 << 11 ,
  kLastCViewFlag = 11
}
 
 ~CControl () noexcept override
 
 ~CView () noexcept override
 
CGraphicsPathgetHitTestPath () const
 
bool hasViewFlag (int32_t bit) const
 
void setViewFlag (int32_t bit, bool state)
 
void setAlphaValueNoInvalidate (float value)
 
void setParentFrame (CFrame *frame)
 
void setParentView (CView *parent)
 
static int32_t mapVstKeyModifier (int32_t vstModifier)
 
IControlListenerlistener
 
int32_t tag
 
float value
 

Detailed Description

Control which draws a segmented button.

Member Typedef Documentation

◆ Segments

using Segments = std::vector<Segment>

Member Enumeration Documentation

◆ SelectionMode

enum class SelectionMode
strong
Enumerator
kSingle 

a single segment is selected at any time

kSingleToggle 

a single segment is selected at any time, when a segment is clicked which is already selected, the next segment is selected

kMultiple 

multiple segments may be selected

◆ Style

enum class Style
strong
Enumerator
kHorizontal 

horizontally layouted segments

kVertical 

vertically layouted segments

kHorizontalInverse 

horizontally inverse layouted segments

kVerticalInverse 

vertically inverse layouted segments

Constructor & Destructor Documentation

◆ CSegmentButton()

CSegmentButton ( const CRect & size,
IControlListener * listener = nullptr,
int32_t tag = -1 )

Member Function Documentation

◆ addSegment() [1/2]

bool addSegment ( const Segment & segment,
uint32_t index = kPushBack )

◆ addSegment() [2/2]

bool addSegment ( Segment && segment,
uint32_t index = kPushBack )

◆ attached()

bool attached ( CView * parent)
overridevirtual

view is attached to a parent view

Parameters
parentparent view
Returns
true if view successfully attached to parent

Reimplemented from CView.

◆ draw()

void draw ( CDrawContext * pContext)
overridevirtual

called if the view should draw itself

Parameters
pContextdraw context in which to draw

Implements CControl.

◆ drawFocusOnTop()

bool drawFocusOnTop ( )
overridevirtual

draw focus before view will be drawn or afterwards

Reimplemented from CControl.

◆ drawRect()

void drawRect ( CDrawContext * pContext,
const CRect & updateRect )
overridevirtual

called if the view should draw itself

Reimplemented from CView.

◆ getFocusPath()

bool getFocusPath ( CGraphicsPath & outPath)
overridevirtual

the graphics path will be drawn filled with the evenodd method and the color set in CFrame::setFocusColor()

Reimplemented from CControl.

◆ getFont()

CFontRef getFont ( ) const
inline

◆ getFrameColor()

CColor getFrameColor ( ) const
inline

◆ getFrameWidth()

CCoord getFrameWidth ( ) const
inline

◆ getGradient()

CGradient * getGradient ( ) const
inline

◆ getGradientHighlighted()

CGradient * getGradientHighlighted ( ) const
inline

◆ getRoundRadius()

CCoord getRoundRadius ( ) const
inline

◆ getSegments()

const Segments & getSegments ( ) const
inline

◆ getSelectedSegment()

uint32_t getSelectedSegment ( ) const

get the selected segment in single selection mode

◆ getSelectionMode()

SelectionMode getSelectionMode ( ) const
inline

◆ getStyle()

Style getStyle ( ) const
inline

◆ getTextAlignment()

CHoriTxtAlign getTextAlignment ( ) const
inline

◆ getTextColor()

CColor getTextColor ( ) const
inline

◆ getTextColorHighlighted()

CColor getTextColorHighlighted ( ) const
inline

◆ getTextMargin()

CCoord getTextMargin ( ) const
inline

◆ getTextTruncateMode()

CDrawMethods::TextTruncateMode getTextTruncateMode ( ) const
inline

◆ isHorizontalStyle()

static bool isHorizontalStyle ( Style style)
inlinestatic

◆ isInverseStyle()

static bool isInverseStyle ( Style style)
inlinestatic

◆ isSegmentSelected()

bool isSegmentSelected ( uint32_t index) const

get selection state for a segment in multiple selection mode

◆ isVerticalStyle()

static bool isVerticalStyle ( Style style)
inlinestatic

◆ newCopy()

CBaseObject * newCopy ( ) const
inlineoverridevirtual

Implements CControl.

◆ onKeyboardEvent()

void onKeyboardEvent ( KeyboardEvent & event)
overridevirtual

called when a keyboard event is dispatched to this view

This happens normally only if the view is the focus view.

Reimplemented from CView.

◆ onMouseDown()

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

do not use any longer.

if possible refactor your classes to use the newer mouse event methods above.

Parameters
wheremouse location of mouse down
buttonsbutton and modifier state
Returns
event result. see CMouseEventResult

Reimplemented from CView.

◆ removeAllSegments()

void removeAllSegments ( )

◆ removeSegment()

void removeSegment ( uint32_t index)

◆ selectSegment()

void selectSegment ( uint32_t index,
bool state )

set selection state for a segment in multiple selection mode

◆ setFont()

void setFont ( CFontRef font)

◆ setFrameColor()

void setFrameColor ( CColor newColor)

◆ setFrameWidth()

void setFrameWidth ( CCoord newWidth)

◆ setGradient()

void setGradient ( CGradient * newGradient)

◆ setGradientHighlighted()

void setGradientHighlighted ( CGradient * newGradient)

◆ setRoundRadius()

void setRoundRadius ( CCoord newRoundRadius)

◆ setSelectedSegment()

void setSelectedSegment ( uint32_t index)

set the selected segment in single selection mode

◆ setSelectionMode()

void setSelectionMode ( SelectionMode mode)

◆ setStyle()

void setStyle ( Style newStyle)

◆ setTextAlignment()

void setTextAlignment ( CHoriTxtAlign alignment)

◆ setTextColor()

void setTextColor ( CColor newColor)

◆ setTextColorHighlighted()

void setTextColorHighlighted ( CColor newColor)

◆ setTextMargin()

void setTextMargin ( CCoord newMargin)

◆ setTextTruncateMode()

void setTextTruncateMode ( CDrawMethods::TextTruncateMode mode)

◆ setViewSize()

void setViewSize ( const CRect & newSize,
bool doInvalid = true )
overridevirtual

set views size

Parameters
newSizerect of new size of view
doInvalidif true set view dirty

Reimplemented from CView.

◆ valueChanged()

void valueChanged ( )
overridevirtual

notifies listener and dependent objects

Reimplemented from CControl.

Member Data Documentation

◆ kPushBack

uint32_t kPushBack = (std::numeric_limits<uint32_t>::max) ()
staticconstexpr

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