• 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
Re: Hillegass Book (3rd Edition): Chapter 18 Challenge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hillegass Book (3rd Edition): Chapter 18 Challenge


  • Subject: Re: Hillegass Book (3rd Edition): Chapter 18 Challenge
  • From: Grant Limberg <email@hidden>
  • Date: Mon, 26 May 2008 17:42:11 -0700

And as usual, I figure it out right after I send an email to the list

I forgot to set the color of the line to something other than white and had [currentPath stroke] commented out.

Grant Limberg
email@hidden
LinkedIn: http://www.linkedin.com/in/grantlimberg
http://www.glsoftware.net

On May 26, 2008, at 5:33 PM, Grant Limberg wrote:

I'm going through Aaron HIllegass' new book and I'm having a bit of trouble on the first part of the Challenge in chapter 18. You're supposed to write a simple drawing app where the user can draw ovals on a custom view by clicking and dragging. I have it working for the most part except that the oval isn't actually displayed on the screen until after the mouseUp: event has happened. Any ideas on how to get it to draw while the mouse is being dragged? Here's some of the pertinent code. Thanks in advance.

-(void)drawRect:(NSRect)rect {
	NSLog(@"drawRect:");
	NSRect bounds = [self bounds];

	[[NSColor whiteColor] set];
	[NSBezierPath fillRect:bounds];

	//[currentPath stroke];
	[NSBezierPath strokeRect:[self currentRect]];

	for(NSBezierPath *oval in ovals) {
		[[NSColor blueColor] set];
		[oval stroke];
	}
}

-(void)addOval:(NSRect)rect {
	NSBezierPath *thePath =currentPath;
	[ovals addObject:thePath];
	[self setNeedsDisplay:YES];
}

#pragma mark Events

-(void)mouseDown:(NSEvent*)event {
	NSLog(@"mouseDown: %d", [event clickCount]);
	NSPoint p = [event locationInWindow];
	downPoint = [self convertPoint:p fromView:nil];
	currentPoint = downPoint;
	currentPath = [[NSBezierPath alloc] init];
	[self setNeedsDisplay:YES];
}

-(void)mouseDragged:(NSEvent*)event {
NSPoint p = [event locationInWindow];
NSLog(@"mouseDragged: %@", NSStringFromPoint(p));
currentPoint = [self convertPoint:p fromView:nil];
currentPath = [NSBezierPath bezierPathWithOvalInRect:[self currentRect]];
[self autoscroll:event];
[self setNeedsDisplay:YES];
}


-(void)mouseUp:(NSEvent*)event {
	NSLog(@"mouseUp:");
	NSPoint p = [event locationInWindow];
	currentPoint = [self convertPoint:p fromView:nil];
	[self addOval:[self currentRect]];
	[self setNeedsDisplay:YES];
}

-(NSRect)currentRect {
	float minX = MIN(downPoint.x, currentPoint.x);
	float maxX = MAX(downPoint.x, currentPoint.x);
	float minY = MIN(downPoint.y, currentPoint.y);
	float maxY = MAX(downPoint.y, currentPoint.y);

	return NSMakeRect(minX, minY, maxX-minX, maxY-minY);
}

Grant Limberg
email@hidden
LinkedIn: http://www.linkedin.com/in/grantlimberg
http://www.glsoftware.net

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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:
@glsoftware.net


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


References: 
 >Hillegass Book (3rd Edition): Chapter 18 Challenge (From: Grant Limberg <email@hidden>)

  • Prev by Date: Re: Hillegass Book (3rd Edition): Chapter 18 Challenge
  • Next by Date: Re: No-frills print to label printer help please
  • Previous by thread: Re: Hillegass Book (3rd Edition): Chapter 18 Challenge
  • Next by thread: Re: Hillegass Book (3rd Edition): Chapter 18 Challenge
  • Index(es):
    • Date
    • Thread