learn

Orange Part One – The drop

The first of 10 tutorials in 10 days. A simple OBJ object viewer with texture mapping. Named Orange….. Orange… Juice.. Orange Juice.. Wow!

This is what it would be great to be

IMG_6148

Create a new OpenGL Project and open MainComponent.cpp in your c++ editor of choice.

The File drop target

JUCE has a drop-able listener class for handling file drops, simply extend MainContentComponent with FileDragAndDropTarget.

class MainContentComponent   : public OpenGLAppComponent, private FileDragAndDropTarget

From FileDragAndDropTarget we must implement 2 virtual methods, filesDropped and isInterestedInFileDrag. Add these lines to the MainContentComponent

bool isInterestedInFileDrag(const StringArray& files) override
{
}

void filesDropped(const StringArray& files, int x, int y) override
{
}

Straight away I want to try and drop something on the window, but its going to need some debug info. I don’t want to use the console, this is a visual app, we can do better so lets set up some debug text on screen!

This is fairly easy, JUCE has some fantastic text rendering and manipulation options, we can throw a piece of text over the whole window and justify it up in the top left with these two lines in the render() method.

void paint (Graphics& g) override
{
g.setColour(Colours::orange);
g.drawText(debugMessage, Rectangle(0, 0, getWidth(), getHeight()), Justification::topLeft);
}

// private member variables
String debugMessage;

Great! But it won’t build because we arn’t returning from isInterestedInDragSource. So let’s get this thing running.

bool isInterestedInFileDrag(const StringArray& files) override
{
return true;
}

void filesDropped(const StringArray& files, int x, int y) override
{
debugMessage = files[0];
repaint();
}

Build it, run it, drop it, done!

Capture

Ok, it sucks a little bit but I’m getting an idea of the JUCE workflow.

What little amount of source code there is in this demo can be downloaded here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s