• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Custom View Tracking Rectangle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom View Tracking Rectangle


  • Subject: Custom View Tracking Rectangle
  • From: Seth Willits <email@hidden>
  • Date: Thu, 8 Apr 2004 16:52:19 -0700

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.


  • Prev by Date: Re: setNeedsDisplay: thread safe?
  • Next by Date: Re: Best way to obtain the width of a piece of text?
  • Previous by thread: Re: setNeedsDisplay: thread safe?
  • Next by thread: Re: Custom View Tracking Rectangle
  • Index(es):
    • Date
    • Thread