f@0
|
1 //
|
f@0
|
2 // Controls.h
|
f@0
|
3 // AccessibleSpectrumAnalyser
|
f@0
|
4 //
|
f@0
|
5 // Created by Fiore Martin on 18/01/2016.
|
f@0
|
6 //
|
f@0
|
7 //
|
f@0
|
8
|
f@0
|
9 #ifndef Controls_h
|
f@0
|
10 #define Controls_h
|
f@0
|
11
|
f@0
|
12
|
f@0
|
13 /* Knob with a text label and a text displaying the current value */
|
f@0
|
14 class IKnobMultiControlText : public IKnobControl
|
f@0
|
15 {
|
f@0
|
16 private:
|
f@0
|
17 IRECT mDisplayRECT, mImgRECT, mNameRECT, mLabelRECT;
|
f@0
|
18 IBitmap mBitmap;
|
f@0
|
19
|
f@0
|
20 public:
|
f@0
|
21 IKnobMultiControlText(IPlugBase* pPlug, IRECT pR, int paramIdx, IBitmap* pBitmap, IText* pText, int indent = 10)
|
f@0
|
22 : IKnobControl(pPlug, pR, paramIdx), mBitmap(*pBitmap)
|
f@0
|
23 {
|
f@0
|
24 mText = *pText;
|
f@0
|
25 /* mRECT is the bounding rectangle of the whole KnobMultiControlText */
|
f@0
|
26 mNameRECT = IRECT(mRECT.L, mRECT.T,mRECT.R, mRECT.T+16);
|
f@0
|
27 mDisplayRECT = IRECT(mRECT.L, mRECT.B-25, mRECT.R-21, mRECT.B); // left, top, right, bottom
|
f@0
|
28 mLabelRECT = mDisplayRECT;
|
f@0
|
29 mLabelRECT.L = mDisplayRECT.R; // shift it to the right of the diplay RECT
|
f@0
|
30 mLabelRECT.R = mLabelRECT.L+indent; // how much the display is indented
|
f@0
|
31 mImgRECT = IRECT(mRECT.L, mRECT.T+16, &mBitmap);
|
f@0
|
32 mDisablePrompt = false;
|
f@0
|
33 }
|
f@0
|
34
|
f@0
|
35 ~IKnobMultiControlText() {}
|
f@0
|
36
|
f@0
|
37 bool Draw(IGraphics* pGraphics)
|
f@0
|
38 {
|
f@0
|
39 int i = 1 + int(0.5 + mValue * (double) (mBitmap.N - 1));
|
f@0
|
40 i = BOUNDED(i, 1, mBitmap.N);
|
f@0
|
41
|
f@0
|
42 /* draw the knob */
|
f@0
|
43 pGraphics->DrawBitmap(&mBitmap, &mImgRECT, i, &mBlend);
|
f@0
|
44
|
f@0
|
45 /* draw displayed value for host, that is the value as represented in the host */
|
f@0
|
46 char displayedValue[20];
|
f@0
|
47 mPlug->GetParam(mParamIdx)->GetDisplayForHost(displayedValue);
|
f@0
|
48
|
f@0
|
49 bool dispDrawn = true;
|
f@0
|
50 if (CSTR_NOT_EMPTY(displayedValue)) {
|
f@0
|
51 dispDrawn = pGraphics->DrawIText(&mText, displayedValue, &mDisplayRECT);
|
f@0
|
52 }
|
f@0
|
53
|
f@0
|
54 /* name of the parameter */
|
f@0
|
55 if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetNameForHost())){
|
f@0
|
56 char nameDisp[MAX_PARAM_NAME_LEN];
|
f@0
|
57 strcpy(nameDisp, mPlug->GetParam(mParamIdx)->GetNameForHost());
|
f@0
|
58
|
f@0
|
59 if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetLabelForHost())){
|
f@0
|
60 char label[MAX_PARAM_LABEL_LEN];
|
f@0
|
61 strcpy(label, mPlug->GetParam(mParamIdx)->GetLabelForHost());
|
f@0
|
62 pGraphics->DrawIText(&mText, label, &mLabelRECT);
|
f@0
|
63 }
|
f@0
|
64
|
f@0
|
65 return dispDrawn && pGraphics->DrawIText(&mText, nameDisp, &mNameRECT);
|
f@0
|
66 }
|
f@0
|
67
|
f@0
|
68 return dispDrawn;
|
f@0
|
69 }
|
f@0
|
70
|
f@0
|
71 void OnMouseDown(int x, int y, IMouseMod* pMod)
|
f@0
|
72 {
|
f@0
|
73 OnMouseDrag(x, y, 0, 0, pMod);
|
f@0
|
74 }
|
f@0
|
75
|
f@0
|
76 /* double click puts it back to default value */
|
f@0
|
77 void OnMouseDblClick(int x, int y, IMouseMod* pMod)
|
f@0
|
78 {
|
f@0
|
79 if (mDefaultValue >= 0.0)
|
f@0
|
80 {
|
f@0
|
81 mValue = mDefaultValue;
|
f@0
|
82 SetDirty();
|
f@0
|
83 }
|
f@0
|
84 }
|
f@0
|
85
|
f@0
|
86 };
|
f@0
|
87
|
f@0
|
88
|
f@0
|
89 #endif /* Controls_h */
|