Need to ask something about the ViewPort Scrolling


#1

Hi All, 

1.) I firstly want to know about how can the system mouse wheel settings for scrolling can be used in our application, which is using juce. The requirment is we want to scroll the same number of lines as much as that being set in the mouse wheel properties.

2.) secondly, 

below is a code snippet from juce_Viewport.cpp.. One thing that's not clear is the use of the value 14.0f, used as a multiplier for both horizontal and vertical scrolling. We would be really thankful to you,  if you could tell us What is the significance of that value.

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();

        if (hasHorzBar || hasVertBar)
        {
            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);
            }

            Point<int> pos (getViewPosition());

            if (wheelIncrementX != 0 && wheelIncrementY != 0 && hasHorzBar && hasVertBar)
            {
                pos.setX (pos.x - roundToInt (wheelIncrementX));
                pos.setY (pos.y - roundToInt (wheelIncrementY));
            }
            else if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
            {
                if (wheelIncrementX == 0 && ! hasVertBar)
                    wheelIncrementX = wheelIncrementY;

                pos.setX (pos.x - roundToInt (wheelIncrementX));
            }
            else if (hasVertBar && wheelIncrementY != 0)
            {
                pos.setY (pos.y - roundToInt (wheelIncrementY));
            }

            if (pos != getViewPosition())
            {
                setViewPosition (pos);
                return true;
            }
        }
    }

    return false;
}

#2

I can't see how it'd be in any way meaningful to talk about the "number of lines as set in the properties".. Mice are all different, and most these days have free-running wheels - there's no such thing as a number of lines, certainly not when you're dealing with cross-platform differences.

The 14.0 is really just an experimental number that I got by trying different mice in different OSes, and tweaked until the behaviour of most of them roughly matched the speed that most other apps generally scroll at. This is not an exact science!


#3

By saying "number of lines as set in the properties", I mean the system properties(attached setting dialog for windows). Now looking at few of the application, like Google's Chrome, Visual studio, Notepad, X-Code, etc, they consider these setting while scrollling. The number of lines scrolled (in case of text editors)or the number of pixels moved(in case of chrome), vary based on these settings. So I want these settings to even change the scroll amount in my juce app.

Would it be proper to replace the "14.0f" with the values we get for the amount of scroll with the native functions to get the system properties or is there a better way you can suggest us for our requirement..



#ifdef JUCE_WIN32
    BOOL  bISSuccessful = SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0,&uiNumberOfLinesToMove,0);

#else if JUCE_MAC

     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
     [userDefaults addSuiteNamed:NSGlobalDomain];   
     float scrollStepSize = [[userDefaults objectForKey:@"com.apple.scrollwheel.scaling"] floatValue];

#endif

#4

Surely these system scaling factors already get taken into account in the parameters that get delivered to the wheel events? I doubt whether either OS expects every program to manually check these settings in order to scale the wheel events that arrive (?)