ASPiK SDK
cknob.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 __cknob__
6 #define __cknob__
7 
8 #include "ccontrol.h"
9 #include "../ccolor.h"
10 
11 namespace VSTGUI {
12 
13 //-----------------------------------------------------------------------------
14 // CKnob Declaration
17 //-----------------------------------------------------------------------------
18 class CKnob : public CControl
19 {
20 public:
21  enum DrawStyle {
22  kLegacyHandleLineDrawing = 0,
23  kHandleCircleDrawing = 1 << 0,
24  kCoronaDrawing = 1 << 1,
25  kCoronaFromCenter = 1 << 2,
26  kCoronaInverted = 1 << 3,
27  kCoronaLineDashDot = 1 << 4,
28  kCoronaOutline = 1 << 5,
29  kCoronaLineCapButt = 1 << 6,
30  kSkipHandleDrawing = 1 << 7,
31  };
32 
33  CKnob (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, CBitmap* handle, const CPoint& offset = CPoint (0, 0), int32_t drawStyle = kLegacyHandleLineDrawing);
34  CKnob (const CKnob& knob);
35 
36  //-----------------------------------------------------------------------------
38  //-----------------------------------------------------------------------------
40  virtual void setStartAngle (float val);
41  virtual float getStartAngle () const { return startAngle; }
42 
43  virtual void setRangeAngle (float val);
44  virtual float getRangeAngle () const { return rangeAngle; }
45 
46  virtual void valueToPoint (CPoint& point) const;
47  virtual float valueFromPoint (CPoint& point) const;
48 
49  virtual CCoord getInsetValue () const { return inset; }
50  virtual void setInsetValue (CCoord val) { inset = val; }
51 
52  virtual int32_t getDrawStyle () const { return drawStyle; }
53  virtual void setDrawStyle (int32_t style);
54 
55  virtual CColor getCoronaColor () const { return coronaColor; }
56  virtual void setCoronaColor (CColor color);
57 
58  virtual CCoord getCoronaInset () const { return coronaInset; }
59  virtual void setCoronaInset (CCoord inset);
60 
61  virtual CColor getColorShadowHandle () const { return colorShadowHandle; }
62  virtual void setColorShadowHandle (CColor color);
63 
64  virtual CColor getColorHandle () const { return colorHandle; }
65  virtual void setColorHandle (CColor color);
66 
67  virtual CCoord getHandleLineWidth () const { return handleLineWidth; }
68  virtual void setHandleLineWidth (CCoord width);
69 
70  virtual CCoord getCoronaOutlineWidthAdd () const { return coronaOutlineWidthAdd; }
71  virtual void setCoronaOutlineWidthAdd (CCoord width);
72 
73  virtual CBitmap* getHandleBitmap () const { return pHandle; }
74  virtual void setHandleBitmap (CBitmap* bitmap);
75 
76  virtual void setZoomFactor (float val) { zoomFactor = val; }
77  virtual float getZoomFactor () const { return zoomFactor; }
79 
80  // overrides
81  void draw (CDrawContext* pContext) override;
82  bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) override;
83  int32_t onKeyDown (VstKeyCode& keyCode) override;
84  void setViewSize (const CRect &rect, bool invalid = true) override;
85  bool sizeToFit () override;
86  void setMin (float val) override;
87  void setMax (float val) override;
88  bool getFocusPath (CGraphicsPath& outPath) override;
89  bool drawFocusOnTop () override;
90 
91  CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
92  CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
93  CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
94  CMouseEventResult onMouseCancel () override;
95 
96  CLASS_METHODS(CKnob, CControl)
97 protected:
98  ~CKnob () noexcept override;
99  virtual void drawHandle (CDrawContext* pContext);
100  virtual void drawCoronaOutline (CDrawContext* pContext) const;
101  virtual void drawCorona (CDrawContext* pContext) const;
102  virtual void drawHandleAsCircle (CDrawContext* pContext) const;
103  virtual void drawHandleAsLine (CDrawContext* pContext) const;
104  void compute ();
105  void addArc (CGraphicsPath* path, const CRect& r, double startAngle, double sweepAngle) const;
106 
107  CPoint offset;
108 
109  int32_t drawStyle;
110  CColor colorHandle, colorShadowHandle, coronaColor;
111  CCoord handleLineWidth;
112  CCoord inset;
113  CCoord coronaInset;
114  CCoord coronaOutlineWidthAdd;
115 
116  CBitmap* pHandle;
117  float startAngle, rangeAngle;
118  float zoomFactor;
119 
120 private:
121  CPoint firstPoint;
122  CPoint lastPoint;
123  float startValue;
124  float fEntryState;
125  float range;
126  float coef;
127  CButtonState oldButton;
128  bool modeLinear;
129 
130 };
131 
132 //-----------------------------------------------------------------------------
133 // CAnimKnob Declaration
136 //-----------------------------------------------------------------------------
137 class CAnimKnob : public CKnob, public IMultiBitmapControl
138 {
139 public:
140  CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
141  CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps, CCoord heightOfOneImage, CBitmap* background, const CPoint& offset = CPoint (0, 0));
142  CAnimKnob (const CAnimKnob& knob);
143 
144  //-----------------------------------------------------------------------------
146  //-----------------------------------------------------------------------------
148  void setInverseBitmap (bool val) { bInverseBitmap = val; }
149  bool getInverseBitmap () const { return bInverseBitmap; }
151 
152  // overrides
153  void draw (CDrawContext* pContext) override;
154  bool sizeToFit () override;
155  void setHeightOfOneImage (const CCoord& height) override;
156  void setBackground (CBitmap *background) override;
157  void setNumSubPixmaps (int32_t numSubPixmaps) override { IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps); invalid (); }
158 
159  CLASS_METHODS(CAnimKnob, CKnob)
160 protected:
161  ~CAnimKnob () noexcept override = default;
162  bool bInverseBitmap;
163 };
164 
165 } // namespace
166 
167 #endif
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: cknob.cpp:749
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: cknob.cpp:144
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
called when a mouse up event occurs
Definition: cknob.cpp:347
Rect structure.
Definition: crect.h:17
CAnimKnob(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0))
Definition: cknob.cpp:676
a bitmap knob control
Definition: cknob.h:137
Definition: xmlparse.c:181
Definition: vstkeycode.h:12
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
RGBA Color structure.
Definition: ccolor.h:15
a knob control
Definition: cknob.h:18
Graphics Path Object.
Definition: cgraphicspath.h:19
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
called when a mouse move event occurs
Definition: cknob.cpp:371
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
Button and Modifier state.
Definition: cbuttonstate.h:34
bool drawFocusOnTop() override
Definition: cknob.cpp:120
bool sizeToFit() override
resize view to optimal size
Definition: cknob.cpp:716
CMouseEventResult onMouseCancel() override
called when mouse tracking should be canceled
Definition: cknob.cpp:355
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
bool sizeToFit() override
resize view to optimal size
Definition: cknob.cpp:105
CKnob(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, CBitmap *handle, const CPoint &offset=CPoint(0, 0), int32_t drawStyle=kLegacyHandleLineDrawing)
Definition: cknob.cpp:40
bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: cknob.cpp:419
int32_t onKeyDown(VstKeyCode &keyCode) override
called if a key down event occurs and this view has focus
Definition: cknob.cpp:447
Point structure.
Definition: cpoint.h:17
bool getFocusPath(CGraphicsPath &outPath) override
Definition: cknob.cpp:130
void setBackground(CBitmap *background) override
set the background image of this view
Definition: cknob.cpp:739
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: cknob.cpp:98
Definition: icontrollistener.h:14
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
called when a mouse down event occurs
Definition: cknob.cpp:292
interface for controls with sub images
Definition: ccontrol.h:182