From 1e1c9944c9b271e8918e455215bc1fefaf0d89b7 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Sat, 31 Oct 2009 15:26:22 +0000 Subject: [PATCH] Removed methods Graphics::getCurrentFont and Graphics::getCurrentColour, because these methods will become impossible for future native drawing contexts. This required a couple of minor tweaks to LookAndFeel and Drawable methods. Also fixed native CoreGraphics drawing of transparent windows. --- .../src/demos/PathsAndTransformsDemo.cpp | 18 +- juce_amalgamated.cpp | 172 +++++------------- juce_amalgamated.h | 46 ++--- .../buttons/juce_DrawableButton.cpp | 5 +- .../components/buttons/juce_ToolbarButton.cpp | 4 +- .../lookandfeel/juce_LookAndFeel.cpp | 21 ++- .../components/lookandfeel/juce_LookAndFeel.h | 3 +- src/gui/graphics/contexts/juce_Graphics.cpp | 25 +-- src/gui/graphics/contexts/juce_Graphics.h | 21 +-- .../contexts/juce_LowLevelGraphicsContext.h | 5 - ...uce_LowLevelGraphicsPostScriptRenderer.cpp | 33 ---- .../juce_LowLevelGraphicsPostScriptRenderer.h | 4 - .../juce_LowLevelGraphicsSoftwareRenderer.cpp | 31 ---- .../juce_LowLevelGraphicsSoftwareRenderer.h | 4 - src/gui/graphics/drawables/juce_Drawable.cpp | 19 +- src/gui/graphics/drawables/juce_Drawable.h | 9 +- .../mac/juce_mac_CoreGraphicsContext.mm | 29 --- .../mac/juce_mac_NSViewComponentPeer.mm | 8 +- 18 files changed, 114 insertions(+), 343 deletions(-) diff --git a/extras/juce demo/src/demos/PathsAndTransformsDemo.cpp b/extras/juce demo/src/demos/PathsAndTransformsDemo.cpp index 795eacd7e1..9c48c05df0 100644 --- a/extras/juce demo/src/demos/PathsAndTransformsDemo.cpp +++ b/extras/juce demo/src/demos/PathsAndTransformsDemo.cpp @@ -213,25 +213,23 @@ public: } else if (type == 10) { - g.setOpacity ((float) opacitySlider->getValue()); - float x, y, w, h; drawable->getBounds (x, y, w, h); - drawable->draw (g, AffineTransform::translation (-x - 0.5f * w, - -y - 0.5f * h) - .followedBy (getTransform())); + drawable->draw (g, (float) opacitySlider->getValue(), + AffineTransform::translation (-x - 0.5f * w, + -y - 0.5f * h) + .followedBy (getTransform())); } else if (type == 11) { - g.setOpacity ((float) opacitySlider->getValue()); - float x, y, w, h; svgDrawable->getBounds (x, y, w, h); - svgDrawable->draw (g, AffineTransform::translation (-x - 0.5f * w, - -y - 0.5f * h) - .followedBy (getTransform())); + svgDrawable->draw (g, (float) opacitySlider->getValue(), + AffineTransform::translation (-x - 0.5f * w, + -y - 0.5f * h) + .followedBy (getTransform())); } } diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 872269364f..8f2abea690 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -42656,7 +42656,7 @@ void DrawableButton::paintButton (Graphics& g, { if (style == ImageRaw) { - imageToDraw->draw (g); + imageToDraw->draw (g, 1.0f); } else { @@ -42665,7 +42665,8 @@ void DrawableButton::paintButton (Graphics& g, imageSpace.getY(), imageSpace.getWidth(), imageSpace.getHeight(), - RectanglePlacement::centred); + RectanglePlacement::centred, + 1.0f); } } } @@ -43268,14 +43269,14 @@ void ToolbarButton::paintButtonArea (Graphics& g, { Image im (Image::ARGB, width, height, true); Graphics g2 (im); - d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred); + d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f); im.desaturate(); g.drawImageAt (&im, 0, 0); } else { - d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred); + d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f); } } @@ -60719,14 +60720,15 @@ const Font LookAndFeel::getFontForTextButton (TextButton& button) void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) { - g.setFont (getFontForTextButton (button)); + Font font (getFontForTextButton (button)); + g.setFont (font); g.setColour (button.findColour (TextButton::textColourId) .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); const int yIndent = jmin (4, button.proportionOfHeight (0.3f)); const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2; - const int fontHeight = roundFloatToInt (g.getCurrentFont().getHeight() * 0.6f); + const int fontHeight = roundFloatToInt (font.getHeight() * 0.6f); const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2)); const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2)); @@ -61005,7 +61007,7 @@ void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, } } -void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, int h) +void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h) { const float radius = jmin (w, h) * 0.4f; const float thickness = radius * 0.15f; @@ -61018,12 +61020,11 @@ void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, i const float cy = y + h * 0.5f; const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12; - const Colour col (g.getCurrentColour()); for (int i = 0; i < 12; ++i) { const int n = (i + 12 - animationIndex) % 12; - g.setColour (col.withMultipliedAlpha ((n + 1) / 12.0f)); + g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f)) .translated (cx, cy)); @@ -61444,7 +61445,7 @@ void LookAndFeel::drawPopupMenuItem (Graphics& g, if (shortcutKeyText.isNotEmpty()) { - Font f2 (g.getCurrentFont()); + Font f2 (font); f2.setHeight (f2.getHeight() * 0.75f); f2.setHorizontalScale (0.95f); g.setFont (f2); @@ -62111,15 +62112,16 @@ void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window, g.setBrush (&gb); g.fillAll(); - g.setFont (h * 0.65f, Font::bold); + Font font (h * 0.65f, Font::bold); + g.setFont (font); - int textW = g.getCurrentFont().getStringWidth (window.getName()); + int textW = font.getStringWidth (window.getName()); int iconW = 0; int iconH = 0; if (icon != 0) { - iconH = (int) g.getCurrentFont().getHeight(); + iconH = (int) font.getHeight(); iconW = icon->getWidth() * iconH / icon->getHeight() + 4; } @@ -62836,7 +62838,7 @@ void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height, g.setColour (Colours::black); if (! component.isEnabled()) - g.setOpacity (g.getCurrentColour().getFloatAlpha() * 0.6f); + g.setOpacity (0.6f); g.setFont (jmin (height, 24) * 0.65f); @@ -76588,11 +76590,6 @@ void Graphics::setColour (const Colour& newColour) throw() deleteAndZero (state->brush); } -const Colour& Graphics::getCurrentColour() const throw() -{ - return state->colour; -} - void Graphics::setOpacity (const float newOpacity) throw() { saveStateIfPending(); @@ -76643,11 +76640,6 @@ void Graphics::setFont (const float newFontHeight, state->font.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0.0f); } -const Font& Graphics::getCurrentFont() const throw() -{ - return state->font; -} - void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const throw() @@ -77272,11 +77264,16 @@ void Graphics::drawImage (const Image* const imageToDraw, } else { - context->blendImageRescaling (*imageToDraw, - dx, dy, dw, dh, - sx, sy, sw, sh, - state->colour.getFloatAlpha(), - state->quality); + context->blendImageWarping (*imageToDraw, + sx, sy, sw, sh, + AffineTransform::translation ((float) -sx, + (float) -sy) + .scaled (dw / (float) sw, + dh / (float) sh) + .translated ((float) dx, + (float) dy), + state->colour.getFloatAlpha(), + state->quality); } } } @@ -77816,37 +77813,6 @@ void LowLevelGraphicsPostScriptRenderer::fillAlphaChannelWithImage (const Image& notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file } -void LowLevelGraphicsPostScriptRenderer::blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, - const Graphics::ResamplingQuality quality) -{ - if (sw > 0 && sh > 0) - { - jassert (sx >= 0 && sx + sw <= sourceImage.getWidth()); - jassert (sy >= 0 && sy + sh <= sourceImage.getHeight()); - - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::scale (dw / (float) sw, - dh / (float) sh) - .translated ((float) (dx - sx), - (float) (dy - sy)), - alpha, - quality); - } - } -} - void LowLevelGraphicsPostScriptRenderer::blendImage (const Image& sourceImage, int dx, int dy, int dw, int dh, int sx, int sy, float opacity) { blendImageWarping (sourceImage, @@ -79698,36 +79664,6 @@ void LowLevelGraphicsSoftwareRenderer::clippedBlendImage (int clipX, int clipY, sourceImage.releasePixelDataReadOnly (srcPixels); } -void LowLevelGraphicsSoftwareRenderer::blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, - const Graphics::ResamplingQuality quality) -{ - if (sw > 0 && sh > 0) - { - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::translation ((float) -sx, - (float) -sy) - .scaled (dw / (float) sw, - dh / (float) sh) - .translated ((float) dx, - (float) dy), - alpha, - quality); - } - } -} - void LowLevelGraphicsSoftwareRenderer::blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& t, @@ -80326,16 +80262,15 @@ Drawable::~Drawable() { } -void Drawable::draw (Graphics& g, +void Drawable::draw (Graphics& g, const float opacity, const AffineTransform& transform) const { - const RenderingContext context (g, transform, g.getCurrentColour().getFloatAlpha()); - render (context); + render (RenderingContext (g, transform, opacity)); } -void Drawable::drawAt (Graphics& g, const float x, const float y) const +void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const { - draw (g, AffineTransform::translation (x, y)); + draw (g, opacity, AffineTransform::translation (x, y)); } void Drawable::drawWithin (Graphics& g, @@ -80343,16 +80278,18 @@ void Drawable::drawWithin (Graphics& g, const int destY, const int destW, const int destH, - const RectanglePlacement& placement) const + const RectanglePlacement& placement, + const float opacity) const { if (destW > 0 && destH > 0) { float x, y, w, h; getBounds (x, y, w, h); - draw (g, placement.getTransformToFit (x, y, w, h, - (float) destX, (float) destY, - (float) destW, (float) destH)); + draw (g, opacity, + placement.getTransformToFit (x, y, w, h, + (float) destX, (float) destY, + (float) destW, (float) destH)); } } @@ -263283,35 +263220,6 @@ public: CGImageRelease (image); } - void blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, const Graphics::ResamplingQuality quality) - { - if (sw > 0 && sh > 0) - { - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::translation ((float) -sx, - (float) -sy) - .scaled (dw / (float) sw, - dh / (float) sh) - .translated ((float) dx, - (float) dy), - alpha, - quality); - } - } - } - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, @@ -264946,8 +264854,12 @@ void NSViewComponentPeer::drawRect (NSRect r) return; #if USE_COREGRAPHICS_RENDERING - CoreGraphicsContext context ((CGContextRef) [[NSGraphicsContext currentContext] graphicsPort], - [view frame].size.height); + CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; + + if (! component->isOpaque()) + CGContextClearRect (cg, CGContextGetClipBoundingBox (cg)); + + CoreGraphicsContext context (cg, [view frame].size.height); handlePaint (context); #else const float y = [view frame].size.height - (r.origin.y + r.size.height); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index b12faea0eb..dd37093bc0 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -19695,23 +19695,14 @@ public: If a brush is being used when this method is called, the brush will be deselected, and any subsequent drawing will be done with a solid colour brush instead. - @see setOpacity, setBrush, getColour + @see setOpacity, setBrush */ void setColour (const Colour& newColour) throw(); - /** Returns the colour that's currently being used. - - This will return the last colour set by setColour(), even if the colour's not - currently being used for drawing because a brush has been selected instead. - - @see setColour - */ - const Colour& getCurrentColour() const throw(); - /** Changes the opacity to use with the current colour. - If a solid colour is being used for drawing, this changes its opacity (and this - will be reflected by calls to the getColour() method). + If a solid colour is being used for drawing, this changes its opacity + to this new value (i.e. it doesn't multiply the colour's opacity by this amount). A value of 0.0 is completely transparent, 1.0 is completely opaque. */ @@ -19748,12 +19739,6 @@ public: void setFont (const float newFontHeight, const int fontStyleFlags = Font::plain) throw(); - /** Returns the font that's currently being used for text operations. - - @see setFont - */ - const Font& getCurrentFont() const throw(); - /** Draws a one-line text string. This will use the current colour (or brush) to fill the text. The font is the last @@ -39997,11 +39982,6 @@ public: int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha) = 0; - virtual void blendImageRescaling (const Image& sourceImage, - int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality) = 0; - virtual void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, @@ -40069,10 +40049,6 @@ public: void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha); - void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality); - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, float alpha, const Graphics::ResamplingQuality quality); @@ -40173,10 +40149,6 @@ public: void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha); - void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality); - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, float alpha, const Graphics::ResamplingQuality quality); @@ -41264,7 +41236,7 @@ public: /** Renders this Drawable object. @see drawWithin */ - void draw (Graphics& g, + void draw (Graphics& g, const float opacity, const AffineTransform& transform = AffineTransform::identity) const; /** Renders the Drawable at a given offset within the Graphics context. @@ -41278,7 +41250,8 @@ public: */ void drawAt (Graphics& g, const float x, - const float y) const; + const float y, + const float opacity) const; /** Renders the Drawable within a rectangle, scaling it to fit neatly inside without changing its aspect-ratio. @@ -41293,13 +41266,15 @@ public: @param destHeight size of the target rectangle to fit the image into @param placement defines the alignment and rescaling to use to fit this object within the target rectangle. + @param opacity the opacity to use, in the range 0 to 1.0 */ void drawWithin (Graphics& g, const int destX, const int destY, const int destWidth, const int destHeight, - const RectanglePlacement& placement) const; + const RectanglePlacement& placement, + const float opacity) const; /** Holds the information needed when telling a drawable to render itself. @see Drawable::draw @@ -54088,7 +54063,8 @@ public: // Draws a small image that spins to indicate that something's happening.. // This method should use the current time to animate itself, so just keep // repainting it every so often. - virtual void drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, int h); + virtual void drawSpinningWaitAnimation (Graphics& g, const Colour& colour, + int x, int y, int w, int h); /** Draws one of the buttons on a scrollbar. diff --git a/src/gui/components/buttons/juce_DrawableButton.cpp b/src/gui/components/buttons/juce_DrawableButton.cpp index e37378828e..12be5fdeed 100644 --- a/src/gui/components/buttons/juce_DrawableButton.cpp +++ b/src/gui/components/buttons/juce_DrawableButton.cpp @@ -222,7 +222,7 @@ void DrawableButton::paintButton (Graphics& g, { if (style == ImageRaw) { - imageToDraw->draw (g); + imageToDraw->draw (g, 1.0f); } else { @@ -231,7 +231,8 @@ void DrawableButton::paintButton (Graphics& g, imageSpace.getY(), imageSpace.getWidth(), imageSpace.getHeight(), - RectanglePlacement::centred); + RectanglePlacement::centred, + 1.0f); } } } diff --git a/src/gui/components/buttons/juce_ToolbarButton.cpp b/src/gui/components/buttons/juce_ToolbarButton.cpp index 6603d91042..e1dc642d22 100644 --- a/src/gui/components/buttons/juce_ToolbarButton.cpp +++ b/src/gui/components/buttons/juce_ToolbarButton.cpp @@ -74,14 +74,14 @@ void ToolbarButton::paintButtonArea (Graphics& g, { Image im (Image::ARGB, width, height, true); Graphics g2 (im); - d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred); + d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f); im.desaturate(); g.drawImageAt (&im, 0, 0); } else { - d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred); + d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f); } } diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp index e82ddfd2fe..f5638a0ee9 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -367,14 +367,15 @@ const Font LookAndFeel::getFontForTextButton (TextButton& button) void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, bool /*isMouseOverButton*/, bool /*isButtonDown*/) { - g.setFont (getFontForTextButton (button)); + Font font (getFontForTextButton (button)); + g.setFont (font); g.setColour (button.findColour (TextButton::textColourId) .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); const int yIndent = jmin (4, button.proportionOfHeight (0.3f)); const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2; - const int fontHeight = roundFloatToInt (g.getCurrentFont().getHeight() * 0.6f); + const int fontHeight = roundFloatToInt (font.getHeight() * 0.6f); const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2)); const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2)); @@ -655,7 +656,7 @@ void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, } } -void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, int h) +void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h) { const float radius = jmin (w, h) * 0.4f; const float thickness = radius * 0.15f; @@ -668,12 +669,11 @@ void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, i const float cy = y + h * 0.5f; const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12; - const Colour col (g.getCurrentColour()); for (int i = 0; i < 12; ++i) { const int n = (i + 12 - animationIndex) % 12; - g.setColour (col.withMultipliedAlpha ((n + 1) / 12.0f)); + g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f)) .translated (cx, cy)); @@ -1099,7 +1099,7 @@ void LookAndFeel::drawPopupMenuItem (Graphics& g, if (shortcutKeyText.isNotEmpty()) { - Font f2 (g.getCurrentFont()); + Font f2 (font); f2.setHeight (f2.getHeight() * 0.75f); f2.setHorizontalScale (0.95f); g.setFont (f2); @@ -1777,15 +1777,16 @@ void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window, g.setBrush (&gb); g.fillAll(); - g.setFont (h * 0.65f, Font::bold); + Font font (h * 0.65f, Font::bold); + g.setFont (font); - int textW = g.getCurrentFont().getStringWidth (window.getName()); + int textW = font.getStringWidth (window.getName()); int iconW = 0; int iconH = 0; if (icon != 0) { - iconH = (int) g.getCurrentFont().getHeight(); + iconH = (int) font.getHeight(); iconW = icon->getWidth() * iconH / icon->getHeight() + 4; } @@ -2515,7 +2516,7 @@ void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height, g.setColour (Colours::black); if (! component.isEnabled()) - g.setOpacity (g.getCurrentColour().getFloatAlpha() * 0.6f); + g.setOpacity (0.6f); g.setFont (jmin (height, 24) * 0.65f); diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.h b/src/gui/components/lookandfeel/juce_LookAndFeel.h index 8ec587abca..0389a75d3b 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.h @@ -210,7 +210,8 @@ public: // Draws a small image that spins to indicate that something's happening.. // This method should use the current time to animate itself, so just keep // repainting it every so often. - virtual void drawSpinningWaitAnimation (Graphics& g, int x, int y, int w, int h); + virtual void drawSpinningWaitAnimation (Graphics& g, const Colour& colour, + int x, int y, int w, int h); //============================================================================== /** Draws one of the buttons on a scrollbar. diff --git a/src/gui/graphics/contexts/juce_Graphics.cpp b/src/gui/graphics/contexts/juce_Graphics.cpp index 013d74d737..3df8df459e 100644 --- a/src/gui/graphics/contexts/juce_Graphics.cpp +++ b/src/gui/graphics/contexts/juce_Graphics.cpp @@ -195,11 +195,6 @@ void Graphics::setColour (const Colour& newColour) throw() deleteAndZero (state->brush); } -const Colour& Graphics::getCurrentColour() const throw() -{ - return state->colour; -} - void Graphics::setOpacity (const float newOpacity) throw() { saveStateIfPending(); @@ -252,11 +247,6 @@ void Graphics::setFont (const float newFontHeight, state->font.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0.0f); } -const Font& Graphics::getCurrentFont() const throw() -{ - return state->font; -} - //============================================================================== void Graphics::drawSingleLineText (const String& text, const int startX, @@ -891,11 +881,16 @@ void Graphics::drawImage (const Image* const imageToDraw, } else { - context->blendImageRescaling (*imageToDraw, - dx, dy, dw, dh, - sx, sy, sw, sh, - state->colour.getFloatAlpha(), - state->quality); + context->blendImageWarping (*imageToDraw, + sx, sy, sw, sh, + AffineTransform::translation ((float) -sx, + (float) -sy) + .scaled (dw / (float) sw, + dh / (float) sh) + .translated ((float) dx, + (float) dy), + state->colour.getFloatAlpha(), + state->quality); } } } diff --git a/src/gui/graphics/contexts/juce_Graphics.h b/src/gui/graphics/contexts/juce_Graphics.h index 5e45fcb14a..71cee84825 100644 --- a/src/gui/graphics/contexts/juce_Graphics.h +++ b/src/gui/graphics/contexts/juce_Graphics.h @@ -78,23 +78,14 @@ public: If a brush is being used when this method is called, the brush will be deselected, and any subsequent drawing will be done with a solid colour brush instead. - @see setOpacity, setBrush, getColour + @see setOpacity, setBrush */ void setColour (const Colour& newColour) throw(); - /** Returns the colour that's currently being used. - - This will return the last colour set by setColour(), even if the colour's not - currently being used for drawing because a brush has been selected instead. - - @see setColour - */ - const Colour& getCurrentColour() const throw(); - /** Changes the opacity to use with the current colour. - If a solid colour is being used for drawing, this changes its opacity (and this - will be reflected by calls to the getColour() method). + If a solid colour is being used for drawing, this changes its opacity + to this new value (i.e. it doesn't multiply the colour's opacity by this amount). A value of 0.0 is completely transparent, 1.0 is completely opaque. */ @@ -132,12 +123,6 @@ public: void setFont (const float newFontHeight, const int fontStyleFlags = Font::plain) throw(); - /** Returns the font that's currently being used for text operations. - - @see setFont - */ - const Font& getCurrentFont() const throw(); - /** Draws a one-line text string. This will use the current colour (or brush) to fill the text. The font is the last diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h b/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h index 8589ac0167..3a4f801862 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsContext.h @@ -102,11 +102,6 @@ public: int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha) = 0; - virtual void blendImageRescaling (const Image& sourceImage, - int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality) = 0; - virtual void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp index 46ccae7ae3..5b6cbae3bb 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp @@ -449,39 +449,6 @@ void LowLevelGraphicsPostScriptRenderer::fillAlphaChannelWithImage (const Image& notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file } - -//============================================================================== -void LowLevelGraphicsPostScriptRenderer::blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, - const Graphics::ResamplingQuality quality) -{ - if (sw > 0 && sh > 0) - { - jassert (sx >= 0 && sx + sw <= sourceImage.getWidth()); - jassert (sy >= 0 && sy + sh <= sourceImage.getHeight()); - - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::scale (dw / (float) sw, - dh / (float) sh) - .translated ((float) (dx - sx), - (float) (dy - sy)), - alpha, - quality); - } - } -} - //============================================================================== void LowLevelGraphicsPostScriptRenderer::blendImage (const Image& sourceImage, int dx, int dy, int dw, int dh, int sx, int sy, float opacity) { diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h index 006876ae13..2f39a75270 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h @@ -79,10 +79,6 @@ public: void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha); - void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality); - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, float alpha, const Graphics::ResamplingQuality quality); diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index 869a9f5826..4836eff73b 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -1757,37 +1757,6 @@ void LowLevelGraphicsSoftwareRenderer::clippedBlendImage (int clipX, int clipY, sourceImage.releasePixelDataReadOnly (srcPixels); } -//============================================================================== -void LowLevelGraphicsSoftwareRenderer::blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, - const Graphics::ResamplingQuality quality) -{ - if (sw > 0 && sh > 0) - { - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::translation ((float) -sx, - (float) -sy) - .scaled (dw / (float) sw, - dh / (float) sh) - .translated ((float) dx, - (float) dy), - alpha, - quality); - } - } -} - //============================================================================== void LowLevelGraphicsSoftwareRenderer::blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h index 6b700a33e5..1881a97595 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h @@ -78,10 +78,6 @@ public: void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH, int sourceX, int sourceY, float alpha); - void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH, - int sourceX, int sourceY, int sourceW, int sourceH, - float alpha, const Graphics::ResamplingQuality quality); - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, float alpha, const Graphics::ResamplingQuality quality); diff --git a/src/gui/graphics/drawables/juce_Drawable.cpp b/src/gui/graphics/drawables/juce_Drawable.cpp index 4c2c6bfcfa..c95d838351 100644 --- a/src/gui/graphics/drawables/juce_Drawable.cpp +++ b/src/gui/graphics/drawables/juce_Drawable.cpp @@ -53,16 +53,15 @@ Drawable::~Drawable() { } -void Drawable::draw (Graphics& g, +void Drawable::draw (Graphics& g, const float opacity, const AffineTransform& transform) const { - const RenderingContext context (g, transform, g.getCurrentColour().getFloatAlpha()); - render (context); + render (RenderingContext (g, transform, opacity)); } -void Drawable::drawAt (Graphics& g, const float x, const float y) const +void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const { - draw (g, AffineTransform::translation (x, y)); + draw (g, opacity, AffineTransform::translation (x, y)); } void Drawable::drawWithin (Graphics& g, @@ -70,16 +69,18 @@ void Drawable::drawWithin (Graphics& g, const int destY, const int destW, const int destH, - const RectanglePlacement& placement) const + const RectanglePlacement& placement, + const float opacity) const { if (destW > 0 && destH > 0) { float x, y, w, h; getBounds (x, y, w, h); - draw (g, placement.getTransformToFit (x, y, w, h, - (float) destX, (float) destY, - (float) destW, (float) destH)); + draw (g, opacity, + placement.getTransformToFit (x, y, w, h, + (float) destX, (float) destY, + (float) destW, (float) destH)); } } diff --git a/src/gui/graphics/drawables/juce_Drawable.h b/src/gui/graphics/drawables/juce_Drawable.h index 93f526980f..27bfe9964d 100644 --- a/src/gui/graphics/drawables/juce_Drawable.h +++ b/src/gui/graphics/drawables/juce_Drawable.h @@ -61,7 +61,7 @@ public: /** Renders this Drawable object. @see drawWithin */ - void draw (Graphics& g, + void draw (Graphics& g, const float opacity, const AffineTransform& transform = AffineTransform::identity) const; /** Renders the Drawable at a given offset within the Graphics context. @@ -75,7 +75,8 @@ public: */ void drawAt (Graphics& g, const float x, - const float y) const; + const float y, + const float opacity) const; /** Renders the Drawable within a rectangle, scaling it to fit neatly inside without changing its aspect-ratio. @@ -90,13 +91,15 @@ public: @param destHeight size of the target rectangle to fit the image into @param placement defines the alignment and rescaling to use to fit this object within the target rectangle. + @param opacity the opacity to use, in the range 0 to 1.0 */ void drawWithin (Graphics& g, const int destX, const int destY, const int destWidth, const int destHeight, - const RectanglePlacement& placement) const; + const RectanglePlacement& placement, + const float opacity) const; //============================================================================== diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 83cc83c5fe..b454a4aebc 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -240,35 +240,6 @@ public: CGImageRelease (image); } - void blendImageRescaling (const Image& sourceImage, - int dx, int dy, int dw, int dh, - int sx, int sy, int sw, int sh, - float alpha, const Graphics::ResamplingQuality quality) - { - if (sw > 0 && sh > 0) - { - if (sw == dw && sh == dh) - { - blendImage (sourceImage, - dx, dy, dw, dh, - sx, sy, alpha); - } - else - { - blendImageWarping (sourceImage, - sx, sy, sw, sh, - AffineTransform::translation ((float) -sx, - (float) -sy) - .scaled (dw / (float) sw, - dh / (float) sh) - .translated ((float) dx, - (float) dy), - alpha, - quality); - } - } - } - void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH, const AffineTransform& transform, diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 4d67db2399..e8fc381162 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -1436,8 +1436,12 @@ void NSViewComponentPeer::drawRect (NSRect r) return; #if USE_COREGRAPHICS_RENDERING - CoreGraphicsContext context ((CGContextRef) [[NSGraphicsContext currentContext] graphicsPort], - [view frame].size.height); + CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; + + if (! component->isOpaque()) + CGContextClearRect (cg, CGContextGetClipBoundingBox (cg)); + + CoreGraphicsContext context (cg, [view frame].size.height); handlePaint (context); #else const float y = [view frame].size.height - (r.origin.y + r.size.height);