Re: Custom View Tracking Rectangle
Re: Custom View Tracking Rectangle
- Subject: Re: Custom View Tracking Rectangle
- From: Sunil <email@hidden>
- Date: Fri, 9 Apr 2004 09:13:05 +0530
Hi Seth Willits,
Ya you are right am also able get the mouse moved events (i.e
mouseEntered, mouseExited) with the same type of code
but when i place the code "trackingTag = [self addTrackingRect:[self
bounds] owner:self
>
userData:nil assumeInside:NO];" in drawRect am able get the mouseDown
>
events why it is happening like that i dont know. If u know plz let me
>
know.
-Sunil.
On 09-Apr-04, at 5:55 AM, email@hidden wrote:
>
I'm trying to install a tracking rectangle so I can implement a
>
rollover image, but the mouseEntered event never fires. The code below
>
is what I'm using. The view in question is embedded within two other
>
views if that makes a difference.
>
>
>
- (id)initWithFrame:(NSRect)frame {
>
self = [super initWithFrame:frame];
>
if (self) {
>
>
// Set State
>
_state = 0;
>
>
// Install Tracking Rectangle
>
trackingTag = [self addTrackingRect:[self bounds] owner:self
>
userData:nil assumeInside:NO];
>
}
>
return self;
>
}
>
>
>
- (void)drawRect:(NSRect)rect
>
{
>
switch (_state) {
>
// Up
>
case 0:
>
[[NSImage imageNamed:@"TabClose_Front"]
>
compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeSourceAtop];
>
break;
>
// Down
>
case 1:
>
[[NSImage imageNamed:@"TabClose_Front_Pressed"]
>
compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeSourceAtop];
>
break;
>
// Hover
>
case 2:
>
[[NSImage imageNamed:@"TabClose_Front_Rollover"]
>
compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeSourceAtop];
>
break;
>
}
>
}
>
>
- (void)mouseDown:(NSEvent *)theEvent
>
{
>
// Set State and Redraw
>
_state = 1;
>
[self display];
>
}
>
>
- (void)mouseUp:(NSEvent *)theEvent
>
{
>
// Set State and Redraw
>
_state = 0;
>
[self display];
>
>
// Fire Action
>
if (_target && _selector && [_target respondsToSelector:_selector])
>
[_target performSelector:_selector];
>
}
>
>
- (void)mouseEntered:(NSEvent *)theEvent
>
{
>
NSBeep();
>
>
// Set State and Redraw
>
_state = 2;
>
[self display];
>
}
>
>
- (void)mouseExited:(NSEvent *)theEvent
>
{
>
// Set State and Redraw
>
_state = 0;
>
[self display];
>
}
>
>
>
>
>
>
Seth Willits
>
-----------------------------------------------------------------------
>
-
>
---
>
President and Head Developer of Freak Software - http://www.freaksw.com
>
REALbasic Guru at ResExcellence -
>
http://www.resexcellence.com/realbasic
>
Webmaster for REALbasic Game Central - http://www.freaksw.com/rbgames
>
>
Friendship is a beautiful thing. "The best and most beautiful things in
>
the
>
world cannot be seen or even touched - they must be felt with the
>
heart."
>
-- Hellen Keller
>
-----------------------------------------------------------------------
>
-
>
---
>
>
--__--__--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.