Skip to content

Commit

Permalink
Merge pull request #60 from ffAudio/develop
Browse files Browse the repository at this point in the history
Release 1.3.2
  • Loading branch information
ffAudio authored Apr 4, 2021
2 parents 620dc0d + e9b4e2b commit f4a6cb2
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 129 deletions.
6 changes: 5 additions & 1 deletion Editor/foleys_PropertiesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ void PropertiesEditor::createNewClass()
if (auto* editor = dlg.getTextEditor (editorID))
{
auto name = editor->getText().replaceCharacters (".&$@ ", "---__");
builder.getStylesheet().addNewStyleClass (name, &undo);
auto newNode = builder.getStylesheet().addNewStyleClass (name, &undo);
auto index = newNode.getParent().indexOf (newNode);
updatePopupMenu();
nodeSelect.setSelectedId (3000 + index);
}
}

Expand All @@ -188,6 +191,7 @@ void PropertiesEditor::deleteClass (const juce::String& name)
auto& stylesheet = builder.getStylesheet();
stylesheet.deleteStyleClass (name, &undo);
builder.removeStyleClassReferences (builder.getGuiRootNode(), name);
updatePopupMenu();
}

//==============================================================================
Expand Down
8 changes: 4 additions & 4 deletions Editor/foleys_StyleColourPropertyComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ juce::Colour StyleColourPropertyComponent::ColourPanel::ColourSelectorWithSwatch
return swatchColours [size_t (index)];
}

void StyleColourPropertyComponent::ColourPanel::ColourSelectorWithSwatches::setSwatchColour (int index, const juce::Colour& colour)
void StyleColourPropertyComponent::ColourPanel::ColourSelectorWithSwatches::setSwatchColour (int index, const juce::Colour& newColour)
{
swatchColours [size_t (index)] = colour;
swatchColours [size_t (index)] = newColour;
}

void StyleColourPropertyComponent::ColourPanel::ColourSelectorWithSwatches::loadSwatches()
Expand All @@ -281,8 +281,8 @@ void StyleColourPropertyComponent::ColourPanel::ColourSelectorWithSwatches::save
coloursNode->deleteAllChildElements();
for (int i = 0; i < int (swatchColours.size()); ++i)
{
auto* node = coloursNode->createNewChildElement (IDs::colour);
node->addTextElement (swatchColours [size_t (i)].toDisplayString (true));
auto* colourNode = coloursNode->createNewChildElement (IDs::colour);
colourNode->addTextElement (swatchColours [size_t (i)].toDisplayString (true));
}

p->setValue (IDs::swatches, coloursNode.get());
Expand Down
8 changes: 4 additions & 4 deletions Editor/foleys_StyleGradientPropertyComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ juce::Colour StyleGradientPropertyComponent::GradientPanel::ColourSelectorWithSw
return swatchColours [size_t (index)];
}

void StyleGradientPropertyComponent::GradientPanel::ColourSelectorWithSwatches::setSwatchColour (int index, const juce::Colour& colour)
void StyleGradientPropertyComponent::GradientPanel::ColourSelectorWithSwatches::setSwatchColour (int index, const juce::Colour& newColour)
{
swatchColours [size_t (index)] = colour;
swatchColours [size_t (index)] = newColour;
}

void StyleGradientPropertyComponent::GradientPanel::ColourSelectorWithSwatches::loadSwatches()
Expand All @@ -267,8 +267,8 @@ void StyleGradientPropertyComponent::GradientPanel::ColourSelectorWithSwatches::
coloursNode->deleteAllChildElements();
for (int i = 0; i < int (swatchColours.size()); ++i)
{
auto* node = coloursNode->createNewChildElement (IDs::colour);
node->addTextElement (swatchColours [size_t (i)].toDisplayString (true));
auto* colourNode = coloursNode->createNewChildElement (IDs::colour);
colourNode->addTextElement (swatchColours [size_t (i)].toDisplayString (true));
}

p->setValue (IDs::swatches, coloursNode.get());
Expand Down
13 changes: 7 additions & 6 deletions Editor/foleys_ToolBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void ToolBox::stateWasReloaded()
treeEditor.updateTree();
propertiesEditor.setStyle (builder.getStylesheet().getCurrentStyle());
palette.update();
builder.updateComponents();
}

