diff --git a/extras/Introjucer/JuceLibraryCode/BinaryData.cpp b/extras/Introjucer/JuceLibraryCode/BinaryData.cpp index af8ef250a1..d9fa19fcf3 100644 --- a/extras/Introjucer/JuceLibraryCode/BinaryData.cpp +++ b/extras/Introjucer/JuceLibraryCode/BinaryData.cpp @@ -5,38 +5,8 @@ */ -#include "BinaryData.h" - - -const char* BinaryData::getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +namespace BinaryData { - int hash = 0; - if (resourceNameUTF8 != 0) - while (*resourceNameUTF8 != 0) - hash = 31 * hash + *resourceNameUTF8++; - - switch (hash) - { - case 0x44be9398: numBytes = BinaryData::AudioPluginXCodeScript_txtSize; return BinaryData::AudioPluginXCodeScript_txt; - case 0x950fd7dd: numBytes = BinaryData::brushed_aluminium_pngSize; return BinaryData::brushed_aluminium_png; - case 0x27c5a93a: numBytes = BinaryData::jucer_AudioPluginEditorTemplate_cppSize; return BinaryData::jucer_AudioPluginEditorTemplate_cpp; - case 0x4d0721bf: numBytes = BinaryData::jucer_AudioPluginEditorTemplate_hSize; return BinaryData::jucer_AudioPluginEditorTemplate_h; - case 0x51b49ac5: numBytes = BinaryData::jucer_AudioPluginFilterTemplate_cppSize; return BinaryData::jucer_AudioPluginFilterTemplate_cpp; - case 0x488afa0a: numBytes = BinaryData::jucer_AudioPluginFilterTemplate_hSize; return BinaryData::jucer_AudioPluginFilterTemplate_h; - case 0x8905395b: numBytes = BinaryData::jucer_MainConsoleAppTemplate_cppSize; return BinaryData::jucer_MainConsoleAppTemplate_cpp; - case 0x7a0186b1: numBytes = BinaryData::jucer_MainTemplate_cppSize; return BinaryData::jucer_MainTemplate_cpp; - case 0x02a2a077: numBytes = BinaryData::jucer_NewCppFileTemplate_cppSize; return BinaryData::jucer_NewCppFileTemplate_cpp; - case 0x0842c43c: numBytes = BinaryData::jucer_NewCppFileTemplate_hSize; return BinaryData::jucer_NewCppFileTemplate_h; - case 0x3f052be8: numBytes = BinaryData::jucer_WindowTemplate_cppSize; return BinaryData::jucer_WindowTemplate_cpp; - case 0xb20377ed: numBytes = BinaryData::jucer_WindowTemplate_hSize; return BinaryData::jucer_WindowTemplate_h; - case 0x154a7275: numBytes = BinaryData::juce_icon_pngSize; return BinaryData::juce_icon_png; - default: break; - } - - numBytes = 0; - return 0; -} - //================== AudioPluginXCodeScript.txt ================== static const unsigned char temp_43731c40[] = @@ -85,7 +55,7 @@ static const unsigned char temp_43731c40[] = " cp -r \"$original\" \"$RTAS\"\r\n" "fi\r\n"; -const char* BinaryData::AudioPluginXCodeScript_txt = (const char*) temp_43731c40; +const char* AudioPluginXCodeScript_txt = (const char*) temp_43731c40; //================== brushed_aluminium.png ================== static const unsigned char temp_9aa09877[] = @@ -297,7 +267,7 @@ static const unsigned char temp_9aa09877[] = 141,20,180,27,72,224,103,149,105,220,112,255,4,89,131,64,4,23,42,115,215,231,245,156,43,234,151,42,11,138,116,121,82,135,79,3,255,178,101,152,75,177,57,53,232,244,11,46,246,251,67,98,174,121,193,110,222,30,8,28,132,216,112,88,219,73,10,62,169,115,60, 233,137,16,177,58,98,69,178,95,87,93,157,5,174,93,143,182,244,186,210,167,70,131,11,5,88,2,12,0,52,103,80,26,178,200,170,15,0,0,0,0,73,69,78,68,174,66,96,130,0,0 }; -const char* BinaryData::brushed_aluminium_png = (const char*) temp_9aa09877; +const char* brushed_aluminium_png = (const char*) temp_9aa09877; //================== jucer_AudioPluginEditorTemplate.cpp ================== static const unsigned char temp_6eda5614[] = @@ -337,7 +307,7 @@ static const unsigned char temp_6eda5614[] = " Justification::centred, 1);\r\n" "}\r\n"; -const char* BinaryData::jucer_AudioPluginEditorTemplate_cpp = (const char*) temp_6eda5614; +const char* jucer_AudioPluginEditorTemplate_cpp = (const char*) temp_6eda5614; //================== jucer_AudioPluginEditorTemplate.h ================== static const unsigned char temp_67353d19[] = @@ -374,7 +344,7 @@ static const unsigned char temp_67353d19[] = "\r\n" "#endif // HEADERGUARD\r\n"; -const char* BinaryData::jucer_AudioPluginEditorTemplate_h = (const char*) temp_67353d19; +const char* jucer_AudioPluginEditorTemplate_h = (const char*) temp_67353d19; //================== jucer_AudioPluginFilterTemplate.cpp ================== static const unsigned char temp_98c9479f[] = @@ -556,7 +526,7 @@ static const unsigned char temp_98c9479f[] = " return new FILTERCLASSNAME();\r\n" "}\r\n"; -const char* BinaryData::jucer_AudioPluginFilterTemplate_cpp = (const char*) temp_98c9479f; +const char* jucer_AudioPluginFilterTemplate_cpp = (const char*) temp_98c9479f; //================== jucer_AudioPluginFilterTemplate.h ================== static const unsigned char temp_62b91564[] = @@ -633,7 +603,7 @@ static const unsigned char temp_62b91564[] = "\r\n" "#endif // HEADERGUARD\r\n"; -const char* BinaryData::jucer_AudioPluginFilterTemplate_h = (const char*) temp_62b91564; +const char* jucer_AudioPluginFilterTemplate_h = (const char*) temp_62b91564; //================== jucer_MainConsoleAppTemplate.cpp ================== static const unsigned char temp_794304c3[] = @@ -660,7 +630,7 @@ static const unsigned char temp_794304c3[] = " return 0;\r\n" "}\r\n"; -const char* BinaryData::jucer_MainConsoleAppTemplate_cpp = (const char*) temp_794304c3; +const char* jucer_MainConsoleAppTemplate_cpp = (const char*) temp_794304c3; //================== jucer_MainTemplate.cpp ================== static const unsigned char temp_292512d9[] = @@ -738,7 +708,7 @@ static const unsigned char temp_292512d9[] = "// This macro generates the main() routine that starts the app.\r\n" "START_JUCE_APPLICATION(APPCLASSNAME)\r\n"; -const char* BinaryData::jucer_MainTemplate_cpp = (const char*) temp_292512d9; +const char* jucer_MainTemplate_cpp = (const char*) temp_292512d9; //================== jucer_NewCppFileTemplate.cpp ================== static const unsigned char temp_79decf5f[] = @@ -753,7 +723,7 @@ static const unsigned char temp_79decf5f[] = "*/\r\n" "\r\n"; -const char* BinaryData::jucer_NewCppFileTemplate_cpp = (const char*) temp_79decf5f; +const char* jucer_NewCppFileTemplate_cpp = (const char*) temp_79decf5f; //================== jucer_NewCppFileTemplate.h ================== static const unsigned char temp_70d8d24[] = @@ -776,7 +746,7 @@ static const unsigned char temp_70d8d24[] = "\r\n" "#endif // HEADERGUARD\r\n"; -const char* BinaryData::jucer_NewCppFileTemplate_h = (const char*) temp_70d8d24; +const char* jucer_NewCppFileTemplate_h = (const char*) temp_70d8d24; //================== jucer_WindowTemplate.cpp ================== static const unsigned char temp_6fd7e50[] = @@ -812,7 +782,7 @@ static const unsigned char temp_6fd7e50[] = " JUCEApplication::getInstance()->systemRequestedQuit();\r\n" "}\r\n"; -const char* BinaryData::jucer_WindowTemplate_cpp = (const char*) temp_6fd7e50; +const char* jucer_WindowTemplate_cpp = (const char*) temp_6fd7e50; //================== jucer_WindowTemplate.h ================== static const unsigned char temp_613d4455[] = @@ -858,7 +828,7 @@ static const unsigned char temp_613d4455[] = "\r\n" "#endif // HEADERGUARD\r\n"; -const char* BinaryData::jucer_WindowTemplate_h = (const char*) temp_613d4455; +const char* jucer_WindowTemplate_h = (const char*) temp_613d4455; //================== juce_icon.png ================== static const unsigned char temp_ee6f0c0f[] = @@ -1139,4 +1109,49 @@ static const unsigned char temp_ee6f0c0f[] = 169,9,0,87,15,129,129,1,247,197,140,255,7,123,160,2,4,208,80,74,0,184,18,2,250,200,222,95,34,70,253,24,73,176,3,215,216,5,190,132,57,100,0,64,0,13,197,4,64,76,201,64,40,146,73,77,0,164,202,15,25,0,16,96,0,155,121,235,71,10,157,3,42,0,0,0,0,73,69,78,68, 174,66,96,130,0,0 }; -const char* BinaryData::juce_icon_png = (const char*) temp_ee6f0c0f; +const char* juce_icon_png = (const char*) temp_ee6f0c0f; + + +const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +{ + int hash = 0; + if (resourceNameUTF8 != 0) + while (*resourceNameUTF8 != 0) + hash = 31 * hash + *resourceNameUTF8++; + + switch (hash) + { + case 0x44be9398: + case 0x2981a553: numBytes = 1449; return AudioPluginXCodeScript_txt; + case 0x950fd7dd: + case 0xa6cfe0e2: numBytes = 14724; return brushed_aluminium_png; + case 0x27c5a93a: + case 0xb6575890: numBytes = 1008; return jucer_AudioPluginEditorTemplate_cpp; + case 0x4d0721bf: + case 0xc244271a: numBytes = 799; return jucer_AudioPluginEditorTemplate_h; + case 0x51b49ac5: + case 0xc68aa4a1: numBytes = 4455; return jucer_AudioPluginFilterTemplate_cpp; + case 0x488afa0a: + case 0x99c7f951: numBytes = 2400; return jucer_AudioPluginFilterTemplate_h; + case 0x8905395b: + case 0x84a71cc0: numBytes = 470; return jucer_MainConsoleAppTemplate_cpp; + case 0x7a0186b1: + case 0x73760f7c: numBytes = 1825; return jucer_MainTemplate_cpp; + case 0x02a2a077: + case 0x9a5d0862: numBytes = 232; return jucer_NewCppFileTemplate_cpp; + case 0x0842c43c: + case 0xfbfcda3c: numBytes = 308; return jucer_NewCppFileTemplate_h; + case 0x3f052be8: + case 0xb905d1ba: numBytes = 781; return jucer_WindowTemplate_cpp; + case 0xb20377ed: + case 0x959d5d38: numBytes = 1216; return jucer_WindowTemplate_h; + case 0x154a7275: + case 0xcd05ca61: numBytes = 19826; return juce_icon_png; + default: break; + } + + numBytes = 0; + return 0; +} + +} diff --git a/extras/Introjucer/JuceLibraryCode/BinaryData.h b/extras/Introjucer/JuceLibraryCode/BinaryData.h index 22a570087f..0fd7c5355d 100644 --- a/extras/Introjucer/JuceLibraryCode/BinaryData.h +++ b/extras/Introjucer/JuceLibraryCode/BinaryData.h @@ -49,4 +49,25 @@ namespace BinaryData // If you provide the name of one of the binary resource variables above, this function will // return the corresponding data and its size (or a null pointer if the name isn't found). const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw(); + + //============================================================================== + // This class acts as an ImageProvider that will access the BinaryData images + class ImageProvider : public juce::ComponentBuilder::ImageProvider + { + public: + ImageProvider() noexcept {} + + juce::Image getImageForIdentifier (const juce::var& imageIdentifier) + { + int dataSize = 0; + const char* const data = getNamedResource (imageIdentifier.toString().toUTF8(), dataSize); + + if (data != nullptr) + return juce::ImageCache::getFromMemory (data, dataSize); + + return juce::Image(); + } + + juce::var getIdentifierForImage (const juce::Image&) { return juce::var(); } + }; } diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index 6db2599c8e..69ec4b7e68 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -180,7 +180,7 @@ public: return StringArray ((const char**) names); } - const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName) + const PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& /*menuName*/) { PopupMenu menu; @@ -276,7 +276,7 @@ public: return menu; } - void menuItemSelected (int menuItemID, int topLevelMenuIndex) + void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) { if (menuItemID >= 100 && menuItemID < 200) { diff --git a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp index 631f4c23f3..3a9359b565 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp +++ b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp @@ -70,22 +70,17 @@ void ResourceFile::addResourcesFromProjectItem (const Project::Item& projectItem else { if (projectItem.shouldBeAddedToBinaryResources()) - addFile (projectItem.getFile()); + addFile (projectItem.getFile(), projectItem.getImageFileID()); } } //============================================================================== -void ResourceFile::setJuceHeaderToInclude (const File& header) -{ - juceHeader = header; -} - void ResourceFile::setClassName (const String& className_) { className = className_; } -void ResourceFile::addFile (const File& file) +void ResourceFile::addFile (const File& file, const String& imageProviderId) { files.add (file); @@ -96,6 +91,9 @@ void ResourceFile::addFile (const File& file) while (variableNames.contains (variableName)) variableName = variableNameRoot + String (suffix++); + if (imageProviderId.isNotEmpty()) + variableName << "|" << imageProviderId; + variableNames.add (variableName); } @@ -135,51 +133,34 @@ bool ResourceFile::write (const File& cppFile, OutputStream& cpp, OutputStream& cpp << "/* ==================================== " << resourceFileIdentifierString << " ====================================" << comment; - if (juceHeader.exists()) - header << CodeHelpers::createIncludeStatement (juceHeader, cppFile) << newLine; - const String namespaceName (className); - StringArray returnCodes; - - int i; - for (i = 0; i < files.size(); ++i) - returnCodes.add ("numBytes = " + namespaceName + "::" + variableNames[i] + "Size; return " - + namespaceName + "::" + variableNames[i] + ";"); - - cpp << CodeHelpers::createIncludeStatement (cppFile.withFileExtension (".h"), cppFile) << newLine - << newLine - << newLine - << "const char* " << namespaceName << "::getNamedResource (const char* resourceNameUTF8, int& numBytes) throw()" << newLine - << "{" << newLine; - - CodeHelpers::createStringMatcher (cpp, "resourceNameUTF8", variableNames, returnCodes, 4); - - cpp << " numBytes = 0;" << newLine - << " return 0;" << newLine - << "}" << newLine - << newLine; + cpp << "namespace " << namespaceName << newLine << "{" << newLine; header << "namespace " << namespaceName << newLine << "{" << newLine; - for (i = 0; i < files.size(); ++i) + StringArray returnCodes; + + for (int i = 0; i < files.size(); ++i) { const File& file = files.getReference(i); const int64 dataSize = file.getSize(); + const String variableName (variableNames[i].upToFirstOccurrenceOf ("|", false, false)); + + returnCodes.add ("numBytes = " + String (dataSize) + "; return " + variableName + ";"); + ScopedPointer fileStream (file.createInputStream()); jassert (fileStream != nullptr); if (fileStream != nullptr) { - const String variableName (variableNames[i]); const String tempVariable ("temp_" + String::toHexString (file.hashCode())); header << " extern const char* " << variableName << ";" << newLine; header << " const int " << variableName << "Size = " << (int) dataSize << ";" << newLine << newLine; cpp << newLine << "//================== " << file.getFileName() << " ==================" << newLine - << "static const unsigned char " << tempVariable - << "[] =" << newLine; + << "static const unsigned char " << tempVariable << "[] =" << newLine; { MemoryBlock data; @@ -188,14 +169,47 @@ bool ResourceFile::write (const File& cppFile, OutputStream& cpp, OutputStream& } cpp << newLine << newLine - << "const char* " << namespaceName << "::" << variableName << " = (const char*) " - << tempVariable << ";" << newLine; + << "const char* " << variableName << " = (const char*) " << tempVariable << ";" << newLine; } } + cpp << newLine + << newLine + << "const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw()" << newLine + << "{" << newLine; + + CodeHelpers::createStringMatcher (cpp, "resourceNameUTF8", variableNames, returnCodes, 4); + + cpp << " numBytes = 0;" << newLine + << " return 0;" << newLine + << "}" << newLine + << newLine + << "}" << newLine; + header << " // If you provide the name of one of the binary resource variables above, this function will" << newLine << " // return the corresponding data and its size (or a null pointer if the name isn't found)." << newLine << " const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw();" << newLine + << newLine + << " //==============================================================================" << newLine + << " // This class acts as an ImageProvider that will access the BinaryData images" << newLine + << " class ImageProvider : public juce::ComponentBuilder::ImageProvider" << newLine + << " {" << newLine + << " public:" << newLine + << " ImageProvider() noexcept {}" << newLine + << newLine + << " juce::Image getImageForIdentifier (const juce::var& imageIdentifier)" << newLine + << " {" << newLine + << " int dataSize = 0;" << newLine + << " const char* const data = getNamedResource (imageIdentifier.toString().toUTF8(), dataSize);" << newLine + << newLine + << " if (data != nullptr)" << newLine + << " return juce::ImageCache::getFromMemory (data, dataSize);" << newLine + << newLine + << " return juce::Image();" << newLine + << " }" << newLine + << newLine + << " juce::var getIdentifierForImage (const juce::Image&) { return juce::var(); }" << newLine + << " };" << newLine << "}" << newLine; return true; diff --git a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h index 1274adf7f3..1b2fc80e7d 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h @@ -42,12 +42,10 @@ public: static bool isResourceFile (const File& file); //============================================================================== - void setJuceHeaderToInclude (const File& header); - void setClassName (const String& className); String getClassName() const { return className; } - void addFile (const File& file); + void addFile (const File& file, const String& imageProviderId); String getDataVariableFor (const File& file) const; String getSizeVariableFor (const File& file) const; @@ -62,7 +60,6 @@ private: Array files; StringArray variableNames; Project& project; - File juceHeader; String className; void addResourcesFromProjectItem (const Project::Item& node); diff --git a/extras/Introjucer/Source/Project/jucer_Project.cpp b/extras/Introjucer/Source/Project/jucer_Project.cpp index f340b93592..71acfd667b 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.cpp +++ b/extras/Introjucer/Source/Project/jucer_Project.cpp @@ -91,8 +91,8 @@ void Project::updateProjectSettings() void Project::setMissingDefaultValues() { - if (! projectRoot.hasProperty (Ids::id_)) - projectRoot.setProperty (Ids::id_, createAlphaNumericUID(), nullptr); + if (! projectRoot.hasProperty (ComponentBuilder::idProperty)) + projectRoot.setProperty (ComponentBuilder::idProperty, createAlphaNumericUID(), nullptr); // Create main file group if missing if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid()) @@ -430,8 +430,8 @@ Project::Item::~Item() Project::Item Project::Item::createCopy() { Item i (*this); i.node = i.node.createCopy(); return i; } -String Project::Item::getID() const { return node [Ids::id_]; } -void Project::Item::setID (const String& newID) { node.setProperty (Ids::id_, newID, nullptr); } +String Project::Item::getID() const { return node [ComponentBuilder::idProperty]; } +void Project::Item::setID (const String& newID) { node.setProperty (ComponentBuilder::idProperty, newID, nullptr); } String Project::Item::getImageFileID() const { return "id:" + getID(); } @@ -451,7 +451,7 @@ bool Project::Item::isImageFile() const { return isFile() && getFile().hasFi Project::Item Project::Item::findItemWithID (const String& targetId) const { - if (node [Ids::id_] == targetId) + if (node [ComponentBuilder::idProperty] == targetId) return *this; if (isGroup()) @@ -595,7 +595,7 @@ File Project::Item::determineGroupFolder() const void Project::Item::initialiseNodeValues() { - if (! node.hasProperty (Ids::id_)) + if (! node.hasProperty (ComponentBuilder::idProperty)) setID (createAlphaNumericUID()); if (isFile()) @@ -820,7 +820,7 @@ bool Project::isModuleEnabled (const String& moduleID) const ValueTree modules (projectRoot.getChildWithName (Tags::modulesGroup)); for (int i = 0; i < modules.getNumChildren(); ++i) - if (modules.getChild(i) [Ids::id_] == moduleID) + if (modules.getChild(i) [ComponentBuilder::idProperty] == moduleID) return true; return false; @@ -828,13 +828,13 @@ bool Project::isModuleEnabled (const String& moduleID) const Value Project::shouldShowAllModuleFilesInProject (const String& moduleID) { - return getModulesNode().getChildWithProperty (Ids::id_, moduleID) + return getModulesNode().getChildWithProperty (ComponentBuilder::idProperty, moduleID) .getPropertyAsValue (Ids::showAllCode, getUndoManagerFor (getModulesNode())); } Value Project::shouldCopyModuleFilesLocally (const String& moduleID) { - return getModulesNode().getChildWithProperty (Ids::id_, moduleID) + return getModulesNode().getChildWithProperty (ComponentBuilder::idProperty, moduleID) .getPropertyAsValue (Ids::useLocalCopy, getUndoManagerFor (getModulesNode())); } @@ -843,7 +843,7 @@ void Project::addModule (const String& moduleID, bool shouldCopyFilesLocally) if (! isModuleEnabled (moduleID)) { ValueTree module (Tags::module); - module.setProperty (Ids::id_, moduleID, nullptr); + module.setProperty (ComponentBuilder::idProperty, moduleID, nullptr); ValueTree modules (getModulesNode()); modules.addChild (module, -1, getUndoManagerFor (modules)); @@ -860,7 +860,7 @@ void Project::removeModule (const String& moduleID) ValueTree modules (getModulesNode()); for (int i = 0; i < modules.getNumChildren(); ++i) - if (modules.getChild(i) [Ids::id_] == moduleID) + if (modules.getChild(i) [ComponentBuilder::idProperty] == moduleID) modules.removeChild (i, getUndoManagerFor (modules)); } @@ -879,7 +879,7 @@ int Project::getNumModules() const String Project::getModuleID (int index) const { - return projectRoot.getChildWithName (Tags::modulesGroup).getChild (index) [Ids::id_].toString(); + return projectRoot.getChildWithName (Tags::modulesGroup).getChild (index) [ComponentBuilder::idProperty].toString(); } //============================================================================== diff --git a/extras/Introjucer/Source/Project/jucer_Project.h b/extras/Introjucer/Source/Project/jucer_Project.h index 8cf7791d1a..be3b2301f4 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.h +++ b/extras/Introjucer/Source/Project/jucer_Project.h @@ -55,7 +55,7 @@ public: ValueTree getProjectRoot() const { return projectRoot; } Value getProjectName() { return getMainGroup().getName(); } String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); } - String getProjectUID() const { return projectRoot [Ids::id_]; } + String getProjectUID() const { return projectRoot [ComponentBuilder::idProperty]; } //============================================================================== template @@ -292,7 +292,7 @@ public: void valueTreeParentChanged (ValueTree& tree); //============================================================================== - UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; } + UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; } //============================================================================== static const char* projectFileExtension; diff --git a/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp b/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp index 286d4163f4..40a938ad17 100644 --- a/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp +++ b/extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp @@ -460,15 +460,20 @@ namespace CodeHelpers static int findBestHashMultiplier (const StringArray& strings) { + StringArray allStrings; + + for (int i = strings.size(); --i >= 0;) + allStrings.addTokens (strings[i], "|", ""); + int v = 31; for (;;) { SortedSet hashes; bool collision = false; - for (int i = strings.size(); --i >= 0;) + for (int i = allStrings.size(); --i >= 0;) { - const int hash = calculateHash (strings[i], v); + const int hash = calculateHash (allStrings[i], v); if (hashes.contains (hash)) { collision = true; @@ -503,8 +508,20 @@ namespace CodeHelpers << indent << "{" << newLine; for (int i = 0; i < strings.size(); ++i) - out << indent << " case 0x" << hexString8Digits (calculateHash (strings[i], hashMultiplier)) - << ": " << codeToExecute[i] << newLine; + { + StringArray matchingStrings; + matchingStrings.addTokens (strings[i], "|", ""); + + for (int j = 0; j < matchingStrings.size(); ++j) + { + out << indent << " case 0x" << hexString8Digits (calculateHash (matchingStrings[j], hashMultiplier)) << ":"; + + if (j < matchingStrings.size() - 1) + out << newLine; + } + + out << " " << codeToExecute[i] << newLine; + } out << indent << " default: break;" << newLine << indent << "}" << newLine << newLine; diff --git a/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h b/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h index d9d922c139..cb5f8e5310 100644 --- a/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h +++ b/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h @@ -62,7 +62,7 @@ public: virtual void showRenameBox(); // Text editor listener for renaming.. - void textEditorTextChanged (TextEditor& editor) {} + void textEditorTextChanged (TextEditor&) {} void textEditorReturnKeyPressed (TextEditor& editor) { editor.exitModalState (1); } void textEditorEscapeKeyPressed (TextEditor& editor) { editor.exitModalState (0); } void textEditorFocusLost (TextEditor& editor) { editor.exitModalState (0); } diff --git a/extras/Introjucer/Source/Utility/jucer_PresetIDs.h b/extras/Introjucer/Source/Utility/jucer_PresetIDs.h index cb0fdc5fd7..a7690eb504 100644 --- a/extras/Introjucer/Source/Utility/jucer_PresetIDs.h +++ b/extras/Introjucer/Source/Utility/jucer_PresetIDs.h @@ -32,46 +32,15 @@ namespace Ids { #define DECLARE_ID(name) const Identifier name (#name) - DECLARE_ID (text); DECLARE_ID (name); DECLARE_ID (file); - DECLARE_ID (font); - DECLARE_ID (mode); - DECLARE_ID (type); DECLARE_ID (version); DECLARE_ID (position); DECLARE_ID (source); - DECLARE_ID (readOnly); - DECLARE_ID (editMode); - DECLARE_ID (justification); - DECLARE_ID (placement); - DECLARE_ID (items); - DECLARE_ID (editable); - DECLARE_ID (textJustification); - DECLARE_ID (unselectedText); - DECLARE_ID (noItemsText); - DECLARE_ID (min); - DECLARE_ID (max); DECLARE_ID (width); DECLARE_ID (height); DECLARE_ID (background); - DECLARE_ID (interval); - DECLARE_ID (textBoxPos); - DECLARE_ID (textBoxWidth); - DECLARE_ID (textBoxHeight); - DECLARE_ID (skew); - DECLARE_ID (scrollBarV); - DECLARE_ID (scrollBarH); - DECLARE_ID (scrollbarWidth); DECLARE_ID (initialState); - DECLARE_ID (scrollbarsShown); - DECLARE_ID (caretVisible); - DECLARE_ID (popupMenuEnabled); - DECLARE_ID (radioGroup); - DECLARE_ID (connectedLeft); - DECLARE_ID (connectedRight); - DECLARE_ID (connectedTop); - DECLARE_ID (connectedBottom); DECLARE_ID (juceFolder); DECLARE_ID (targetFolder); DECLARE_ID (vstFolder); @@ -108,12 +77,9 @@ namespace Ids DECLARE_ID (parentClasses); DECLARE_ID (constructorParams); DECLARE_ID (memberInitialisers); - DECLARE_ID (lossOfFocusDiscardsChanges); - DECLARE_ID (url); DECLARE_ID (rootItemVisible); DECLARE_ID (openByDefault); DECLARE_ID (locked); - DECLARE_ID (image); DECLARE_ID (tooltip); DECLARE_ID (memberName); DECLARE_ID (focusOrder); @@ -124,17 +90,7 @@ namespace Ids DECLARE_ID (androidSDKPath); DECLARE_ID (androidNDKPath); DECLARE_ID (androidInternetNeeded); - DECLARE_ID (upImage); - DECLARE_ID (downImage); - DECLARE_ID (overImage); - DECLARE_ID (upOverlay); - DECLARE_ID (downOverlay); - DECLARE_ID (overOverlay); - DECLARE_ID (upOpacity); - DECLARE_ID (downOpacity); - DECLARE_ID (overOpacity); const Identifier class_ ("class"); - const Identifier id_ ("id"); #undef DECLARE_ID } diff --git a/extras/JuceDemo/JuceLibraryCode/BinaryData.cpp b/extras/JuceDemo/JuceLibraryCode/BinaryData.cpp index 3b24907906..5c942bebb0 100644 --- a/extras/JuceDemo/JuceLibraryCode/BinaryData.cpp +++ b/extras/JuceDemo/JuceLibraryCode/BinaryData.cpp @@ -5,30 +5,8 @@ */ -#include "BinaryData.h" - - -const char* BinaryData::getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +namespace BinaryData { - int hash = 0; - if (resourceNameUTF8 != 0) - while (*resourceNameUTF8 != 0) - hash = 31 * hash + *resourceNameUTF8++; - - switch (hash) - { - case 0x62032efa: numBytes = BinaryData::cello_wavSize; return BinaryData::cello_wav; - case 0xaec3f52f: numBytes = BinaryData::demo_table_data_xmlSize; return BinaryData::demo_table_data_xml; - case 0xae303c7c: numBytes = BinaryData::icons_zipSize; return BinaryData::icons_zip; - case 0xdf2195d7: numBytes = BinaryData::juce_pngSize; return BinaryData::juce_png; - case 0xdd644959: numBytes = BinaryData::treedemo_xmlSize; return BinaryData::treedemo_xml; - default: break; - } - - numBytes = 0; - return 0; -} - //================== cello.wav ================== static const unsigned char temp_55d084b5[] = @@ -639,7 +617,7 @@ static const unsigned char temp_55d084b5[] = 255,242,255,242,255,238,255,241,255,238,255,239,255,237,255,239,255,241,255,235,255,232,255,231,255,230,255,234,255,231,255,232,255,230,255,234,255,235,255,234,255,227,255,230,255,231,255,220,255,217,255,210,255,213,255,217,255,217,255,219,255,220,255, 219,255,226,255,223,255,212,255,220,255,220,255,220,255,210,255,223,255,230,255,224,255,227,255,231,255,231,255,231,255,234,255,226,255,232,255,237,255,241,255,235,255,232,255,231,255,232,255,237,255,235,255,234,255,0,0 }; -const char* BinaryData::cello_wav = (const char*) temp_55d084b5; +const char* cello_wav = (const char*) temp_55d084b5; //================== demo table data.xml ================== static const unsigned char temp_5a40772c[] = @@ -693,7 +671,7 @@ static const unsigned char temp_5a40772c[] = " \r\n" ""; -const char* BinaryData::demo_table_data_xml = (const char*) temp_5a40772c; +const char* demo_table_data_xml = (const char*) temp_5a40772c; //================== icons.zip ================== static const unsigned char temp_a1fd9237[] = @@ -1887,7 +1865,7 @@ static const unsigned char temp_a1fd9237[] = 194,180,16,0,0,195,74,0,0,22,0,0,0,0,0,0,0,1,0,32,0,0,0,236,35,1,0,112,114,101,102,101,114,101,110,99,101,115,45,115,121,115,116,101,109,46,115,118,103,80,75,1,2,20,0,20,0,2,0,8,0,183,128,249,52,199,174,1,222,145,13,0,0,154,63,0,0,18,0,0,0,0,0,0,0,1, 0,32,0,0,0,212,52,1,0,115,121,115,116,101,109,45,108,111,103,45,111,117,116,46,115,118,103,80,75,5,6,0,0,0,0,20,0,20,0,249,4,0,0,149,66,1,0,0,0,0,0 }; -const char* BinaryData::icons_zip = (const char*) temp_a1fd9237; +const char* icons_zip = (const char*) temp_a1fd9237; //================== juce.png ================== static const unsigned char temp_ffaf8e7e[] = @@ -2106,7 +2084,7 @@ static const unsigned char temp_ffaf8e7e[] = 5,5,121,88,4,4,120,152,128,189,32,208,249,43,255,222,188,249,8,154,219,1,221,19,4,219,204,143,60,183,67,179,173,12,163,128,58,0,32,128,24,169,104,14,108,152,30,148,104,96,183,130,192,206,199,67,62,144,8,54,143,129,124,139,202,223,209,196,50,52,0,64,0, 49,82,217,44,88,245,132,126,19,61,174,9,48,228,33,254,209,196,50,4,0,64,128,1,0,102,20,176,16,7,130,12,56,0,0,0,0,73,69,78,68,174,66,96,130,0,0 }; -const char* BinaryData::juce_png = (const char*) temp_ffaf8e7e; +const char* juce_png = (const char*) temp_ffaf8e7e; //================== treedemo.xml ================== static const unsigned char temp_816ae700[] = @@ -2161,4 +2139,33 @@ static const unsigned char temp_816ae700[] = " \r\n" ""; -const char* BinaryData::treedemo_xml = (const char*) temp_816ae700; +const char* treedemo_xml = (const char*) temp_816ae700; + + +const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +{ + int hash = 0; + if (resourceNameUTF8 != 0) + while (*resourceNameUTF8 != 0) + hash = 31 * hash + *resourceNameUTF8++; + + switch (hash) + { + case 0x62032efa: + case 0x877c5941: numBytes = 46348; return cello_wav; + case 0xaec3f52f: + case 0x5ef7e0f0: numBytes = 5239; return demo_table_data_xml; + case 0xae303c7c: + case 0xae3ee894: numBytes = 83876; return icons_zip; + case 0xdf2195d7: + case 0xc23b6643: numBytes = 15290; return juce_png; + case 0xdd644959: + case 0x0ff8e16f: numBytes = 1126; return treedemo_xml; + default: break; + } + + numBytes = 0; + return 0; +} + +} diff --git a/extras/JuceDemo/JuceLibraryCode/BinaryData.h b/extras/JuceDemo/JuceLibraryCode/BinaryData.h index 144c767467..89d27cf6c8 100644 --- a/extras/JuceDemo/JuceLibraryCode/BinaryData.h +++ b/extras/JuceDemo/JuceLibraryCode/BinaryData.h @@ -25,4 +25,25 @@ namespace BinaryData // If you provide the name of one of the binary resource variables above, this function will // return the corresponding data and its size (or a null pointer if the name isn't found). const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw(); + + //============================================================================== + // This class acts as an ImageProvider that will access the BinaryData images + class ImageProvider : public juce::ComponentBuilder::ImageProvider + { + public: + ImageProvider() noexcept {} + + juce::Image getImageForIdentifier (const juce::var& imageIdentifier) + { + int dataSize = 0; + const char* const data = getNamedResource (imageIdentifier.toString().toUTF8(), dataSize); + + if (data != nullptr) + return juce::ImageCache::getFromMemory (data, dataSize); + + return juce::Image(); + } + + juce::var getIdentifierForImage (const juce::Image&) { return juce::var(); } + }; } diff --git a/extras/the jucer/JuceLibraryCode/BinaryData.cpp b/extras/the jucer/JuceLibraryCode/BinaryData.cpp index c3624f9025..fb209241c7 100644 --- a/extras/the jucer/JuceLibraryCode/BinaryData.cpp +++ b/extras/the jucer/JuceLibraryCode/BinaryData.cpp @@ -5,29 +5,8 @@ */ -#include "BinaryData.h" - - -const char* BinaryData::getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +namespace BinaryData { - int hash = 0; - if (resourceNameUTF8 != 0) - while (*resourceNameUTF8 != 0) - hash = 31 * hash + *resourceNameUTF8++; - - switch (hash) - { - case 0xe23b4891: numBytes = BinaryData::jules_jpgSize; return BinaryData::jules_jpg; - case 0x496477a8: numBytes = BinaryData::prefs_about_pngSize; return BinaryData::prefs_about_png; - case 0x44e88a0d: numBytes = BinaryData::prefs_keys_pngSize; return BinaryData::prefs_keys_png; - case 0xdd254505: numBytes = BinaryData::prefs_misc_pngSize; return BinaryData::prefs_misc_png; - default: break; - } - - numBytes = 0; - return 0; -} - //================== jules.jpg ================== static const unsigned char temp_ec935dd1[] = @@ -349,7 +328,7 @@ static const unsigned char temp_ec935dd1[] = 148,76,143,157,191,200,191,163,9,117,152,15,242,170,125,188,31,241,67,254,85,205,182,34,56,24,127,200,142,189,125,159,246,46,103,124,93,118,171,46,56,244,252,235,113,189,21,239,91,116,110,79,218,160,1,107,212,217,105,250,99,194,218,181,27,250,180,248, 215,255,217,0,0 }; -const char* BinaryData::jules_jpg = (const char*) temp_ec935dd1; +const char* jules_jpg = (const char*) temp_ec935dd1; //================== prefs_about.png ================== static const unsigned char temp_101ffda8[] = @@ -379,7 +358,7 @@ static const unsigned char temp_101ffda8[] = 7,143,191,253,252,247,239,255,15,160,186,223,12,116,0,0,1,196,56,210,150,15,3,4,208,136,155,16,7,8,160,17,231,97,128,0,26,113,30,6,8,160,17,231,97,128,0,26,113,30,6,8,160,17,231,97,128,0,26,113,30,6,8,160,17,231,97,128,0,26,113,30,6,8,160,17,231,97,128, 0,26,113,30,6,8,160,17,231,97,128,0,3,0,159,22,207,49,216,248,213,199,0,0,0,0,73,69,78,68,174,66,96,130,0,0 }; -const char* BinaryData::prefs_about_png = (const char*) temp_101ffda8; +const char* prefs_about_png = (const char*) temp_101ffda8; //================== prefs_keys.png ================== static const unsigned char temp_958eb5cf[] = @@ -436,7 +415,7 @@ static const unsigned char temp_958eb5cf[] = 0,2,8,91,212,33,15,238,226,74,147,12,104,105,141,145,152,73,45,28,195,82,255,208,216,200,14,135,203,1,4,16,35,17,179,116,184,102,238,112,241,255,227,160,137,153,40,195,233,49,128,0,98,36,194,98,98,166,38,25,137,156,54,68,155,43,33,56,179,7,23,3,8,32, 198,161,178,166,4,32,128,134,204,236,50,64,0,13,25,135,2,4,208,144,113,40,64,0,13,25,135,2,4,208,144,113,40,64,0,13,25,135,2,4,208,144,113,40,64,128,1,0,18,155,223,249,154,121,1,250,0,0,0,0,73,69,78,68,174,66,96,130,0,0 }; -const char* BinaryData::prefs_keys_png = (const char*) temp_958eb5cf; +const char* prefs_keys_png = (const char*) temp_958eb5cf; //================== prefs_misc.png ================== static const unsigned char temp_2dcb70c7[] = @@ -527,4 +506,31 @@ static const unsigned char temp_2dcb70c7[] = 69,179,251,63,182,209,53,164,214,21,85,22,227,2,4,16,205,151,103,35,205,117,50,16,72,154,140,216,2,235,63,21,28,8,16,64,244,90,104,255,159,80,106,128,165,252,255,52,8,117,128,0,98,28,9,155,95,0,2,104,68,236,11,1,8,160,17,225,73,128,0,3,0,120,52,172,151, 198,78,252,63,0,0,0,0,73,69,78,68,174,66,96,130,0,0 }; -const char* BinaryData::prefs_misc_png = (const char*) temp_2dcb70c7; +const char* prefs_misc_png = (const char*) temp_2dcb70c7; + + +const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw() +{ + int hash = 0; + if (resourceNameUTF8 != 0) + while (*resourceNameUTF8 != 0) + hash = 31 * hash + *resourceNameUTF8++; + + switch (hash) + { + case 0xe23b4891: + case 0xfe8a1589: numBytes = 24218; return jules_jpg; + case 0x496477a8: + case 0xf26e465b: numBytes = 1819; return prefs_about_png; + case 0x44e88a0d: + case 0xf6e6db91: numBytes = 3794; return prefs_keys_png; + case 0xdd254505: + case 0xe1146fbf: numBytes = 6162; return prefs_misc_png; + default: break; + } + + numBytes = 0; + return 0; +} + +} diff --git a/extras/the jucer/JuceLibraryCode/BinaryData.h b/extras/the jucer/JuceLibraryCode/BinaryData.h index e92a404d31..dcbdb79d74 100644 --- a/extras/the jucer/JuceLibraryCode/BinaryData.h +++ b/extras/the jucer/JuceLibraryCode/BinaryData.h @@ -22,4 +22,25 @@ namespace BinaryData // If you provide the name of one of the binary resource variables above, this function will // return the corresponding data and its size (or a null pointer if the name isn't found). const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw(); + + //============================================================================== + // This class acts as an ImageProvider that will access the BinaryData images + class ImageProvider : public juce::ComponentBuilder::ImageProvider + { + public: + ImageProvider() noexcept {} + + juce::Image getImageForIdentifier (const juce::var& imageIdentifier) + { + int dataSize = 0; + const char* const data = getNamedResource (imageIdentifier.toString().toUTF8(), dataSize); + + if (data != nullptr) + return juce::ImageCache::getFromMemory (data, dataSize); + + return juce::Image(); + } + + juce::var getIdentifierForImage (const juce::Image&) { return juce::var(); } + }; } diff --git a/modules/juce_core/text/juce_StringPool.cpp b/modules/juce_core/text/juce_StringPool.cpp index 5ef5f31870..decf8a85a6 100644 --- a/modules/juce_core/text/juce_StringPool.cpp +++ b/modules/juce_core/text/juce_StringPool.cpp @@ -76,7 +76,7 @@ namespace StringPoolHelpers } } -const String::CharPointerType StringPool::getPooledString (const String& s) +String::CharPointerType StringPool::getPooledString (const String& s) { if (s.isEmpty()) return String::empty.getCharPointer(); @@ -84,7 +84,7 @@ const String::CharPointerType StringPool::getPooledString (const String& s) return StringPoolHelpers::getPooledStringFromArray (strings, s); } -const String::CharPointerType StringPool::getPooledString (const char* const s) +String::CharPointerType StringPool::getPooledString (const char* const s) { if (s == nullptr || *s == 0) return String::empty.getCharPointer(); @@ -92,7 +92,7 @@ const String::CharPointerType StringPool::getPooledString (const char* const s) return StringPoolHelpers::getPooledStringFromArray (strings, s); } -const String::CharPointerType StringPool::getPooledString (const wchar_t* const s) +String::CharPointerType StringPool::getPooledString (const wchar_t* const s) { if (s == nullptr || *s == 0) return String::empty.getCharPointer(); @@ -105,7 +105,7 @@ int StringPool::size() const noexcept return strings.size(); } -const String::CharPointerType StringPool::operator[] (const int index) const noexcept +String::CharPointerType StringPool::operator[] (const int index) const noexcept { return strings [index].getCharPointer(); } diff --git a/modules/juce_core/text/juce_StringPool.h b/modules/juce_core/text/juce_StringPool.h index 0c83fd96d7..4268fac495 100644 --- a/modules/juce_core/text/juce_StringPool.h +++ b/modules/juce_core/text/juce_StringPool.h @@ -58,7 +58,7 @@ public: The pool will own all the pointers that it returns, deleting them when the pool itself is deleted. */ - const String::CharPointerType getPooledString (const String& original); + String::CharPointerType getPooledString (const String& original); /** Returns a pointer to a copy of the string that is passed in. @@ -66,7 +66,7 @@ public: The pool will own all the pointers that it returns, deleting them when the pool itself is deleted. */ - const String::CharPointerType getPooledString (const char* original); + String::CharPointerType getPooledString (const char* original); /** Returns a pointer to a copy of the string that is passed in. @@ -74,14 +74,14 @@ public: The pool will own all the pointers that it returns, deleting them when the pool itself is deleted. */ - const String::CharPointerType getPooledString (const wchar_t* original); + String::CharPointerType getPooledString (const wchar_t* original); //============================================================================== /** Returns the number of strings in the pool. */ int size() const noexcept; /** Returns one of the strings in the pool, by index. */ - const String::CharPointerType operator[] (int index) const noexcept; + String::CharPointerType operator[] (int index) const noexcept; private: Array strings; diff --git a/modules/juce_gui_basics/buttons/juce_Button.cpp b/modules/juce_gui_basics/buttons/juce_Button.cpp index 32d448696b..a6132f60c4 100644 --- a/modules/juce_gui_basics/buttons/juce_Button.cpp +++ b/modules/juce_gui_basics/buttons/juce_Button.cpp @@ -667,4 +667,30 @@ Button::RepeatTimer& Button::getRepeatTimer() return *repeatTimer; } +const Identifier Button::Ids::text ("text"); +const Identifier Button::Ids::radioGroup ("radioGroup"); +const Identifier Button::Ids::connectedLeft ("connectedLeft"); +const Identifier Button::Ids::connectedRight ("connectedRight"); +const Identifier Button::Ids::connectedTop ("connectedTop"); +const Identifier Button::Ids::connectedBottom ("connectedBottom"); + +void Button::refreshFromValueTree (const ValueTree& state, ComponentBuilder&) +{ + ComponentBuilder::refreshBasicComponentProperties (*this, state); + + setButtonText (state [Ids::text].toString()); + setRadioGroupId (state [Ids::radioGroup]); + setConnectedEdges (getConnectedFlags (state)); +} + +int Button::getConnectedFlags (const ValueTree& state) +{ + int connected = 0; + if (state [Button::Ids::connectedLeft]) connected |= Button::ConnectedOnLeft; + if (state [Button::Ids::connectedRight]) connected |= Button::ConnectedOnRight; + if (state [Button::Ids::connectedTop]) connected |= Button::ConnectedOnTop; + if (state [Button::Ids::connectedBottom]) connected |= Button::ConnectedOnBottom; + return connected; +} + END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/buttons/juce_Button.h b/modules/juce_gui_basics/buttons/juce_Button.h index 3ad12a2049..593b5e4fbc 100644 --- a/modules/juce_gui_basics/buttons/juce_Button.h +++ b/modules/juce_gui_basics/buttons/juce_Button.h @@ -30,6 +30,7 @@ #include "../keyboard/juce_KeyListener.h" #include "../commands/juce_ApplicationCommandManager.h" #include "../windows/juce_TooltipWindow.h" +#include "../layout/juce_ComponentBuilder.h" #if JUCE_VC6 #define Listener ButtonListener @@ -370,6 +371,16 @@ public: void setState (const ButtonState newState); + //============================================================================== + struct Ids + { + static const Identifier text, radioGroup, + connectedLeft, connectedRight, connectedTop, connectedBottom; + }; + + void refreshFromValueTree (const ValueTree&, ComponentBuilder&); + static int getConnectedFlags (const ValueTree& state); + //============================================================================== // These are deprecated - please use addListener() and removeListener() instead! JUCE_DEPRECATED (void addButtonListener (Listener*)); @@ -421,7 +432,6 @@ protected: */ virtual void buttonStateChanged(); - //============================================================================== /** @internal */ virtual void internalClickCallback (const ModifierKeys& modifiers); diff --git a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp index 202cf87d1c..015d145b5c 100644 --- a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.cpp @@ -38,6 +38,15 @@ HyperlinkButton::HyperlinkButton (const String& linkText, setTooltip (linkURL.toString (false)); } +HyperlinkButton::HyperlinkButton () + : Button (String::empty), + font (14.0f, Font::underlined), + resizeFont (true), + justification (Justification::centred) +{ + setMouseCursor (MouseCursor::PointingHandCursor); +} + HyperlinkButton::~HyperlinkButton() { } @@ -106,5 +115,16 @@ void HyperlinkButton::paintButton (Graphics& g, true); } +const Identifier HyperlinkButton::Ids::tagType ("HYPERLINKBUTTON"); +const Identifier HyperlinkButton::Ids::text ("text"); +const Identifier HyperlinkButton::Ids::url ("url"); + +void HyperlinkButton::refreshFromValueTree (const ValueTree& state, ComponentBuilder&) +{ + ComponentBuilder::refreshBasicComponentProperties (*this, state); + + setButtonText (state [Ids::text].toString()); + setURL (URL (state [Ids::url].toString())); +} END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.h b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.h index 1501f3f9fd..c2e285fb31 100644 --- a/modules/juce_gui_basics/buttons/juce_HyperlinkButton.h +++ b/modules/juce_gui_basics/buttons/juce_HyperlinkButton.h @@ -50,6 +50,9 @@ public: HyperlinkButton (const String& linkText, const URL& linkURL); + /** Creates a HyperlinkButton. */ + HyperlinkButton(); + /** Destructor. */ ~HyperlinkButton(); @@ -90,6 +93,13 @@ public: */ void changeWidthToFitText(); + //============================================================================== + struct Ids + { + static const Identifier tagType, text, url; + }; + + void refreshFromValueTree (const ValueTree&, ComponentBuilder&); protected: //============================================================================== diff --git a/modules/juce_gui_basics/buttons/juce_ImageButton.cpp b/modules/juce_gui_basics/buttons/juce_ImageButton.cpp index 7013d35150..42f0181044 100644 --- a/modules/juce_gui_basics/buttons/juce_ImageButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_ImageButton.cpp @@ -192,4 +192,49 @@ bool ImageButton::hitTest (int x, int y) ((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha()); } +const Identifier ImageButton::Ids::tagType ("IMAGEBUTTON"); +const Identifier ImageButton::Ids::upImage ("upImage"); +const Identifier ImageButton::Ids::overImage ("overImage"); +const Identifier ImageButton::Ids::downImage ("downImage"); +const Identifier ImageButton::Ids::upOverlay ("upOverlay"); +const Identifier ImageButton::Ids::overOverlay ("overOverlay"); +const Identifier ImageButton::Ids::downOverlay ("downOverlay"); +const Identifier ImageButton::Ids::upOpacity ("upOpacity"); +const Identifier ImageButton::Ids::overOpacity ("overOpacity"); +const Identifier ImageButton::Ids::downOpacity ("downOpacity"); + +static Colour getColourFromVar (const var& col) +{ + if (col.isString()) + return Colour (col.toString().getHexValue32()); + + return Colours::transparentBlack; +} + +void ImageButton::refreshFromValueTree (const ValueTree& state, ComponentBuilder& builder) +{ + Button::refreshFromValueTree (state, builder); + + const var upImageIdentifier (state [Ids::upImage]), + overImageIdentifier (state [Ids::overImage]), + downImageIdentifier (state [Ids::downImage]); + + ComponentBuilder::ImageProvider* const imageProvider = builder.getImageProvider(); + jassert (imageProvider != nullptr || upImageIdentifier.isVoid()); + + Image newUpImage, newOverImage, newDownImage; + + if (imageProvider != nullptr) + { + newUpImage = imageProvider->getImageForIdentifier (upImageIdentifier); + newOverImage = imageProvider->getImageForIdentifier (overImageIdentifier); + newDownImage = imageProvider->getImageForIdentifier (downImageIdentifier); + } + + setImages (false, true, true, + newUpImage, state[Ids::upOpacity], getColourFromVar (state[Ids::upOverlay]), + newOverImage, state[Ids::overOpacity], getColourFromVar (state[Ids::overOverlay]), + newDownImage, state[Ids::downOpacity], getColourFromVar (state[Ids::downOverlay])); +} + END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/buttons/juce_ImageButton.h b/modules/juce_gui_basics/buttons/juce_ImageButton.h index abb6c9d8d3..6828603fd1 100644 --- a/modules/juce_gui_basics/buttons/juce_ImageButton.h +++ b/modules/juce_gui_basics/buttons/juce_ImageButton.h @@ -127,6 +127,16 @@ public: */ Image getDownImage() const; + //============================================================================== + struct Ids + { + static const Identifier tagType, upImage, overImage, downImage, + upOverlay, overOverlay, downOverlay, + upOpacity, overOpacity, downOpacity; + }; + + void refreshFromValueTree (const ValueTree&, ComponentBuilder&); + protected: //============================================================================== /** @internal */ diff --git a/modules/juce_gui_basics/buttons/juce_TextButton.cpp b/modules/juce_gui_basics/buttons/juce_TextButton.cpp index 4c72e2018b..c2cff0683b 100644 --- a/modules/juce_gui_basics/buttons/juce_TextButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_TextButton.cpp @@ -71,5 +71,6 @@ void TextButton::changeWidthToFitText (const int newHeight) getHeight()); } +const Identifier TextButton::Ids::tagType ("TEXTBUTTON"); END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/buttons/juce_TextButton.h b/modules/juce_gui_basics/buttons/juce_TextButton.h index b7e1bb4d38..03baf61d12 100644 --- a/modules/juce_gui_basics/buttons/juce_TextButton.h +++ b/modules/juce_gui_basics/buttons/juce_TextButton.h @@ -89,6 +89,11 @@ public: */ virtual Font getFont(); + //============================================================================== + struct Ids + { + static const Identifier tagType; + }; protected: /** @internal */ diff --git a/modules/juce_gui_basics/buttons/juce_ToggleButton.cpp b/modules/juce_gui_basics/buttons/juce_ToggleButton.cpp index 43f6ea0822..d4fe3587d1 100644 --- a/modules/juce_gui_basics/buttons/juce_ToggleButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_ToggleButton.cpp @@ -55,4 +55,6 @@ void ToggleButton::colourChanged() repaint(); } +const Identifier ToggleButton::Ids::tagType ("TOGGLEBUTTON"); + END_JUCE_NAMESPACE diff --git a/modules/juce_gui_basics/buttons/juce_ToggleButton.h b/modules/juce_gui_basics/buttons/juce_ToggleButton.h index 6806224607..41f511ba49 100644 --- a/modules/juce_gui_basics/buttons/juce_ToggleButton.h +++ b/modules/juce_gui_basics/buttons/juce_ToggleButton.h @@ -73,6 +73,12 @@ public: textColourId = 0x1006501 /**< The colour to use for the button's text. */ }; + //============================================================================== + struct Ids + { + static const Identifier tagType; + }; + protected: /** @internal */ void paintButton (Graphics& g, diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 85c05a9f0b..0a11b9b62a 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1438,6 +1438,15 @@ void Component::addAndMakeVisible (Component* const child, int zOrder) } } +void Component::addChildAndSetID (Component* const child, const String& componentID) +{ + if (child != nullptr) + { + child->setComponentID (componentID); + addAndMakeVisible (child); + } +} + void Component::removeChildComponent (Component* const child) { removeChildComponent (childComponentList.indexOf (child), true, true); diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 933a5de707..ad55829d7d 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -719,7 +719,7 @@ public: the child of another component, it'll first be removed from it current parent. @param zOrder The index in the child-list at which this component should be inserted. A value of -1 will insert it in front of the others, 0 is the back. - @see removeChildComponent, addAndMakeVisible, getChild, ComponentListener::componentChildrenChanged + @see removeChildComponent, addAndMakeVisible, addChildAndSetID, getChild, ComponentListener::componentChildrenChanged */ void addChildComponent (Component* child, int zOrder = -1); @@ -730,6 +730,11 @@ public: */ void addAndMakeVisible (Component* child, int zOrder = -1); + /** Adds a child component to this one, makes it visible, and sets its component ID. + @see addAndMakeVisible, addChildComponent + */ + void addChildAndSetID (Component* child, const String& componentID); + /** Removes one of this component's child-components. If the child passed-in isn't actually a child of this component (either because diff --git a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp index d93c1eb05a..914200af3c 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp @@ -48,15 +48,15 @@ namespace ComponentBuilderHelpers return nullptr; } - Component* findComponentWithID (Component* const c, const String& compId) + Component* findComponentWithID (Component& c, const String& compId) { jassert (compId.isNotEmpty()); - if (c->getComponentID() == compId) - return c; + if (c.getComponentID() == compId) + return &c; - for (int i = c->getNumChildComponents(); --i >= 0;) + for (int i = c.getNumChildComponents(); --i >= 0;) { - Component* const child = findComponentWithID (c->getChildComponent (i), compId); + Component* const child = findComponentWithID (*c.getChildComponent (i), compId); if (child != nullptr) return child; @@ -91,18 +91,78 @@ namespace ComponentBuilderHelpers } else { - Component* const changedComp = findComponentWithID (topLevelComp, uid); + Component* const changedComp = findComponentWithID (*topLevelComp, uid); if (changedComp != nullptr) type->updateComponentFromState (changedComp, state); } } } + + void updateComponentColours (Component& component, const ValueTree& colourState) + { + NamedValueSet& properties = component.getProperties(); + + for (int i = properties.size(); --i >= 0;) + { + const Identifier name (properties.getName (i)); + + if (name.toString().startsWith ("jcclr_")) + { + const String colourName (name.toString().substring (6)); + + if (colourState [colourName].isVoid()) + component.removeColour (colourName.getHexValue32()); + } + } + + for (int i = 0; i < colourState.getNumProperties(); ++i) + { + const Identifier colourName (colourState.getPropertyName (i)); + const String colour (colourState [colourName].toString()); + + if (colour.isNotEmpty()) + component.setColour (colourName.toString().getHexValue32(), Colour::fromString (colour)); + } + } + + template + class StandardTypeHandler : public ComponentBuilder::TypeHandler + { + public: + StandardTypeHandler() : ComponentBuilder::TypeHandler (ComponentClass::Ids::tagType) + {} + + Component* addNewComponentFromState (const ValueTree& state, Component* parent) + { + ComponentClass* const c = new ComponentClass(); + + if (parent != nullptr) + parent->addAndMakeVisible (c); + + updateComponentFromState (c, state); + return c; + } + + void updateComponentFromState (Component* component, const ValueTree& state) + { + ComponentClass* const c = dynamic_cast (component); + jassert (c != nullptr); + + c->setComponentID (state [ComponentBuilder::idProperty]); + c->refreshFromValueTree (state, *this->getBuilder()); + } + }; } //============================================================================= const Identifier ComponentBuilder::idProperty ("id"); +ComponentBuilder::ComponentBuilder() + : imageProvider (nullptr) +{ +} + ComponentBuilder::ComponentBuilder (const ValueTree& state_) : state (state_), imageProvider (nullptr) { @@ -181,6 +241,23 @@ ComponentBuilder::TypeHandler* ComponentBuilder::getHandler (const int index) co return types [index]; } +void ComponentBuilder::registerStandardComponentTypes() +{ + Drawable::registerDrawableTypeHandlers (*this); + + registerTypeHandler (new ComponentBuilderHelpers::StandardTypeHandler ()); + registerTypeHandler (new ComponentBuilderHelpers::StandardTypeHandler ()); + registerTypeHandler (new ComponentBuilderHelpers::StandardTypeHandler