Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Last active July 8, 2022 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olilarkin/949034284462a120bc64be8652b66e11 to your computer and use it in GitHub Desktop.
Save olilarkin/949034284462a120bc64be8652b66e11 to your computer and use it in GitHub Desktop.
Demonstrates a popup menu to resize the UI
#include "IPlugEffect.h"
#include "IPlug_include_in_plug_src.h"
#include "IControls.h"
class ResizeMenuControl : public IControl
{
public:
ResizeMenuControl(const IRECT& bounds)
: IControl(bounds)
{}
void Draw(IGraphics& g) override
{
g.FillRect(COLOR_RED, mRECT);
}
void OnMouseDown(float x, float y, const IMouseMod& mod) override
{
mMenu.CheckItemAlone(mUiSize);
GetUI()->CreatePopupMenu(*this, mMenu, x, y);
}
void OnPopupMenuSelection(IPopupMenu* pSelectedMenu, int valIdx) override
{
auto chosenItemIdx = pSelectedMenu->GetChosenItemIdx();
switch (chosenItemIdx) {
case 0: mUiSize = 0; GetUI()->Resize(300, 300, 1.f); break;
case 1: mUiSize = 1; GetUI()->Resize(600, 600, 1.f); break;
case 2: mUiSize = 2; GetUI()->Resize(900, 900, 1.f); break;
default:
break;
}
}
private:
int mUiSize = 1;
IPopupMenu mMenu {"Menu", {"300x300", "600x600", "900x900"}};
};
IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
{
GetParam(kGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%");
mMakeGraphicsFunc = [&]() {
return MakeGraphics(*this, PLUG_WIDTH, PLUG_HEIGHT, PLUG_FPS, GetScaleForScreen(PLUG_WIDTH, PLUG_HEIGHT));
};
mLayoutFunc = [&](IGraphics* pGraphics) {
const IRECT b = pGraphics->GetBounds();
if (pGraphics->NControls()) {
pGraphics->GetBackgroundControl()->SetTargetAndDrawRECTs(b);
return;
}
pGraphics->AttachCornerResizer(EUIResizerMode::Scale, true);
pGraphics->AttachPanelBackground(COLOR_GRAY);
pGraphics->LoadFont("Roboto-Regular", ROBOTO_FN);
pGraphics->AttachControl(new ResizeMenuControl(b.GetPadded(-10).GetFromTLHC(100, 50)));
};
}
#if IPLUG_DSP
void IPlugEffect::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
const double gain = GetParam(kGain)->Value() / 100.;
const int nChans = NOutChansConnected();
for (int s = 0; s < nFrames; s++) {
for (int c = 0; c < nChans; c++) {
outputs[c][s] = inputs[c][s] * gain;
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment