diff --git a/modules/juce_core/memory/juce_ContainerDeletePolicy.h b/modules/juce_core/memory/juce_ContainerDeletePolicy.h index 7a3c44fd75..94a352c665 100644 --- a/modules/juce_core/memory/juce_ContainerDeletePolicy.h +++ b/modules/juce_core/memory/juce_ContainerDeletePolicy.h @@ -54,7 +54,7 @@ struct ContainerDeletePolicy // of the class owning it) into cpp files where they can see to the definition // of ObjectType. This should fix the error. ignoreUnused (sizeof (ObjectType)); - + delete object; } }; diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 49f2d30079..0726414491 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -52,21 +52,21 @@ public: } /** Creates a rectangle with a given position and size. */ - Rectangle (const ValueType initialX, const ValueType initialY, - const ValueType width, const ValueType height) noexcept + Rectangle (ValueType initialX, ValueType initialY, + ValueType width, ValueType height) noexcept : pos (initialX, initialY), w (width), h (height) { } /** Creates a rectangle with a given size, and a position of (0, 0). */ - Rectangle (const ValueType width, const ValueType height) noexcept + Rectangle (ValueType width, ValueType height) noexcept : w (width), h (height) { } /** Creates a Rectangle from the positions of two opposite corners. */ - Rectangle (const Point corner1, const Point corner2) noexcept + Rectangle (Point corner1, Point corner2) noexcept : pos (jmin (corner1.x, corner2.x), jmin (corner1.y, corner2.y)), w (corner1.x - corner2.x), @@ -80,8 +80,8 @@ public: The right and bottom values must be larger than the left and top ones, or the resulting rectangle will have a negative size. */ - static Rectangle leftTopRightBottom (const ValueType left, const ValueType top, - const ValueType right, const ValueType bottom) noexcept + static Rectangle leftTopRightBottom (ValueType left, ValueType top, + ValueType right, ValueType bottom) noexcept { return Rectangle (left, top, right - left, bottom - top); } @@ -134,17 +134,17 @@ public: /** Returns the aspect ratio of the rectangle's width / height. If widthOverHeight is true, it returns width / height; if widthOverHeight is false, it returns height / width. */ - ValueType getAspectRatio (const bool widthOverHeight = true) const noexcept { return widthOverHeight ? w / h : h / w; } + ValueType getAspectRatio (bool widthOverHeight = true) const noexcept { return widthOverHeight ? w / h : h / w; } //============================================================================== /** Returns the rectangle's top-left position as a Point. */ inline Point getPosition() const noexcept { return pos; } /** Changes the position of the rectangle's top-left corner (leaving its size unchanged). */ - inline void setPosition (const Point newPos) noexcept { pos = newPos; } + inline void setPosition (Point newPos) noexcept { pos = newPos; } /** Changes the position of the rectangle's top-left corner (leaving its size unchanged). */ - inline void setPosition (const ValueType newX, const ValueType newY) noexcept { pos.setXY (newX, newY); } + inline void setPosition (ValueType newX, ValueType newY) noexcept { pos.setXY (newX, newY); } /** Returns the rectangle's top-left position as a Point. */ Point getTopLeft() const noexcept { return pos; } @@ -158,62 +158,75 @@ public: /** Returns the rectangle's bottom-right position as a Point. */ Point getBottomRight() const noexcept { return Point (pos.x + w, pos.y + h); } + /** Returns the rectangle's left and right positions as a Range. */ + Range getHorizontalRange() const noexcept { return Range::withStartAndLength (pos.x, w); } + + /** Returns the rectangle's top and bottom positions as a Range. */ + Range getVerticalRange() const noexcept { return Range::withStartAndLength (pos.y, h); } + /** Changes the rectangle's size, leaving the position of its top-left corner unchanged. */ - void setSize (const ValueType newWidth, const ValueType newHeight) noexcept { w = newWidth; h = newHeight; } + void setSize (ValueType newWidth, ValueType newHeight) noexcept { w = newWidth; h = newHeight; } /** Changes all the rectangle's coordinates. */ - void setBounds (const ValueType newX, const ValueType newY, - const ValueType newWidth, const ValueType newHeight) noexcept { pos.x = newX; pos.y = newY; w = newWidth; h = newHeight; } + void setBounds (ValueType newX, ValueType newY, + ValueType newWidth, ValueType newHeight) noexcept { pos.x = newX; pos.y = newY; w = newWidth; h = newHeight; } /** Changes the rectangle's X coordinate */ - inline void setX (const ValueType newX) noexcept { pos.x = newX; } + inline void setX (ValueType newX) noexcept { pos.x = newX; } /** Changes the rectangle's Y coordinate */ - inline void setY (const ValueType newY) noexcept { pos.y = newY; } + inline void setY (ValueType newY) noexcept { pos.y = newY; } /** Changes the rectangle's width */ - inline void setWidth (const ValueType newWidth) noexcept { w = newWidth; } + inline void setWidth (ValueType newWidth) noexcept { w = newWidth; } /** Changes the rectangle's height */ - inline void setHeight (const ValueType newHeight) noexcept { h = newHeight; } + inline void setHeight (ValueType newHeight) noexcept { h = newHeight; } /** Changes the position of the rectangle's centre (leaving its size unchanged). */ - inline void setCentre (const ValueType newCentreX, const ValueType newCentreY) noexcept { pos.x = newCentreX - w / (ValueType) 2; pos.y = newCentreY - h / (ValueType) 2; } + inline void setCentre (ValueType newCentreX, ValueType newCentreY) noexcept { pos.x = newCentreX - w / (ValueType) 2; + pos.y = newCentreY - h / (ValueType) 2; } /** Changes the position of the rectangle's centre (leaving its size unchanged). */ - inline void setCentre (const Point newCentre) noexcept { setCentre (newCentre.x, newCentre.y); } + inline void setCentre (Point newCentre) noexcept { setCentre (newCentre.x, newCentre.y); } + + /** Changes the position of the rectangle's left and right edges. */ + void setHorizontalRange (Range range) noexcept { pos.x = range.getStart(); w = range.getLength(); } + + /** Changes the position of the rectangle's top and bottom edges. */ + void setVerticalRange (Range range) noexcept { pos.y = range.getStart(); h = range.getLength(); } /** Returns a rectangle which has the same size and y-position as this one, but with a different x-position. */ - Rectangle withX (const ValueType newX) const noexcept { return Rectangle (newX, pos.y, w, h); } + Rectangle withX (ValueType newX) const noexcept { return Rectangle (newX, pos.y, w, h); } /** Returns a rectangle which has the same size and x-position as this one, but with a different y-position. */ - Rectangle withY (const ValueType newY) const noexcept { return Rectangle (pos.x, newY, w, h); } + Rectangle withY (ValueType newY) const noexcept { return Rectangle (pos.x, newY, w, h); } /** Returns a rectangle with the same size as this one, but a new position. */ - Rectangle withPosition (const ValueType newX, const ValueType newY) const noexcept { return Rectangle (newX, newY, w, h); } + Rectangle withPosition (ValueType newX, ValueType newY) const noexcept { return Rectangle (newX, newY, w, h); } /** Returns a rectangle with the same size as this one, but a new position. */ - Rectangle withPosition (const Point newPos) const noexcept { return Rectangle (newPos.x, newPos.y, w, h); } + Rectangle withPosition (Point newPos) const noexcept { return Rectangle (newPos.x, newPos.y, w, h); } /** Returns a rectangle whose size is the same as this one, but whose top-left position is (0, 0). */ - Rectangle withZeroOrigin() const noexcept { return Rectangle (w, h); } + Rectangle withZeroOrigin() const noexcept { return Rectangle (w, h); } /** Returns a rectangle with the same size as this one, but a new centre position. */ - Rectangle withCentre (const Point newCentre) const noexcept { return Rectangle (newCentre.x - w / (ValueType) 2, - newCentre.y - h / (ValueType) 2, w, h); } + Rectangle withCentre (Point newCentre) const noexcept { return Rectangle (newCentre.x - w / (ValueType) 2, + newCentre.y - h / (ValueType) 2, w, h); } /** Returns a rectangle which has the same position and height as this one, but with a different width. */ - Rectangle withWidth (ValueType newWidth) const noexcept { return Rectangle (pos.x, pos.y, newWidth, h); } + Rectangle withWidth (ValueType newWidth) const noexcept { return Rectangle (pos.x, pos.y, newWidth, h); } /** Returns a rectangle which has the same position and width as this one, but with a different height. */ - Rectangle withHeight (ValueType newHeight) const noexcept { return Rectangle (pos.x, pos.y, w, newHeight); } + Rectangle withHeight (ValueType newHeight) const noexcept { return Rectangle (pos.x, pos.y, w, newHeight); } /** Returns a rectangle with the same top-left position as this one, but a new size. */ - Rectangle withSize (ValueType newWidth, ValueType newHeight) const noexcept { return Rectangle (pos.x, pos.y, newWidth, newHeight); } + Rectangle withSize (ValueType newWidth, ValueType newHeight) const noexcept { return Rectangle (pos.x, pos.y, newWidth, newHeight); } /** Returns a rectangle with the same centre position as this one, but a new size. */ - Rectangle withSizeKeepingCentre (ValueType newWidth, ValueType newHeight) const noexcept { return Rectangle (pos.x + (w - newWidth) / (ValueType) 2, - pos.y + (h - newHeight) / (ValueType) 2, newWidth, newHeight); } + Rectangle withSizeKeepingCentre (ValueType newWidth, ValueType newHeight) const noexcept { return Rectangle (pos.x + (w - newWidth) / (ValueType) 2, + pos.y + (h - newHeight) / (ValueType) 2, newWidth, newHeight); } /** Moves the x position, adjusting the width so that the right-hand edge remains in the same place. If the x is moved to be on the right of the current right-hand edge, the width will be set to zero. @@ -277,41 +290,41 @@ public: //============================================================================== /** Moves the rectangle's position by adding amount to its x and y coordinates. */ - void translate (const ValueType deltaX, - const ValueType deltaY) noexcept + void translate (ValueType deltaX, + ValueType deltaY) noexcept { pos.x += deltaX; pos.y += deltaY; } /** Returns a rectangle which is the same as this one moved by a given amount. */ - Rectangle translated (const ValueType deltaX, - const ValueType deltaY) const noexcept + Rectangle translated (ValueType deltaX, + ValueType deltaY) const noexcept { return Rectangle (pos.x + deltaX, pos.y + deltaY, w, h); } /** Returns a rectangle which is the same as this one moved by a given amount. */ - Rectangle operator+ (const Point deltaPosition) const noexcept + Rectangle operator+ (Point deltaPosition) const noexcept { return Rectangle (pos.x + deltaPosition.x, pos.y + deltaPosition.y, w, h); } /** Moves this rectangle by a given amount. */ - Rectangle& operator+= (const Point deltaPosition) noexcept + Rectangle& operator+= (Point deltaPosition) noexcept { pos += deltaPosition; return *this; } /** Returns a rectangle which is the same as this one moved by a given amount. */ - Rectangle operator- (const Point deltaPosition) const noexcept + Rectangle operator- (Point deltaPosition) const noexcept { return Rectangle (pos.x - deltaPosition.x, pos.y - deltaPosition.y, w, h); } /** Moves this rectangle by a given amount. */ - Rectangle& operator-= (const Point deltaPosition) noexcept + Rectangle& operator-= (Point deltaPosition) noexcept { pos -= deltaPosition; return *this; @@ -396,8 +409,8 @@ public: Effectively, its new size is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2). @see expanded, reduce, reduced */ - void expand (const ValueType deltaX, - const ValueType deltaY) noexcept + void expand (ValueType deltaX, + ValueType deltaY) noexcept { const ValueType nw = jmax (ValueType(), w + deltaX * 2); const ValueType nh = jmax (ValueType(), h + deltaY * 2); @@ -409,8 +422,8 @@ public: Effectively, the rectangle returned is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2). @see expand, reduce, reduced */ - Rectangle expanded (const ValueType deltaX, - const ValueType deltaY) const noexcept + Rectangle expanded (ValueType deltaX, + ValueType deltaY) const noexcept { const ValueType nw = jmax (ValueType(), w + deltaX * 2); const ValueType nh = jmax (ValueType(), h + deltaY * 2); @@ -422,7 +435,7 @@ public: Effectively, the rectangle returned is (x - delta, y - delta, w + delta * 2, h + delta * 2). @see expand, reduce, reduced */ - Rectangle expanded (const ValueType delta) const noexcept + Rectangle expanded (ValueType delta) const noexcept { return expanded (delta, delta); } @@ -432,8 +445,8 @@ public: Effectively, its new size is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2). @see reduced, expand, expanded */ - void reduce (const ValueType deltaX, - const ValueType deltaY) noexcept + void reduce (ValueType deltaX, + ValueType deltaY) noexcept { expand (-deltaX, -deltaY); } @@ -443,8 +456,8 @@ public: Effectively, the rectangle returned is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2). @see reduce, expand, expanded */ - Rectangle reduced (const ValueType deltaX, - const ValueType deltaY) const noexcept + Rectangle reduced (ValueType deltaX, + ValueType deltaY) const noexcept { return expanded (-deltaX, -deltaY); } @@ -454,7 +467,7 @@ public: Effectively, the rectangle returned is (x + delta, y + delta, w - delta * 2, h - delta * 2). @see reduce, expand, expanded */ - Rectangle reduced (const ValueType delta) const noexcept + Rectangle reduced (ValueType delta) const noexcept { return reduced (delta, delta); } @@ -468,7 +481,7 @@ public: If amountToRemove is greater than the height of this rectangle, it'll be clipped to that value. */ - Rectangle removeFromTop (const ValueType amountToRemove) noexcept + Rectangle removeFromTop (ValueType amountToRemove) noexcept { const Rectangle r (pos.x, pos.y, w, jmin (amountToRemove, h)); pos.y += r.h; h -= r.h; @@ -484,7 +497,7 @@ public: If amountToRemove is greater than the width of this rectangle, it'll be clipped to that value. */ - Rectangle removeFromLeft (const ValueType amountToRemove) noexcept + Rectangle removeFromLeft (ValueType amountToRemove) noexcept { const Rectangle r (pos.x, pos.y, jmin (amountToRemove, w), h); pos.x += r.w; w -= r.w; @@ -533,13 +546,13 @@ public: bool operator!= (const Rectangle& other) const noexcept { return pos != other.pos || w != other.w || h != other.h; } /** Returns true if this coordinate is inside the rectangle. */ - bool contains (const ValueType xCoord, const ValueType yCoord) const noexcept + bool contains (ValueType xCoord, ValueType yCoord) const noexcept { return xCoord >= pos.x && yCoord >= pos.y && xCoord < pos.x + w && yCoord < pos.y + h; } /** Returns true if this coordinate is inside the rectangle. */ - bool contains (const Point point) const noexcept + bool contains (Point point) const noexcept { return point.x >= pos.x && point.y >= pos.y && point.x < pos.x + w && point.y < pos.y + h; } @@ -552,7 +565,7 @@ public: } /** Returns the nearest point to the specified point that lies within this rectangle. */ - Point getConstrainedPoint (const Point point) const noexcept + Point getConstrainedPoint (Point point) const noexcept { return Point (jlimit (pos.x, pos.x + w, point.x), jlimit (pos.y, pos.y + h, point.y));