From 2f5a2ad613f34fd4733048d45272a5af2c983c7e Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 27 Jan 2009 19:07:24 +0000 Subject: [PATCH] Moved ImageButton painting into the LookAndFeel, added a couple of methods to AudioSampleBuffer, and fixed a compile error in VS2003 --- build/win32/vc6/JUCE.dsp | 8 -- juce_amalgamated.cpp | 130 ++++++++++++++---- juce_amalgamated.h | 43 ++++++ .../audio/dsp/juce_AudioSampleBuffer.cpp | 61 ++++++++ .../audio/dsp/juce_AudioSampleBuffer.h | 37 +++++ .../components/buttons/juce_ImageButton.cpp | 34 ++--- .../lookandfeel/juce_LookAndFeel.cpp | 26 ++++ .../components/lookandfeel/juce_LookAndFeel.h | 8 ++ .../image_file_formats/juce_PNGLoader.cpp | 12 +- 9 files changed, 303 insertions(+), 56 deletions(-) diff --git a/build/win32/vc6/JUCE.dsp b/build/win32/vc6/JUCE.dsp index 11f1d17938..0eeacc9012 100644 --- a/build/win32/vc6/JUCE.dsp +++ b/build/win32/vc6/JUCE.dsp @@ -535,14 +535,6 @@ SOURCE=..\..\..\src\juce_appframework\audio\processors\juce_GenericAudioProcesso # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\..\src\juce_appframework\audio\plugins\formats\juce_AudioUnitPluginFormat.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\juce_appframework\audio\plugins\formats\juce_AudioUnitPluginFormat.h -# End Source File -# Begin Source File - SOURCE=..\..\..\src\juce_appframework\audio\plugins\formats\juce_DirectXPluginFormat.h # End Source File # Begin Source File diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index f75ef7643c..86a69ab042 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -602,6 +602,7 @@ #import #import #import +#import #include #include @@ -23993,6 +23994,67 @@ void AudioSampleBuffer::copyFrom (const int destChannel, } } +void AudioSampleBuffer::copyFrom (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + const float gain) throw() +{ + jassert (((unsigned int) destChannel) < (unsigned int) numChannels); + jassert (destStartSample >= 0 && destStartSample + numSamples <= size); + jassert (source != 0); + + if (numSamples > 0 && gain != 0) + { + float* d = channels [destChannel] + destStartSample; + + if (gain != 1.0f) + { + while (--numSamples >= 0) + *d++ = gain * *source++; + } + else + { + memcpy (d, source, sizeof (float) * numSamples); + } + } +} + +void AudioSampleBuffer::copyFromWithRamp (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + float startGain, + float endGain) throw() +{ + jassert (((unsigned int) destChannel) < (unsigned int) numChannels); + jassert (destStartSample >= 0 && destStartSample + numSamples <= size); + jassert (source != 0); + + if (startGain == endGain) + { + copyFrom (destChannel, + destStartSample, + source, + numSamples, + startGain); + } + else + { + if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f)) + { + const float increment = (endGain - startGain) / numSamples; + float* d = channels [destChannel] + destStartSample; + + while (--numSamples >= 0) + { + *d++ = startGain * *source++; + startGain += increment; + } + } + } +} + void AudioSampleBuffer::findMinMax (const int channel, const int startSample, int numSamples, @@ -42477,31 +42539,20 @@ void ImageButton::paintButton (Graphics& g, } } - const Colour& overlayColour = (isButtonDown) ? downOverlay - : ((isMouseOverButton) ? overOverlay - : normalOverlay); - - if (! overlayColour.isOpaque()) + if (! scaleImageToFit) { - g.setOpacity ((isButtonDown) ? downOpacity - : ((isMouseOverButton) ? overOpacity - : normalOpacity)); - - if (scaleImageToFit) - g.drawImage (im, imageX, imageY, imageW, imageH, 0, 0, iw, ih, false); - else - g.drawImageAt (im, imageX, imageY, false); + imageW = iw; + imageH = ih; } - if (! overlayColour.isTransparent()) - { - g.setColour (overlayColour); - - if (scaleImageToFit) - g.drawImage (im, imageX, imageY, imageW, imageH, 0, 0, iw, ih, true); - else - g.drawImageAt (im, imageX, imageY, true); - } + getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH, + isButtonDown ? downOverlay + : (isMouseOverButton ? overOverlay + : normalOverlay), + isButtonDown ? downOpacity + : (isMouseOverButton ? overOpacity + : normalOpacity), + *this); } } @@ -61278,6 +61329,29 @@ void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp, filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight()); } +void LookAndFeel::drawImageButton (Graphics& g, Image* image, + int imageX, int imageY, int imageW, int imageH, + const Colour& overlayColour, + float imageOpacity, + ImageButton& button) +{ + if (! overlayColour.isOpaque()) + { + g.setOpacity (imageOpacity); + + g.drawImage (image, imageX, imageY, imageW, imageH, + 0, 0, image->getWidth(), image->getHeight(), false); + } + + if (! overlayColour.isTransparent()) + { + g.setColour (overlayColour); + + g.drawImage (image, imageX, imageY, imageW, imageH, + 0, 0, image->getWidth(), image->getHeight(), true); + } +} + void LookAndFeel::drawCornerResizer (Graphics& g, int w, int h, bool /*isMouseOver*/, @@ -213920,8 +213994,11 @@ namespace pnglibNamespace using namespace zlibNamespace; #if JUCE_INCLUDE_PNGLIB_CODE - using ::malloc; - using ::free; + + #if (! defined(_MSC_VER)) || _MSC_VER != 1310 + using ::malloc; // (causes conflict in VS.NET 2003) + using ::free; + #endif extern "C" { @@ -239320,6 +239397,11 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) BEGIN_JUCE_NAMESPACE using namespace pnglibNamespace; + +#if defined (_MSC_VER) && _MSC_VER == 1310 && ! defined (JUCE_DEBUG) + using ::calloc; // (needed in VS.NET 2003) +#endif + using ::malloc; using ::free; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 8f1acd1c57..bc9def1734 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -26998,6 +26998,42 @@ public: const float* source, int numSamples) throw(); + /** Copies samples from an array of floats into one of the channels, applying a gain to it. + + @param destChannel the channel within this buffer to copy the samples to + @param destStartSample the start sample within this buffer's channel + @param source the source buffer to read from + @param numSamples the number of samples to process + @param gain the gain to apply + + @see addFrom + */ + void copyFrom (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + const float gain) throw(); + + /** Copies samples from an array of floats into one of the channels, applying a gain ramp. + + @param destChannel the channel within this buffer to copy the samples to + @param destStartSample the start sample within this buffer's channel + @param source the source buffer to read from + @param numSamples the number of samples to process + @param startGain the gain to apply to the first sample (this is multiplied with + the source samples before they are copied to this buffer) + @param endGain the gain to apply to the final sample. The gain is linearly + interpolated between the first and last samples. + + @see addFrom + */ + void copyFromWithRamp (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + float startGain, + float endGain) throw(); + /** Finds the highest and lowest sample values in a given range. @param channel the channel to read from @@ -52970,6 +53006,7 @@ class ProgressBar; class FileBrowserComponent; class DirectoryContentsDisplayComponent; class FilePreviewComponent; +class ImageButton; /** LookAndFeel objects define the appearance of all the JUCE widgets, and subclasses @@ -53415,6 +53452,12 @@ public: virtual Button* createTabBarExtrasButton(); + virtual void drawImageButton (Graphics& g, Image* image, + int imageX, int imageY, int imageW, int imageH, + const Colour& overlayColour, + float imageOpacity, + ImageButton& button); + virtual void drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header); virtual void drawTableHeaderColumn (Graphics& g, const String& columnName, int columnId, diff --git a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp index 3ddea55a55..7b42748d90 100644 --- a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp +++ b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp @@ -453,6 +453,67 @@ void AudioSampleBuffer::copyFrom (const int destChannel, } } +void AudioSampleBuffer::copyFrom (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + const float gain) throw() +{ + jassert (((unsigned int) destChannel) < (unsigned int) numChannels); + jassert (destStartSample >= 0 && destStartSample + numSamples <= size); + jassert (source != 0); + + if (numSamples > 0 && gain != 0) + { + float* d = channels [destChannel] + destStartSample; + + if (gain != 1.0f) + { + while (--numSamples >= 0) + *d++ = gain * *source++; + } + else + { + memcpy (d, source, sizeof (float) * numSamples); + } + } +} + +void AudioSampleBuffer::copyFromWithRamp (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + float startGain, + float endGain) throw() +{ + jassert (((unsigned int) destChannel) < (unsigned int) numChannels); + jassert (destStartSample >= 0 && destStartSample + numSamples <= size); + jassert (source != 0); + + if (startGain == endGain) + { + copyFrom (destChannel, + destStartSample, + source, + numSamples, + startGain); + } + else + { + if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f)) + { + const float increment = (endGain - startGain) / numSamples; + float* d = channels [destChannel] + destStartSample; + + while (--numSamples >= 0) + { + *d++ = startGain * *source++; + startGain += increment; + } + } + } +} + void AudioSampleBuffer::findMinMax (const int channel, const int startSample, int numSamples, diff --git a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h index dafd71229f..4340c0bba6 100644 --- a/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h +++ b/src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h @@ -306,6 +306,43 @@ public: const float* source, int numSamples) throw(); + /** Copies samples from an array of floats into one of the channels, applying a gain to it. + + @param destChannel the channel within this buffer to copy the samples to + @param destStartSample the start sample within this buffer's channel + @param source the source buffer to read from + @param numSamples the number of samples to process + @param gain the gain to apply + + @see addFrom + */ + void copyFrom (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + const float gain) throw(); + + /** Copies samples from an array of floats into one of the channels, applying a gain ramp. + + @param destChannel the channel within this buffer to copy the samples to + @param destStartSample the start sample within this buffer's channel + @param source the source buffer to read from + @param numSamples the number of samples to process + @param startGain the gain to apply to the first sample (this is multiplied with + the source samples before they are copied to this buffer) + @param endGain the gain to apply to the final sample. The gain is linearly + interpolated between the first and last samples. + + @see addFrom + */ + void copyFromWithRamp (const int destChannel, + const int destStartSample, + const float* source, + int numSamples, + float startGain, + float endGain) throw(); + + /** Finds the highest and lowest sample values in a given range. @param channel the channel to read from diff --git a/src/juce_appframework/gui/components/buttons/juce_ImageButton.cpp b/src/juce_appframework/gui/components/buttons/juce_ImageButton.cpp index b8a13e981e..78fd389b3e 100644 --- a/src/juce_appframework/gui/components/buttons/juce_ImageButton.cpp +++ b/src/juce_appframework/gui/components/buttons/juce_ImageButton.cpp @@ -35,6 +35,7 @@ BEGIN_JUCE_NAMESPACE #include "juce_ImageButton.h" #include "../../graphics/imaging/juce_ImageCache.h" +#include "../lookandfeel/juce_LookAndFeel.h" //============================================================================== @@ -208,31 +209,20 @@ void ImageButton::paintButton (Graphics& g, } } - const Colour& overlayColour = (isButtonDown) ? downOverlay - : ((isMouseOverButton) ? overOverlay - : normalOverlay); - - if (! overlayColour.isOpaque()) + if (! scaleImageToFit) { - g.setOpacity ((isButtonDown) ? downOpacity - : ((isMouseOverButton) ? overOpacity - : normalOpacity)); - - if (scaleImageToFit) - g.drawImage (im, imageX, imageY, imageW, imageH, 0, 0, iw, ih, false); - else - g.drawImageAt (im, imageX, imageY, false); + imageW = iw; + imageH = ih; } - if (! overlayColour.isTransparent()) - { - g.setColour (overlayColour); - - if (scaleImageToFit) - g.drawImage (im, imageX, imageY, imageW, imageH, 0, 0, iw, ih, true); - else - g.drawImageAt (im, imageX, imageY, true); - } + getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH, + isButtonDown ? downOverlay + : (isMouseOverButton ? overOverlay + : normalOverlay), + isButtonDown ? downOpacity + : (isMouseOverButton ? overOpacity + : normalOpacity), + *this); } } diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp index 0873e16fb5..df79c0f782 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -38,6 +38,7 @@ BEGIN_JUCE_NAMESPACE #include "../buttons/juce_ToggleButton.h" #include "../buttons/juce_ShapeButton.h" #include "../buttons/juce_ArrowButton.h" +#include "../buttons/juce_ImageButton.h" #include "../buttons/juce_DrawableButton.h" #include "../buttons/juce_HyperlinkButton.h" #include "../windows/juce_AlertWindow.h" @@ -1619,6 +1620,31 @@ void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp, filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight()); } + +//============================================================================== +void LookAndFeel::drawImageButton (Graphics& g, Image* image, + int imageX, int imageY, int imageW, int imageH, + const Colour& overlayColour, + float imageOpacity, + ImageButton& button) +{ + if (! overlayColour.isOpaque()) + { + g.setOpacity (imageOpacity); + + g.drawImage (image, imageX, imageY, imageW, imageH, + 0, 0, image->getWidth(), image->getHeight(), false); + } + + if (! overlayColour.isTransparent()) + { + g.setColour (overlayColour); + + g.drawImage (image, imageX, imageY, imageW, imageH, + 0, 0, image->getWidth(), image->getHeight(), true); + } +} + //============================================================================== void LookAndFeel::drawCornerResizer (Graphics& g, int w, int h, diff --git a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h index e831607898..8f74eb85af 100644 --- a/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/juce_appframework/gui/components/lookandfeel/juce_LookAndFeel.h @@ -61,6 +61,7 @@ class ProgressBar; class FileBrowserComponent; class DirectoryContentsDisplayComponent; class FilePreviewComponent; +class ImageButton; //============================================================================== @@ -534,6 +535,13 @@ public: virtual Button* createTabBarExtrasButton(); + //============================================================================== + virtual void drawImageButton (Graphics& g, Image* image, + int imageX, int imageY, int imageW, int imageH, + const Colour& overlayColour, + float imageOpacity, + ImageButton& button); + //============================================================================== virtual void drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header); diff --git a/src/juce_appframework/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp b/src/juce_appframework/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp index 5ebeb58e96..c9df33e4ef 100644 --- a/src/juce_appframework/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp +++ b/src/juce_appframework/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp @@ -53,8 +53,11 @@ namespace pnglibNamespace using namespace zlibNamespace; #if JUCE_INCLUDE_PNGLIB_CODE - using ::malloc; - using ::free; + + #if (! defined(_MSC_VER)) || _MSC_VER != 1310 + using ::malloc; // (causes conflict in VS.NET 2003) + using ::free; + #endif extern "C" { @@ -105,6 +108,11 @@ BEGIN_JUCE_NAMESPACE #include "../../colour/juce_PixelFormats.h" using namespace pnglibNamespace; + +#if defined (_MSC_VER) && _MSC_VER == 1310 && ! defined (JUCE_DEBUG) + using ::calloc; // (needed in VS.NET 2003) +#endif + using ::malloc; using ::free;