LMMS
Loading...
Searching...
No Matches
juce_DrawableImage.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
29DrawableImage::DrawableImage() : bounds ({ 0.0f, 0.0f, 1.0f, 1.0f })
30{
31}
32
34 : Drawable (other),
35 image (other.image),
36 opacity (other.opacity),
38 bounds (other.bounds)
39{
40 setBounds (other.getBounds());
41}
42
44{
45 setImageInternal (imageToUse);
46}
47
51
52std::unique_ptr<Drawable> DrawableImage::createCopy() const
53{
54 return std::make_unique<DrawableImage> (*this);
55}
56
57//==============================================================================
58void DrawableImage::setImage (const Image& imageToUse)
59{
60 if (setImageInternal (imageToUse))
61 repaint();
62}
63
64void DrawableImage::setOpacity (const float newOpacity)
65{
66 opacity = newOpacity;
67}
68
70{
71 overlayColour = newOverlayColour;
72}
73
78
80{
81 if (bounds != newBounds)
82 {
83 bounds = newBounds;
84
85 if (image.isValid())
86 {
87 auto tr = bounds.topLeft + (bounds.topRight - bounds.topLeft) / (float) image.getWidth();
88 auto bl = bounds.topLeft + (bounds.bottomLeft - bounds.topLeft) / (float) image.getHeight();
89
90 auto t = AffineTransform::fromTargetPoints (bounds.topLeft.x, bounds.topLeft.y,
91 tr.x, tr.y,
92 bl.x, bl.y);
93
94 if (t.isSingularity())
95 t = {};
96
98 }
99 }
100}
101
102//==============================================================================
104{
105 if (image.isValid())
106 {
107 if (opacity > 0.0f && ! overlayColour.isOpaque())
108 {
109 g.setOpacity (opacity);
110 g.drawImageAt (image, 0, 0, false);
111 }
112
113 if (! overlayColour.isTransparent())
114 {
115 g.setColour (overlayColour.withMultipliedAlpha (opacity));
116 g.drawImageAt (image, 0, 0, true);
117 }
118 }
119}
120
122{
123 return image.getBounds().toFloat();
124}
125
127{
128 return Drawable::hitTest (x, y) && image.isValid() && image.getPixelAt (x, y).getAlpha() >= 127;
129}
130
132{
133 return {}; // not applicable for images
134}
135
136//==============================================================================
138{
139 if (image != imageToUse)
140 {
141 image = imageToUse;
142 setBounds (image.getBounds());
143 setBoundingBox (image.getBounds().toFloat());
144 return true;
145 }
146
147 return false;
148}
149
150//==============================================================================
151std::unique_ptr<AccessibilityHandler> DrawableImage::createAccessibilityHandler()
152{
153 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::image);
154}
155
156} // namespace juce
static AffineTransform fromTargetPoints(float x00, float y00, float x10, float y10, float x01, float y01) noexcept
Definition juce_AffineTransform.cpp:213
Definition juce_Colour.h:38
void setTransform(const AffineTransform &transform)
Definition juce_Component.cpp:1341
Rectangle< int > getBounds() const noexcept
Definition juce_Component.h:304
void repaint()
Definition juce_Component.cpp:1917
virtual bool hitTest(int x, int y)
Definition juce_Component.cpp:1400
void setBounds(int x, int y, int width, int height)
Definition juce_Component.cpp:1147
Drawable()
Definition juce_Drawable.cpp:29
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_DrawableImage.cpp:151
bool setImageInternal(const Image &)
Definition juce_DrawableImage.cpp:137
void setOverlayColour(Colour newOverlayColour)
Definition juce_DrawableImage.cpp:69
~DrawableImage() override
Definition juce_DrawableImage.cpp:48
void setOpacity(float newOpacity)
Definition juce_DrawableImage.cpp:64
bool hitTest(int x, int y) override
Definition juce_DrawableImage.cpp:126
void setBoundingBox(Parallelogram< float > newBounds)
Definition juce_DrawableImage.cpp:79
Parallelogram< float > bounds
Definition juce_DrawableImage.h:110
void setImage(const Image &imageToUse)
Definition juce_DrawableImage.cpp:58
Colour overlayColour
Definition juce_DrawableImage.h:109
std::unique_ptr< Drawable > createCopy() const override
Definition juce_DrawableImage.cpp:52
Rectangle< float > getDrawableBounds() const override
Definition juce_DrawableImage.cpp:121
void paint(Graphics &) override
Definition juce_DrawableImage.cpp:103
DrawableImage()
Definition juce_DrawableImage.cpp:29
Path getOutlineAsPath() const override
Definition juce_DrawableImage.cpp:131
float opacity
Definition juce_DrawableImage.h:108
Image image
Definition juce_DrawableImage.h:107
Definition juce_GraphicsContext.h:45
Definition juce_Image.h:58
Definition juce_Parallelogram.h:38
Definition juce_Path.h:65
Definition juce_Rectangle.h:67
struct huft * t
Definition inflate.c:943
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
unsigned bl
Definition inflate.c:935
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition carla_juce.cpp:31
@ image
Definition juce_AccessibilityRole.h:42