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.

105 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. BinaryResource();
  37. ~BinaryResource();
  38. String name;
  39. String originalFilename;
  40. MemoryBlock data;
  41. Drawable* drawable;
  42. };
  43. void clear();
  44. bool add (const String& name, const File& file);
  45. void add (const String& name, const String& originalFileName, const MemoryBlock& data);
  46. void remove (const int index);
  47. bool reload (const int index);
  48. String browseForResource (const String& title, const String& wildcard,
  49. const File& fileToStartFrom, const String& resourceToReplace);
  50. String findUniqueName (const String& rootName) const;
  51. int size() const noexcept { return resources.size(); }
  52. const BinaryResource* operator[] (const int index) const noexcept { return resources [index]; }
  53. const BinaryResource* getResource (const String& resourceName) const;
  54. const BinaryResource* getResourceForFile (const File& file) const;
  55. StringArray getResourceNames() const;
  56. const Drawable* getDrawable (const String& name) const;
  57. Image getImageFromCache (const String& name) const;
  58. template <class ElementComparator>
  59. void sort (ElementComparator& sorter)
  60. {
  61. resources.sort (sorter, true);
  62. changed();
  63. }
  64. //==============================================================================
  65. void setDocument (JucerDocument* const doc) { document = doc; }
  66. JucerDocument* getDocument() const noexcept { return document; }
  67. void fillInGeneratedCode (GeneratedCode& code) const;
  68. private:
  69. //==============================================================================
  70. JucerDocument* document;
  71. OwnedArray <BinaryResource> resources;
  72. BinaryResource* findResource (const String& name) const noexcept;
  73. void changed();
  74. };
  75. #endif // __JUCER_BINARYRESOURCES_JUCEHEADER__