I've emboldened pertinent lines of the parent for easier reading. Adding 'public DragAndDropTarget', 'public FileDragAndDropTarget', 'public TextDragAndDropTarget' to the child cpp just causes the error 'cannot instantiate abstract class'. Also, 'message' and 'somethingIsBeingDraggedOver' is coming up as undeclared, even though they are declared as a member variable in the header. Very confused. Thank you.
Parent.h
#ifndef SECTIONCONTROLS_H_INCLUDED
#define SECTIONCONTROLS_H_INCLUDED
#include "../JuceLibraryCode/JuceHeader.h"
#include "FloorComponent.h"
#include "MidiDropFile.h"
class SectionControls : public Component,
public Button::Listener,
public DragAndDropContainer
{
public:
SectionControls();
~SectionControls();
void paint (Graphics& g) override;
void resized() override;
void buttonClicked (Button* button) override;
private:
FloorComponent floor;
TextButton addNewPhraseButton;
Label addNewPhraseLabel;
MidiDropFile midiDropFile;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SectionControls);
};
#endif
Parent.cpp
#include "../JuceLibraryCode/JuceHeader.h"
#include "SectionControls.h"
#include "PhraseCreator.h"
SectionControls::SectionControls()
{
addAndMakeVisible (floor);
addAndMakeVisible (addNewPhraseButton);
addNewPhraseButton.setButtonText ("Add New Phrase");
addNewPhraseButton.setColour(TextButton::buttonColourId, Colours::crimson);
addNewPhraseButton.addListener(this);
addAndMakeVisible (addNewPhraseLabel);
addNewPhraseLabel.setColour (Label::backgroundColourId, Colours::black);
addNewPhraseLabel.setColour (Label::textColourId, Colours::white);
addNewPhraseLabel.setJustificationType (Justification::centred);
addAndMakeVisible (midiDropFile);
}
SectionControls::~SectionControls()
{
addNewPhraseButton.removeListener(this);
}
void SectionControls::paint (Graphics& g)
{
g.fillAll (Colours::lightblue);
}
void SectionControls::resized()
{
floor.setBounds (getWidth() / 10, getHeight() / 10, getWidth() + 100, 5);
addNewPhraseButton.setBounds(5, 5, 60, 20);
addNewPhraseButton.changeWidthToFitText();
addNewPhraseLabel.setBounds(120, 5, 100, 20);
midiDropFile.setBounds (5, 100, 100, 40);
}
void SectionControls::buttonClicked (Button* button)
{
if (button == &addNewPhraseButton)
{
PhraseCreator newPhrase;
newPhrase.setName("newPhrase");
String newName = newPhrase.getName();
addNewPhraseLabel.setText (newName, dontSendNotification);
}
}
Child.h
#ifndef MIDIDROPFILE_H_INCLUDED
#define MIDIDROPFILE_H_INCLUDED
class MidiDropFile : public Component,
public DragAndDropTarget,
public FileDragAndDropTarget,
public TextDragAndDropTarget
{
public:
MidiDropFile();
~MidiDropFile();
void paint (Graphics& g) override;
void resized() override;
private:
String message;
bool somethingIsBeingDraggedOver;
};
#endif
Child.cpp
#include "../JuceLibraryCode/JuceHeader.h"
#include "MidiDropFile.h"
MidiDropFile::MidiDropFile()
: message ("Drop Midi File Here"),
somethingIsBeingDraggedOver (false)
{
}
MidiDropFile::~MidiDropFile()
{
}
void paint (Graphics& g)
{
g.fillAll (Colours::green.withAlpha (0.2f));
// draw a red line around the comp if the user's currently dragging something over it..
if (somethingIsBeingDraggedOver)
{
g.setColour (Colours::red);
g.drawRect (getLocalBounds(), 3);
}
g.setColour (Colours::black);
g.setFont (14.0f);
g.drawFittedText (message, getLocalBounds().reduced (10, 0), Justification::centred, 4);
}