• 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
drawRect problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

drawRect problem


  • Subject: drawRect problem
  • From: Ken Tozier <email@hidden>
  • Date: Fri, 23 Feb 2007 14:26:45 -0500

Hi

Is it possible to mark two separate rects as needing display? I wrote a custom view that draws cells and when two cells butt, mouse movement out of one cell into another is a simultaneous event. I tried saving reference to the last "mouseover" cell but despite many different attempts, I can't get the drawing right. What's happening is that new cells hilight but old ones don't.

Here's the methods I use to hilight a cell

- (void) sampleMouse:(NSTimer *) inTimer
{
NSPoint windowPoint = [[self window] mouseLocationOutsideOfEventStream];

// make sure the point has changed since the last sample
if (NSEqualPoints(windowPoint, lastPoint) == NO)
{
// convert from window coordinates to view coordinates
NSPoint viewPoint = [self convertPoint: windowPoint fromView: [self superview]];//[[self window] contentView]];

// save windowPoint point for future reference
lastPoint = windowPoint;

// see if viewPoint is in usable rect
if (NSPointInRect(viewPoint, usableRect) == YES)
[self hilightCell: [self cellForPoint: viewPoint]];
else
[self hilightCell: nil];
}
}


- (void) hilightCell:(id) inCell
{
if ((inCell == nil) && (lastCell != nil))
{
NSRect cellRect = [self rectForCell: lastCell];
NSLog(@"unhilighting cell: %i, rect: %@", [cells indexOfObject: lastCell], [NSDictionary dictionaryWithNSRect: cellRect]);

// unhighlight mouse cell
[lastCell mouseEntered: nil];
[self setNeedsDisplayInRect: cellRect];
}
else if (inCell != lastCell)
{
NSRect cellRect = [self rectForCell: inCell];
NSLog(@"hilighting cell: %i, rect: %@", [cells indexOfObject: inCell], [NSDictionary dictionaryWithNSRect: cellRect]);

lastCell = inCell;

// we're no longer in the cell
[lastCell mouseEntered: nil];
[self setNeedsDisplayInRect: cellRect];
}
}



And here's the drawRect method

- (void) drawRect:(NSRect) rect
{
float oldHeight = height,
oldWidth = width;

// update the geometry
[self updateGeometry];

BOOL sizeChanged = ((oldHeight == height) && (oldWidth == width)) ? NO : YES ;

[backColor set];


if (sizeChanged == YES)
{
// this reflows the cells based on the view width
NSEnumerator *enumerator = [cells objectEnumerator];
id cell;
NSRect curFrame = [self frame],
cellRect = NSMakeRect(margin, margin, cellWidth, cellHeight),
newFrame = NSMakeRect(curFrame.origin.x, curFrame.origin.y, curFrame.size.width, height);

float max = [self maxX];

NSRectFillUsingOperation(newFrame, NSCompositeSourceOver);

while (cell = [enumerator nextObject])
{
if (cellRect.origin.x + cellWidth + horizontalSpacing > max)
{
cellRect.origin.x = margin;
cellRect.origin.y += cellHeight + verticalSpacing;
}

if (active)
[cell mouseEntered: nil];

[cell drawWithFrame: cellRect
inView: self];

cellRect.origin.x += cellWidth + horizontalSpacing;
}
}
else if (lastCell != nil)
{
NSLog(@"drawing mouse cell");

NSRect cellFrame = [self rectForCell: lastCell];

NSRectFillUsingOperation(cellFrame, NSCompositeSourceOver);
[lastCell drawWithFrame: cellFrame inView: self];

lastCell = nil;
}
}



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: drawRect problem
      • From: Uli Kusterer <email@hidden>
    • Re: drawRect problem
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: Re: NSObjectController and Core Data
  • Next by Date: Re: NSObjectController and Core Data
  • Previous by thread: Permissions
  • Next by thread: Re: drawRect problem
  • Index(es):
    • Date
    • Thread