The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_BINARYRESOURCES_JUCEHEADER__
  18. #define __JUCER_BINARYRESOURCES_JUCEHEADER__
  19. class JucerDocument;
  20. //==============================================================================
  21. /**
  22. Manages a list of binary data objects that a JucerDocument wants to embed in
  23. the code it generates.
  24. */
  25. class BinaryResources
  26. {
  27. public:
  28. //==============================================================================
  29. BinaryResources();
  30. ~BinaryResources();
  31. BinaryResources& operator= (const BinaryResources& other);
  32. void loadFromCpp (const File& cppFileLocation, const String& cpp);
  33. //==============================================================================
  34. struct BinaryResource
  35. {
  36. String name;
  37. String originalFilename;
  38. MemoryBlock data;
  39. ScopedPointer<Drawable> drawable;
  40. };
  41. void clear();
  42. bool add (const String& name, const File& file);
  43. void add (const String& name, const String& originalFileName, const MemoryBlock& data);
  44. void remove (const int index);
  45. bool reload (const int index);
  46. String browseForResource (const String& title, const String& wildcard,
  47. const File& fileToStartFrom, const String& resourceToReplace);
  48. String findUniqueName (const String& rootName) const;
  49. int size() const noexcept { return resources.size(); }
  50. const BinaryResource* operator[] (const int index) const noexcept { return resources [index]; }
  51. const BinaryResource* getResource (const String& resourceName) const;
  52. const BinaryResource* getResourceForFile (const File& file) const;
  53. StringArray getResourceNames() const;
  54. const Drawable* getDrawable (const String& name) const;
  55. Image getImageFromCache (const String& name) const;
  56. template <class ElementComparator>
  57. void sort (ElementComparator& sorter)
  58. {
  59. resources.sort (sorter, true);
  60. changed();
  61. }
  62. //==============================================================================
  63. void setDocument (JucerDocument* const doc) { document = doc; }
  64. JucerDocument* getDocument() const noexcept { return document; }
  65. void fillInGeneratedCode (GeneratedCode& code) const;
  66. private:
  67. //==============================================================================
  68. JucerDocument* document;
  69. OwnedArray <BinaryResource> resources;
  70. BinaryResource* findResource (const String& name) const noexcept;
  71. void changed();
  72. };
  73. #endif // __JUCER_BINARYRESOURCES_JUCEHEADER__