Mouse position inconsistent rounding strategy


Due to a rounding discrepancy, a component can receive a mouseEnter event while isMouseOver returns false.

NSViewComponentPeer::getMousePos which uses c-style casts.

    static Point<int> getMousePos (NSEvent* e, NSView* view)
        NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];

        //old using c-style casts
        //return Point<int> ((int) p.x, (int) ([view frame].size.height - p.y));

        //proposed fix uses roundToInt to be consistent
       //with MouseInputSource::getCurrentRawMousePosition
        return Point<int> (roundToInt(p.x), roundToInt([view frame].size.height - p.y));

    }  MouseInputSource::getCurrentRawMousePosition uses roundToInt:

Point<int> MouseInputSource::getCurrentRawMousePosition()
        const NSPoint p ([NSEvent mouseLocation]);
        //using roundToInt here
        return Point<int> (roundToInt (p.x), roundToInt (getMainScreenHeight() - p.y));

I've tested with them both using roundToInt and it fixes the problem.  That said, it looks like roundToInt isn't used much with other platforms, so perhaps the fix should go the other way around.  

iOS UIViewComponentPeer::handleTouches (c-style) e.g.:

        const Point<int> pos ((int) p.x, (int) p.y);
        juce_lastMousePos = pos + getBounds (true).getPosition();


And for Android (Point.toInt() uses static_cast<int>):

    void handleMouseDownCallback (int index, Point<float> pos, int64 time)
        lastMousePos = pos;

        // this forces a mouse-enter/up event, in case for some reason we didn't get a mouse-up before.
        handleMouseEvent (index, pos.toInt(), currentModifiers.withoutMouseButtons(), time);



Thanks - I had been meaning to start converting all the underlying mouse-handling code to use floating point positions rather than ints. I might do that today, since you've reminded me..


Hey thanks Jules, that's a nice change.  My issue is solved with the latest tip and things otherwise look good.  If there's anything you'd specifically like tested I'd be happy to give it a run. (I currently only have access to OSX)


Thanks, glad it works for you! I'm not expecting any problems with it, but let me know if you spot anything strange.