VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_graphics / images / juce_ScaledImage.h
blobfac21453600843f4ee96b2b6e4c2715dbcf7b179
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
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.
23 ==============================================================================
26 namespace juce
29 /**
30 An image that will be resampled before it is drawn.
32 A plain Image only stores plain pixels, but does not store any information
33 about how these pixels correspond to points. This means that if the image's
34 dimensions are interpreted as points, then the image will be blurry when
35 drawn on high resolution displays. If the image's dimensions are instead
36 interpreted as corresponding to exact pixel positions, then the logical
37 size of the image will change depending on the scale factor of the screen
38 used to draw it.
40 The ScaledImage class is designed to store an image alongside a scale
41 factor that informs a renderer how to convert between the image's pixels
42 and points.
44 class JUCE_API ScaledImage
46 public:
47 /** Creates a ScaledImage with an invalid image and unity scale.
49 ScaledImage() = default;
51 /** Creates a ScaledImage from an Image, where the dimensions of the image
52 in pixels are exactly equal to its dimensions in points.
54 explicit ScaledImage (const Image& imageIn)
55 : ScaledImage (imageIn, 1.0) {}
57 /** Creates a ScaledImage from an Image, using a custom scale factor.
59 A scale of 1.0 means that the image's dimensions in pixels is equal to
60 its dimensions in points.
62 A scale of 2.0 means that the image contains 2 pixels per point in each
63 direction.
65 ScaledImage (const Image& imageIn, double scaleIn)
66 : image (imageIn), scaleFactor (scaleIn) {}
68 /** Returns the image at its original dimensions. */
69 Image getImage() const { return image; }
71 /** Returns the image's scale. */
72 double getScale() const { return scaleFactor; }
74 /** Returns the bounds of this image expressed in points. */
75 Rectangle<double> getScaledBounds() const { return image.getBounds().toDouble() / scaleFactor; }
77 private:
78 Image image;
79 double scaleFactor = 1.0;
82 } // namespace juce