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 "../cfont.h"
9 #include "../ccolor.h"
10 #include "../cdrawdefs.h"
11 #include <functional>
12 
13 namespace VSTGUI {
14 
15 //-----------------------------------------------------------------------------
16 using CParamDisplayValueToStringProc = bool (*) (float value, char utf8String[256], void* userData);
17 
18 //-----------------------------------------------------------------------------
19 // CParamDisplay Declaration
20 //! @brief a parameter display
21 /// @ingroup views
22 //-----------------------------------------------------------------------------
23 class CParamDisplay : public CControl
24 {
25 protected:
26 	enum StyleEnum
27 	{
28 		StyleShadowText = 0,
29 		Style3DIn,
30 		Style3DOut,
31 		StyleNoText,
32 		StyleNoDraw,
33 		StyleRoundRect,
34 		StyleNoFrame,
35 		StyleAntialias,
36 		LastStyle
37 	};
38 
39 public:
40 	CParamDisplay (const CRect& size, CBitmap* background = nullptr, int32_t style = 0);
41 	CParamDisplay (const CParamDisplay& paramDisplay);
42 
43 	//-----------------------------------------------------------------------------
44 	/// @name CParamDisplay Methods
45 	//-----------------------------------------------------------------------------
46 	//@{
47 	virtual void setFont (CFontRef fontID);
getFont()48 	const CFontRef getFont () const { return fontID; }
49 
50 	virtual void setFontColor (CColor color);
getFontColor()51 	CColor getFontColor () const { return fontColor; }
52 
53 	virtual void setBackColor (CColor color);
getBackColor()54 	CColor getBackColor () const { return backColor; }
55 
56 	virtual void setFrameColor (CColor color);
getFrameColor()57 	CColor getFrameColor () const { return frameColor; }
58 
59 	virtual void setShadowColor (CColor color);
getShadowColor()60 	CColor getShadowColor () const { return shadowColor; }
61 
62 	virtual void setShadowTextOffset (const CPoint& offset);
getShadowTextOffset()63 	CPoint getShadowTextOffset () const { return shadowTextOffset; }
64 
setAntialias(bool state)65 	virtual void setAntialias (bool state) { setBit (style, kAntialias, state); }
getAntialias()66 	bool getAntialias () const { return hasBit (style, kAntialias); }
67 
68 	virtual void setHoriAlign (CHoriTxtAlign hAlign);
getHoriAlign()69 	CHoriTxtAlign getHoriAlign () const { return horiTxtAlign; }
70 
71 	virtual void setTextInset (const CPoint& p);
getTextInset()72 	CPoint getTextInset () const { return textInset; }
73 
74 	virtual void setTextRotation (double angle);
getTextRotation()75 	double getTextRotation () const { return textRotation; }
76 
77 	virtual void setRoundRectRadius (const CCoord& radius);
getRoundRectRadius()78 	CCoord getRoundRectRadius () const { return roundRectRadius; }
79 
80 	virtual void setFrameWidth (const CCoord& width);
getFrameWidth()81 	CCoord getFrameWidth () const { return frameWidth; }
82 
83 	using ValueToStringUserData = CParamDisplay;
84 	using ValueToStringFunction = std::function<bool (float value, char utf8String[256], CParamDisplay* display)>;
85 
86 	void setValueToStringFunction (const ValueToStringFunction& valueToStringFunc);
87 	void setValueToStringFunction (ValueToStringFunction&& valueToStringFunc);
88 
89 	using ValueToStringFunction2 = std::function<bool (float value, std::string& result, CParamDisplay* display)>;
90 
91 	void setValueToStringFunction2 (const ValueToStringFunction2& valueToStringFunc);
92 	void setValueToStringFunction2 (ValueToStringFunction2&& valueToStringFunc);
93 
94 	enum Style
95 	{
96 		kShadowText		= 1 << StyleShadowText,
97 		k3DIn			= 1 << Style3DIn,
98 		k3DOut			= 1 << Style3DOut,
99 		kNoTextStyle	= 1 << StyleNoText,
100 		kNoDrawStyle	= 1 << StyleNoDraw,
101 		kRoundRectStyle = 1 << StyleRoundRect,
102 		kNoFrame		= 1 << StyleNoFrame,
103 	};
104 	virtual void setStyle (int32_t val);
105 	int32_t getStyle () const;
106 
107 	virtual void setPrecision (uint8_t precision);
getPrecision()108 	uint8_t getPrecision () const { return valuePrecision; }
109 
110 	virtual void setBackOffset (const CPoint& offset);
getBackOffset()111 	const CPoint& getBackOffset () const { return backOffset; }
112 	void copyBackOffset ();
113 
114 	//@}
115 
116 	void draw (CDrawContext* pContext) override;
117 	bool getFocusPath (CGraphicsPath& outPath) override;
118 	bool removed (CView* parent) override;
119 
120 	CLASS_METHODS(CParamDisplay, CControl)
121 protected:
122 	~CParamDisplay () noexcept override;
123 	virtual void drawBack (CDrawContext* pContext, CBitmap* newBack = nullptr);
124 
125 	virtual void drawPlatformText (CDrawContext* pContext, IPlatformString* string);
126 	virtual void drawPlatformText (CDrawContext* pContext, IPlatformString* string, const CRect& size);
127 
128 	virtual void drawStyleChanged ();
129 
130 	ValueToStringFunction2 valueToStringFunction;
131 
132 	enum StylePrivate {
133 		kAntialias		= 1 << StyleAntialias,
134 	};
135 
136 	CHoriTxtAlign horiTxtAlign;
137 	int32_t		style;
138 	uint8_t		valuePrecision;
139 
140 	CFontRef	fontID;
141 	CColor		fontColor;
142 	CColor		backColor;
143 	CColor		frameColor;
144 	CColor		shadowColor;
145 	CPoint		textInset;
146 	CPoint		shadowTextOffset {1., 1.};
147 	CPoint		backOffset;
148 	CCoord		roundRectRadius;
149 	CCoord		frameWidth;
150 	double		textRotation;
151 };
152 
153 } // VSTGUI
154