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) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  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. std::unique_ptr<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. };