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