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.

91 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. class JucerDocument;
  15. //==============================================================================
  16. /**
  17. Manages a list of binary data objects that a JucerDocument wants to embed in
  18. the code it generates.
  19. */
  20. class BinaryResources
  21. {
  22. public:
  23. //==============================================================================
  24. BinaryResources();
  25. ~BinaryResources();
  26. BinaryResources& operator= (const BinaryResources& other);
  27. void loadFromCpp (const File& cppFileLocation, const String& cpp);
  28. //==============================================================================
  29. struct BinaryResource
  30. {
  31. String name;
  32. String originalFilename;
  33. MemoryBlock data;
  34. std::unique_ptr<Drawable> drawable;
  35. };
  36. void clear();
  37. bool add (const String& name, const File& file);
  38. void add (const String& name, const String& originalFileName, const MemoryBlock& data);
  39. void remove (const int index);
  40. bool reload (const int index);
  41. String browseForResource (const String& title, const String& wildcard,
  42. const File& fileToStartFrom, const String& resourceToReplace);
  43. String findUniqueName (const String& rootName) const;
  44. int size() const noexcept { return resources.size(); }
  45. const BinaryResource* operator[] (const int index) const noexcept { return resources [index]; }
  46. const BinaryResource* getResource (const String& resourceName) const;
  47. const BinaryResource* getResourceForFile (const File& file) const;
  48. StringArray getResourceNames() const;
  49. const Drawable* getDrawable (const String& name) const;
  50. Image getImageFromCache (const String& name) const;
  51. template <class ElementComparator>
  52. void sort (ElementComparator& sorter)
  53. {
  54. resources.sort (sorter, true);
  55. changed();
  56. }
  57. //==============================================================================
  58. void setDocument (JucerDocument* const doc) { document = doc; }
  59. JucerDocument* getDocument() const noexcept { return document; }
  60. void fillInGeneratedCode (GeneratedCode& code) const;
  61. private:
  62. //==============================================================================
  63. JucerDocument* document;
  64. OwnedArray <BinaryResource> resources;
  65. BinaryResource* findResource (const String& name) const noexcept;
  66. void changed();
  67. };