1 class ITestPopupMenu
: public IControl
4 IPopupMenu mMainMenu
, mSubMenu
;
7 ITestPopupMenu(IPlugBase
*pPlug
, IRECT pR
)
8 : IControl(pPlug
, pR
, -1)
10 mMainMenu
.AddItem("first item");
11 mMainMenu
.AddItem("second item");
12 mMainMenu
.AddItem("third item");
14 mSubMenu
.AddItem("first item");
15 mSubMenu
.AddItem("second item");
16 mSubMenu
.AddItem("third item");
18 mMainMenu
.AddItem("sub menu", &mSubMenu
);
21 bool Draw(IGraphics
* pGraphics
)
23 return pGraphics
->FillIRect(&COLOR_WHITE
, &mRECT
);;
26 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
30 Redraw(); // seems to need this
36 IPopupMenu
* selectedMenu
= mPlug
->GetGUI()->CreateIPopupMenu(&mMainMenu
, &mRECT
);
38 if (selectedMenu
== &mMainMenu
)
40 int itemChosen
= selectedMenu
->GetChosenItemIdx();
41 selectedMenu
->CheckItemAlone(itemChosen
);
42 DBGMSG("item chosen, main menu %i\n", itemChosen
);
44 else if (selectedMenu
== &mSubMenu
)
46 int itemChosen
= selectedMenu
->GetChosenItemIdx();
47 selectedMenu
->CheckItemAlone(itemChosen
);
48 DBGMSG("item chosen, sub menu %i\n", itemChosen
);
52 DBGMSG("nothing chosen\n");
57 class ITestPopupMenuB
: public IControl
63 ITestPopupMenuB(IPlugBase
*pPlug
, IRECT pR
)
64 : IControl(pPlug
, pR
, -1)
66 mMainMenu
.SetMultiCheck(true);
67 mMainMenu
.AddItem("first item");
68 mMainMenu
.AddItem("second item");
69 mMainMenu
.AddItem("third item");
72 bool Draw(IGraphics
* pGraphics
)
74 return pGraphics
->FillIRect(&COLOR_WHITE
, &mRECT
);;
77 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
81 Redraw(); // seems to need this
87 IPopupMenu
* selectedMenu
= mPlug
->GetGUI()->CreateIPopupMenu(&mMainMenu
, &mRECT
);
91 int idx
= selectedMenu
->GetChosenItemIdx();
92 selectedMenu
->CheckItem(idx
, !selectedMenu
->IsItemChecked(idx
));
94 WDL_String checkedItems
;
96 checkedItems
.Append("checked: ", 1024);
98 for (int i
= 0; i
< selectedMenu
->GetNItems(); i
++)
100 checkedItems
.AppendFormatted(1024, "%i ", selectedMenu
->IsItemChecked(i
));
103 DBGMSG("%s\n", checkedItems
.Get());
108 class IPresetMenu
: public IControl
113 IPresetMenu(IPlugBase
*pPlug
, IRECT pR
)
114 : IControl(pPlug
, pR
, -1)
116 mTextEntryLength
= MAX_PRESET_NAME_LEN
- 3;
117 mText
= IText(14, &COLOR_BLACK
, "Arial", IText::kStyleNormal
, IText::kAlignNear
);
120 bool Draw(IGraphics
* pGraphics
)
122 int pNumber
= mPlug
->GetCurrentPresetIdx();
123 mDisp
.SetFormatted(32, "%02d: %s", pNumber
+1, mPlug
->GetPresetName(pNumber
));
125 pGraphics
->FillIRect(&COLOR_WHITE
, &mRECT
);
127 if (CSTR_NOT_EMPTY(mDisp
.Get()))
129 return pGraphics
->DrawIText(&mText
, mDisp
.Get(), &mRECT
);
135 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
139 const char* pname
= mPlug
->GetPresetName(mPlug
->GetCurrentPresetIdx());
140 mPlug
->GetGUI()->CreateTextEntry(this, &mText
, &mRECT
, pname
);
147 Redraw(); // seems to need this
153 int numItems
= mPlug
->NPresets();
156 IGraphics
* gui
= mPlug
->GetGUI();
158 int currentPresetIdx
= mPlug
->GetCurrentPresetIdx();
160 for(int i
= 0; i
< numItems
; i
++)
162 const char* str
= mPlug
->GetPresetName(i
);
163 if (i
== currentPresetIdx
)
164 menu
.AddItem(str
, -1, IPopupMenuItem::kChecked
);
171 if(gui
->CreateIPopupMenu(&menu
, &mRECT
))
173 int itemChosen
= menu
.GetChosenItemIdx();
177 mPlug
->RestorePreset(itemChosen
);
178 mPlug
->InformHostOfProgramChange();
179 mPlug
->DirtyParameters();
184 void TextFromTextEntry(const char* txt
)
187 safeName
.Set(txt
, MAX_PRESET_NAME_LEN
);
189 mPlug
->ModifyCurrentPreset(safeName
.Get());
190 mPlug
->InformHostOfProgramChange();
191 mPlug
->DirtyParameters();
196 class IPopUpMenuControl
: public IControl
199 IPopUpMenuControl(IPlugBase
*pPlug
, IRECT pR
, int paramIdx
)
200 : IControl(pPlug
, pR
, paramIdx
)
202 mDisablePrompt
= false;
203 mDblAsSingleClick
= true;
207 bool Draw(IGraphics
* pGraphics
)
209 pGraphics
->FillIRect(&COLOR_WHITE
, &mRECT
);
212 mPlug
->GetParam(mParamIdx
)->GetDisplayForHost(disp
);
214 if (CSTR_NOT_EMPTY(disp
))
216 return pGraphics
->DrawIText(&mText
, disp
, &mRECT
);
222 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
226 PromptUserInput(&mRECT
);
229 mPlug
->GetGUI()->SetAllControlsDirty();
232 //void OnMouseWheel(int x, int y, IMouseMod* pMod, int d){} //TODO: popup menus seem to hog the mousewheel
236 // Key catcher is an icontrol but only its OnKeyDown() is called... after all the other controls have been tested to see if they want keyboard input
237 class IKeyCatcher
: public IControl
240 IKeyCatcher(IPlugBase
* pPlug
, IRECT pR
)
241 : IControl(pPlug
, pR
) {}
243 // this never gets called but is needed for an IControl
244 bool Draw(IGraphics
* pGraphics
) { return false; }
246 bool OnKeyDown(int x
, int y
, int key
)
251 /// DBGMSG("Space\n");
271 class ITempoDisplay
: public IControl
274 ITimeInfo
* mTimeInfo
;
278 ITempoDisplay(IPlugBase
* pPlug
, IRECT pR
, IText
* pText
, ITimeInfo
* pTimeInfo
)
279 : IControl(pPlug
, pR
)
282 mTimeInfo
= pTimeInfo
;
285 bool Draw(IGraphics
* pGraphics
)
287 mDisplay
.SetFormatted(80, "Tempo: %f, SamplePos: %i, PPQPos: %f", mTimeInfo
->mTempo
, (int) mTimeInfo
->mSamplePos
, mTimeInfo
->mPPQPos
);
288 return pGraphics
->DrawIText(&mText
, mDisplay
.Get(), &mRECT
);
291 bool IsDirty() { return true;}
294 class IKnobMultiControlText
: public IKnobControl
297 IRECT mTextRECT
, mImgRECT
;
301 IKnobMultiControlText(IPlugBase
* pPlug
, IRECT pR
, int paramIdx
, IBitmap
* pBitmap
, IText
* pText
)
302 : IKnobControl(pPlug
, pR
, paramIdx
), mBitmap(*pBitmap
)
305 mTextRECT
= IRECT(mRECT
.L
, mRECT
.B
-20, mRECT
.R
, mRECT
.B
);
306 mImgRECT
= IRECT(mRECT
.L
, mRECT
.T
, &mBitmap
);
307 mDisablePrompt
= false;
310 ~IKnobMultiControlText() {}
312 bool Draw(IGraphics
* pGraphics
)
314 int i
= 1 + int(0.5 + mValue
* (double) (mBitmap
.N
- 1));
315 i
= BOUNDED(i
, 1, mBitmap
.N
);
316 pGraphics
->DrawBitmap(&mBitmap
, &mImgRECT
, i
, &mBlend
);
317 //pGraphics->FillIRect(&COLOR_WHITE, &mTextRECT);
320 mPlug
->GetParam(mParamIdx
)->GetDisplayForHost(disp
);
322 if (CSTR_NOT_EMPTY(disp
))
324 return pGraphics
->DrawIText(&mText
, disp
, &mTextRECT
);
329 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
331 if (mTextRECT
.Contains(x
, y
)) PromptUserInput(&mTextRECT
);
335 if (mDefaultValue
>= 0.0)
337 mValue
= mDefaultValue
;
344 OnMouseDrag(x
, y
, 0, 0, pMod
);
348 void OnMouseDblClick(int x
, int y
, IMouseMod
* pMod
)
351 PromptUserInput(&mTextRECT
);
353 if (mDefaultValue
>= 0.0)
355 mValue
= mDefaultValue
;
363 class IPeakMeterVert
: public IControl
367 IPeakMeterVert(IPlugBase
* pPlug
, IRECT pR
)
368 : IControl(pPlug
, pR
)
375 bool Draw(IGraphics
* pGraphics
)
377 //IRECT(mRECT.L, mRECT.T, mRECT.W , mRECT.T + (mValue * mRECT.H));
378 pGraphics
->FillIRect(&COLOR_RED
, &mRECT
);
380 //pGraphics->FillIRect(&COLOR_BLUE, &mRECT);
382 IRECT filledBit
= IRECT(mRECT
.L
, mRECT
.T
, mRECT
.R
, mRECT
.B
- (mValue
* mRECT
.H()));
383 pGraphics
->FillIRect(&mColor
, &filledBit
);
387 bool IsDirty() { return true;}
393 class IPeakMeterHoriz
: public IPeakMeterVert
397 bool Draw(IGraphics
* pGraphics
)
399 pGraphics
->FillIRect(&COLOR_BLUE
, &mRECT
);
400 IRECT filledBit
= IRECT(mRECT
.L
, mRECT
.T
, mRECT
.L
+ (mValue
* mRECT
.W() ) , mRECT
.B
);
401 pGraphics
->FillIRect(&mColor
, &filledBit
);