Browse Source

Changed drawables to correctly render semi-transparently; added accessors for properties of some brush classes.

tags/2021-05-28
jules 15 years ago
parent
commit
c41ae8188d
16 changed files with 232 additions and 102 deletions
  1. +1
    -1
      extras/audio plugins/demo/build/mac/JuceDemoPlugin.xcodeproj/project.pbxproj
  2. +75
    -41
      juce_amalgamated.cpp
  3. +39
    -9
      juce_amalgamated.h
  4. +2
    -0
      src/audio/devices/juce_AudioDeviceManager.cpp
  5. +4
    -0
      src/gui/graphics/brushes/juce_GradientBrush.h
  6. +12
    -0
      src/gui/graphics/brushes/juce_ImageBrush.h
  7. +16
    -0
      src/gui/graphics/drawables/juce_Drawable.cpp
  8. +21
    -5
      src/gui/graphics/drawables/juce_Drawable.h
  9. +37
    -6
      src/gui/graphics/drawables/juce_DrawableComposite.cpp
  10. +1
    -1
      src/gui/graphics/drawables/juce_DrawableComposite.h
  11. +9
    -15
      src/gui/graphics/drawables/juce_DrawableImage.cpp
  12. +1
    -1
      src/gui/graphics/drawables/juce_DrawableImage.h
  13. +9
    -14
      src/gui/graphics/drawables/juce_DrawablePath.cpp
  14. +1
    -1
      src/gui/graphics/drawables/juce_DrawablePath.h
  15. +3
    -7
      src/gui/graphics/drawables/juce_DrawableText.cpp
  16. +1
    -1
      src/gui/graphics/drawables/juce_DrawableText.h

+ 1
- 1
extras/audio plugins/demo/build/mac/JuceDemoPlugin.xcodeproj/project.pbxproj View File

