2
votes

I'm programming in Eclipse (not Xcode) on Yosemita 10.10... I try to catch MouseMoved event, but it not called (mouseDown, mouseDragged - works fine). So I'm using this example code from here http://lists.apple.com/archives/mac-opengl/2003/Feb/msg00069.html but compiller show error on
[app setDelegate: view]; (- cannot initialize a parameter of type 'id' with an lvalue of type 'NSView *')
If I comment this line - it's work, but mouseMoved don't calling.
Please help! I'm newbie in objective-c

1

1 Answers

0
votes

OS X does not automatically track the mouse movement events for you unless you request them.

In order to receive mouseMoved: events, you should add an NSTrackingArea to your subclass of NSOpenGLView. For example:

- (void)awakeFromNib {
    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:self.frame options:NSTrackingActiveAlways|NSTrackingMouseMoved owner:self userInfo:nil];
    [self addTrackingArea:trackingArea];
}

After that, your mouseMoved: method will be called.

- (void)mouseMoved:(NSEvent *)theEvent {
    NSLog(@"moved");
}

You can optionally implement updateTrackingAreas if you need to update your tracking area manually when the view resizes. For details, please refer to Using Tracking-Area Objects.