Re: non-trivial NSCursor example?
Re: non-trivial NSCursor example?
- Subject: Re: non-trivial NSCursor example?
- From: Gérard Iglesias <email@hidden>
- Date: Sun, 23 Sep 2001 00:53:19 -0700
Le samedi 22 septembre 2001, ` 10:35 , Michael B. Johnson a icrit :
>
Hi folks. I'm trying to write a view that changes the cursor depending
>
on what the hot keys the user is pressing, perhaps in conjunction with
>
a mouseDown: (i.e. translating the view, zooming in, zooming out,
>
etc.), and am looking for any example that shows how the right way to
>
do this.
>
>
Looking around, I'm coming up surprisingly blank (even Sketch just sets
>
a crosshair cursor and is done with it). The doc on
>
NSCursor/NSView/NSWindow is interesting, but not as clear as I'd like
>
on how the flow should be.
I use the following approach that I think is conform and generic:
In case of special key changed I override flagsChanged:
//
**************************************************************************
***
- (void)flagsChanged:(NSEvent *)theEvent
{
[[self window] invalidateCursorRectsForView:self];
}
Then I overide resetCursorRect: , modified from ScreenGlass (look at
softtrack)
- (void)resetCursorRects
{
// set the cross cursor for the view rect
if(!posTimer_)
{
NSCursor * cursor;
NSEvent * event = [[self window] currentEvent];
if ([event modifierFlags] & NSShiftKeyMask)
cursor = [NSCursor IBeamCursor];
else
cursor = [NSCursor reticuleCursor];
[self addCursorRect:[self bounds] cursor:cursor];
[cursor setOnMouseEntered:YES];
}
// tracking rect
if (flags_.trackingRectNeedUpdate){
[self setTrackingRect];
flags_.trackingRectNeedUpdate = NO;
}
}
Hope this help.
Gerard