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.

123 lines
5.0KB

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