1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Workaround to avoid misplaced wheel events when scrolling a viewport than contains wheel-able subcomponents.

This commit is contained in:
jules 2014-12-16 16:28:02 +00:00
parent aae0b7a5af
commit 0b67cb2b93
2 changed files with 33 additions and 0 deletions

View file

@ -52,6 +52,7 @@ Viewport::Viewport (const String& name)
Viewport::~Viewport()
{
deleteContentComp();
mouseWheelTimer = nullptr;
}
//==============================================================================
@ -357,6 +358,30 @@ static int rescaleMouseWheelDistance (float distance, int singleStepSize) noexce
: jmax (distance, 1.0f));
}
// This puts a temporary component overlay over the content component, to prevent
// wheel events from reaching components inside it, so that while spinning a wheel
// with momentum, it won't accidentally scroll any subcomponents of the viewport.
struct Viewport::MouseWheelTimer : public Timer
{
MouseWheelTimer (Viewport& v) : viewport (v)
{
viewport.contentHolder.addAndMakeVisible (dummyOverlay);
dummyOverlay.setAlwaysOnTop (true);
dummyOverlay.setPaintingIsUnclipped (true);
dummyOverlay.setBounds (viewport.contentHolder.getLocalBounds());
}
void timerCallback() override
{
viewport.mouseWheelTimer = nullptr;
}
Component dummyOverlay;
Viewport& viewport;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseWheelTimer)
};
bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelDetails& wheel)
{
if (! (e.mods.isAltDown() || e.mods.isCtrlDown() || e.mods.isCommandDown()))
@ -387,6 +412,11 @@ bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, const MouseWheelD
if (pos != getViewPosition())
{
if (mouseWheelTimer == nullptr)
mouseWheelTimer = new MouseWheelTimer (*this);
mouseWheelTimer->startTimer (300);
setViewPosition (pos);
return true;
}

View file

@ -267,6 +267,9 @@ private:
bool allowScrollingWithoutScrollbarV, allowScrollingWithoutScrollbarH;
Component contentHolder;
ScrollBar verticalScrollBar, horizontalScrollBar;
struct MouseWheelTimer;
ScopedPointer<Timer> mouseWheelTimer;
Point<int> viewportPosToCompPos (Point<int>) const;
void updateVisibleArea();