Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed May 3, 2021
1 parent 984d0ae commit 786f8d9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ struct COptionMenu : public CControl
SEP,
COLBK,
SECT,
CUSTOM,
ROOT
} type = ROOT;

Expand All @@ -1840,6 +1841,8 @@ struct COptionMenu : public CControl
std::string label = "";
std::function<void(void)> op = []() {};
std::vector<MenuNode> children;
//std::unique_ptr<juce::PopupMenu::CustomComponent> customComponent;
juce::PopupMenu::CustomComponent *customComponent;
bool checked = false;
bool enabled = true;
} rootNode;
Expand Down Expand Up @@ -1881,6 +1884,19 @@ struct COptionMenu : public CControl
r->nodeIndex = rootNode.children.size() - 1;
return r;
}
std::shared_ptr<CMenuItem> addEntry(juce::PopupMenu::CustomComponent *compPtr, // I own
const std::function<void(void)> &callback )
{
auto q = MenuNode{MenuNode::CUSTOM};
q.customComponent = compPtr;
q.op = callback;
rootNode.children.push_back(q);

auto res = std::make_shared<CMenuItem>();
res->weakPtr = this;
res->nodeIndex = rootNode.children.size() - 1;
return res;
}
std::shared_ptr<CMenuItem> addEntry(COptionMenu *m, const std::string &nm)
{
m->remember();
Expand Down Expand Up @@ -1948,6 +1964,11 @@ struct COptionMenu : public CControl
case MenuNode::SECT:
m.addSectionHeader(k.label);
break;
case MenuNode::CUSTOM:
auto rr = std::unique_ptr<juce::PopupMenu::CustomComponent>(k.customComponent);

m.addCustomItem(-1, std::move(rr));
break;
}
ct++;
if (nbi > 0 && ct % nbi == 0)
Expand Down
50 changes: 50 additions & 0 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,56 @@ int32_t SurgeGUIEditor::controlModifierClicked(CControl *control, CButtonState b
eid++;
}

struct BS : public juce::PopupMenu::CustomComponent,
public juce::Button::Listener
{
BS(){
std::cout << "Made a BS" << std::endl;
flarg = std::make_unique<juce::TextButton>("Foo");
flarg->setButtonText("Cool" );
flarg->addListener(this);
addAndMakeVisible(*flarg);
};
~BS() {std::cout << "Killed a BS" << std::endl; };
std::unique_ptr<juce::TextButton> flarg;
void getIdealSize(int &idealWidth, int &idealHeight) override {
idealWidth = 200;
idealHeight = 25;
}
void buttonClicked(juce::Button *button1) override {
std::cout << "BUtton Clicked" << std::endl;
}
void paint(juce::Graphics &g) override {
g.fillAll(juce::Colour(255,0,255));
g.setColour(juce::Colour(isDown * 255,255,isDown * 255));
auto w = getWidth();
auto h = getHeight();
int v = startP;
for( int i=0; i<w; i += 3 )
{
v ++;
v = v % h;
g.drawLine(i,0,i,v);
}
}
void resized() override {
auto button = getBounds().withRight(50);
flarg->setBounds(button);
}
void mouseDown(const juce::MouseEvent &event) override
{
std::cout << "mouseDown" << std::endl;
isDown = true;
repaint();
}
void mouseUp(const juce::MouseEvent &event) override {
std::cout << "mouseUp" << std::endl;
}
bool isDown = false;
int startP = 0;
};
contextMenu->addEntry(new BS(), [](){});

contextMenu->addSeparator(eid++);

char txt[TXT_SIZE], txt2[512];
Expand Down

0 comments on commit 786f8d9

Please sign in to comment.