ASPiK SDK
cbuttons.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 __cbuttons__
6 #define __cbuttons__
7 
8 #include "ccontrol.h"
9 #include "../cfont.h"
10 #include "../ccolor.h"
11 #include "../cbitmap.h"
12 #include "../cgradient.h"
13 #include "../cgraphicspath.h"
14 #include "../cstring.h"
15 #include "../cdrawmethods.h"
16 
17 namespace VSTGUI {
18 
19 //-----------------------------------------------------------------------------
20 // COnOffButton Declaration
23 //-----------------------------------------------------------------------------
24 class COnOffButton : public CControl
25 {
26 public:
27  COnOffButton (const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, CBitmap* background = nullptr, int32_t style = 0);
28  COnOffButton (const COnOffButton& onOffButton);
29 
30  //-----------------------------------------------------------------------------
32  //-----------------------------------------------------------------------------
34  virtual int32_t getStyle () const { return style; }
35  virtual void setStyle (int32_t newStyle) { style = newStyle; }
37 
38  // overrides
39  void draw (CDrawContext*) override;
40  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
41  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
42  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
43  CMouseEventResult onMouseCancel () override;
44  int32_t onKeyDown (VstKeyCode& keyCode) override;
45  bool sizeToFit () override;
46 
47  CLASS_METHODS(COnOffButton, CControl)
48 protected:
49  ~COnOffButton () noexcept override = default;
50  int32_t style;
51 };
52 
53 //-----------------------------------------------------------------------------
54 // CCheckBox Declaration
58 //-----------------------------------------------------------------------------
59 class CCheckBox : public CControl
60 {
61 public:
62  CCheckBox (const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr, CBitmap* bitmap = nullptr, int32_t style = 0);
63  CCheckBox (const CCheckBox& checkbox);
64 
65  enum Styles {
66  kAutoSizeToFit = 1 << 0,
67  kDrawCrossBox = 1 << 1
68  };
69 
70  //-----------------------------------------------------------------------------
72  //-----------------------------------------------------------------------------
74  virtual void setTitle (const UTF8String& newTitle);
75  const UTF8String& getTitle () const { return title; }
76 
77  virtual void setFont (CFontRef newFont);
78  const CFontRef getFont () const { return font; }
79 
80  virtual void setFontColor (const CColor& newColor) { fontColor = newColor; invalid (); }
81  const CColor& getFontColor () const { return fontColor; }
82 
83  virtual void setBoxFrameColor (const CColor& newColor) { boxFrameColor = newColor; invalid (); }
84  const CColor& getBoxFrameColor () const { return boxFrameColor; }
85  virtual void setBoxFillColor (const CColor& newColor) { boxFillColor = newColor; invalid (); }
86  const CColor& getBoxFillColor () const { return boxFillColor; }
87  virtual void setCheckMarkColor (const CColor& newColor) { checkMarkColor = newColor; invalid (); }
88  const CColor& getCheckMarkColor () const { return checkMarkColor; }
89 
90  virtual int32_t getStyle () const { return style; }
91  virtual void setStyle (int32_t newStyle);
92 
93  CCoord getFrameWidth () const { return frameWidth; }
94  virtual void setFrameWidth (CCoord width);
95  CCoord getRoundRectRadius () const { return roundRectRadius; }
96  virtual void setRoundRectRadius (CCoord radius);
97 
99 
100  // overrides
101  void draw (CDrawContext* context) override;
102  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
103  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
104  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
105  CMouseEventResult onMouseCancel () override;
106  int32_t onKeyDown (VstKeyCode& keyCode) override;
107  bool sizeToFit () override;
108  void setBackground (CBitmap *background) override;
109  bool getFocusPath (CGraphicsPath& outPath) override;
110 
111  CLASS_METHODS(CCheckBox, CControl)
112 protected:
113  ~CCheckBox () noexcept override = default;
114 
115  UTF8String title;
116  int32_t style;
117  CColor fontColor;
118  CColor boxFrameColor;
119  CColor boxFillColor;
120  CColor checkMarkColor;
121  CCoord frameWidth {1};
122  CCoord roundRectRadius {0};
123  SharedPointer<CFontDesc> font;
124 
125 private:
126  float previousValue {0.f};
127  bool hilight {false};
128 };
129 
130 //-----------------------------------------------------------------------------
131 // CKickButton Declaration
134 //-----------------------------------------------------------------------------
136 {
137 public:
138  CKickButton (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
139  CKickButton (const CRect& size, IControlListener* listener, int32_t tag, CCoord heightOfOneImage, CBitmap* background, const CPoint& offset = CPoint (0, 0));
140  CKickButton (const CKickButton& kickButton);
141 
142  void draw (CDrawContext*) override;
143 
144  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
145  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
146  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
147  CMouseEventResult onMouseCancel () override;
148  int32_t onKeyDown (VstKeyCode& keyCode) override;
149  int32_t onKeyUp (VstKeyCode& keyCode) override;
150 
151  bool sizeToFit () override;
152 
153  void setNumSubPixmaps (int32_t numSubPixmaps) override { IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps); invalid (); }
154 
155  CLASS_METHODS(CKickButton, CControl)
156 protected:
157  ~CKickButton () noexcept override = default;
158  CPoint offset;
159 };
160 
161 //-----------------------------------------------------------------------------
162 // CTextButton Declaration
166 //-----------------------------------------------------------------------------
167 class CTextButton : public CControl
168 {
169 public:
170  enum Style
171  {
172  kKickStyle = 0,
173  kOnOffStyle
174  };
175 
176  CTextButton (const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr, Style = kKickStyle);
177 
178  //-----------------------------------------------------------------------------
180  //-----------------------------------------------------------------------------
182  virtual void setTitle (const UTF8String& newTitle);
183  const UTF8String& getTitle () const { return title; }
184 
185  virtual void setFont (CFontRef newFont);
186  CFontRef getFont () const { return font; }
187 
188  virtual void setTextColor (const CColor& color);
189  const CColor& getTextColor () const { return textColor; }
190  virtual void setTextColorHighlighted (const CColor& color);
191  const CColor& getTextColorHighlighted () const { return textColorHighlighted; }
192 
193  virtual void setGradient (CGradient* gradient);
194  CGradient* getGradient () const;
195  virtual void setGradientHighlighted (CGradient* gradient);
196  CGradient* getGradientHighlighted () const;
197 
198  virtual void setFrameColor (const CColor& color);
199  const CColor& getFrameColor () const { return frameColor; }
200  virtual void setFrameColorHighlighted (const CColor& color);
201  const CColor& getFrameColorHighlighted () const { return frameColorHighlighted; }
202 
203  virtual void setFrameWidth (CCoord width);
204  CCoord getFrameWidth () const { return frameWidth; }
205 
206  virtual void setRoundRadius (CCoord radius);
207  CCoord getRoundRadius () const { return roundRadius; }
208 
209  virtual void setStyle (Style style);
210  Style getStyle () const { return style; }
211 
212  virtual void setIcon (CBitmap* bitmap);
213  CBitmap* getIcon () const;
214 
215  virtual void setIconHighlighted (CBitmap* bitmap);
216  CBitmap* getIconHighlighted () const;
217 
218  virtual void setIconPosition (CDrawMethods::IconPosition pos);
219  CDrawMethods::IconPosition getIconPosition () const { return iconPosition; }
220 
221  virtual void setTextMargin (CCoord margin);
222  CCoord getTextMargin () const { return textMargin; }
223 
224  virtual void setTextAlignment (CHoriTxtAlign hAlign);
225  CHoriTxtAlign getTextAlignment () const { return horiTxtAlign; }
227 
228  // overrides
229  void draw (CDrawContext* context) override;
230  bool getFocusPath (CGraphicsPath& outPath) override;
231  bool drawFocusOnTop () override;
232  void setViewSize (const CRect& rect, bool invalid = true) override;
233  bool removed (CView* parent) override;
234  bool sizeToFit () override;
235  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
236  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
237  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
238  CMouseEventResult onMouseCancel () override;
239  int32_t onKeyDown (VstKeyCode& keyCode) override;
240  int32_t onKeyUp (VstKeyCode& keyCode) override;
241 
242  CLASS_METHODS(CTextButton, CControl)
243 protected:
244  ~CTextButton () noexcept override = default;
245 
246  void invalidPath ();
247  CGraphicsPath* getPath (CDrawContext* context, CCoord lineWidth);
248 
249  SharedPointer<CFontDesc> font;
250  SharedPointer<CGraphicsPath> _path;
251  SharedPointer<CBitmap> icon;
252  SharedPointer<CBitmap> iconHighlighted;
253  SharedPointer<CGradient> gradient;
254  SharedPointer<CGradient> gradientHighlighted;
255 
256  CColor textColor;
257  CColor frameColor;
258 
259  CColor textColorHighlighted;
260  CColor frameColorHighlighted;
261 
262  CCoord frameWidth;
263  CCoord roundRadius;
264  CCoord textMargin;
265 
266  CHoriTxtAlign horiTxtAlign;
267  CDrawMethods::IconPosition iconPosition;
268  Style style;
269  UTF8String title;
270 private:
271  float fEntryState;
272 };
273 
274 } // namespace
275 
276 #endif
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: cbuttons.cpp:720
bool sizeToFit() override
resize view to optimal size
Definition: cbuttons.cpp:880
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cbuttons.cpp:216
int32_t onKeyUp(VstKeyCode &keyCode) override
called if a key up event occurs and this view has focus
Definition: cbuttons.cpp:283
int32_t onKeyUp(VstKeyCode &keyCode) override
called if a key up event occurs and this view has focus
Definition: cbuttons.cpp:1067
bool removed(CView *parent) override
view is removed from parent view
Definition: cbuttons.cpp:713
void draw(CDrawContext *context) override
called if the view should draw itself
Definition: cbuttons.cpp:897
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cbuttons.cpp:66
Rect structure.
Definition: crect.h:17
automatically adjusts the width so that the label is completely visible
Definition: cbuttons.h:66
void setBackground(CBitmap *background) override
set the background image of this view
Definition: cbuttons.cpp:379
Definition: xmlparse.c:181
void draw(CDrawContext *) override
called if the view should draw itself
Definition: cbuttons.cpp:49
bool sizeToFit() override
resize view to optimal size
Definition: cbuttons.cpp:121
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cbuttons.cpp:266
Definition: vstkeycode.h:12
bool getFocusPath(CGraphicsPath &outPath) override
Definition: cbuttons.cpp:933
bool drawFocusOnTop() override
Definition: cbuttons.cpp:946
Style
< CTextButton style
Definition: cbuttons.h:170
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cbuttons.cpp:624
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cbuttons.cpp:98
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cbuttons.cpp:673
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cbuttons.cpp:248
CKickButton(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0))
Definition: cbuttons.cpp:153
bool getFocusPath(CGraphicsPath &outPath) override
Definition: cbuttons.cpp:587
a button control with 2 states
Definition: cbuttons.h:24
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cbuttons.cpp:993
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
base class of all VSTGUI controls
Definition: ccontrol.h:76
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cbuttons.cpp:76
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cbuttons.cpp:612
Button and Modifier state.
Definition: cbuttonstate.h:34
draws a crossbox instead of a checkmark if no bitmap is provided
Definition: cbuttons.h:67
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cbuttons.cpp:207
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cbuttons.cpp:970
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cbuttons.cpp:656
void draw(CDrawContext *) override
called if the view should draw itself
Definition: cbuttons.cpp:190
COnOffButton(const CRect &size, IControlListener *listener=nullptr, int32_t tag=-1, CBitmap *background=nullptr, int32_t style=0)
Definition: cbuttons.cpp:33
bool sizeToFit() override
resize view to optimal size
Definition: cbuttons.cpp:297
Definition: cbuttons.h:135
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cbuttons.cpp:82
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
Styles
Definition: cbuttons.h:65
bool sizeToFit() override
resize view to optimal size
Definition: cbuttons.cpp:440
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cbuttons.cpp:232
void draw(CDrawContext *context) override
called if the view should draw itself
Definition: cbuttons.cpp:466
Point structure.
Definition: cpoint.h:17
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cbuttons.cpp:1014
a check box control with a title and 3 states
Definition: cbuttons.h:59
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cbuttons.cpp:106
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cbuttons.cpp:641
a button which renders without bitmaps
Definition: cbuttons.h:167
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cbuttons.cpp:980
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cbuttons.cpp:1032
Definition: icontrollistener.h:14
interface for controls with sub images
Definition: ccontrol.h:182