From e7c8702d4ede988ec8ed5f0c43b003b4c85e82ef Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Sat, 15 May 2010 23:38:40 +0100 Subject: [PATCH] Rendering speed improvement and small viewport tweak. --- juce_amalgamated.cpp | 117 ++++++++---------- src/gui/components/layout/juce_Viewport.cpp | 114 ++++++++--------- .../graphics/geometry/juce_RectangleList.cpp | 3 - 3 files changed, 110 insertions(+), 124 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 48f185ab0b..a225377c0c 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -63262,12 +63262,12 @@ void Viewport::setViewedComponent (Component* const newViewedComponent) int Viewport::getMaximumVisibleWidth() const { - return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0)); + return contentHolder->getWidth(); } int Viewport::getMaximumVisibleHeight() const { - return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0)); + return contentHolder->getHeight(); } void Viewport::setViewPosition (const int xPixelsOffset, const int yPixelsOffset) @@ -63347,27 +63347,12 @@ void Viewport::updateVisibleArea() bool hBarVisible = canShowHBar && ! horizontalScrollBar->autoHides(); bool vBarVisible = canShowVBar && ! horizontalScrollBar->autoHides(); - if (contentComp != 0) + Rectangle contentArea (getLocalBounds()); + + if (contentComp != 0 && ! contentArea.contains (contentComp->getBounds())) { - Rectangle contentArea (getLocalBounds()); - - if (! contentArea.contains (contentComp->getBounds())) - { - hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth()); - vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight()); - - if (vBarVisible) - contentArea.setWidth (getWidth() - scrollbarWidth); - - if (hBarVisible) - contentArea.setHeight (getHeight() - scrollbarWidth); - - if (! contentArea.contains (contentComp->getBounds())) - { - hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth()); - vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight()); - } - } + hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth()); + vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight()); if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); @@ -63375,48 +63360,59 @@ void Viewport::updateVisibleArea() if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); - const Point visibleOrigin (-contentComp->getPosition()); - - if (hBarVisible) + if (! contentArea.contains (contentComp->getBounds())) { - horizontalScrollBar->setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); - horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth()); - horizontalScrollBar->setCurrentRange (visibleOrigin.getX(), contentArea.getWidth()); - horizontalScrollBar->setSingleStepSize (singleStepX); + hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth()); + vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight()); } - - if (vBarVisible) - { - verticalScrollBar->setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); - verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight()); - verticalScrollBar->setCurrentRange (visibleOrigin.getY(), contentArea.getHeight()); - verticalScrollBar->setSingleStepSize (singleStepY); - } - - // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. - horizontalScrollBar->setVisible (hBarVisible); - verticalScrollBar->setVisible (vBarVisible); - - contentHolder->setBounds (contentArea); - - const Rectangle visibleArea (visibleOrigin.getX(), visibleOrigin.getY(), - jmin (contentComp->getWidth() - visibleOrigin.getX(), contentArea.getWidth()), - jmin (contentComp->getHeight() - visibleOrigin.getY(), contentArea.getHeight())); - - if (lastVisibleArea != visibleArea) - { - lastVisibleArea = visibleArea; - visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight()); - } - - horizontalScrollBar->handleUpdateNowIfNeeded(); - verticalScrollBar->handleUpdateNowIfNeeded(); } - else + + if (vBarVisible) + contentArea.setWidth (getWidth() - scrollbarWidth); + + if (hBarVisible) + contentArea.setHeight (getHeight() - scrollbarWidth); + + contentHolder->setBounds (contentArea); + + Rectangle contentBounds; + if (contentComp != 0) + contentBounds = contentComp->getBounds(); + + const Point visibleOrigin (-contentBounds.getPosition()); + + if (hBarVisible) { - horizontalScrollBar->setVisible (hBarVisible); - verticalScrollBar->setVisible (vBarVisible); + horizontalScrollBar->setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); + horizontalScrollBar->setRangeLimits (0.0, contentBounds.getWidth()); + horizontalScrollBar->setCurrentRange (visibleOrigin.getX(), contentArea.getWidth()); + horizontalScrollBar->setSingleStepSize (singleStepX); } + + if (vBarVisible) + { + verticalScrollBar->setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); + verticalScrollBar->setRangeLimits (0.0, contentBounds.getHeight()); + verticalScrollBar->setCurrentRange (visibleOrigin.getY(), contentArea.getHeight()); + verticalScrollBar->setSingleStepSize (singleStepY); + } + + // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. + horizontalScrollBar->setVisible (hBarVisible); + verticalScrollBar->setVisible (vBarVisible); + + const Rectangle visibleArea (visibleOrigin.getX(), visibleOrigin.getY(), + jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()), + jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight())); + + if (lastVisibleArea != visibleArea) + { + lastVisibleArea = visibleArea; + visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight()); + } + + horizontalScrollBar->handleUpdateNowIfNeeded(); + verticalScrollBar->handleUpdateNowIfNeeded(); } void Viewport::setSingleStepSizes (const int stepX, const int stepY) @@ -91085,9 +91081,6 @@ void RectangleList::subtract (const Rectangle& rect) } } } - - if (rects.size() > originalNumRects + 10) - consolidate(); } } diff --git a/src/gui/components/layout/juce_Viewport.cpp b/src/gui/components/layout/juce_Viewport.cpp index 8feba6e1ee..85ed09cd73 100644 --- a/src/gui/components/layout/juce_Viewport.cpp +++ b/src/gui/components/layout/juce_Viewport.cpp @@ -94,12 +94,12 @@ void Viewport::setViewedComponent (Component* const newViewedComponent) int Viewport::getMaximumVisibleWidth() const { - return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0)); + return contentHolder->getWidth(); } int Viewport::getMaximumVisibleHeight() const { - return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0)); + return contentHolder->getHeight(); } void Viewport::setViewPosition (const int xPixelsOffset, const int yPixelsOffset) @@ -181,27 +181,12 @@ void Viewport::updateVisibleArea() bool hBarVisible = canShowHBar && ! horizontalScrollBar->autoHides(); bool vBarVisible = canShowVBar && ! horizontalScrollBar->autoHides(); - if (contentComp != 0) + Rectangle contentArea (getLocalBounds()); + + if (contentComp != 0 && ! contentArea.contains (contentComp->getBounds())) { - Rectangle contentArea (getLocalBounds()); - - if (! contentArea.contains (contentComp->getBounds())) - { - hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth()); - vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight()); - - if (vBarVisible) - contentArea.setWidth (getWidth() - scrollbarWidth); - - if (hBarVisible) - contentArea.setHeight (getHeight() - scrollbarWidth); - - if (! contentArea.contains (contentComp->getBounds())) - { - hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth()); - vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight()); - } - } + hBarVisible = canShowHBar && (hBarVisible || contentComp->getX() < 0 || contentComp->getRight() > contentArea.getWidth()); + vBarVisible = canShowVBar && (vBarVisible || contentComp->getY() < 0 || contentComp->getBottom() > contentArea.getHeight()); if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); @@ -209,48 +194,59 @@ void Viewport::updateVisibleArea() if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); - const Point visibleOrigin (-contentComp->getPosition()); - - if (hBarVisible) + if (! contentArea.contains (contentComp->getBounds())) { - horizontalScrollBar->setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); - horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth()); - horizontalScrollBar->setCurrentRange (visibleOrigin.getX(), contentArea.getWidth()); - horizontalScrollBar->setSingleStepSize (singleStepX); + hBarVisible = canShowHBar && (hBarVisible || contentComp->getRight() > contentArea.getWidth()); + vBarVisible = canShowVBar && (vBarVisible || contentComp->getBottom() > contentArea.getHeight()); } - - if (vBarVisible) - { - verticalScrollBar->setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); - verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight()); - verticalScrollBar->setCurrentRange (visibleOrigin.getY(), contentArea.getHeight()); - verticalScrollBar->setSingleStepSize (singleStepY); - } - - // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. - horizontalScrollBar->setVisible (hBarVisible); - verticalScrollBar->setVisible (vBarVisible); - - contentHolder->setBounds (contentArea); - - const Rectangle visibleArea (visibleOrigin.getX(), visibleOrigin.getY(), - jmin (contentComp->getWidth() - visibleOrigin.getX(), contentArea.getWidth()), - jmin (contentComp->getHeight() - visibleOrigin.getY(), contentArea.getHeight())); - - if (lastVisibleArea != visibleArea) - { - lastVisibleArea = visibleArea; - visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight()); - } - - horizontalScrollBar->handleUpdateNowIfNeeded(); - verticalScrollBar->handleUpdateNowIfNeeded(); } - else + + if (vBarVisible) + contentArea.setWidth (getWidth() - scrollbarWidth); + + if (hBarVisible) + contentArea.setHeight (getHeight() - scrollbarWidth); + + contentHolder->setBounds (contentArea); + + Rectangle contentBounds; + if (contentComp != 0) + contentBounds = contentComp->getBounds(); + + const Point visibleOrigin (-contentBounds.getPosition()); + + if (hBarVisible) { - horizontalScrollBar->setVisible (hBarVisible); - verticalScrollBar->setVisible (vBarVisible); + horizontalScrollBar->setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); + horizontalScrollBar->setRangeLimits (0.0, contentBounds.getWidth()); + horizontalScrollBar->setCurrentRange (visibleOrigin.getX(), contentArea.getWidth()); + horizontalScrollBar->setSingleStepSize (singleStepX); } + + if (vBarVisible) + { + verticalScrollBar->setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); + verticalScrollBar->setRangeLimits (0.0, contentBounds.getHeight()); + verticalScrollBar->setCurrentRange (visibleOrigin.getY(), contentArea.getHeight()); + verticalScrollBar->setSingleStepSize (singleStepY); + } + + // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. + horizontalScrollBar->setVisible (hBarVisible); + verticalScrollBar->setVisible (vBarVisible); + + const Rectangle visibleArea (visibleOrigin.getX(), visibleOrigin.getY(), + jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()), + jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight())); + + if (lastVisibleArea != visibleArea) + { + lastVisibleArea = visibleArea; + visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight()); + } + + horizontalScrollBar->handleUpdateNowIfNeeded(); + verticalScrollBar->handleUpdateNowIfNeeded(); } //============================================================================== diff --git a/src/gui/graphics/geometry/juce_RectangleList.cpp b/src/gui/graphics/geometry/juce_RectangleList.cpp index 34312762c7..8b6a1a3f3c 100644 --- a/src/gui/graphics/geometry/juce_RectangleList.cpp +++ b/src/gui/graphics/geometry/juce_RectangleList.cpp @@ -260,9 +260,6 @@ void RectangleList::subtract (const Rectangle& rect) } } } - - if (rects.size() > originalNumRects + 10) - consolidate(); } }