Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Mac] sf::Mouse::getPosition(relativeTo) in fullscreen always returns (0/0)  (Read 3282 times)

0 Members and 1 Guest are viewing this topic.

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
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

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
SFML / OS X developer

Sherman

  • Newbie
  • *
  • Posts: 4
    • View Profile
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.
« Last Edit: February 03, 2015, 11:36:15 am by rpt_stash »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Yep, I had something similar in mind. Do you mind creating a pull request on github?  :)
SFML / OS X developer

Sherman

  • Newbie
  • *
  • Posts: 4
    • View Profile
Never made a pull request before but I'm working on it, might take a while though.
« Last Edit: February 03, 2015, 04:19:26 pm by ThomR »

 

anything