@@ -147,7 +147,7 @@
843796670EFBF357002A2725 /* MusicDeviceBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MusicDeviceBase.cpp; path = Examples/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.cpp; sourceTree = DEVELOPER_DIR; };
843796680EFBF357002A2725 /* MusicDeviceBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MusicDeviceBase.h; path = Examples/CoreAudio/AudioUnits/AUPublic/OtherBases/MusicDeviceBase.h; sourceTree = DEVELOPER_DIR; };
8437967D0EFBF5E4002A2725 /* juce_VST_Wrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = juce_VST_Wrapper.cpp; path = ../../../wrapper/VST/juce_VST_Wrapper.cpp; sourceTree = SOURCE_ROOT; };
8437967E0EFBF5E4002A2725 /* juce_VST_Wrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = juce_VST_Wrapper.mm; path = ../../../wrapper/VST/juce_VST_Wrapper.mm; sourceTree = SOURCE_ROOT; };
8437967E0EFBF5E4002A2725 /* juce_VST_Wrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 2; name = juce_VST_Wrapper.mm; path = ../../../wrapper/VST/juce_VST_Wrapper.mm; sourceTree = SOURCE_ROOT; };
843796D50EFBFD16002A2725 /* juce_RTAS_DigiCode1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = juce_RTAS_DigiCode1.cpp; path = ../../../wrapper/RTAS/juce_RTAS_DigiCode1.cpp; sourceTree = SOURCE_ROOT; };
843796D60EFBFD16002A2725 /* juce_RTAS_DigiCode2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = juce_RTAS_DigiCode2.cpp; path = ../../../wrapper/RTAS/juce_RTAS_DigiCode2.cpp; sourceTree = SOURCE_ROOT; };
843796D70EFBFD16002A2725 /* juce_RTAS_DigiCode3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = juce_RTAS_DigiCode3.cpp; path = ../../../wrapper/RTAS/juce_RTAS_DigiCode3.cpp; sourceTree = SOURCE_ROOT; };


+ 75
- 41
juce_amalgamated.cpp View File

@@ -23331,6 +23331,8 @@ void AudioDeviceManager::stopDevice()
{
if (currentAudioDevice != 0)
currentAudioDevice->stop();

deleteAndZero (testSound);
}

void AudioDeviceManager::closeAudioDevice()
@@ -79837,6 +79839,15 @@ END_JUCE_NAMESPACE

BEGIN_JUCE_NAMESPACE

Drawable::RenderingContext::RenderingContext (Graphics& g_,
const AffineTransform& transform_,
const float opacity_) throw()
: g (g_),
transform (transform_),
opacity (opacity_)
{
}

Drawable::Drawable()
{
}
@@ -79845,6 +79856,13 @@ Drawable::~Drawable()
{
}

void Drawable::draw (Graphics& g,
const AffineTransform& transform) const
{
const RenderingContext context (g, transform, g.getCurrentColour().getFloatAlpha());
draw (context);
}

void Drawable::drawAt (Graphics& g, const float x, const float y) const
{
draw (g, AffineTransform::translation (x, y));
@@ -79984,14 +80002,45 @@ void DrawableComposite::bringToFront (const int index)
}
}

void DrawableComposite::draw (Graphics& g, const AffineTransform& transform) const
void DrawableComposite::draw (const Drawable::RenderingContext& context) const
{
for (int i = 0; i < drawables.size(); ++i)
if (drawables.size() > 1)
{
const AffineTransform* const t = transforms.getUnchecked(i);
Drawable::RenderingContext contextCopy (context);

if (context.opacity >= 1.0f)
{
for (int i = 0; i < drawables.size(); ++i)
{
const AffineTransform* const t = transforms.getUnchecked(i);
contextCopy.transform = (t == 0) ? context.transform
: t->followedBy (context.transform);

drawables.getUnchecked(i)->draw (context);
}
}
else
{
// To correctly render a whole composite layer with an overall transparency,
// we need to render everything opaquely into a temp buffer, then blend that
// with the target opacity...
const Rectangle clipBounds (context.g.getClipBounds());
Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);

{
Graphics tempG (tempImage);
tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
draw (tempContext);
}

drawables.getUnchecked(i)->draw (g, t == 0 ? transform
: t->followedBy (transform));
context.g.setOpacity (context.opacity);
context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
}
}
else if (drawables.size() > 0)
{
drawables.getUnchecked(0)->draw (context);
}
}

@@ -80112,31 +80161,25 @@ void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
overlayColour = newOverlayColour;
}

void DrawableImage::draw (Graphics& g, const AffineTransform& transform) const
void DrawableImage::draw (const Drawable::RenderingContext& context) const
{
if (image != 0)
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later

if (opacity > 0.0f && ! overlayColour.isOpaque())
{
g.setColour (oldColour.withMultipliedAlpha (opacity));

g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
transform, false);
context.g.setOpacity (context.opacity * opacity);
context.g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
context.transform, false);
}

if (! overlayColour.isTransparent())
{
g.setColour (overlayColour.withMultipliedAlpha (oldColour.getFloatAlpha()));

g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
transform, true);
context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
context.g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
context.transform, true);
}

g.setColour (oldColour);
}
}

@@ -80241,18 +80284,15 @@ void DrawablePath::setOutline (const PathStrokeType& strokeType_, const Brush& n
updateOutline();
}

void DrawablePath::draw (Graphics& g, const AffineTransform& transform) const
void DrawablePath::draw (const Drawable::RenderingContext& context) const
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later
const float currentOpacity = oldColour.getFloatAlpha();

{
Brush* const tempBrush = fillBrush->createCopy();
tempBrush->applyTransform (transform);
tempBrush->multiplyOpacity (currentOpacity);
tempBrush->applyTransform (context.transform);
tempBrush->multiplyOpacity (context.opacity);

g.setBrush (tempBrush);
g.fillPath (path, transform);
context.g.setBrush (tempBrush);
context.g.fillPath (path, context.transform);

delete tempBrush;
}
@@ -80260,16 +80300,14 @@ void DrawablePath::draw (Graphics& g, const AffineTransform& transform) const
if (strokeBrush != 0 && strokeType.getStrokeThickness() > 0.0f)
{
Brush* const tempBrush = strokeBrush->createCopy();
tempBrush->applyTransform (transform);
tempBrush->multiplyOpacity (currentOpacity);
tempBrush->applyTransform (context.transform);
tempBrush->multiplyOpacity (context.opacity);

g.setBrush (tempBrush);
g.fillPath (outline, transform);
context.g.setBrush (tempBrush);
context.g.fillPath (outline, context.transform);

delete tempBrush;
}

g.setColour (oldColour);
}

void DrawablePath::updateOutline()
@@ -80337,14 +80375,10 @@ void DrawableText::setColour (const Colour& newColour)
colour = newColour;
}

void DrawableText::draw (Graphics& g, const AffineTransform& transform) const
void DrawableText::draw (const Drawable::RenderingContext& context) const
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later

g.setColour (colour.withMultipliedAlpha (oldColour.getFloatAlpha()));
text.draw (g, transform);

g.setColour (oldColour);
context.g.setColour (colour.withMultipliedAlpha (context.opacity));
text.draw (context.g, context.transform);
}

void DrawableText::getBounds (float& x, float& y, float& width, float& height) const


+ 39
- 9
juce_amalgamated.h View File

@@ -38743,6 +38743,9 @@ public:
/** Destructor. */
~GradientBrush() throw();

