/*
  ==============================================================================

    This file was auto-generated by the Introjucer!

    It contains the basic framework code for a JUCE plugin editor.

  ==============================================================================
*/

#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "BinaryData.h"

//==============================================================================
SFXAudioProcessorEditor::SFXAudioProcessorEditor (SFXAudioProcessor& p)
    : gin::ProcessorEditor (p), sfxProcessor (p)
{
    logo = juce::ImageFileFormat::loadFrom (BinaryData::logo_png, BinaryData::logo_pngSize);

    addAndMakeVisible (padGrid);
    addAndMakeVisible (params);

    setGridSize (16, 6);

    auto& padComponents = padGrid.getPads();
    for (int i = 0; i < padComponents.size(); i++)
    {
        auto pc = padComponents[i];

        pc->onDown = [this, i] ()
        {
            sfxProcessor.midiNoteOn (sfxProcessor.getPads()[i]->note);
            params.setPage (i);
        };

        pc->onUp = [this, i] ()
        {
            sfxProcessor.midiNoteOff (sfxProcessor.getPads()[i]->note);
        };
    }
}

SFXAudioProcessorEditor::~SFXAudioProcessorEditor()
{
}

//==============================================================================
void SFXAudioProcessorEditor::refresh()
{
}

void SFXAudioProcessorEditor::resized()
{
    gin::ProcessorEditor::resized();

    auto rc = getFullGridArea();

    padGrid.setBounds (rc.removeFromLeft (rc.getHeight()));
    params.setBounds (rc);
}

void SFXAudioProcessorEditor::paint (juce::Graphics& g)
{
    gin::ProcessorEditor::paint (g);

    g.drawImageAt (logo, getWidth() / 2 - logo.getWidth() / 2, 0);
}
