2010-02-07 1 views
1

마우스 이동 이벤트를 받으려면 NSTrackingArea를 전체 화면보기에 설치하려고합니다.NSTrackingArea 전체 화면 창 /보기

그러나 내가 할 때마다 나는 어설 션 오류가 발생합니다. 웹을 검색했지만 리드를 찾을 수 없었습니다.

cocoaWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, x,y) 
               styleMask: NSTitledWindowMask 
               backing: NSBackingStoreBuffered 
                defer:NO]; 
    glView = [[WLMacGLView alloc] initWithFrame:NSMakeRect(0.0, 0.0, x,y) pixelFormat:[WLMacGLView defaultPixelFormat]]; 
    [glView setCocoaController:self]; 

    //add the glView as a subview of the window's content view 
    [[cocoaWindow contentView] addSubview:glView]; 
    NSRect r = [glView frame]; 
    NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:r options: NSTrackingMouseMoved | NSTrackingActiveWhenFirstResponder | NSTrackingActiveInKeyWindow 
            owner:self userInfo:nil]; 
    [glView addTrackingArea:track]; 
    [glView enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; 
    [glView createContext]; 

어설 바로 enterFullScreenMode 호출 후 발생 : withOptions :

사람 여기

*** Assertion failure in -[_NSFullScreenWindow _setTrackingRect:inside:owner:userData:useTrackingNum:install:], /SourceCache/AppKit/AppKit-1038.25/AppKit.subproj/NSWindow.m:3944 

는 (Y, X = 1024 = 768) 추적 영역을 설정하는 코드의 아이디어 있어요? 전체 화면 창에서 마우스 이동 이벤트를 얻기 위해 취해야하는 접근 방식이 아닙니까?

답변

0

그래서이 질문에 대한 대답은 제 코드의 버그로 밝혀졌습니다.

NSTrackingArea를 초기화 할 때 소유자에 대해 잘못된 개체를 전달하고있었습니다. 통과해야 할 적절한 것은 NSView였습니다. 그걸 수정하면 모두 예상대로 작동합니다.

0

전체보기에서 마우스를 추적하려면 마우스 이벤트를 얻기 위해 mouseDown:, mouseMoved:mouseUp: 메서드를 구현하는 것이 더 쉽다고 생각합니다.

+0

이러한 메서드는 구현되지만 창이 전체 화면 일 때 호출되지 않습니다. – wadesworld

+1

http://developer.apple.com/mac/library/samplecode/GeekGameBoard/index.html (OpenGL이 아닌 NSView 서브 클래스를 사용함)에서 살펴볼 수있는 샘플 응용 프로그램이 있습니다. –

+1

'-mouseMoved :'를 사용하려면'[[glView window] setAcceptsMouseMovedEvents : YES]'를 호출해야합니다. –