/** Returns the current gradient information */
const ColourGradient& getGradient() const throw() { return gradient; }

Brush* createCopy() const throw();

void applyTransform (const AffineTransform& transform) throw();
@@ -39056,6 +39059,18 @@ public:
/** Destructor. */
~ImageBrush() throw();

/** Returns the image currently being used. */
Image* getImage() const throw() { return image; }

/** Returns the current anchor X position. */
int getAnchorX() const throw() { return anchorX; }

/** Returns the current anchor Y position. */
int getAnchorY() const throw() { return anchorY; }

/** Returns the current opacity. */
float getOpacity() const throw() { return opacity; }

Brush* createCopy() const throw();

void applyTransform (const AffineTransform& transform) throw();
@@ -41135,13 +41150,10 @@ public:
virtual Drawable* createCopy() const = 0;

/** Renders this Drawable object.

This is the main rendering method you should call to render a Drawable.

@see drawWithin
*/
virtual void draw (Graphics& g,
const AffineTransform& transform = AffineTransform::identity) const = 0;
void draw (Graphics& g,
const AffineTransform& transform = AffineTransform::identity) const;

/** Renders the Drawable at a given offset within the Graphics context.

@@ -41177,6 +41189,24 @@ public:
const int destHeight,
const RectanglePlacement& placement) const;

/** Holds the information needed when telling a drawable to render itself.
@see Drawable::draw
*/
class RenderingContext
{
public:
RenderingContext (Graphics& g, const AffineTransform& transform, const float opacity) throw();

Graphics& g;
AffineTransform transform;
float opacity;
};

/** Renders this Drawable object.
@see drawWithin
*/
virtual void draw (const RenderingContext& context) const = 0;

/** Returns the smallest rectangle that can contain this Drawable object.

Co-ordinates are relative to the object's own origin.
@@ -41345,7 +41375,7 @@ public:
void bringToFront (const int index);

/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */
@@ -41440,7 +41470,7 @@ public:
const Colour& getOverlayColour() const throw() { return overlayColour; }

/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */
@@ -41540,7 +41570,7 @@ public:
Brush* getOutlineBrush() const throw() { return strokeBrush; }

/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */
@@ -41608,7 +41638,7 @@ public:
const Colour& getColour() const throw() { return colour; }

/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */


+ 2
- 0
src/audio/devices/juce_AudioDeviceManager.cpp View File

@@ -509,6 +509,8 @@ void AudioDeviceManager::stopDevice()
{
if (currentAudioDevice != 0)
currentAudioDevice->stop();
deleteAndZero (testSound);
}
void AudioDeviceManager::closeAudioDevice()


+ 4
- 0
src/gui/graphics/brushes/juce_GradientBrush.h View File

@@ -75,6 +75,10 @@ public:
/** Destructor. */
~GradientBrush() throw();
//==============================================================================
/** Returns the current gradient information */
const ColourGradient& getGradient() const throw() { return gradient; }
//==============================================================================
Brush* createCopy() const throw();


+ 12
- 0
src/gui/graphics/brushes/juce_ImageBrush.h View File

