1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

whitespace clean-up

This commit is contained in:
jules 2009-02-25 21:10:27 +00:00
parent b7eb1587b5
commit 08d0621c07
22 changed files with 5916 additions and 5911 deletions

View file

@ -1,242 +1,242 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
#include "../../../../juce_core/basics/juce_StandardHeader.h"
BEGIN_JUCE_NAMESPACE
#include "juce_ImageButton.h"
#include "../../graphics/imaging/juce_ImageCache.h"
#include "../lookandfeel/juce_LookAndFeel.h"
//==============================================================================
ImageButton::ImageButton (const String& text)
: Button (text),
scaleImageToFit (true),
preserveProportions (true),
alphaThreshold (0),
imageX (0),
imageY (0),
imageW (0),
imageH (0),
normalImage (0),
overImage (0),
downImage (0)
{
}
ImageButton::~ImageButton()
{
deleteImages();
}
void ImageButton::deleteImages()
{
if (normalImage != 0)
{
if (ImageCache::isImageInCache (normalImage))
ImageCache::release (normalImage);
else
delete normalImage;
}
if (overImage != 0)
{
if (ImageCache::isImageInCache (overImage))
ImageCache::release (overImage);
else
delete overImage;
}
if (downImage != 0)
{
if (ImageCache::isImageInCache (downImage))
ImageCache::release (downImage);
else
delete downImage;
}
}
void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
const bool rescaleImagesWhenButtonSizeChanges,
const bool preserveImageProportions,
Image* const normalImage_,
const float imageOpacityWhenNormal,
const Colour& overlayColourWhenNormal,
Image* const overImage_,
const float imageOpacityWhenOver,
const Colour& overlayColourWhenOver,
Image* const downImage_,
const float imageOpacityWhenDown,
const Colour& overlayColourWhenDown,
const float hitTestAlphaThreshold)
{
deleteImages();
normalImage = normalImage_;
overImage = overImage_;
downImage = downImage_;
if (resizeButtonNowToFitThisImage && normalImage != 0)
{
imageW = normalImage->getWidth();
imageH = normalImage->getHeight();
setSize (imageW, imageH);
}
scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
preserveProportions = preserveImageProportions;
normalOpacity = imageOpacityWhenNormal;
normalOverlay = overlayColourWhenNormal;
overOpacity = imageOpacityWhenOver;
overOverlay = overlayColourWhenOver;
downOpacity = imageOpacityWhenDown;
downOverlay = overlayColourWhenDown;
alphaThreshold = (unsigned char) jlimit (0, 0xff, roundFloatToInt (255.0f * hitTestAlphaThreshold));
repaint();
}
Image* ImageButton::getCurrentImage() const
{
if (isDown() || getToggleState())
return getDownImage();
if (isOver())
return getOverImage();
return getNormalImage();
}
Image* ImageButton::getNormalImage() const throw()
{
return normalImage;
}
Image* ImageButton::getOverImage() const throw()
{
return (overImage != 0) ? overImage
: normalImage;
}
Image* ImageButton::getDownImage() const throw()
{
return (downImage != 0) ? downImage
: getOverImage();
}
void ImageButton::paintButton (Graphics& g,
bool isMouseOverButton,
bool isButtonDown)
{
if (! isEnabled())
{
isMouseOverButton = false;
isButtonDown = false;
}
Image* const im = getCurrentImage();
if (im != 0)
{
const int iw = im->getWidth();
const int ih = im->getHeight();
imageW = getWidth();
imageH = getHeight();
imageX = (imageW - iw) >> 1;
imageY = (imageH - ih) >> 1;
if (scaleImageToFit)
{
if (preserveProportions)
{
int newW, newH;
const float imRatio = ih / (float)iw;
const float destRatio = imageH / (float)imageW;
if (imRatio > destRatio)
{
newW = roundFloatToInt (imageH / imRatio);
newH = imageH;
}
else
{
newW = imageW;
newH = roundFloatToInt (imageW * imRatio);
}
imageX = (imageW - newW) / 2;
imageY = (imageH - newH) / 2;
imageW = newW;
imageH = newH;
}
else
{
imageX = 0;
imageY = 0;
}
}
if (! scaleImageToFit)
{
imageW = iw;
imageH = ih;
}
getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
isButtonDown ? downOverlay
: (isMouseOverButton ? overOverlay
: normalOverlay),
isButtonDown ? downOpacity
: (isMouseOverButton ? overOpacity
: normalOpacity),
*this);
}
}
bool ImageButton::hitTest (int x, int y)
{
if (alphaThreshold == 0)
return true;
Image* const im = getCurrentImage();
return im == 0
|| (imageW > 0 && imageH > 0
&& alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
((y - imageY) * im->getHeight()) / imageH).getAlpha());
}
END_JUCE_NAMESPACE
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
#include "../../../../juce_core/basics/juce_StandardHeader.h"
BEGIN_JUCE_NAMESPACE
#include "juce_ImageButton.h"
#include "../../graphics/imaging/juce_ImageCache.h"
#include "../lookandfeel/juce_LookAndFeel.h"
//==============================================================================
ImageButton::ImageButton (const String& text)
: Button (text),
scaleImageToFit (true),
preserveProportions (true),
alphaThreshold (0),
imageX (0),
imageY (0),
imageW (0),
imageH (0),
normalImage (0),
overImage (0),
downImage (0)
{
}
ImageButton::~ImageButton()
{
deleteImages();
}
void ImageButton::deleteImages()
{
if (normalImage != 0)
{
if (ImageCache::isImageInCache (normalImage))
ImageCache::release (normalImage);
else
delete normalImage;
}
if (overImage != 0)
{
if (ImageCache::isImageInCache (overImage))
ImageCache::release (overImage);
else
delete overImage;
}
if (downImage != 0)
{
if (ImageCache::isImageInCache (downImage))
ImageCache::release (downImage);
else
delete downImage;
}
}
void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
const bool rescaleImagesWhenButtonSizeChanges,
const bool preserveImageProportions,
Image* const normalImage_,
const float imageOpacityWhenNormal,
const Colour& overlayColourWhenNormal,
Image* const overImage_,
const float imageOpacityWhenOver,
const Colour& overlayColourWhenOver,
Image* const downImage_,
const float imageOpacityWhenDown,
const Colour& overlayColourWhenDown,
const float hitTestAlphaThreshold)
{
deleteImages();
normalImage = normalImage_;
overImage = overImage_;
downImage = downImage_;
if (resizeButtonNowToFitThisImage && normalImage != 0)
{
imageW = normalImage->getWidth();
imageH = normalImage->getHeight();
setSize (imageW, imageH);
}
scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
preserveProportions = preserveImageProportions;
normalOpacity = imageOpacityWhenNormal;
normalOverlay = overlayColourWhenNormal;
overOpacity = imageOpacityWhenOver;
overOverlay = overlayColourWhenOver;
downOpacity = imageOpacityWhenDown;
downOverlay = overlayColourWhenDown;
alphaThreshold = (unsigned char) jlimit (0, 0xff, roundFloatToInt (255.0f * hitTestAlphaThreshold));
repaint();
}
Image* ImageButton::getCurrentImage() const
{
if (isDown() || getToggleState())
return getDownImage();
if (isOver())
return getOverImage();
return getNormalImage();
}
Image* ImageButton::getNormalImage() const throw()
{
return normalImage;
}
Image* ImageButton::getOverImage() const throw()
{
return (overImage != 0) ? overImage
: normalImage;
}
Image* ImageButton::getDownImage() const throw()
{
return (downImage != 0) ? downImage
: getOverImage();
}
void ImageButton::paintButton (Graphics& g,
bool isMouseOverButton,
bool isButtonDown)
{
if (! isEnabled())
{
isMouseOverButton = false;
isButtonDown = false;
}
Image* const im = getCurrentImage();
if (im != 0)
{
const int iw = im->getWidth();
const int ih = im->getHeight();
imageW = getWidth();
imageH = getHeight();
imageX = (imageW - iw) >> 1;
imageY = (imageH - ih) >> 1;
if (scaleImageToFit)
{
if (preserveProportions)
{
int newW, newH;
const float imRatio = ih / (float)iw;
const float destRatio = imageH / (float)imageW;
if (imRatio > destRatio)
{
newW = roundFloatToInt (imageH / imRatio);
newH = imageH;
}
else
{
newW = imageW;
newH = roundFloatToInt (imageW * imRatio);
}
imageX = (imageW - newW) / 2;
imageY = (imageH - newH) / 2;
imageW = newW;
imageH = newH;
}
else
{
imageX = 0;
imageY = 0;
}
}
if (! scaleImageToFit)
{
imageW = iw;
imageH = ih;
}
getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
isButtonDown ? downOverlay
: (isMouseOverButton ? overOverlay
: normalOverlay),
isButtonDown ? downOpacity
: (isMouseOverButton ? overOpacity
: normalOpacity),
*this);
}
}
bool ImageButton::hitTest (int x, int y)
{
if (alphaThreshold == 0)
return true;
Image* const im = getCurrentImage();
return im == 0
|| (imageW > 0 && imageH > 0
&& alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
((y - imageY) * im->getHeight()) / imageH).getAlpha());
}
END_JUCE_NAMESPACE

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1158,7 +1158,7 @@ void TreeViewItem::paintRecursively (Graphics& g, int width)
g.saveState();
g.setOrigin (indent, 0);
if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
paintItem (g, itemW, itemHeight);

