Skip to content

Commit

Permalink
add GuiAtomList class
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreguillot committed Nov 1, 2021
1 parent 276601d commit 88f8ca0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Source/PluginEditorObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ PluginEditorObject* PluginEditorObject::createTyped(CamomileEditorMouseManager&
{
return new GuiAtomSymbol(p, g);
}
else if(g.getType() == pd::Gui::Type::AtomList)
{
return new GuiAtomList(p, g);
}
else if(g.getType() == pd::Gui::Type::Array)
{
return new GuiArray(p, g);
Expand Down Expand Up @@ -845,6 +849,92 @@ void GuiAtomSymbol::updateValue()
}
}

GuiAtomList::GuiAtomList(CamomileEditorMouseManager& p, pd::Gui& g) : GuiTextEditor(p, g)
{
label.onEditorHide = [this]()
{
auto array = StringArray();
array.addTokens(label.getText(), true);
std::vector<pd::Atom> list;
list.reserve(array.size());
for(auto const& elem : array)
{
if(elem.getCharPointer().isDigit())
{
list.push_back({elem.getFloatValue()});
}
else
{
list.push_back({elem.toStdString()});
}
}
if(list != gui.getList())
{
startEdition();
gui.setList(list);
stopEdition();
label.setText(juce::String(gui.getSymbol()), juce::NotificationType::dontSendNotification);
}
};

label.onEditorShow = [this]()
{
auto* editor = label.getCurrentTextEditor();
if(editor != nullptr)
{
editor->setIndents(1, 2);
editor->setBorder(juce::BorderSize<int>(0));
}
};

updateValue();
}

void GuiAtomList::paint(juce::Graphics& g)
{
static auto const border = 1.0f;
const float h = static_cast<float>(getHeight());
const float w = static_cast<float>(getWidth());
const float o = h * 0.25f;
juce::Path p;
p.startNewSubPath(0.5f, 0.5f);
p.lineTo(0.5f, h - 0.5f);
p.lineTo(w - o, h - 0.5f);
p.lineTo(w - 0.5f, h - o);
p.lineTo(w - 0.5f, o);
p.lineTo(w - o, 0.5f);
p.closeSubPath();
g.setColour(juce::Colour(static_cast<uint32>(gui.getBackgroundColor())));
g.fillPath(p);
g.setColour(juce::Colours::black);
g.strokePath(p, juce::PathStrokeType(border));
}

void GuiAtomList::updateValue()
{
if(edited == false && !label.isBeingEdited())
{
auto const array = gui.getList();
juce::String message;
for(auto const& atom : array)
{
if(message.isNotEmpty())
{
message += " ";
}
if(atom.isFloat())
{
message += juce::String(atom.getFloat());
}
else if(atom.isSymbol())
{
message += juce::String(atom.getSymbol());
}
}
label.setText(message, juce::NotificationType::dontSendNotification);
}
}

GuiArray::GuiArray(CamomileEditorMouseManager& p, pd::Gui& g) : PluginEditorObject(p, g),
m_graph(gui.getArray()), m_array(p.getProcessor(), m_graph)
{
Expand Down
8 changes: 8 additions & 0 deletions Source/PluginEditorObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ class GuiAtomSymbol : public GuiTextEditor
void updateValue() override;
};

class GuiAtomList : public GuiTextEditor
{
public:
GuiAtomList(CamomileEditorMouseManager& p, pd::Gui& g);
void paint(juce::Graphics& g) override;
void updateValue() override;
};

class GuiArray : public PluginEditorObject
{
public:
Expand Down

0 comments on commit 88f8ca0

Please sign in to comment.