From af9c71be388ec42d9ea07172424f23a2f92a8dd6 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 7 Aug 2012 20:26:52 +0100 Subject: [PATCH] Added Image::Bitmap::getBounds method. --- .../Source/Utility/jucer_JucerTreeViewBase.h | 15 ++++++++++----- modules/juce_graphics/images/juce_Image.h | 14 +++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h b/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h index 5a4cf7b661..7b3f631253 100644 --- a/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h +++ b/extras/Introjucer/Source/Utility/jucer_JucerTreeViewBase.h @@ -169,14 +169,19 @@ public: } } + static void drawEmptyPanelMessage (Component& comp, Graphics& g, const String& message) + { + const int fontHeight = 13; + const Rectangle area (comp.getLocalBounds()); + g.setColour (comp.findColour (mainBackgroundColourId).contrasting (0.7f)); + g.setFont ((float) fontHeight); + g.drawFittedText (message, area.reduced (4, 2), Justification::centred, area.getHeight() / fontHeight); + } + void paint (Graphics& g) { if (emptyTreeMessage.isNotEmpty() && (rootItem == nullptr || rootItem->getNumSubItems() == 0)) - { - g.setColour (findColour (mainBackgroundColourId).contrasting (0.7f)); - g.setFont (13.0f); - g.drawFittedText (emptyTreeMessage, getLocalBounds().reduced (4, 2), Justification::centred, 50); - } + drawEmptyPanelMessage (*this, g, emptyTreeMessage); } void resized() diff --git a/modules/juce_graphics/images/juce_Image.h b/modules/juce_graphics/images/juce_Image.h index daf378ce5b..eb97414a25 100644 --- a/modules/juce_graphics/images/juce_Image.h +++ b/modules/juce_graphics/images/juce_Image.h @@ -346,9 +346,14 @@ public: */ void setPixelColour (int x, int y, const Colour& colour) const noexcept; - uint8* data; - PixelFormat pixelFormat; - int lineStride, pixelStride, width, height; + /** Returns the size of the bitmap. */ + Rectangle getBounds() const noexcept { return Rectangle (width, height); } + + uint8* data; /**< The raw pixel data, packed according to the image's pixel format. */ + PixelFormat pixelFormat; /**< The format of the data. */ + int lineStride; /**< The number of bytes between each line. */ + int pixelStride; /**< The number of bytes between each pixel. */ + int width, height; //============================================================================== /** Used internally by custom image types to manage pixel data lifetime. */ @@ -379,8 +384,7 @@ public: @param alphaThreshold for a semi-transparent image, any pixels whose alpha is above this level will be considered opaque */ - void createSolidAreaMask (RectangleList& result, - float alphaThreshold = 0.5f) const; + void createSolidAreaMask (RectangleList& result, float alphaThreshold) const; //============================================================================== /** Returns a NamedValueSet that is attached to the image and which can be used for