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.

122 lines
4.8KB

  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. #include "../JuceDemoHeader.h"
  18. //==============================================================================
  19. class ImagesDemo : public Component,
  20. public FileBrowserListener
  21. {
  22. public:
  23. ImagesDemo()
  24. : imagesWildcardFilter ("*.jpeg;*.jpg;*.png;*.gif", "*", "Image File Filter"),
  25. directoryThread ("Image File Scanner Thread"),
  26. imageList (&imagesWildcardFilter, directoryThread),
  27. fileTree (imageList),
  28. resizerBar (&stretchableManager, 1, false)
  29. {
  30. setOpaque (true);
  31. imageList.setDirectory (File::getSpecialLocation (File::userPicturesDirectory), true, true);
  32. directoryThread.startThread (1);
  33. fileTree.addListener (this);
  34. fileTree.setColour (TreeView::backgroundColourId, Colours::lightgrey.withAlpha (0.6f));
  35. addAndMakeVisible (fileTree);
  36. addAndMakeVisible (resizerBar);
  37. addAndMakeVisible (imagePreview);
  38. // we have to set up our StretchableLayoutManager so it know the limits and preferred sizes of it's contents
  39. stretchableManager.setItemLayout (0, // for the fileTree
  40. -0.1, -0.9, // must be between 50 pixels and 90% of the available space
  41. -0.3); // and its preferred size is 30% of the total available space
  42. stretchableManager.setItemLayout (1, // for the resize bar
  43. 5, 5, 5); // hard limit to 5 pixels
  44. stretchableManager.setItemLayout (2, // for the imagePreview
  45. -0.1, -0.9, // size must be between 50 pixels and 90% of the available space
  46. -0.7); // and its preferred size is 70% of the total available space
  47. }
  48. ~ImagesDemo()
  49. {
  50. fileTree.removeListener (this);
  51. }
  52. void paint (Graphics& g) override
  53. {
  54. fillStandardDemoBackground (g);
  55. }
  56. void resized() override
  57. {
  58. Rectangle<int> r (getLocalBounds().reduced (4));
  59. // make a list of two of our child components that we want to reposition
  60. Component* comps[] = { &fileTree, &resizerBar, &imagePreview };
  61. // this will position the 3 components, one above the other, to fit
  62. // vertically into the rectangle provided.
  63. stretchableManager.layOutComponents (comps, 3,
  64. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  65. true, true);
  66. }
  67. private:
  68. WildcardFileFilter imagesWildcardFilter;
  69. TimeSliceThread directoryThread;
  70. DirectoryContentsList imageList;
  71. FileTreeComponent fileTree;
  72. ImageComponent imagePreview;
  73. StretchableLayoutManager stretchableManager;
  74. StretchableLayoutResizerBar resizerBar;
  75. void selectionChanged() override
  76. {
  77. // we're only really interested in when the selection changes, regardless of if it was
  78. // clicked or not so we'll only override this method
  79. const File selectedFile (fileTree.getSelectedFile());
  80. if (selectedFile.existsAsFile())
  81. imagePreview.setImage (ImageCache::getFromFile (selectedFile));
  82. // the image cahce is a handly way to load images from files or directly from memory and
  83. // will keep them hanging around for a few seconds in case they are requested elsewhere
  84. }
  85. void fileClicked (const File&, const MouseEvent&) override {}
  86. void fileDoubleClicked (const File&) override {}
  87. void browserRootChanged (const File&) override {}
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImagesDemo)
  89. };
  90. // This static object will register this demo type in a global list of demos..
  91. static JuceDemoType<ImagesDemo> demo ("20 Graphics: Image formats");