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.

94 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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 "../jucer_Headers.h"
  19. #include "jucer_ItemPreviewComponent.h"
  20. //==============================================================================
  21. ItemPreviewComponent::ItemPreviewComponent (const File& file_)
  22. : file (file_)
  23. {
  24. facts.add (file.getFullPathName());
  25. tryToLoadImage (file.createInputStream());
  26. facts.removeEmptyStrings (true);
  27. }
  28. ItemPreviewComponent::ItemPreviewComponent (InputStream* input, const String& name)
  29. {
  30. facts.add (name);
  31. tryToLoadImage (input);
  32. facts.removeEmptyStrings (true);
  33. }
  34. ItemPreviewComponent::~ItemPreviewComponent()
  35. {
  36. }
  37. void ItemPreviewComponent::tryToLoadImage (InputStream* in)
  38. {
  39. if (in != 0)
  40. {
  41. ScopedPointer <InputStream> input (in);
  42. ImageFileFormat* format = ImageFileFormat::findImageFormatForStream (*input);
  43. String formatName;
  44. if (format != 0)
  45. formatName = " " + format->getFormatName();
  46. image = ImageFileFormat::loadFrom (*input);
  47. if (image != 0)
  48. facts.add (String (image->getWidth()) + " x " + String (image->getHeight()) + formatName);
  49. const int64 totalSize = input->getTotalLength();
  50. if (totalSize > 0)
  51. facts.add (File::descriptionOfSizeInBytes (totalSize));
  52. }
  53. }
  54. void ItemPreviewComponent::paint (Graphics& g)
  55. {
  56. if (image != 0)
  57. {
  58. g.drawImageWithin (image,
  59. 2, 22, getWidth() - 4, getHeight() - 24,
  60. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  61. false);
  62. }
  63. g.setFont (15.0f, Font::bold);
  64. g.setColour (Colours::white);
  65. g.drawMultiLineText (facts.joinIntoString ("\n"),
  66. 10, 15, getWidth() - 16);
  67. }
  68. void ItemPreviewComponent::resized()
  69. {
  70. }