void ChannelViewport::resized() { int w = getWidth(); int h = content.getTotalChildHeight() + 5; if (h > getHeight()) w -= getScrollBarThickness(); content.setSize(w, h); Viewport::resized(); }
void StaticStreamViewport::resized() { int width = 600; int height = MARGIN*2 + (STREAM_H + STREAM_GAP) * content->streamBoxes.size(); if (height > getHeight()) { width -= getScrollBarThickness(); } content->setSize(width, height); Viewport::resized(); }
//============================================================================== void Viewport::updateVisibleArea() { const int scrollbarWidth = getScrollBarThickness(); const bool canShowAnyBars = getWidth() > scrollbarWidth && getHeight() > scrollbarWidth; const bool canShowHBar = showHScrollbar && canShowAnyBars; const bool canShowVBar = showVScrollbar && canShowAnyBars; bool hBarVisible = false, vBarVisible = false; Rectangle<int> contentArea; for (int i = 3; --i >= 0;) { hBarVisible = canShowHBar && ! horizontalScrollBar.autoHides(); vBarVisible = canShowVBar && ! verticalScrollBar.autoHides(); contentArea = getLocalBounds(); if (contentComp != nullptr && ! 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()); } } if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); if (contentComp == nullptr) { contentHolder.setBounds (contentArea); break; } const Rectangle<int> oldContentBounds (contentComp->getBounds()); contentHolder.setBounds (contentArea); // If the content has changed its size, that might affect our scrollbars, so go round again and re-caclulate.. if (oldContentBounds == contentComp->getBounds()) break; } Rectangle<int> contentBounds; if (contentComp != nullptr) contentBounds = contentHolder.getLocalArea (contentComp, contentComp->getLocalBounds()); Point<int> visibleOrigin (-contentBounds.getPosition()); horizontalScrollBar.setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); horizontalScrollBar.setRangeLimits (0.0, contentBounds.getWidth()); horizontalScrollBar.setCurrentRange (visibleOrigin.x, contentArea.getWidth()); horizontalScrollBar.setSingleStepSize (singleStepX); horizontalScrollBar.cancelPendingUpdate(); if (canShowHBar && ! hBarVisible) visibleOrigin.setX (0); verticalScrollBar.setBounds (contentArea.getWidth(), 0, scrollbarWidth, contentArea.getHeight()); verticalScrollBar.setRangeLimits (0.0, contentBounds.getHeight()); verticalScrollBar.setCurrentRange (visibleOrigin.y, contentArea.getHeight()); verticalScrollBar.setSingleStepSize (singleStepY); verticalScrollBar.cancelPendingUpdate(); if (canShowVBar && ! vBarVisible) visibleOrigin.setY (0); // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. horizontalScrollBar.setVisible (hBarVisible); verticalScrollBar.setVisible (vBarVisible); if (contentComp != nullptr) { const Point<int> newContentCompPos (viewportPosToCompPos (visibleOrigin)); if (contentComp->getBounds().getPosition() != newContentCompPos) { contentComp->setTopLeftPosition (newContentCompPos); // (this will re-entrantly call updateVisibleArea again) return; } } const Rectangle<int> visibleArea (visibleOrigin.x, visibleOrigin.y, jmin (contentBounds.getWidth() - visibleOrigin.x, contentArea.getWidth()), jmin (contentBounds.getHeight() - visibleOrigin.y, contentArea.getHeight())); if (lastVisibleArea != visibleArea) { lastVisibleArea = visibleArea; visibleAreaChanged (visibleArea); } horizontalScrollBar.handleUpdateNowIfNeeded(); verticalScrollBar.handleUpdateNowIfNeeded(); }
//============================================================================== void Viewport::updateVisibleArea() { const int scrollbarWidth = getScrollBarThickness(); const bool canShowAnyBars = getWidth() > scrollbarWidth && getHeight() > scrollbarWidth; const bool canShowHBar = showHScrollbar && canShowAnyBars; const bool canShowVBar = showVScrollbar && canShowAnyBars; bool hBarVisible = canShowHBar && ! horizontalScrollBar.autoHides(); bool vBarVisible = canShowVBar && ! verticalScrollBar.autoHides(); Rectangle<int> contentArea (getLocalBounds()); if (contentComp != nullptr && ! 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()); } } if (vBarVisible) contentArea.setWidth (getWidth() - scrollbarWidth); if (hBarVisible) contentArea.setHeight (getHeight() - scrollbarWidth); contentHolder.setBounds (contentArea); Rectangle<int> contentBounds; if (contentComp != nullptr) contentBounds = contentHolder.getLocalArea (contentComp, contentComp->getLocalBounds()); Point<int> visibleOrigin (-contentBounds.getPosition()); if (hBarVisible) { horizontalScrollBar.setBounds (0, contentArea.getHeight(), contentArea.getWidth(), scrollbarWidth); horizontalScrollBar.setRangeLimits (0.0, contentBounds.getWidth()); horizontalScrollBar.setCurrentRange (visibleOrigin.getX(), contentArea.getWidth()); horizontalScrollBar.setSingleStepSize (singleStepX); horizontalScrollBar.cancelPendingUpdate(); } else if (canShowHBar) { visibleOrigin.setX (0); } 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); verticalScrollBar.cancelPendingUpdate(); } else if (canShowVBar) { visibleOrigin.setY (0); } // Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers. horizontalScrollBar.setVisible (hBarVisible); verticalScrollBar.setVisible (vBarVisible); setViewPosition (visibleOrigin); const Rectangle<int> 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); } horizontalScrollBar.handleUpdateNowIfNeeded(); verticalScrollBar.handleUpdateNowIfNeeded(); }
//============================================================================== void Viewport::updateVisibleRegion() { if (contentComp != 0) { const int newVX = -contentComp->getX(); const int newVY = -contentComp->getY(); if (newVX == 0 && newVY == 0 && contentComp->getWidth() <= getWidth() && contentComp->getHeight() <= getHeight()) { horizontalScrollBar->setVisible (false); verticalScrollBar->setVisible (false); } horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth()); horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth()); horizontalScrollBar->setSingleStepSize (singleStepX); if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness())) horizontalScrollBar->setVisible (false); verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight()); verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight()); verticalScrollBar->setSingleStepSize (singleStepY); if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness())) verticalScrollBar->setVisible (false); if (verticalScrollBar->isVisible()) { horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth()); verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight()); verticalScrollBar ->setBounds (getMaximumVisibleWidth(), 0, getScrollBarThickness(), getMaximumVisibleHeight()); } if (horizontalScrollBar->isVisible()) { horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth()); horizontalScrollBar ->setBounds (0, getMaximumVisibleHeight(), getMaximumVisibleWidth(), getScrollBarThickness()); } contentHolder->setSize (getMaximumVisibleWidth(), getMaximumVisibleHeight()); const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth()); const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight()); if (newVX != lastVX || newVY != lastVY || newVW != lastVW || newVH != lastVH) { lastVX = newVX; lastVY = newVY; lastVW = newVW; lastVH = newVH; visibleAreaChanged (newVX, newVY, newVW, newVH); for (int i = viewportListeners.size(); --i >= 0;) { ((ViewportListener*) viewportListeners.getUnchecked (i)) ->visibleAreaChanged (this, newVX, newVY, newVW, newVH); } } horizontalScrollBar->handleUpdateNowIfNeeded(); verticalScrollBar->handleUpdateNowIfNeeded(); } else { horizontalScrollBar->setVisible (false); verticalScrollBar->setVisible (false); } }
int Viewport::getMaximumVisibleHeight() const throw() { return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0)); }
int Viewport::getMaximumVisibleWidth() const throw() { return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0)); }