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.

98 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. class JucerDocument;
  19. //==============================================================================
  20. /**
  21. Manages a list of binary data objects that a JucerDocument wants to embed in
  22. the code it generates.
  23. */
  24. class BinaryResources
  25. {
  26. public:
  27. //==============================================================================
  28. BinaryResources();
  29. ~BinaryResources();
  30. BinaryResources& operator= (const BinaryResources& other);
  31. void loadFromCpp (const File& cppFileLocation, const String& cpp);
  32. //==============================================================================
  33. struct BinaryResource
  34. {
  35. String name;
  36. String originalFilename;
  37. MemoryBlock data;
  38. ScopedPointer<Drawable> drawable;
  39. };
  40. void clear();
  41. bool add (const String& name, const File& file);
  42. void add (const String& name, const String& originalFileName, const MemoryBlock& data);
  43. void remove (const int index);
  44. bool reload (const int index);
  45. String browseForResource (const String& title, const String& wildcard,
  46. const File& fileToStartFrom, const String& resourceToReplace);
  47. String findUniqueName (const String& rootName) const;
  48. int size() const noexcept { return resources.size(); }
  49. const BinaryResource* operator[] (const int index) const noexcept { return resources [index]; }
  50. const BinaryResource* getResource (const String& resourceName) const;
  51. const BinaryResource* getResourceForFile (const File& file) const;
  52. StringArray getResourceNames() const;
  53. const Drawable* getDrawable (const String& name) const;
  54. Image getImageFromCache (const String& name) const;
  55. template <class ElementComparator>
  56. void sort (ElementComparator& sorter)
  57. {
  58. resources.sort (sorter, true);
  59. changed();
  60. }
  61. //==============================================================================
  62. void setDocument (JucerDocument* const doc) { document = doc; }
  63. JucerDocument* getDocument() const noexcept { return document; }
  64. void fillInGeneratedCode (GeneratedCode& code) const;
  65. private:
  66. //==============================================================================
  67. JucerDocument* document;
  68. OwnedArray <BinaryResource> resources;
  69. BinaryResource* findResource (const String& name) const noexcept;
  70. void changed();
  71. };