Make duplicate script compatible with Python 3
[wdl/wdl-ol.git] / IPlugExamples / IPlugMultiTargets / IPlugMultiTargets_controls.h
blobf7c90749d669aaf8d3d020397dc7efc353442770
1 class ITestPopupMenu : public IControl
3 private:
4 IPopupMenu mMainMenu, mSubMenu;
6 public:
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)
28 doPopupMenu();
30 Redraw(); // seems to need this
31 SetDirty();
34 void doPopupMenu()
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);
50 else
52 DBGMSG("nothing chosen\n");
57 class ITestPopupMenuB : public IControl
59 private:
60 IPopupMenu mMainMenu;
62 public:
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)
79 doPopupMenu();
81 Redraw(); // seems to need this
82 SetDirty();
85 void doPopupMenu()
87 IPopupMenu* selectedMenu = mPlug->GetGUI()->CreateIPopupMenu(&mMainMenu, &mRECT);
89 if(selectedMenu)
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
110 private:
111 WDL_String mDisp;
112 public:
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);
132 return true;
135 void OnMouseDown(int x, int y, IMouseMod* pMod)
137 if (pMod->R)
139 const char* pname = mPlug->GetPresetName(mPlug->GetCurrentPresetIdx());
140 mPlug->GetGUI()->CreateTextEntry(this, &mText, &mRECT, pname);
142 else
144 doPopupMenu();
147 Redraw(); // seems to need this
148 SetDirty();
151 void doPopupMenu()
153 int numItems = mPlug->NPresets();
154 IPopupMenu menu;
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);
165 else
166 menu.AddItem(str);
169 menu.SetPrefix(2);
171 if(gui->CreateIPopupMenu(&menu, &mRECT))
173 int itemChosen = menu.GetChosenItemIdx();
175 if (itemChosen > -1)
177 mPlug->RestorePreset(itemChosen);
178 mPlug->InformHostOfProgramChange();
179 mPlug->DirtyParameters();
184 void TextFromTextEntry(const char* txt)
186 WDL_String safeName;
187 safeName.Set(txt, MAX_PRESET_NAME_LEN);
189 mPlug->ModifyCurrentPreset(safeName.Get());
190 mPlug->InformHostOfProgramChange();
191 mPlug->DirtyParameters();
192 SetDirty(false);
196 class IPopUpMenuControl : public IControl
198 public:
199 IPopUpMenuControl(IPlugBase *pPlug, IRECT pR, int paramIdx)
200 : IControl(pPlug, pR, paramIdx)
202 mDisablePrompt = false;
203 mDblAsSingleClick = true;
204 mText = IText(14);
207 bool Draw(IGraphics* pGraphics)
209 pGraphics->FillIRect(&COLOR_WHITE, &mRECT);
211 char disp[32];
212 mPlug->GetParam(mParamIdx)->GetDisplayForHost(disp);
214 if (CSTR_NOT_EMPTY(disp))
216 return pGraphics->DrawIText(&mText, disp, &mRECT);
219 return true;
222 void OnMouseDown(int x, int y, IMouseMod* pMod)
224 if (pMod->L)
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
239 public:
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)
248 switch (key)
250 //case KEY_SPACE:
251 /// DBGMSG("Space\n");
252 // return true;
253 case KEY_LEFTARROW:;
254 DBGMSG("Left\n");
255 return true;
256 case KEY_RIGHTARROW:
257 DBGMSG("Right\n");
258 return true;
259 case KEY_UPARROW:;
260 DBGMSG("Up\n");
261 return true;
262 case KEY_DOWNARROW:
263 DBGMSG("Down\n");
264 return true;
265 default:
266 return false;
271 class ITempoDisplay : public IControl
273 private:
274 ITimeInfo* mTimeInfo;
275 WDL_String mDisplay;
277 public:
278 ITempoDisplay(IPlugBase* pPlug, IRECT pR, IText* pText, ITimeInfo* pTimeInfo)
279 : IControl(pPlug, pR)
281 mText = *pText;
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
296 private:
297 IRECT mTextRECT, mImgRECT;
298 IBitmap mBitmap;
300 public:
301 IKnobMultiControlText(IPlugBase* pPlug, IRECT pR, int paramIdx, IBitmap* pBitmap, IText* pText)
302 : IKnobControl(pPlug, pR, paramIdx), mBitmap(*pBitmap)
304 mText = *pText;
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);
319 char disp[20];
320 mPlug->GetParam(mParamIdx)->GetDisplayForHost(disp);
322 if (CSTR_NOT_EMPTY(disp))
324 return pGraphics->DrawIText(&mText, disp, &mTextRECT);
326 return true;
329 void OnMouseDown(int x, int y, IMouseMod* pMod)
331 if (mTextRECT.Contains(x, y)) PromptUserInput(&mTextRECT);
332 #ifdef RTAS_API
333 else if (pMod->A)
335 if (mDefaultValue >= 0.0)
337 mValue = mDefaultValue;
338 SetDirty();
341 #endif
342 else
344 OnMouseDrag(x, y, 0, 0, pMod);
348 void OnMouseDblClick(int x, int y, IMouseMod* pMod)
350 #ifdef RTAS_API
351 PromptUserInput(&mTextRECT);
352 #else
353 if (mDefaultValue >= 0.0)
355 mValue = mDefaultValue;
356 SetDirty();
358 #endif
363 class IPeakMeterVert : public IControl
365 public:
367 IPeakMeterVert(IPlugBase* pPlug, IRECT pR)
368 : IControl(pPlug, pR)
370 mColor = COLOR_BLUE;
373 ~IPeakMeterVert() {}
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);
384 return true;
387 bool IsDirty() { return true;}
389 protected:
390 IColor mColor;
393 class IPeakMeterHoriz : public IPeakMeterVert
395 public:
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);
402 return true;