void ToolBox::paint (juce::Graphics& g)
Expand Down Expand Up @@ -361,9 +362,9 @@ juce::File ToolBox::getLastLocation() const
{
juce::File lastLocation;

juce::ApplicationProperties properties;
properties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = properties.getUserSettings())
juce::ApplicationProperties appProperties;
appProperties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = appProperties.getUserSettings())
lastLocation = juce::File (p->getValue (IDs::lastLocation));

if (lastLocation.exists())
Expand All @@ -389,9 +390,9 @@ juce::File ToolBox::getLastLocation() const

void ToolBox::setLastLocation(juce::File file)
{
juce::ApplicationProperties properties;
properties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = properties.getUserSettings())
juce::ApplicationProperties appProperties;
appProperties.setStorageParameters (ToolBox::getApplicationPropertyStorage());
if (auto* p = appProperties.getUserSettings())
p->setValue (IDs::lastLocation, file.getFullPathName());
}

Expand Down
2 changes: 1 addition & 1 deletion General/foleys_MagicGUIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MagicGUIBuilder : public juce::ChangeListener
void updateStylesheet();

/**
Recreates all components from the <div/> tree.
Recreates all components from the <View/> tree.
If no div tree is found, createDefaultGUITree is called to give subclasses
a chance to create a suitable default.
*/
Expand Down
52 changes: 14 additions & 38 deletions General/foleys_MagicPluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,28 @@ MagicPluginEditor::MagicPluginEditor (MagicProcessorState& stateToUse, std::uniq
: juce::AudioProcessorEditor (*stateToUse.getProcessor()),
processorState (stateToUse),
builder (std::move (builderToUse))
{
initialise();
}

MagicPluginEditor::MagicPluginEditor (MagicProcessorState& stateToUse, const char* data, const int dataSize, std::unique_ptr<MagicGUIBuilder> builderToUse)
: juce::AudioProcessorEditor (*stateToUse.getProcessor()),
processorState (stateToUse),
builder (std::move (builderToUse))
{
initialise (data, dataSize);
}

MagicPluginEditor::~MagicPluginEditor()
{
#if JUCE_MODULE_AVAILABLE_juce_opengl && FOLEYS_ENABLE_OPEN_GL_CONTEXT
oglContext.detach();
#endif
}

void MagicPluginEditor::initialise (const char* data, int dataSize)
{
#if JUCE_MODULE_AVAILABLE_juce_opengl && FOLEYS_ENABLE_OPEN_GL_CONTEXT
oglContext.attachTo (*this);
#endif

if (builder.get() == nullptr)
builder = createBuilderInstance();
{
builder = std::make_unique<MagicGUIBuilder>(processorState);
builder->registerJUCEFactories();
builder->registerJUCELookAndFeels();
}

#if FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE
auto guiTree = processorState.getValueTree().getChildWithName ("magic");
if (guiTree.isValid())
setConfigTree (guiTree);
else if (data != nullptr)
setConfigTree (data, dataSize);
else
builder->createGUI (*this);
#else // FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE
auto guiTree = processorState.getGuiTree();
if (guiTree.isValid())
setConfigTree (guiTree);
#endif // FOLEYS_SAVE_EDITED_GUI_IN_PLUGIN_STATE

updateSize();
Expand All @@ -93,13 +77,11 @@ void MagicPluginEditor::initialise (const char* data, int dataSize)
#endif
}

std::unique_ptr<MagicGUIBuilder> MagicPluginEditor::createBuilderInstance()
MagicPluginEditor::~MagicPluginEditor()
{
auto newBuilder = std::make_unique<MagicGUIBuilder>(processorState);
newBuilder->registerJUCEFactories();
newBuilder->registerJUCELookAndFeels();

return newBuilder;
#if JUCE_MODULE_AVAILABLE_juce_opengl && FOLEYS_ENABLE_OPEN_GL_CONTEXT
oglContext.detach();
#endif
}

void MagicPluginEditor::updateSize()
Expand All @@ -121,10 +103,11 @@ void MagicPluginEditor::updateSize()
{
processorState.getLastEditorSize (width, height);

auto maximalBounds = juce::Desktop::getInstance().getDisplays().getTotalBounds (true);
int minWidth = rootNode.getProperty (IDs::minWidth, 10);
int minHeight = rootNode.getProperty (IDs::minHeight, 10);
int maxWidth = rootNode.getProperty (IDs::maxWidth, std::numeric_limits<int>::max());
int maxHeight = rootNode.getProperty (IDs::maxHeight, std::numeric_limits<int>::max());
int maxWidth = rootNode.getProperty (IDs::maxWidth, maximalBounds.getWidth());
int maxHeight = rootNode.getProperty (IDs::maxHeight, maximalBounds.getHeight());
setResizable (resizable, resizeCorner);
setResizeLimits (minWidth, minHeight, maxWidth, maxHeight);
}
Expand All @@ -146,13 +129,6 @@ void MagicPluginEditor::setConfigTree (const juce::ValueTree& gui)
updateSize();
}

