The Red Penguin

Implementing drag and drop triggers


Monday 3 August 2020

In order to implement drag and drop, as you might imagine, there's another abstract class we have to deal with. It's called FileDragAndDropTarget.

1. We need to go to DeckGUI.h and add this to our inheritances.
class DeckGUI  : public juce::Component, 
public juce::Button::Listener,
public juce::Slider::Listener,
public juce::FileDragAndDropTarget

2. In public: add the functions we need:
bool isInterestedInDragAndDrop(const juce::StringArray &files) override;
void filesDropped(const juce::StringArray &files, int x, int y) override;

3. We have now defined our functions and the next step is to go and implement them. At the bottom of DeckGUI.cpp we add:
bool DeckGUI::isInterestedInFileDrag (const juce::StringArray &files)
{
return true;
}

void DeckGUI::filesDropped (const juce::StringArray &files, int x, int y)
{
std::cout << "DeckGUI::filesDropped" << std::endl;
if (files.size() == 1)
{
player->loadURL(juce::URL{ juce::File{files[0]} });
}
}

And that seems to work!