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 #pragma once
6 
7 #include "ccontrol.h"
8 #include "../ccolor.h"
9 #include "../clinestyle.h"
10 
11 namespace VSTGUI {
12 
13 //-----------------------------------------------------------------------------
14 class CKnobBase : public CControl, protected CMouseWheelEditingSupport
15 {
16 public:
17 	//-----------------------------------------------------------------------------
18 	/// @name CKnobBase Methods
19 	//-----------------------------------------------------------------------------
20 	//@{
21 	virtual void  valueToPoint (CPoint& point) const;
22 	virtual float valueFromPoint (CPoint& point) const;
23 
24 	virtual void  setStartAngle (float val);
getStartAngle()25 	virtual float getStartAngle () const { return startAngle; }
26 
27 	virtual void  setRangeAngle (float val);
getRangeAngle()28 	virtual float getRangeAngle () const { return rangeAngle; }
29 
setZoomFactor(float val)30 	virtual void  setZoomFactor (float val) { zoomFactor = val; }
getZoomFactor()31 	virtual float getZoomFactor () const { return zoomFactor; }
32 
getInsetValue()33 	virtual CCoord getInsetValue () const { return inset; }
setInsetValue(CCoord val)34 	virtual void setInsetValue (CCoord val) { inset = val; }
35 	//@}
36 
37 	// overrides
38 	bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override;
39 	int32_t onKeyDown (VstKeyCode& keyCode) override;
40 	void setViewSize (const CRect &rect, bool invalid = true) override;
41 	bool sizeToFit () override;
42 	void setMin (float val) override;
43 	void setMax (float val) override;
44 
45 	CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
46 	CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
47 	CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
48 	CMouseEventResult onMouseCancel () override;
49 
50 	CLASS_METHODS_VIRTUAL(CKnobBase, CControl)
51 protected:
52 	CKnobBase (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background);
53 	CKnobBase (const CKnobBase& knob);
54 	void compute ();
55 
56 	float startAngle, rangeAngle;
57 	float zoomFactor;
58 	CCoord inset;
59 
60 private:
61 	struct MouseEditingState;
62 
63 	MouseEditingState& getMouseEditingState ();
64 	void clearMouseEditingState ();
65 };
66 
67 //-----------------------------------------------------------------------------
68 // CKnob Declaration
69 //! @brief a knob control
70 /// @ingroup controls
71 //-----------------------------------------------------------------------------
72 class CKnob : public CKnobBase
73 {
74 public:
75 	enum DrawStyle {
76 		kLegacyHandleLineDrawing	= 0,
77 		kHandleCircleDrawing		= 1 << 0,
78 		kCoronaDrawing				= 1 << 1,
79 		kCoronaFromCenter			= 1 << 2,
80 		kCoronaInverted				= 1 << 3,
81 		kCoronaLineDashDot			= 1 << 4,
82 		kCoronaOutline				= 1 << 5,
83 		kCoronaLineCapButt			= 1 << 6,
84 		kSkipHandleDrawing			= 1 << 7,
85 	};
86 
87 	CKnob (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, CBitmap* handle, const CPoint& offset = CPoint (0, 0), int32_t drawStyle = kLegacyHandleLineDrawing);
88 	CKnob (const CKnob& knob);
89 
90 	//-----------------------------------------------------------------------------
91 	/// @name CKnob Methods
92 	//-----------------------------------------------------------------------------
93 	//@{
getDrawStyle()94 	int32_t getDrawStyle () const { return drawStyle; }
95 	virtual void setDrawStyle (int32_t style);
96 
getCoronaColor()97 	CColor getCoronaColor () const { return coronaColor; }
98 	virtual void setCoronaColor (CColor color);
99 
getCoronaInset()100 	CCoord getCoronaInset () const { return coronaInset; }
101 	virtual void setCoronaInset (CCoord inset);
102 
getColorShadowHandle()103 	CColor getColorShadowHandle () const { return colorShadowHandle; }
104 	virtual void setColorShadowHandle (CColor color);
105 
getColorHandle()106 	CColor getColorHandle () const { return colorHandle; }
107 	virtual void setColorHandle (CColor color);
108 
getHandleLineWidth()109 	CCoord getHandleLineWidth () const { return handleLineWidth; }
110 	virtual void setHandleLineWidth (CCoord width);
111 
getCoronaOutlineWidthAdd()112 	CCoord getCoronaOutlineWidthAdd () const { return coronaOutlineWidthAdd; }
113 	virtual void setCoronaOutlineWidthAdd (CCoord width);
114 
115 	const CLineStyle::CoordVector& getCoronaDashDotLengths () const;
116 	virtual void setCoronaDashDotLengths (const CLineStyle::CoordVector& lengths);
117 
getHandleBitmap()118 	CBitmap* getHandleBitmap () const { return pHandle; }
119 	void setHandleBitmap (CBitmap* bitmap);
120 	//@}
121 
122 	// overrides
123 	void draw (CDrawContext* pContext) override;
124 	bool getFocusPath (CGraphicsPath& outPath) override;
125 	bool drawFocusOnTop () override;
126 
127 	CLASS_METHODS(CKnob, CKnobBase)
128 protected:
129 	~CKnob () noexcept override;
130 
131 	virtual void drawHandle (CDrawContext* pContext);
132 	virtual void drawCoronaOutline (CDrawContext* pContext) const;
133 	virtual void drawCorona (CDrawContext* pContext) const;
134 	virtual void drawHandleAsCircle (CDrawContext* pContext) const;
135 	virtual void drawHandleAsLine (CDrawContext* pContext) const;
136 
137 	static void addArc (CGraphicsPath* path, const CRect& r, double startAngle, double sweepAngle);
138 
139 	CPoint offset;
140 
141 	int32_t drawStyle;
142 	CColor colorHandle, colorShadowHandle, coronaColor;
143 	CCoord handleLineWidth;
144 	CCoord coronaInset;
145 	CCoord coronaOutlineWidthAdd;
146 
147 	CLineStyle coronaLineStyle;
148 	CBitmap* pHandle;
149 };
150 
151 //-----------------------------------------------------------------------------
152 // CAnimKnob Declaration
153 //! @brief a bitmap knob control
154 /// @ingroup controls
155 //-----------------------------------------------------------------------------
156 class CAnimKnob : public CKnobBase, public IMultiBitmapControl
157 {
158 public:
159 	CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
160 	CAnimKnob (const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps, CCoord heightOfOneImage, CBitmap* background, const CPoint& offset = CPoint (0, 0));
161 	CAnimKnob (const CAnimKnob& knob);
162 
163 	//-----------------------------------------------------------------------------
164 	/// @name CAnimKnob Methods
165 	//-----------------------------------------------------------------------------
166 	//@{
setInverseBitmap(bool val)167 	void setInverseBitmap (bool val) { bInverseBitmap = val; }
getInverseBitmap()168 	bool getInverseBitmap () const { return bInverseBitmap; }
169 	//@}
170 
171 	// overrides
172 	void draw (CDrawContext* pContext) override;
173 	bool sizeToFit () override;
174 	void setHeightOfOneImage (const CCoord& height) override;
175 	void setBackground (CBitmap *background) override;
setNumSubPixmaps(int32_t numSubPixmaps)176 	void setNumSubPixmaps (int32_t numSubPixmaps) override { IMultiBitmapControl::setNumSubPixmaps (numSubPixmaps); invalid (); }
177 
178 	CLASS_METHODS(CAnimKnob, CKnobBase)
179 protected:
180 	~CAnimKnob () noexcept override = default;
181 	bool	bInverseBitmap;
182 };
183 
184 } // VSTGUI
185