bug fix in mouse position on Mac OSX

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.

bug fix in mouse position on Mac OSX

Postby glut32 » Thu Apr 20, 2017 2:49 pm

found and I fixed a bug about mouse position on Mac OSX version of Irrlicht 1.8.4.

This is the steps to reproduce :

1. Compile this code : I modify the "06.2DGraphics\main.cpp" example like : https://pastebin.com/CnupCugU
You can see the mouse cursor position

2. Launch the exe

3. Go to in fullscreen mode

4. Check the position on Left Top of the view of the window, see the mouse position you have (0,18) instead of (0,0)

5. Go to windowed mode

6. Check the position on Left Top of the view of the window, see the mouse position you have again (0,18) instead of (0,0)

remark: I think that PositionInWindow count the title bar of the window in the position


This is the bug fix : There are only two modified functions in "Irrlicht/MacOSX/CIrrDeviceMacOSX.mm"

cpp Code: Select all
void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
{
    bool post = true;
 
    if (Window != NULL)
    {    
        NSView* mainView = [Window contentView];
        NSPoint locationInMainView = [mainView convertPoint:[(NSEvent *)event locationInWindow] fromView:mainView];
 
       
        ievent.MouseInput.X = (int)(locationInMainView.x - mainView.bounds.origin.x);
        ievent.MouseInput.Y = (int)(mainView.bounds.size.height - locationInMainView.y  - mainView.bounds.origin.y);
 
       
        if (ievent.MouseInput.Y < 0)
            post = false;
    }
    else
    {
        CGEventRef ourEvent = CGEventCreate(NULL);
        CGPoint point = CGEventGetLocation(ourEvent);
        CFRelease(ourEvent);
 
        ievent.MouseInput.X = (int)point.x;
        ievent.MouseInput.Y = (int)point.y;
 
        if (ievent.MouseInput.Y < 0)
            post = false;
    }
 
    if (post)
        postEventFromUser(ievent);
 
    [NSApp sendEvent:(NSEvent *)event];
}
 


cpp Code: Select all
void CIrrDeviceMacOSX::storeMouseLocation()
{
    int x,y;
 
    if (Window != NULL)
    {
        NSPoint    p;
        p = [NSEvent mouseLocation];
        p = [Window convertScreenToBase:p];
        NSView* mainView = [Window contentView];
        NSPoint locationInMainView = [mainView convertPoint:p fromView:mainView];
       
        x = (int)(locationInMainView.x - mainView.bounds.origin.x);
        y = (int)(mainView.bounds.size.height - locationInMainView.y  - mainView.bounds.origin.y);
    }
    else
    {
        CGEventRef ourEvent = CGEventCreate(NULL);
        CGPoint point = CGEventGetLocation(ourEvent);
        CFRelease(ourEvent);
 
        x = (int)point.x;
        y = (int)point.y;
 
        const core::position2di& curr = ((CCursorControl *)CursorControl)->getPosition();
        if (curr.X != x || curr.Y != y)
        {
            // In fullscreen mode, events are not sent regularly so rely on polling
            irr::SEvent ievent;
            ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
            ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
            ievent.MouseInput.X = x;
            ievent.MouseInput.Y = y;
            postEventFromUser(ievent);
        }
    }
 
    ((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y);
}


Does someone can put this fix on the svn of irrlicht? Please contact cutealien, if you want to know my real name.
glut32
 
Posts: 3
Joined: Tue Mar 28, 2017 2:29 pm

Return to Bug reports

Who is online

Users browsing this forum: No registered users and 1 guest