JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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
33DrawableImage::DrawableImage (const DrawableImage& other)
34 : Drawable (other),
35 image (other.image),
36 opacity (other.opacity),
37 overlayColour (other.overlayColour),
38 bounds (other.bounds)
39{
40 setBounds (other.getBounds());
41}
42
43DrawableImage::DrawableImage (const Image& imageToUse)
44{
45 setImageInternal (imageToUse);
46}
47
48DrawableImage::~DrawableImage()
49{
50}
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
69void DrawableImage::setOverlayColour (Colour newOverlayColour)
70{
71 overlayColour = newOverlayColour;
72}
73
74void DrawableImage::setBoundingBox (Rectangle<float> newBounds)
75{
76 setBoundingBox (Parallelogram<float> (newBounds));
77}
78
79void DrawableImage::setBoundingBox (Parallelogram<float> newBounds)
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
97 setTransform (t);
98 }
99 }
100}
101
102//==============================================================================
103void DrawableImage::paint (Graphics& g)
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
121Rectangle<float> DrawableImage::getDrawableBounds() const
122{
123 return image.getBounds().toFloat();
124}
125
126bool DrawableImage::hitTest (int x, int y)
127{
128 return Drawable::hitTest (x, y) && image.isValid() && image.getPixelAt (x, y).getAlpha() >= 127;
129}
130
131Path DrawableImage::getOutlineAsPath() const
132{
133 return {}; // not applicable for images
134}
135
136//==============================================================================
137bool DrawableImage::setImageInternal (const Image& imageToUse)
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
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
A graphics context, used for drawing a component or image.
void setOpacity(float newOpacity)
Changes the opacity to use with the current colour.
void drawImageAt(const Image &imageToDraw, int topLeftX, int topLeftY, bool fillAlphaChannelWithCurrentBrush=false) const
Draws an image.
void setColour(Colour newColour)
Changes the current drawing colour.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
Represents a parallelogram that is defined by 3 points.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
Manages a rectangle and allows geometric operations to be performed on it.
JUCE Namespace.