Skip to content

Commit

Permalink
move palette window and editing components out of library
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 15, 2024
1 parent a94c094 commit 198b7b2
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
==============================================================================
*/

#include "colour_palette_window.h"
#include "ColourPaletteWindow.h"

#include "./colour_palette_component.h"
#include "./lumatone_editor_library/palettes/colour_selection_group.h"
#include "./lumatone_editor_library/palettes/colour_picker_panel.h"

#include "./palette_selection_panel.h"
#include "./colour_picker_panel.h"
#include "./colour_palette_component.h"
#include "./palette_edit_panel.h"

#include "./LumatoneEditorLookAndFeel.h"


//==============================================================================
// ColourPaletteWindow Definitions

ColourPaletteWindow::ColourPaletteWindow(juce::Array<LumatoneEditorColourPalette>& colourPalettesIn)
// : lookAndFeel(TerpstraSysExApplication::getApp().getLookAndFeel()),
: colourPalettes(colourPalettesIn)
ColourPaletteWindow::ColourPaletteWindow(const LumatoneEditorState& stateIn)
: LumatoneEditorStateController("ColourPaletteWindow", stateIn)
{
// setLookAndFeel(&lookAndFeel);

setName("ColourPaletteWindow");
setLookAndFeel(&getEditorLookAndFeel());

colourSelectorGroup.reset(new ColourSelectionGroup());
palettePanel.reset(new ColourPalettesPanel(colourPalettes, colourSelectorGroup.get()));

palettePanel.reset(new ColourPalettesPanel(getColourPalettes(), colourSelectorGroup.get()));
palettePanel->addListener(this);

palettePanelViewport.reset(new juce::Viewport("PalettePanelViewport"));
Expand All @@ -46,26 +47,26 @@ ColourPaletteWindow::ColourPaletteWindow(juce::Array<LumatoneEditorColourPalette
colourToolTabs->addTab(juce::translate("ColourPalettes"), juce::Colour(), palettePanelViewport.get(), false);
colourToolTabs->addTab(juce::translate("CustomPicker"), juce::Colour(), customPickerPanel.get(), false);
colourToolTabs->setColour(juce::TabbedComponent::ColourIds::outlineColourId, juce::Colour());
// colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.9f);
colourToolTabs->getTabbedButtonBar().getProperties().set(LumatoneEditorStyleIDs::fontHeightScalar, 0.9f);
addAndMakeVisible(*colourToolTabs);
const int firstTabIndex = 0;//; TerpstraSysExApplication::getApp().getPropertiesFile()->getIntValue("LastColourPopupTabIndex");

const int firstTabIndex = getProperty(LumatoneEditorProperty::LastColourWindowTab, "0").getIntValue();
colourToolTabs->setCurrentTabIndex(firstTabIndex);
colourToolTabs->getTabbedButtonBar().addChangeListener(this);
}

ColourPaletteWindow::~ColourPaletteWindow()
{
{
paletteEditPanel = nullptr;
colourToolTabs = nullptr;

colourSelectorGroup->removeSelector(customPickerPanel.get());
customPickerPanel = nullptr;

palettePanelViewport = nullptr;
palettePanel = nullptr;
colourSelectorGroup = nullptr;

setLookAndFeel(nullptr);
}

Expand All @@ -77,13 +78,13 @@ void ColourPaletteWindow::resized()
if (paletteEditPanel.get())
paletteEditPanel->setBounds(getLocalBounds());

palettePanel->rebuildPanel(colourPalettes, palettePanelViewport->getMaximumVisibleWidth());
palettePanel->rebuildPanel(getColourPalettes(), palettePanelViewport->getMaximumVisibleWidth());
}

void ColourPaletteWindow::startEditingPalette(int paletteIndexIn, int selectedSwatchIndex)
{
paletteIndexEditing = paletteIndexIn;
paletteEditPanel.reset(new PaletteEditPanel(colourPalettes[paletteIndexIn]));
paletteEditPanel.reset(new PaletteEditPanel(*this, LumatoneEditorState::getColourPalettes()[paletteIndexIn]));
paletteEditPanel->setBounds(getLocalBounds());
paletteEditPanel->setLookAndFeel(&getLookAndFeel());
addAndMakeVisible(*paletteEditPanel);
Expand All @@ -96,36 +97,47 @@ void ColourPaletteWindow::startEditingPalette(int paletteIndexIn, int selectedSw

void ColourPaletteWindow::duplicatePalette(int paletteIndexIn)
{
auto copiedPalette = colourPalettes[paletteIndexIn].clone();
auto colourPalettes = getColourPalettes();
auto copiedPalette = getColourPalettes()[paletteIndexIn].clone();

if (! copiedPalette.saveToFile())
return; // TODO

colourPalettes.insert(paletteIndexIn + 1, copiedPalette);
// TerpstraSysExApplication::getApp().saveColourPalette(copiedPalette);
setColourPalettes(colourPalettes);

palettePanel->rebuildPanel(colourPalettes);
}

void ColourPaletteWindow::removePalette(int paletteIndexToRemove)
{
// Remove loaded colour palette
juce::String deletedPalette = colourPalettes[paletteIndexToRemove].getPathToFile();
auto colourPalettes = getColourPalettes();
auto deletedPalette = colourPalettes[paletteIndexToRemove];

if (!deletedPalette.deleteFile())
return; // TODO

colourPalettes.remove(paletteIndexToRemove);

// TerpstraSysExApplication::getApp().deletePaletteFile(deletedPalette);
setColourPalettes(colourPalettes);

palettePanel->rebuildPanel(colourPalettes);
}

void ColourPaletteWindow::editPaletteRequested(int paletteIndex, int selectedSwatchIndex)
{
if (paletteIndex >= 0 && paletteIndex < colourPalettes.size())
if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size())
{
startEditingPalette(paletteIndex, selectedSwatchIndex);
}
else
jassert(true); // Something bad happened!
jassert(true); // Something bad happened!
}

void ColourPaletteWindow::clonePaletteRequested(int paletteIndex)
{
if (paletteIndex >= 0 && paletteIndex < colourPalettes.size())
if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size())
{
duplicatePalette(paletteIndex);
}
Expand All @@ -135,7 +147,7 @@ void ColourPaletteWindow::clonePaletteRequested(int paletteIndex)

void ColourPaletteWindow::deletePaletteRequested(int paletteIndex)
{
if (paletteIndex >= 0 && paletteIndex < colourPalettes.size())
if (paletteIndex >= 0 && paletteIndex < getColourPalettes().size())
{
removePalette(paletteIndex);
}
Expand All @@ -146,7 +158,13 @@ void ColourPaletteWindow::deletePaletteRequested(int paletteIndex)
void ColourPaletteWindow::newPaletteRequested()
{
paletteEditingIsNew = true;
colourPalettes.insert(0, LumatoneEditorColourPalette());

auto colourPalettes = getColourPalettes();
auto newPalette = LumatoneEditorColourPalette();
newPalette.saveToFile();
colourPalettes.insert(0, newPalette);

setColourPalettes(colourPalettes);
startEditingPalette(0, 0);
}

Expand All @@ -157,21 +175,23 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source
{
if (paletteEditPanel->wasSaveRequested())
{
if (paletteIndexEditing >= 0 && paletteIndexEditing < colourPalettes.size())
if (paletteIndexEditing >= 0 && paletteIndexEditing < getColourPalettes().size())
{
auto colourPalettes = getColourPalettes();
auto palette = colourPalettes.getReference(paletteIndexEditing);
palette.setColours(paletteEditPanel->getCurrentPalette());

juce::String newName = paletteEditPanel->getPaletteName();
palette.setName(newName);

// TerpstraSysExApplication::getApp().saveColourPalette(palette);
palette.saveToFile();
setColourPalettes(colourPalettes);
}
else
jassert(true); // Something bad happened!


palettePanel->rebuildPanel(colourPalettes);
palettePanel->rebuildPanel(getColourPalettes());
}
else if (paletteEditingIsNew)
removePalette(paletteIndexEditing);
Expand All @@ -180,10 +200,10 @@ void ColourPaletteWindow::changeListenerCallback(juce::ChangeBroadcaster* source
paletteEditingIsNew = false;
paletteEditPanel = nullptr;
}

else if (source == &colourToolTabs->getTabbedButtonBar())
{
const int newTab = colourToolTabs->getCurrentTabIndex();
// TerpstraSysExApplication::getApp().getPropertiesFile()->setValue("LastColourPopupTabIndex", newTab);
getPropertiesFile()->setValue(LumatoneEditorProperty::LastColourWindowTab, juce::String(newTab));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

#pragma once

#include <JuceHeader.h>
// #include "LumatoneEditorStyleCommon.h"

#include "./colour_selection_group.h"
#include "./colour_palette_file.h"
#include "./lumatone_editor_library/palettes/colour_selection_group.h"
#include "./lumatone_editor_library/palettes/colour_palette_file.h"

#include "./palette_selection_panel.h"

#include "./LumatoneEditorState.h"

class ColourSelectionGroup;
class ColourPaletteComponent;

class CustomPickerPanel;
Expand All @@ -26,12 +26,13 @@ class PaletteEditPanel;
//==============================================================================
/*
*/
class ColourPaletteWindow : public juce::Component,
public juce::ChangeListener,
public ColourPalettesPanel::Listener
class ColourPaletteWindow : public juce::Component
, private LumatoneEditorStateController
, public juce::ChangeListener
, public ColourPalettesPanel::Listener
{
public:
ColourPaletteWindow(juce::Array<LumatoneEditorColourPalette>& colourPalettesIn);
ColourPaletteWindow(const LumatoneEditorState& stateIn);
~ColourPaletteWindow() override;

void resized() override;
Expand All @@ -56,13 +57,13 @@ class ColourPaletteWindow : public juce::Component,
/// Force a colour selector (added to the group) to be selected
/// </summary>
/// <param name="newSelector"></param>
void setCurrentColourSelector(ColourSelectionBroadcaster* newSelector)
{
void setCurrentColourSelector(ColourSelectionBroadcaster* newSelector)
{
// This statement is kind of a kludge - vsicurella
if (colourSelectorGroup->getIndexOfSelector(newSelector) < 0)
colourSelectorGroup->addSelector(newSelector);

colourSelectorGroup->setCurrentSelector(newSelector);
colourSelectorGroup->setCurrentSelector(newSelector);
}

private:
Expand Down Expand Up @@ -96,10 +97,10 @@ class ColourPaletteWindow : public juce::Component,
void newPaletteRequested() override;

private:

// LumatoneEditorLookAndFeel lookAndFeel;

juce::Array<LumatoneEditorColourPalette>& colourPalettes;
//juce::Array<LumatoneEditorColourPalette>& colourPalettes;

std::unique_ptr<juce::TabbedComponent> colourToolTabs;
std::unique_ptr<ColourPalettesPanel> palettePanel;
Expand Down
2 changes: 1 addition & 1 deletion Source/GlobalSettingsArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "./LumatoneEditorState.h"

#include "./lumatone_editor_library/listeners/status_listener.h"
#include "./lumatone_editor_library/palettes/colour_view_component.h"
#include "./colour_view_component.h"

//[/Headers]

Expand Down
5 changes: 3 additions & 2 deletions Source/IsomorphicMassAssign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "./lumatone_editor_library/graphics/view_constants.h"
#include "./lumatone_editor_library/device/lumatone_controller.h"
#include "./lumatone_editor_library/palettes/colour_palette_component.h"
#include "./colour_palette_component.h"

//[/Headers]

Expand Down Expand Up @@ -733,7 +733,8 @@ void IsomorphicMassAssign::colourChangedCallback(ColourSelectionBroadcaster* sou
colourTable = newColours;
}

mappingLogic->setColourTable(colourTable);
if (mappingLogic)
mappingLogic->setColourTable(colourTable);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/NoteEditArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "./lumatone_editor_library/graphics/view_constants.h"

#include "MainComponent.h"
#include "./lumatone_editor_library/palettes/colour_view_component.h"
#include "./colour_view_component.h"
//[/Headers]

#include "NoteEditArea.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/SingleNoteAssign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

//[Headers] You can add your own extra header files here...
#include "./lumatone_editor_library/actions/edit_actions.h"
#include "./lumatone_editor_library/palettes/colour_view_component.h"
#include "./lumatone_editor_library/palettes/colour_edit_textbox.h"
#include "./colour_view_component.h"

#include "LumatoneEditorLookAndFeel.h"
//[/Headers]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <JuceHeader.h>
#include "colour_palette_component.h"
#include "../graphics/lumatone_assets.h"
#include "lumatone_editor_library/graphics/lumatone_assets.h"

//==============================================================================
// ColourPaletteComponent Definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#include <JuceHeader.h>

#include "./hex_group_palette.h"
#include "./colour_selection_broadcaster.h"
#include "./lumatone_editor_library/palettes/hex_group_palette.h"
#include "./lumatone_editor_library/palettes/colour_selection_broadcaster.h"

#include "./colour_palette_file.h"
#include "./lumatone_editor_library/palettes/colour_palette_file.h"

// #include "LumatoneEditorStyleCommon.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

//[Headers] You can add your own extra header files here...
#include "../graphics/view_constants.h"
#include "./lumatone_editor_library/graphics/view_constants.h"
//[/Headers]

#include "colour_view_component.h"
Expand Down Expand Up @@ -311,4 +311,3 @@ END_JUCER_METADATA

//[EndFile] You can add extra defines here...
//[/EndFile]

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#pragma once

//[Headers] -- You can add your own extra header files here --
#include <JuceHeader.h>
#include "colour_selection_group.h"
#include "./lumatone_editor_library/palettes/colour_selection_group.h"

/*
==============================================================================
Expand Down Expand Up @@ -137,4 +136,3 @@ class ColourViewComponent : public juce::Button,
//[EndFile] You can add extra defines here...

//[/EndFile]

Loading

0 comments on commit 198b7b2

Please sign in to comment.