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
15 //! @brief a knob control
16 /// @ingroup controls
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 	//-----------------------------------------------------------------------------
37 	/// @name CKnob Methods
38 	//-----------------------------------------------------------------------------
39 	//@{
40 	virtual void  setStartAngle (float val);
getStartAngle()41 	virtual float getStartAngle () const { return startAngle; }
42 
43 	virtual void  setRangeAngle (float val);
getRangeAngle()44 	virtual float getRangeAngle () const { return rangeAngle; }
45 
46 	virtual void  valueToPoint (CPoint& point) const;
47 	virtual float valueFromPoint (CPoint& point) const;
48 
getInsetValue()49 	virtual CCoord getInsetValue () const { return inset; }
setInsetValue(CCoord val)50 	virtual void setInsetValue (CCoord val) { inset = val; }
51 
getDrawStyle()52 	virtual int32_t getDrawStyle () const { return drawStyle; }
53 	virtual void setDrawStyle (int32_t style);
54 
getCoronaColor()55 	virtual CColor getCoronaColor () const { return coronaColor; }
56 	virtual void setCoronaColor (CColor color);
57 
getCoronaInset()58 	virtual CCoord getCoronaInset () const { return coronaInset; }
59 	virtual void setCoronaInset (CCoord inset);
60 
getColorShadowHandle()61 	virtual CColor getColorShadowHandle () const { return colorShadowHandle; }
62 	virtual void setColorShadowHandle (CColor color);
63 
getColorHandle()64 	virtual CColor getColorHandle () const { return colorHandle; }
65 	virtual void setColorHandle (CColor color);
66 
getHandleLineWidth()67 	virtual CCoord getHandleLineWidth () const { return handleLineWidth; }
68 	virtual void setHandleLineWidth (CCoord width);
69 
getCoronaOutlineWidthAdd()70 	virtual CCoord getCoronaOutlineWidthAdd () const { return coronaOutlineWidthAdd; }
71 	virtual void setCoronaOutlineWidthAdd (CCoord width);
72 
getHandleBitmap()73 	virtual CBitmap* getHandleBitmap () const { return pHandle; }
74 	virtual void setHandleBitmap (CBitmap* bitmap);
75 
setZoomFactor(float val)76 	virtual void  setZoomFactor (float val) { zoomFactor = val; }
getZoomFactor()77 	virtual float getZoomFactor () const { return zoomFactor; }
78 	//@}
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 	struct MouseEditingState;
122 
123 	MouseEditingState& getMouseEditingState ();
124 	void clearMouseEditingState ();
125 };
126 
127 //-----------------------------------------------------------------------------
128 // CAnimKnob Declaration
129 //! @brief a bitmap knob control
130 /// @ingroup controls
131 //-----------------------------------------------------------------------------
132 class CAnimKnob : public CKnob, public IMultiBitmapControl
133 {
134 public:
135 	CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
136 	CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps, CCoord heightOfOneImage, CBitmap* background, const CPoint& offset = CPoint (0, 0));
137 	CAnimKnob (const CAnimKnob& knob);
138 
139 	//-----------------------------------------------------------------------------
140 	/// @name CAnimKnob Methods
141 	//-----------------------------------------------------------------------------
142 	//@{
setInverseBitmap(bool val)143 	void setInverseBitmap (bool val) { bInverseBitmap = val; }
getInverseBitmap()144 	bool getInverseBitmap () const { return bInverseBitmap; }
145 	//@}
146 
147 	// overrides
148 	void draw (CDrawContext* pContext) override;
149 	bool sizeToFit () override;
150 	void setHeightOfOneImage (const CCoord& height) override;
151 	void setBackground (CBitmap *background) override;
setNumSubPixmaps(int32_t numSubPixmaps)152 	void setNumSubPixmaps (int32_t numSubPixmaps) override { IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps); invalid (); }
153 
154 	CLASS_METHODS(CAnimKnob, CKnob)
155 protected:
156 	~CAnimKnob () noexcept override = default;
157 	bool	bInverseBitmap;
158 };
159 
160 } // namespace
161 
162 #endif
163