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.

106 lines
3.8KB

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