@@ -54,6 +54,18 @@ public:
/** Destructor. */
~ImageBrush() throw();
//==============================================================================
/** Returns the image currently being used. */
Image* getImage() const throw() { return image; }
/** Returns the current anchor X position. */
int getAnchorX() const throw() { return anchorX; }
/** Returns the current anchor Y position. */
int getAnchorY() const throw() { return anchorY; }
/** Returns the current opacity. */
float getOpacity() const throw() { return opacity; }
//==============================================================================
Brush* createCopy() const throw();


+ 16
- 0
src/gui/graphics/drawables/juce_Drawable.cpp View File

@@ -33,6 +33,15 @@ BEGIN_JUCE_NAMESPACE
#include "../../../text/juce_XmlDocument.h"
#include "../../../io/files/juce_FileInputStream.h"
//==============================================================================
Drawable::RenderingContext::RenderingContext (Graphics& g_,
const AffineTransform& transform_,
const float opacity_) throw()
: g (g_),
transform (transform_),
opacity (opacity_)
{
}
//==============================================================================
Drawable::Drawable()
@@ -43,6 +52,13 @@ Drawable::~Drawable()
{
}
void Drawable::draw (Graphics& g,
const AffineTransform& transform) const
{
const RenderingContext context (g, transform, g.getCurrentColour().getFloatAlpha());
draw (context);
}
void Drawable::drawAt (Graphics& g, const float x, const float y) const
{
draw (g, AffineTransform::translation (x, y));


+ 21
- 5
src/gui/graphics/drawables/juce_Drawable.h View File

@@ -59,13 +59,10 @@ public:
//==============================================================================
/** Renders this Drawable object.
This is the main rendering method you should call to render a Drawable.
@see drawWithin
*/
virtual void draw (Graphics& g,
const AffineTransform& transform = AffineTransform::identity) const = 0;
void draw (Graphics& g,
const AffineTransform& transform = AffineTransform::identity) const;
/** Renders the Drawable at a given offset within the Graphics context.
@@ -102,6 +99,25 @@ public:
const RectanglePlacement& placement) const;
//==============================================================================
/** Holds the information needed when telling a drawable to render itself.
@see Drawable::draw
*/
class RenderingContext
{
public:
RenderingContext (Graphics& g, const AffineTransform& transform, const float opacity) throw();
Graphics& g;
AffineTransform transform;
float opacity;
};
/** Renders this Drawable object.
@see drawWithin
*/
virtual void draw (const RenderingContext& context) const = 0;
//==============================================================================
/** Returns the smallest rectangle that can contain this Drawable object.


+ 37
- 6
src/gui/graphics/drawables/juce_DrawableComposite.cpp View File

@@ -27,8 +27,8 @@
BEGIN_JUCE_NAMESPACE
#include "juce_DrawableComposite.h"
#include "../imaging/juce_Image.h"
//==============================================================================
@@ -84,14 +84,45 @@ void DrawableComposite::bringToFront (const int index)
}
}
void DrawableComposite::draw (Graphics& g, const AffineTransform& transform) const
void DrawableComposite::draw (const Drawable::RenderingContext& context) const
{
for (int i = 0; i < drawables.size(); ++i)
if (drawables.size() > 1)
{
const AffineTransform* const t = transforms.getUnchecked(i);
Drawable::RenderingContext contextCopy (context);
drawables.getUnchecked(i)->draw (g, t == 0 ? transform
: t->followedBy (transform));
if (context.opacity >= 1.0f)
{
for (int i = 0; i < drawables.size(); ++i)
{
const AffineTransform* const t = transforms.getUnchecked(i);
contextCopy.transform = (t == 0) ? context.transform
: t->followedBy (context.transform);
drawables.getUnchecked(i)->draw (context);
}
}
else
{
// To correctly render a whole composite layer with an overall transparency,
// we need to render everything opaquely into a temp buffer, then blend that
// with the target opacity...
const Rectangle clipBounds (context.g.getClipBounds());
Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
{
Graphics tempG (tempImage);
tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
draw (tempContext);
}
context.g.setOpacity (context.opacity);
context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
}
}
else if (drawables.size() > 0)
{
drawables.getUnchecked(0)->draw (context);
}
}


+ 1
- 1
src/gui/graphics/drawables/juce_DrawableComposite.h View File

@@ -130,7 +130,7 @@ public:
//==============================================================================
/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */


+ 9
- 15
src/gui/graphics/drawables/juce_DrawableImage.cpp View File

@@ -86,31 +86,25 @@ void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
}
//==============================================================================
void DrawableImage::draw (Graphics& g, const AffineTransform& transform) const
void DrawableImage::draw (const Drawable::RenderingContext& context) const
{
if (image != 0)
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later
if (opacity > 0.0f && ! overlayColour.isOpaque())
{
g.setColour (oldColour.withMultipliedAlpha (opacity));
g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
transform, false);
context.g.setOpacity (context.opacity * opacity);
context.g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
context.transform, false);
}
if (! overlayColour.isTransparent())
{
g.setColour (overlayColour.withMultipliedAlpha (oldColour.getFloatAlpha()));
g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
transform, true);
context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
context.g.drawImageTransformed (image,
0, 0, image->getWidth(), image->getHeight(),
context.transform, true);
}
g.setColour (oldColour);
}
}


