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.

101 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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& operator= (const BinaryResources& other);
  30. void loadFromCpp (const File& cppFileLocation, const String& cpp);
  31. //==============================================================================
  32. struct BinaryResource
  33. {
  34. String name;
  35. String originalFilename;
  36. MemoryBlock data;
  37. std::unique_ptr<Drawable> drawable;
  38. };
  39. void clear();
  40. bool add (const String& name, const File& file);
  41. void add (const String& name, const String& originalFileName, const MemoryBlock& data);
  42. void remove (int index);
  43. bool reload (int index);
  44. void browseForResource (const String& title, const String& wildcard,
  45. const File& fileToStartFrom, const String& resourceToReplace,
  46. std::function<void (String)> callback);
  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. BinaryResource* findResource (const String& name) const noexcept;
  68. void changed();
  69. //==============================================================================
  70. JucerDocument* document;
  71. OwnedArray<BinaryResource> resources;
  72. std::unique_ptr<FileChooser> chooser;
  73. ScopedMessageBox messageBox;
  74. //==============================================================================
  75. JUCE_DECLARE_WEAK_REFERENCEABLE (BinaryResources)
  76. };