LMMS
Loading...
Searching...
No Matches
juce_ImagePreviewComponent.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
32
36
37//==============================================================================
39{
40 auto availableW = proportionOfWidth (0.97f);
41 auto availableH = getHeight() - 13 * 4;
42
43 auto scale = jmin (1.0,
44 availableW / (double) w,
45 availableH / (double) h);
46
47 w = roundToInt (scale * w);
48 h = roundToInt (scale * h);
49}
50
52{
53 if (fileToLoad != file)
54 {
56 startTimer (100);
57 }
58}
59
61{
62 stopTimer();
63
65 currentDetails.clear();
66 repaint();
67
69
70 if (in.openedOk() && fileToLoad.existsAsFile())
71 {
73 {
74 currentThumbnail = format->decodeImage (in);
75
76 if (currentThumbnail.isValid())
77 {
78 auto w = currentThumbnail.getWidth();
79 auto h = currentThumbnail.getHeight();
80
82 << fileToLoad.getFileName() << "\n"
83 << format->getFormatName() << "\n"
84 << w << " x " << h << " pixels\n"
86
87 getThumbSize (w, h);
88
90 }
91 }
92 }
93}
94
96{
97 if (currentThumbnail.isValid())
98 {
99 g.setFont (13.0f);
100
101 auto w = currentThumbnail.getWidth();
102 auto h = currentThumbnail.getHeight();
103 getThumbSize (w, h);
104
105 const int numLines = 4;
106 auto totalH = 13 * numLines + h + 4;
107 auto y = (getHeight() - totalH) / 2;
108
109 g.drawImageWithin (currentThumbnail,
110 (getWidth() - w) / 2, y, w, h,
112 false);
113
114 g.drawFittedText (currentDetails,
115 0, y + h + 4, getWidth(), 100,
116 Justification::centredTop, numLines);
117 }
118}
119
120//==============================================================================
121std::unique_ptr<AccessibilityHandler> ImagePreviewComponent::createAccessibilityHandler()
122{
123 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::image);
124}
125
126} // namespace juce
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
static String descriptionOfSizeInBytes(int64 bytes)
Definition File.cpp:479
int proportionOfWidth(float proportion) const noexcept
Definition juce_Component.cpp:1111
int getHeight() const noexcept
Definition juce_Component.h:274
void repaint()
Definition juce_Component.cpp:1917
int getWidth() const noexcept
Definition juce_Component.h:271
Definition juce_File.h:45
Definition juce_FileInputStream.h:35
Definition juce_GraphicsContext.h:45
static ImageFileFormat * findImageFormatForStream(InputStream &input)
Definition juce_ImageFileFormat.cpp:53
Definition juce_Image.h:58
String currentDetails
Definition juce_ImagePreviewComponent.h:59
ImagePreviewComponent()
Definition juce_ImagePreviewComponent.cpp:29
Image currentThumbnail
Definition juce_ImagePreviewComponent.h:58
void selectedFileChanged(const File &newSelectedFile) override
Definition juce_ImagePreviewComponent.cpp:51
void paint(Graphics &) override
Definition juce_ImagePreviewComponent.cpp:95
~ImagePreviewComponent() override
Definition juce_ImagePreviewComponent.cpp:33
File fileToLoad
Definition juce_ImagePreviewComponent.h:57
void getThumbSize(int &w, int &h) const
Definition juce_ImagePreviewComponent.cpp:38
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_ImagePreviewComponent.cpp:121
void timerCallback() override
Definition juce_ImagePreviewComponent.cpp:60
@ centredTop
Definition juce_Justification.h:153
@ onlyReduceInSize
Definition juce_RectanglePlacement.h:106
@ centred
Definition juce_RectanglePlacement.h:119
void stopTimer() noexcept
Definition juce_Timer.cpp:357
void startTimer(int intervalInMilliseconds) noexcept
Definition juce_Timer.cpp:332
UINT_D64 w
Definition inflate.c:942
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
float in
Definition lilv_test.c:1460
Definition carla_juce.cpp:31
int roundToInt(const FloatType value) noexcept
Definition juce_MathsFunctions.h:465
@ image
Definition juce_AccessibilityRole.h:42
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
struct zdirent * file
Definition win32.c:1500
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263