#pragma once #include "Widget.h" namespace GuiApp { struct Canvas : juce::Component, juce::FileDragAndDropTarget { Canvas() {} void makeNewWidget(int x, int y) { clearHighlighted(); objects.emplace_back(std::make_unique()); auto& newComp = *objects.back(); addAndMakeVisible(newComp); juce::Rectangle bounds {0, 0, 50, 50}; bounds.setCentre(juce::Point(x, y)); newComp.setBounds(bounds); newComp.setHighlight(true); newComp.onClick = [&] { clearHighlighted(); }; } void mouseDown(const juce::MouseEvent& event) override { makeNewWidget(event.getMouseDownX(), event.getMouseDownY()); } void clearHighlighted() { for (auto& obj: objects) obj->setHighlight(false); } void filesDropped(const juce::StringArray& files, int x, int y) override { makeNewWidget(x, y); } bool isInterestedInFileDrag (const juce::StringArray& files) override { return true; } std::vector> objects; }; } // namespace GuiApp