|
|
|
@@ -30,6 +30,8 @@ Viewport::Viewport (const String& name) |
|
|
|
showHScrollbar (true),
|
|
|
|
showVScrollbar (true),
|
|
|
|
deleteContent (true),
|
|
|
|
allowScrollingWithoutScrollbarV (false),
|
|
|
|
allowScrollingWithoutScrollbarH (false),
|
|
|
|
verticalScrollBar (true),
|
|
|
|
horizontalScrollBar (false)
|
|
|
|
{
|
|
|
|
@@ -234,31 +236,23 @@ void Viewport::updateVisibleArea() |
|
|
|
|
|
|
|
Point<int> visibleOrigin (-contentBounds.getPosition());
|
|
|
|
|
|
|
|
if (hBarVisible)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
else if (canShowHBar)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vBarVisible)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
else if (canShowVBar)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
@@ -301,8 +295,13 @@ void Viewport::setSingleStepSizes (const int stepX, const int stepY) |
|
|
|
}
|
|
|
|
|
|
|
|
void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
|
|
|
|
const bool showHorizontalScrollbarIfNeeded)
|
|
|
|
const bool showHorizontalScrollbarIfNeeded,
|
|
|
|
const bool allowVerticalScrollingWithoutScrollbar,
|
|
|
|
const bool allowHorizontalScrollingWithoutScrollbar)
|
|
|
|
{
|
|
|
|
allowScrollingWithoutScrollbarV = allowVerticalScrollingWithoutScrollbar;
|
|
|
|
allowScrollingWithoutScrollbarH = allowHorizontalScrollingWithoutScrollbar;
|
|
|
|
|
|
|
|
if (showVScrollbar != showVerticalScrollbarIfNeeded
|
|
|
|
|| showHScrollbar != showHorizontalScrollbarIfNeeded)
|
|
|
|
{
|
|
|
|
@@ -347,47 +346,44 @@ void Viewport::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& whe |
|
|
|
Component::mouseWheelMove (e, wheel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float rescaleMouseWheelDistance (float distance, int singleStepSize) noexcept
|
|
|
|
{
|
|
|
|
if (distance == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
distance *= 14.0f * singleStepSize;
|
|
|
|
|
|
|
|
return distance < 0 ? jmin (distance, -1.0f)
|
|
|
|
: jmax (distance, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel)
|
|
|
|
{
|
|
|
|
if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown()))
|
|
|
|
{
|
|
|
|
const bool hasVertBar = verticalScrollBar.isVisible();
|
|
|
|
const bool hasHorzBar = horizontalScrollBar.isVisible();
|
|
|
|
const bool canScrollVert = (allowScrollingWithoutScrollbarV || verticalScrollBar.isVisible());
|
|
|
|
const bool canScrollHorz = (allowScrollingWithoutScrollbarH || horizontalScrollBar.isVisible());
|
|
|
|
|
|
|
|
if (hasHorzBar || hasVertBar)
|
|
|
|
if (canScrollHorz || canScrollVert)
|
|
|
|
{
|
|
|
|
float wheelIncrementX = wheel.deltaX;
|
|
|
|
float wheelIncrementY = wheel.deltaY;
|
|
|
|
|
|
|
|
if (wheelIncrementX != 0)
|
|
|
|
{
|
|
|
|
wheelIncrementX *= 14.0f * singleStepX;
|
|
|
|
wheelIncrementX = (wheelIncrementX < 0) ? jmin (wheelIncrementX, -1.0f)
|
|
|
|
: jmax (wheelIncrementX, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wheelIncrementY != 0)
|
|
|
|
{
|
|
|
|
wheelIncrementY *= 14.0f * singleStepY;
|
|
|
|
wheelIncrementY = (wheelIncrementY < 0) ? jmin (wheelIncrementY, -1.0f)
|
|
|
|
: jmax (wheelIncrementY, 1.0f);
|
|
|
|
}
|
|
|
|
float wheelIncrementX = rescaleMouseWheelDistance (wheel.deltaX, singleStepX);
|
|
|
|
float wheelIncrementY = rescaleMouseWheelDistance (wheel.deltaY, singleStepY);
|
|
|
|
|
|
|
|
Point<int> pos (getViewPosition());
|
|
|
|
|
|
|
|
if (wheelIncrementX != 0 && wheelIncrementY != 0 && hasHorzBar && hasVertBar)
|
|
|
|
if (wheelIncrementX != 0 && wheelIncrementY != 0 && canScrollHorz && canScrollVert)
|
|
|
|
{
|
|
|
|
pos.setX (pos.x - roundToInt (wheelIncrementX));
|
|
|
|
pos.setY (pos.y - roundToInt (wheelIncrementY));
|
|
|
|
}
|
|
|
|
else if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
|
|
|
|
else if (canScrollHorz && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! canScrollVert))
|
|
|
|
{
|
|
|
|
if (wheelIncrementX == 0 && ! hasVertBar)
|
|
|
|
if (wheelIncrementX == 0 && ! canScrollVert)
|
|
|
|
wheelIncrementX = wheelIncrementY;
|
|
|
|
|
|
|
|
pos.setX (pos.x - roundToInt (wheelIncrementX));
|
|
|
|
}
|
|
|
|
else if (hasVertBar && wheelIncrementY != 0)
|
|
|
|
else if (canScrollVert && wheelIncrementY != 0)
|
|
|
|
{
|
|
|
|
pos.setY (pos.y - roundToInt (wheelIncrementY));
|
|
|
|
}
|
|
|
|
|