+ 1
- 1
src/gui/graphics/drawables/juce_DrawableImage.h View File

@@ -100,7 +100,7 @@ public:
//==============================================================================
/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */


+ 9
- 14
src/gui/graphics/drawables/juce_DrawablePath.cpp View File

@@ -83,18 +83,15 @@ void DrawablePath::setOutline (const PathStrokeType& strokeType_, const Brush& n
//==============================================================================
void DrawablePath::draw (Graphics& g, const AffineTransform& transform) const
void DrawablePath::draw (const Drawable::RenderingContext& context) const
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later
const float currentOpacity = oldColour.getFloatAlpha();
{
Brush* const tempBrush = fillBrush->createCopy();
tempBrush->applyTransform (transform);
tempBrush->multiplyOpacity (currentOpacity);
tempBrush->applyTransform (context.transform);
tempBrush->multiplyOpacity (context.opacity);
g.setBrush (tempBrush);
g.fillPath (path, transform);
context.g.setBrush (tempBrush);
context.g.fillPath (path, context.transform);
delete tempBrush;
}
@@ -102,16 +99,14 @@ void DrawablePath::draw (Graphics& g, const AffineTransform& transform) const
if (strokeBrush != 0 && strokeType.getStrokeThickness() > 0.0f)
{
Brush* const tempBrush = strokeBrush->createCopy();
tempBrush->applyTransform (transform);
tempBrush->multiplyOpacity (currentOpacity);
tempBrush->applyTransform (context.transform);
tempBrush->multiplyOpacity (context.opacity);
g.setBrush (tempBrush);
g.fillPath (outline, transform);
context.g.setBrush (tempBrush);
context.g.fillPath (outline, context.transform);
delete tempBrush;
}
g.setColour (oldColour);
}
void DrawablePath::updateOutline()


+ 1
- 1
src/gui/graphics/drawables/juce_DrawablePath.h View File

@@ -104,7 +104,7 @@ public:
//==============================================================================
/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */


+ 3
- 7
src/gui/graphics/drawables/juce_DrawableText.cpp View File

@@ -59,14 +59,10 @@ void DrawableText::setColour (const Colour& newColour)
}
//==============================================================================
void DrawableText::draw (Graphics& g, const AffineTransform& transform) const
void DrawableText::draw (const Drawable::RenderingContext& context) const
{
const Colour oldColour (g.getCurrentColour()); // save this so we can restore it later
g.setColour (colour.withMultipliedAlpha (oldColour.getFloatAlpha()));
text.draw (g, transform);
g.setColour (oldColour);
context.g.setColour (colour.withMultipliedAlpha (context.opacity));
text.draw (context.g, context.transform);
}
void DrawableText::getBounds (float& x, float& y, float& width, float& height) const


+ 1
- 1
src/gui/graphics/drawables/juce_DrawableText.h View File

@@ -70,7 +70,7 @@ public:
//==============================================================================
/** @internal */
void draw (Graphics& g, const AffineTransform& transform) const;
void draw (const Drawable::RenderingContext& context) const;
/** @internal */
void getBounds (float& x, float& y, float& width, float& height) const;
/** @internal */


Loading…
Cancel
Save