void MagicPluginEditor::setConfigTree (const char* data, int dataSize)
{
juce::String text (data, size_t (dataSize));
auto gui = juce::ValueTree::fromXml (text);
setConfigTree (gui);
}

MagicGUIBuilder& MagicPluginEditor::getGUIBuilder()
{
// This shouldn't be possible, since the builder instance is created if none was supplied...
Expand Down
26 changes: 3 additions & 23 deletions General/foleys_MagicPluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class MagicPluginEditor : public juce::AudioProcessorEditor,
*/
MagicPluginEditor (MagicProcessorState& processorState, std::unique_ptr<MagicGUIBuilder> builder = {});

[[deprecated ("MagicPluginEditor will get the state from the processorState. Call processorState.setGuiValueTree() beforehand.")]]
MagicPluginEditor (MagicProcessorState& processorState, const char* data, const int dataSize, std::unique_ptr<MagicGUIBuilder> builder = {});

~MagicPluginEditor() override;

/**
Expand All @@ -65,23 +62,6 @@ class MagicPluginEditor : public juce::AudioProcessorEditor,
*/
void setConfigTree (const juce::ValueTree& gui);

/**
Setup a GUI from a previously stored ValueTree. This is the
usual way to deploy your finished GUI via the Projucer:
@code{.cpp}
AudioProcessorEditor* MyAudioProcessor::createEditor()
{
auto* editor = new foleys::MagicPluginEditor (magicState, BinaryData::magic_xml, BinaryData::magic_xmlSize);
return editor;
}
@endcode
@param data points to the binary data of the XML file
@param dataSize the number of bytes
*/
void setConfigTree (const char* data, int dataSize);

/**
Grants access to the MagicGUIBuilder
*/
Expand All @@ -92,10 +72,10 @@ class MagicPluginEditor : public juce::AudioProcessorEditor,
void resized() override;

private:
void initialise (const char* data = nullptr, int dataSize = 0);

std::unique_ptr<MagicGUIBuilder> createBuilderInstance();

/**
Setup the size and resizable and size limits
*/
void updateSize();

#if JUCE_MODULE_AVAILABLE_juce_opengl && FOLEYS_ENABLE_OPEN_GL_CONTEXT
Expand Down
19 changes: 10 additions & 9 deletions General/foleys_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@
*/


namespace BinaryDataFallbacks {
const int namedResourceListSize = 0;
const char** namedResourceList = nullptr;
const char* getNamedResource(const char*, int&) { return nullptr; }
} // namespace BinaryDataFallbacks

namespace BinaryData {
using namespace BinaryDataFallbacks;
}

namespace foleys
{

#if FOLEYS_ENABLE_BINARY_DATA

juce::StringArray Resources::getResourceFileNames()
{
juce::StringArray names;
Expand All @@ -60,11 +68,4 @@ juce::Image Resources::getImage (const juce::String& name)
return {};
}

#else

juce::StringArray Resources::getResourceFileNames() { return {}; }
juce::Image Resources::getImage (const juce::String&) { return {}; }

#endif

}
2 changes: 1 addition & 1 deletion Layout/foleys_Decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Decorator::ClientBounds Decorator::getClientBounds (juce::Rectangle<int> overall
else
{
juce::Font f (captionSize * 0.8f);
auto w = f.getStringWidth (caption);
auto w = float (f.getStringWidth (caption));

if (justification.getOnlyHorizontalFlags() & juce::Justification::left)
captionBox = box.removeFromLeft (w).toNearestInt();
Expand Down
Loading

0 comments on commit f4a6cb2

Please sign in to comment.