View file

@ -355,7 +355,7 @@ public:
can draw all the way across to the left margin. Note that the
context will still have its origin in the same place though, so
the coordinates of anything to its left will be negative. It's
mostly useful if you want to draw a wider bar behind the
mostly useful if you want to draw a wider bar behind the
highlighted item.
*/
void setDrawsInLeftMargin (bool canDrawInLeftMargin) throw();

View file

@ -190,7 +190,7 @@ public:
allowed to pop up when the mouse moves onto them. If this is false, it'll try
to hide as much on-screen paraphenalia as possible.
*/
void setKioskModeComponent (Component* componentToUse,
void setKioskModeComponent (Component* componentToUse,
const bool allowMenusAndBars = true);
/** Returns the component that is currently being used in kiosk-mode.

View file

@ -189,9 +189,9 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* const compone
void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
{
setBoundsForComponent (component,
setBoundsForComponent (component,
component->getX(), component->getY(),
component->getWidth(), component->getHeight(),
component->getWidth(), component->getHeight(),
false, false, false, false);
}

View file

@ -172,7 +172,7 @@ public:
const bool isStretchingBottom,
const bool isStretchingRight);
/** Performs a check on the current size of a component, and moves or resizes
/** Performs a check on the current size of a component, and moves or resizes
it if it fails the constraints.
*/
void checkComponentBounds (Component* component);