SFML community forums

Help => Window => Topic started by: BlueCobold on January 14, 2015, 12:07:51 am

Title: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)
Post by: BlueCobold on January 14, 2015, 12:07:51 am
Hi.

I'm using SFML master branch and when calling sf::Mouse::getPosition(const sf::Window &relativeTo) in fullscreen mode, I always get (0/0) returned. Not so on Win7. There it is working as expected. Using sf::Mouse::getPosition() does return changing values when moving the mouse.

Greetings
Title: Re: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)
Post by: Hiura on January 14, 2015, 09:27:11 am
Indeed. Associated issue: https://github.com/SFML/SFML/issues/782
Title: Re: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)
Post by: Sherman on February 03, 2015, 10:21:43 am
I've managed to fix the problem for myself. The main problem lies within InputImp::getSFOpenGLViewFromSFMLWindow.

SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
{
    id nsHandle = (id)window.getSystemHandle();

    // Get our SFOpenGLView from ...
    SFOpenGLView* view = nil;

    if ([nsHandle isKindOfClass:[NSWindow class]])
    {
        // If system handle is a window then from its content view.
        view = [nsHandle contentView];

        // Subview doesn't match ?
        if (![view isKindOfClass:[SFOpenGLView class]])
        {
            sf::err() << "The content view is not a valid SFOpenGLView"
                      << std::endl;
            view = nil;
        }

    }
    else if ([nsHandle isKindOfClass:[NSView class]])
    {
        // If system handle is a view then from a subview of kind SFOpenGLView.
        NSArray* subviews = [nsHandle subviews];
        for (NSView* subview in subviews)
        {
            if ([subview isKindOfClass:[SFOpenGLView class]])
            {
                view = (SFOpenGLView*)subview;
                break;
            }
        }

        // No matching subview ?
        if (view == nil)
            sf::err() << "Cannot find a valid SFOpenGLView subview." << std::endl;
    }
    else
    {
        if (nsHandle != 0)
            sf::err() << "The system handle is neither a <NSWindow*> nor <NSView*>"
                      << "object. This shouldn't happen."
                      << std::endl;
        // Else: this probably means the SFML window was previously closed.
    }

    return view;
}

When a window is created with fullscreen mode (see SFWindowController::setupFullscreenViewTithMode) a NSView called masterview is created with the SFLOpenGLView added as subview of this NSView. This NSView is then set as the window's contentview. This means that whenever InputImp::getSFOpenGLViewFromSFMLWindow is called during fulllscreen mode it'll try to get the SFOpenGLView from the contentview which fails because it's a regular NSView, not a SFOpenGLView. It should try to get the SFOpenGLView from the contentview's subviews instead of the contentview itself.
Title: Re: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)
Post by: Hiura on February 03, 2015, 12:48:35 pm
Yep, I had something similar in mind. Do you mind creating a pull request on github?  :)
Title: Re: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)
Post by: Sherman on February 03, 2015, 03:03:48 pm
Never made a pull request before but I'm working on it, might take a while though.