diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 1fc9bd60c3..6191d1aa7f 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -174,6 +174,12 @@ public: /** Changes the rectangle's height */ inline void setHeight (const 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; } + + /** Changes the position of the rectangle's centre (leaving its size unchanged). */ + inline void setCentre (const Point newCentre) noexcept { setCentre (newCentre.x, newCentre.y); } + /** 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); } @@ -189,6 +195,10 @@ public: /** 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); } + /** 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); } + /** 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); } diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index ffd26f2f52..d424feca48 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -194,7 +194,7 @@ public: .getDisplayContaining (component.getScreenBounds().getCentre()).scale; Rectangle newArea (peer->getComponent().getLocalArea (&component, component.getLocalBounds()) - .withPosition (0, 0) + .withZeroOrigin() * newScale); if (scale != newScale || viewportArea != newArea)