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_Drawable.h
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
29#ifndef DOXYGEN
30namespace detail
31{
32class BoundsChangeListener final : private ComponentListener
33{
34public:
35 BoundsChangeListener (Component& c, std::function<void()> cb)
36 : callback (std::move (cb)),
37 componentListenerGuard { [comp = &c, this] { comp->removeComponentListener (this); } }
38 {
39 jassert (callback != nullptr);
40
41 c.addComponentListener (this);
42 }
43
44private:
45 void componentMovedOrResized (Component&, bool, bool) override
46 {
47 callback();
48 }
49
50 std::function<void()> callback;
51 ErasedScopeGuard componentListenerGuard;
52};
53} // namespace detail
54#endif
55
56//==============================================================================
64class JUCE_API Drawable : public Component
65{
66protected:
67 //==============================================================================
72 Drawable();
73
74public:
76 ~Drawable() override;
77
78 //==============================================================================
84
86 virtual Path getOutlineAsPath() const = 0;
87
88 //==============================================================================
97 void draw (Graphics& g, float opacity,
98 const AffineTransform& transform = AffineTransform()) const;
99
113 void drawAt (Graphics& g, float x, float y, float opacity) const;
114
131 void drawWithin (Graphics& g,
132 Rectangle<float> destArea,
133 RectanglePlacement placement,
134 float opacity) const;
135
136
137 //==============================================================================
141 void setOriginWithOriginalSize (Point<float> originWithinParent);
142
146 void setTransformToFit (const Rectangle<float>& areaInParent, RectanglePlacement placement);
147
149 DrawableComposite* getParent() const;
150
154 void setClipPath (std::unique_ptr<Drawable> drawableClipPath);
155
156 //==============================================================================
162 static std::unique_ptr<Drawable> createFromImageData (const void* data, size_t numBytes);
163
169 static std::unique_ptr<Drawable> createFromImageDataStream (InputStream& dataSource);
170
176 static std::unique_ptr<Drawable> createFromImageFile (const File& file);
177
186 static std::unique_ptr<Drawable> createFromSVG (const XmlElement& svgDocument);
187
199 static std::unique_ptr<Drawable> createFromSVGFile (const File& svgFile);
200
202 static Path parseSVGPath (const String& svgPath);
203
204 //==============================================================================
210
214 virtual bool replaceColour (Colour originalColour, Colour replacementColour);
215
229 void setDrawableTransform (const AffineTransform& transform);
230
231protected:
232 //==============================================================================
233 friend class DrawableComposite;
234 friend class DrawableShape;
235
237 void transformContextToCorrectOrigin (Graphics&);
239 void parentHierarchyChanged() override;
241 void setBoundsToEnclose (Rectangle<float>);
243 void applyDrawableClipPath (Graphics&);
244
245 Point<int> originRelativeToComponent;
246 std::unique_ptr<Drawable> drawableClipPath;
247 AffineTransform drawableTransform;
248
249 void nonConstDraw (Graphics&, float opacity, const AffineTransform&);
250
251 Drawable (const Drawable&);
252 Drawable& operator= (const Drawable&);
254
255
256private:
257 void updateTransform();
258
259 detail::BoundsChangeListener boundsChangeListener { *this, [this] { updateTransform(); } };
260};
261
262} // namespace juce
Represents a 2D affine-transformation matrix.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
The base class for all JUCE user-interface objects.
virtual void parentHierarchyChanged()
Called to indicate that the component's parents have changed.
A drawable object which acts as a container for a set of other Drawables.
A base class implementing common functionality for Drawable classes which consist of some kind of fil...
The base class for objects which can draw themselves, e.g.
virtual std::unique_ptr< Drawable > createCopy() const =0
Creates a deep copy of this Drawable object.
virtual Path getOutlineAsPath() const =0
Creates a path that describes the outline of this drawable.
virtual Rectangle< float > getDrawableBounds() const =0
Returns the area that this drawable covers.
Represents a local file or directory.
Definition juce_File.h:45
A graphics context, used for drawing a component or image.
The base class for streams that read data.
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
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Defines the method used to position some kind of rectangular object within a rectangular viewport.
Manages a rectangle and allows geometric operations to be performed on it.
The JUCE String class!
Definition juce_String.h:53
Used to build a tree of elements representing an XML document.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
#define jassert(expression)
Platform-independent assertion macro.
T move(T... args)
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88