mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
First check-in of the "jucequake": a major re-organisation of the library to break it up into modules. For more details about this, see the website forum..
This commit is contained in:
parent
1a21c89755
commit
b70e0a28d2
1527 changed files with 90380 additions and 396643 deletions
51
modules/juce_graphics/placement/juce_Justification.cpp
Normal file
51
modules/juce_graphics/placement/juce_Justification.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
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.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
//==============================================================================
|
||||
Justification::Justification (const Justification& other) noexcept
|
||||
: flags (other.flags)
|
||||
{
|
||||
}
|
||||
|
||||
Justification& Justification::operator= (const Justification& other) noexcept
|
||||
{
|
||||
flags = other.flags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Justification::getOnlyVerticalFlags() const noexcept
|
||||
{
|
||||
return flags & (top | bottom | verticallyCentred);
|
||||
}
|
||||
|
||||
int Justification::getOnlyHorizontalFlags() const noexcept
|
||||
{
|
||||
return flags & (left | right | horizontallyCentred | horizontallyJustified);
|
||||
}
|
||||
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
189
modules/juce_graphics/placement/juce_Justification.h
Normal file
189
modules/juce_graphics/placement/juce_Justification.h
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
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.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __JUCE_JUSTIFICATION_JUCEHEADER__
|
||||
#define __JUCE_JUSTIFICATION_JUCEHEADER__
|
||||
|
||||
#include "../geometry/juce_Rectangle.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Represents a type of justification to be used when positioning graphical items.
|
||||
|
||||
e.g. it indicates whether something should be placed top-left, top-right,
|
||||
centred, etc.
|
||||
|
||||
It is used in various places wherever this kind of information is needed.
|
||||
*/
|
||||
class JUCE_API Justification
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Creates a Justification object using a combination of flags. */
|
||||
inline Justification (int flags_) noexcept : flags (flags_) {}
|
||||
|
||||
/** Creates a copy of another Justification object. */
|
||||
Justification (const Justification& other) noexcept;
|
||||
|
||||
/** Copies another Justification object. */
|
||||
Justification& operator= (const Justification& other) noexcept;
|
||||
|
||||
bool operator== (const Justification& other) const noexcept { return flags == other.flags; }
|
||||
bool operator!= (const Justification& other) const noexcept { return flags != other.flags; }
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the raw flags that are set for this Justification object. */
|
||||
inline int getFlags() const noexcept { return flags; }
|
||||
|
||||
/** Tests a set of flags for this object.
|
||||
|
||||
@returns true if any of the flags passed in are set on this object.
|
||||
*/
|
||||
inline bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
|
||||
|
||||
/** Returns just the flags from this object that deal with vertical layout. */
|
||||
int getOnlyVerticalFlags() const noexcept;
|
||||
|
||||
/** Returns just the flags from this object that deal with horizontal layout. */
|
||||
int getOnlyHorizontalFlags() const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Adjusts the position of a rectangle to fit it into a space.
|
||||
|
||||
The (x, y) position of the rectangle will be updated to position it inside the
|
||||
given space according to the justification flags.
|
||||
*/
|
||||
template <typename ValueType>
|
||||
void applyToRectangle (ValueType& x, ValueType& y, ValueType w, ValueType h,
|
||||
ValueType spaceX, ValueType spaceY, ValueType spaceW, ValueType spaceH) const noexcept
|
||||
{
|
||||
x = spaceX;
|
||||
if ((flags & horizontallyCentred) != 0) x += (spaceW - w) / (ValueType) 2;
|
||||
else if ((flags & right) != 0) x += spaceW - w;
|
||||
|
||||
y = spaceY;
|
||||
if ((flags & verticallyCentred) != 0) y += (spaceH - h) / (ValueType) 2;
|
||||
else if ((flags & bottom) != 0) y += spaceH - h;
|
||||
}
|
||||
|
||||
/** Returns the new position of a rectangle that has been justified to fit within a given space.
|
||||
*/
|
||||
template <typename ValueType>
|
||||
const Rectangle<ValueType> appliedToRectangle (const Rectangle<ValueType>& areaToAdjust,
|
||||
const Rectangle<ValueType>& targetSpace) const noexcept
|
||||
{
|
||||
ValueType x = areaToAdjust.getX(), y = areaToAdjust.getY();
|
||||
applyToRectangle (x, y, areaToAdjust.getWidth(), areaToAdjust.getHeight(),
|
||||
targetSpace.getX(), targetSpace.getY(), targetSpace.getWidth(), targetSpace.getHeight());
|
||||
return areaToAdjust.withPosition (x, y);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Flag values that can be combined and used in the constructor. */
|
||||
enum
|
||||
{
|
||||
//==============================================================================
|
||||
/** Indicates that the item should be aligned against the left edge of the available space. */
|
||||
left = 1,
|
||||
|
||||
/** Indicates that the item should be aligned against the right edge of the available space. */
|
||||
right = 2,
|
||||
|
||||
/** Indicates that the item should be placed in the centre between the left and right
|
||||
sides of the available space. */
|
||||
horizontallyCentred = 4,
|
||||
|
||||
//==============================================================================
|
||||
/** Indicates that the item should be aligned against the top edge of the available space. */
|
||||
top = 8,
|
||||
|
||||
/** Indicates that the item should be aligned against the bottom edge of the available space. */
|
||||
bottom = 16,
|
||||
|
||||
/** Indicates that the item should be placed in the centre between the top and bottom
|
||||
sides of the available space. */
|
||||
verticallyCentred = 32,
|
||||
|
||||
//==============================================================================
|
||||
/** Indicates that lines of text should be spread out to fill the maximum width
|
||||
available, so that both margins are aligned vertically.
|
||||
*/
|
||||
horizontallyJustified = 64,
|
||||
|
||||
//==============================================================================
|
||||
/** Indicates that the item should be centred vertically and horizontally.
|
||||
This is equivalent to (horizontallyCentred | verticallyCentred)
|
||||
*/
|
||||
centred = 36,
|
||||
|
||||
/** Indicates that the item should be centred vertically but placed on the left hand side.
|
||||
This is equivalent to (left | verticallyCentred)
|
||||
*/
|
||||
centredLeft = 33,
|
||||
|
||||
/** Indicates that the item should be centred vertically but placed on the right hand side.
|
||||
This is equivalent to (right | verticallyCentred)
|
||||
*/
|
||||
centredRight = 34,
|
||||
|
||||
/** Indicates that the item should be centred horizontally and placed at the top.
|
||||
This is equivalent to (horizontallyCentred | top)
|
||||
*/
|
||||
centredTop = 12,
|
||||
|
||||
/** Indicates that the item should be centred horizontally and placed at the bottom.
|
||||
This is equivalent to (horizontallyCentred | bottom)
|
||||
*/
|
||||
centredBottom = 20,
|
||||
|
||||
/** Indicates that the item should be placed in the top-left corner.
|
||||
This is equivalent to (left | top)
|
||||
*/
|
||||
topLeft = 9,
|
||||
|
||||
/** Indicates that the item should be placed in the top-right corner.
|
||||
This is equivalent to (right | top)
|
||||
*/
|
||||
topRight = 10,
|
||||
|
||||
/** Indicates that the item should be placed in the bottom-left corner.
|
||||
This is equivalent to (left | bottom)
|
||||
*/
|
||||
bottomLeft = 17,
|
||||
|
||||
/** Indicates that the item should be placed in the bottom-left corner.
|
||||
This is equivalent to (right | bottom)
|
||||
*/
|
||||
bottomRight = 18
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
int flags;
|
||||
};
|
||||
|
||||
#endif // __JUCE_JUSTIFICATION_JUCEHEADER__
|
||||
134
modules/juce_graphics/placement/juce_RectanglePlacement.cpp
Normal file
134
modules/juce_graphics/placement/juce_RectanglePlacement.cpp
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
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.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
//==============================================================================
|
||||
RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) noexcept
|
||||
: flags (other.flags)
|
||||
{
|
||||
}
|
||||
|
||||
RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) noexcept
|
||||
{
|
||||
flags = other.flags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool RectanglePlacement::operator== (const RectanglePlacement& other) const noexcept
|
||||
{
|
||||
return flags == other.flags;
|
||||
}
|
||||
|
||||
bool RectanglePlacement::operator!= (const RectanglePlacement& other) const noexcept
|
||||
{
|
||||
return flags != other.flags;
|
||||
}
|
||||
|
||||
void RectanglePlacement::applyTo (double& x, double& y, double& w, double& h,
|
||||
const double dx, const double dy, const double dw, const double dh) const noexcept
|
||||
{
|
||||
if (w == 0 || h == 0)
|
||||
return;
|
||||
|
||||
if ((flags & stretchToFit) != 0)
|
||||
{
|
||||
x = dx;
|
||||
y = dy;
|
||||
w = dw;
|
||||
h = dh;
|
||||
}
|
||||
else
|
||||
{
|
||||
double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
|
||||
: jmin (dw / w, dh / h);
|
||||
|
||||
if ((flags & onlyReduceInSize) != 0)
|
||||
scale = jmin (scale, 1.0);
|
||||
|
||||
if ((flags & onlyIncreaseInSize) != 0)
|
||||
scale = jmax (scale, 1.0);
|
||||
|
||||
w *= scale;
|
||||
h *= scale;
|
||||
|
||||
if ((flags & xLeft) != 0)
|
||||
x = dx;
|
||||
else if ((flags & xRight) != 0)
|
||||
x = dx + dw - w;
|
||||
else
|
||||
x = dx + (dw - w) * 0.5;
|
||||
|
||||
if ((flags & yTop) != 0)
|
||||
y = dy;
|
||||
else if ((flags & yBottom) != 0)
|
||||
y = dy + dh - h;
|
||||
else
|
||||
y = dy + (dh - h) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
const AffineTransform RectanglePlacement::getTransformToFit (const Rectangle<float>& source, const Rectangle<float>& destination) const noexcept
|
||||
{
|
||||
if (source.isEmpty())
|
||||
return AffineTransform::identity;
|
||||
|
||||
float newX = destination.getX();
|
||||
float newY = destination.getY();
|
||||
|
||||
float scaleX = destination.getWidth() / source.getWidth();
|
||||
float scaleY = destination.getHeight() / source.getHeight();
|
||||
|
||||
if ((flags & stretchToFit) == 0)
|
||||
{
|
||||
scaleX = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
|
||||
: jmin (scaleX, scaleY);
|
||||
|
||||
if ((flags & onlyReduceInSize) != 0)
|
||||
scaleX = jmin (scaleX, 1.0f);
|
||||
|
||||
if ((flags & onlyIncreaseInSize) != 0)
|
||||
scaleX = jmax (scaleX, 1.0f);
|
||||
|
||||
scaleY = scaleX;
|
||||
|
||||
if ((flags & xRight) != 0)
|
||||
newX += destination.getWidth() - source.getWidth() * scaleX; // right
|
||||
else if ((flags & xLeft) == 0)
|
||||
newX += (destination.getWidth() - source.getWidth() * scaleX) / 2.0f; // centre
|
||||
|
||||
if ((flags & yBottom) != 0)
|
||||
newY += destination.getHeight() - source.getHeight() * scaleX; // bottom
|
||||
else if ((flags & yTop) == 0)
|
||||
newY += (destination.getHeight() - source.getHeight() * scaleX) / 2.0f; // centre
|
||||
}
|
||||
|
||||
return AffineTransform::translation (-source.getX(), -source.getY())
|
||||
.scaled (scaleX, scaleY)
|
||||
.translated (newX, newY);
|
||||
}
|
||||
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
173
modules/juce_graphics/placement/juce_RectanglePlacement.h
Normal file
173
modules/juce_graphics/placement/juce_RectanglePlacement.h
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
==============================================================================
|
||||
|
||||
This file is part of the JUCE library - "Jules' Utility Class Extensions"
|
||||
Copyright 2004-11 by Raw Material Software Ltd.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
JUCE can be redistributed and/or modified under the terms of the GNU General
|
||||
Public License (Version 2), as published by the Free Software Foundation.
|
||||
A copy of the license is included in the JUCE distribution, or can be found
|
||||
online at www.gnu.org/licenses.
|
||||
|
||||
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.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
To release a closed-source product which uses JUCE, commercial licenses are
|
||||
available: visit www.rawmaterialsoftware.com/juce for more information.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#ifndef __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
|
||||
#define __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
|
||||
|
||||
#include "../geometry/juce_AffineTransform.h"
|
||||
#include "../geometry/juce_Rectangle.h"
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
Defines the method used to postion some kind of rectangular object within
|
||||
a rectangular viewport.
|
||||
|
||||
Although similar to Justification, this is more specific, and has some extra
|
||||
options.
|
||||
*/
|
||||
class JUCE_API RectanglePlacement
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Creates a RectanglePlacement object using a combination of flags. */
|
||||
inline RectanglePlacement (int flags_) noexcept : flags (flags_) {}
|
||||
|
||||
/** Creates a copy of another RectanglePlacement object. */
|
||||
RectanglePlacement (const RectanglePlacement& other) noexcept;
|
||||
|
||||
/** Copies another RectanglePlacement object. */
|
||||
RectanglePlacement& operator= (const RectanglePlacement& other) noexcept;
|
||||
|
||||
bool operator== (const RectanglePlacement& other) const noexcept;
|
||||
bool operator!= (const RectanglePlacement& other) const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Flag values that can be combined and used in the constructor. */
|
||||
enum
|
||||
{
|
||||
//==============================================================================
|
||||
/** Indicates that the source rectangle's left edge should be aligned with the left edge of the target rectangle. */
|
||||
xLeft = 1,
|
||||
|
||||
/** Indicates that the source rectangle's right edge should be aligned with the right edge of the target rectangle. */
|
||||
xRight = 2,
|
||||
|
||||
/** Indicates that the source should be placed in the centre between the left and right
|
||||
sides of the available space. */
|
||||
xMid = 4,
|
||||
|
||||
//==============================================================================
|
||||
/** Indicates that the source's top edge should be aligned with the top edge of the
|
||||
destination rectangle. */
|
||||
yTop = 8,
|
||||
|
||||
/** Indicates that the source's bottom edge should be aligned with the bottom edge of the
|
||||
destination rectangle. */
|
||||
yBottom = 16,
|
||||
|
||||
/** Indicates that the source should be placed in the centre between the top and bottom
|
||||
sides of the available space. */
|
||||
yMid = 32,
|
||||
|
||||
//==============================================================================
|
||||
/** If this flag is set, then the source rectangle will be resized to completely fill
|
||||
the destination rectangle, and all other flags are ignored.
|
||||
*/
|
||||
stretchToFit = 64,
|
||||
|
||||
//==============================================================================
|
||||
/** If this flag is set, then the source rectangle will be resized so that it is the
|
||||
minimum size to completely fill the destination rectangle, without changing its
|
||||
aspect ratio. This means that some of the source rectangle may fall outside
|
||||
the destination.
|
||||
|
||||
If this flag is not set, the source will be given the maximum size at which none
|
||||
of it falls outside the destination rectangle.
|
||||
*/
|
||||
fillDestination = 128,
|
||||
|
||||
/** Indicates that the source rectangle can be reduced in size if required, but should
|
||||
never be made larger than its original size.
|
||||
*/
|
||||
onlyReduceInSize = 256,
|
||||
|
||||
/** Indicates that the source rectangle can be enlarged if required, but should
|
||||
never be made smaller than its original size.
|
||||
*/
|
||||
onlyIncreaseInSize = 512,
|
||||
|
||||
/** Indicates that the source rectangle's size should be left unchanged.
|
||||
*/
|
||||
doNotResize = (onlyIncreaseInSize | onlyReduceInSize),
|
||||
|
||||
//==============================================================================
|
||||
/** A shorthand value that is equivalent to (xMid | yMid). */
|
||||
centred = 4 + 32
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the raw flags that are set for this object. */
|
||||
inline int getFlags() const noexcept { return flags; }
|
||||
|
||||
/** Tests a set of flags for this object.
|
||||
|
||||
@returns true if any of the flags passed in are set on this object.
|
||||
*/
|
||||
inline bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** Adjusts the position and size of a rectangle to fit it into a space.
|
||||
|
||||
The source rectangle co-ordinates will be adjusted so that they fit into
|
||||
the destination rectangle based on this object's flags.
|
||||
*/
|
||||
void applyTo (double& sourceX,
|
||||
double& sourceY,
|
||||
double& sourceW,
|
||||
double& sourceH,
|
||||
double destinationX,
|
||||
double destinationY,
|
||||
double destinationW,
|
||||
double destinationH) const noexcept;
|
||||
|
||||
/** Returns the transform that should be applied to these source co-ordinates to fit them
|
||||
into the destination rectangle using the current flags.
|
||||
*/
|
||||
template <typename ValueType>
|
||||
const Rectangle<ValueType> appliedTo (const Rectangle<ValueType>& source,
|
||||
const Rectangle<ValueType>& destination) const noexcept
|
||||
{
|
||||
double x = source.getX(), y = source.getY(), w = source.getWidth(), h = source.getHeight();
|
||||
applyTo (x, y, w, h, static_cast <double> (destination.getX()), static_cast <double> (destination.getY()),
|
||||
static_cast <double> (destination.getWidth()), static_cast <double> (destination.getHeight()));
|
||||
return Rectangle<ValueType> (static_cast <ValueType> (x), static_cast <ValueType> (y),
|
||||
static_cast <ValueType> (w), static_cast <ValueType> (h));
|
||||
}
|
||||
|
||||
/** Returns the transform that should be applied to these source co-ordinates to fit them
|
||||
into the destination rectangle using the current flags.
|
||||
*/
|
||||
const AffineTransform getTransformToFit (const Rectangle<float>& source,
|
||||
const Rectangle<float>& destination) const noexcept;
|
||||
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
int flags;
|
||||
};
|
||||
|
||||
#endif // __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
|
||||
Loading…
Add table
Add a link
Reference in a new issue