ASPiK SDK
csegmentbutton.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __csegmentbutton__
6 #define __csegmentbutton__
7 
8 #include "ccontrol.h"
9 #include "../cdrawmethods.h"
10 #include "../cbitmap.h"
11 #include "../cgradient.h"
12 #include "../cstring.h"
13 #include "../ccolor.h"
14 #include <vector>
15 #include <limits>
16 
17 namespace VSTGUI {
18 
19 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
23 class CSegmentButton : public CControl
24 {
25 public:
26  enum Style {
27  kHorizontal,
28  kVertical
29  };
30 
31  struct Segment {
32  mutable UTF8String name;
33  mutable SharedPointer<CBitmap> icon;
34  mutable SharedPointer<CBitmap> iconHighlighted;
35  mutable SharedPointer<CBitmap> background;
36  mutable SharedPointer<CBitmap> backgroundHighlighted;
37  mutable CDrawMethods::IconPosition iconPosition;
38 
39  CRect rect;
40  };
41  using Segments = std::vector<Segment>;
42  static uint32_t kPushBack;
43 
44  CSegmentButton (const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1);
45 
46  //-----------------------------------------------------------------------------
48  //-----------------------------------------------------------------------------
50  void addSegment (Segment segment, uint32_t index = kPushBack);
51  void removeSegment (uint32_t index);
52  void removeAllSegments ();
53  const Segments& getSegments () const { return segments; }
54 
55  void setSelectedSegment (uint32_t index);
56  uint32_t getSelectedSegment () const;
58 
59  //-----------------------------------------------------------------------------
61  //-----------------------------------------------------------------------------
63  void setStyle (Style newStyle);
64  Style getStyle () const { return style; }
65 
66  void setTextTruncateMode (CDrawMethods::TextTruncateMode mode);
67  CDrawMethods::TextTruncateMode getTextTruncateMode () const { return textTruncateMode; }
68 
69  void setGradient (CGradient* newGradient);
70  CGradient* getGradient () const { return gradient; }
71 
72  void setGradientHighlighted (CGradient* newGradient);
73  CGradient* getGradientHighlighted () const { return gradientHighlighted; }
74 
75  void setRoundRadius (CCoord newRoundRadius);
76  CCoord getRoundRadius () const { return roundRadius; }
77 
78  void setFont (CFontRef font);
79  CFontRef getFont () const { return font; }
80 
81  void setTextAlignment (CHoriTxtAlign alignment);
82  CHoriTxtAlign getTextAlignment () const { return textAlignment; }
83 
84  void setTextMargin (CCoord newMargin);
85  CCoord getTextMargin () const { return textMargin; }
86 
87  void setTextColor (CColor newColor);
88  CColor getTextColor () const { return textColor; }
89 
90  void setTextColorHighlighted (CColor newColor);
91  CColor getTextColorHighlighted () const { return textColorHighlighted; }
92 
93  void setFrameColor (CColor newColor);
94  CColor getFrameColor () const { return frameColor; }
95 
96  void setFrameWidth (CCoord newWidth);
97  CCoord getFrameWidth () const { return frameWidth; }
99 
100  // overrides
101  bool attached (CView *parent) override;
102  void setViewSize (const CRect& rect, bool invalid = true) override;
103  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
104  int32_t onKeyDown (VstKeyCode& keyCode) override;
105  void draw (CDrawContext* pContext) override;
106  void drawRect (CDrawContext* pContext, const CRect& dirtyRect) override;
107  bool drawFocusOnTop () override;
108  bool getFocusPath (CGraphicsPath& outPath) override;
109 
110  CLASS_METHODS(CSegmentButton, CControl)
111 private:
112  void updateSegmentSizes ();
113  uint32_t getSegmentIndex (float value) const;
114 
115  Segments segments;
116  SharedPointer<CGradient> gradient;
117  SharedPointer<CGradient> gradientHighlighted;
118  SharedPointer<CFontDesc> font;
119  CColor textColor {kBlackCColor};
120  CColor textColorHighlighted {kWhiteCColor};
121  CColor frameColor {kBlackCColor};
122  CHoriTxtAlign textAlignment {kCenterText};
123  CCoord textMargin {0.};
124  CCoord roundRadius {5.};
125  CCoord frameWidth {1.};
126  Style style {kHorizontal};
127  CDrawMethods::TextTruncateMode textTruncateMode {CDrawMethods::kTextTruncateNone};
128 };
129 
130 } // namespace
131 
132 #endif // __csegmentbutton__
bool drawFocusOnTop() override
Definition: csegmentbutton.cpp:393
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: csegmentbutton.cpp:289
Rect structure.
Definition: crect.h:17
Definition: xmlparse.c:181
Definition: vstkeycode.h:12
Definition: vstguibase.h:299
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: csegmentbutton.cpp:238
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: csegmentbutton.cpp:209
Control which draws a segmented button.
Definition: csegmentbutton.h:23
Definition: customcontrols.cpp:8
base class of all VSTGUI controls
Definition: ccontrol.h:76
Definition: csegmentbutton.h:31
bool getFocusPath(CGraphicsPath &outPath) override
Definition: csegmentbutton.cpp:399
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: csegmentbutton.cpp:202
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
bool attached(CView *parent) override
view is attached to a parent view
Definition: csegmentbutton.cpp:191
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
void drawRect(CDrawContext *pContext, const CRect &dirtyRect) override
called if the view should draw itself
Definition: csegmentbutton.cpp:295
Definition: icontrollistener.h:14