FROM : Brian O'Brien
DATE : Wed Apr 27 23:41:37 2005
On Apr 27, 2005, at 3:26 PM, glenn andreas wrote:
>
> On Apr 27, 2005, at 4:11 PM, Brian O'Brien wrote:
>
>>
>> On Apr 27, 2005, at 2:44 PM, Clark Cox wrote:
>>
>>> On 4/27/05, Brian O'Brien <<email_removed>> wrote:
>>>>
>>>> On Apr 27, 2005, at 2:32 PM, Brian O'Brien wrote:
>>>>
>>>>> In my subclass of NSImageView I want to receive mouse move events.
>>>>> I defined the method acceptsMouseMovedEvents and returned true.
>>>>> I also defined the method - (void)mouseMoved:(NSEvent *)theEvent
>>>>> and put an NSLog message in that function. However I get no mouse
>>>>> motion events.
>>>>>
>>>>
>>>> in my init I did
>>>> [[self window] setAcceptsMouseMovedEvents:YES];
>>>
>>> While inside you're init method, [self window[ cannot possibly be
>>> returning anything other than nil. That is, if the view's still being
>>> init'ed, it can't have been placed in a superview yet.
>>>
>> I got tracking rects working and I also got mouseEntered and
>> mouseExited events...
>> I figured I could add [[self window] setAcceptsMouseMovedEvents:YES]
>> in the
>> entered event and turn them off in the exited event... but still no
>> mouseMoved events...
>>
>
> I seem to remember (but my memory could be faulty on this one) that
> you need to be the first responder to get the mouse moved events (this
> may have been to get the modifier changed flags though - it's all a
> bit blurry).
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> oh my!
> quadrium | build, mutate, evolve | images, textures, backgrounds, art
>
>
After a bit of muddling around this works:
/
*-----------------------------------------------------------------------
-------\
| The following functions are for setting up to receive mouse movement
events. |
| the mouse movement events are turned on when the mouse enteres the
frame and |
| off when the mouse leaves the frame.
|
\-----------------------------------------------------------------------
-------*/
- (void)clearTrackingRect
{
if (rolloverTrackingRectTag > 0)
{
[self removeTrackingRect:rolloverTrackingRectTag];
rolloverTrackingRectTag = 0;
}
}
- (void)resetTrackingRect
{
[self clearTrackingRect];
rolloverTrackingRectTag = [self addTrackingRect:[self visibleRect]
owner:self userData:NULL assumeInside:NO];
}
- (void)resetCursorRects
{
[super resetCursorRects];
[self resetTrackingRect];
}
- (void)viewDidMoveToWindow
{
if ([self window]) {
[self resetTrackingRect];
}
}
- (void)mouseEntered:(NSEvent *)theEvent
{
NSLog(@"Mouse Entered");
[ [self window] setAcceptsMouseMovedEvents:YES];
NSLog(@"Accepting mouse movements.");
[ [self window] makeFirstResponder:self];
}
- (void)mouseMoved:(NSEvent *)theEvent
{
NSLog(@"mouse moved %@", theEvent);
}
- (void)mouseExited:(NSEvent *)theEvent
{
NSLog(@"Mouse Exited");
[[self window] setAcceptsMouseMovedEvents:NO];
NSLog(@"No longer accepting mouse movements.");
}
DATE : Wed Apr 27 23:41:37 2005
On Apr 27, 2005, at 3:26 PM, glenn andreas wrote:
>
> On Apr 27, 2005, at 4:11 PM, Brian O'Brien wrote:
>
>>
>> On Apr 27, 2005, at 2:44 PM, Clark Cox wrote:
>>
>>> On 4/27/05, Brian O'Brien <<email_removed>> wrote:
>>>>
>>>> On Apr 27, 2005, at 2:32 PM, Brian O'Brien wrote:
>>>>
>>>>> In my subclass of NSImageView I want to receive mouse move events.
>>>>> I defined the method acceptsMouseMovedEvents and returned true.
>>>>> I also defined the method - (void)mouseMoved:(NSEvent *)theEvent
>>>>> and put an NSLog message in that function. However I get no mouse
>>>>> motion events.
>>>>>
>>>>
>>>> in my init I did
>>>> [[self window] setAcceptsMouseMovedEvents:YES];
>>>
>>> While inside you're init method, [self window[ cannot possibly be
>>> returning anything other than nil. That is, if the view's still being
>>> init'ed, it can't have been placed in a superview yet.
>>>
>> I got tracking rects working and I also got mouseEntered and
>> mouseExited events...
>> I figured I could add [[self window] setAcceptsMouseMovedEvents:YES]
>> in the
>> entered event and turn them off in the exited event... but still no
>> mouseMoved events...
>>
>
> I seem to remember (but my memory could be faulty on this one) that
> you need to be the first responder to get the mouse moved events (this
> may have been to get the modifier changed flags though - it's all a
> bit blurry).
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> oh my!
> quadrium | build, mutate, evolve | images, textures, backgrounds, art
>
>
After a bit of muddling around this works:
/
*-----------------------------------------------------------------------
-------\
| The following functions are for setting up to receive mouse movement
events. |
| the mouse movement events are turned on when the mouse enteres the
frame and |
| off when the mouse leaves the frame.
|
\-----------------------------------------------------------------------
-------*/
- (void)clearTrackingRect
{
if (rolloverTrackingRectTag > 0)
{
[self removeTrackingRect:rolloverTrackingRectTag];
rolloverTrackingRectTag = 0;
}
}
- (void)resetTrackingRect
{
[self clearTrackingRect];
rolloverTrackingRectTag = [self addTrackingRect:[self visibleRect]
owner:self userData:NULL assumeInside:NO];
}
- (void)resetCursorRects
{
[super resetCursorRects];
[self resetTrackingRect];
}
- (void)viewDidMoveToWindow
{
if ([self window]) {
[self resetTrackingRect];
}
}
- (void)mouseEntered:(NSEvent *)theEvent
{
NSLog(@"Mouse Entered");
[ [self window] setAcceptsMouseMovedEvents:YES];
NSLog(@"Accepting mouse movements.");
[ [self window] makeFirstResponder:self];
}
- (void)mouseMoved:(NSEvent *)theEvent
{
NSLog(@"mouse moved %@", theEvent);
}
- (void)mouseExited:(NSEvent *)theEvent
{
NSLog(@"Mouse Exited");
[[self window] setAcceptsMouseMovedEvents:NO];
NSLog(@"No longer accepting mouse movements.");
}
| Related mails | Author | Date |
|---|---|---|
| Brian O'Brien | Apr 27, 22:32 | |
| Brian O'Brien | Apr 27, 22:39 | |
| Geoff Levner | Apr 27, 22:40 | |
| Brian O'Brien | Apr 27, 22:44 | |
| Clark Cox | Apr 27, 22:44 | |
| Brian O'Brien | Apr 27, 23:11 | |
| glenn andreas | Apr 27, 23:26 | |
| Brian O'Brien | Apr 27, 23:41 |






Cocoa mail archive

