Jon,

Your post sounds like a statement of fact more than a question, but I assume you're wondering why you can't draw multiple ovals? The view will be redrawn at various points, outside of your control, and your drawRect: routine must re-draw all previously-drawn ovals each time. This means you have to store the ovals in an array or similar and iterate through them each time.

I have an implementation that does this, along with supporting undo/ redo and save to file/open from file; I'm happy to send you the source if you'd like to refer to it.

-Aron

On 15/07/2008, at 3:53 PM, Jon Buys wrote:

Hello All,
I'm working through the challenge app at the end of Chapter 18 of Cocoa Programming, Third Edition. I've got my app to the point where it can draw ovals, but each time I click in the window it seems like the view redraws itself. I'm sure that this is a very simple question with a very simple answer, but I'm stuck. I've been looking at it for three days now, and I
think its time to let another set of eyes look at it.

Any help would be greatly appreciated.

Thanks,

Jon

On a separate note, anyone else working through this book, please feel free
to get in touch.  Maybe we can help each other out!

code follows:

ChalkBoard.m:

//

//  ChalkBoard.m

//  OvalDraw

//

//  Created by Jon on 7/10/08.

//  Copyright 2008 __MyCompanyName__. All rights reserved.

//


#import "ChalkBoard.h"



@implementation ChalkBoard


- (void)drawRect:(NSRect)rect

{

NSRect bounds = [self bounds];

[[NSColor blackColor] set];

[NSBezierPath fillRect:bounds];

NSRect ovalRect = [self currentRect]; //OK, so this should not be here,
but where can I put it so the window will remember it and not redraw?

[[NSColor whiteColor] set];

[[NSBezierPath bezierPathWithOvalInRect:ovalRect] stroke];


[oval stroke];

}



#pragma mark Events


- (void)mouseDown:(NSEvent *)event

{

NSLog(@"mouseDown: %d", [event clickCount]);

NSPoint p = [event locationInWindow];

downPoint = [self convertPoint:p fromView:nil];

currentPoint = downPoint;

[self setNeedsDisplay:YES];

}



- (void)mouseDragged:(NSEvent *)event

{

NSPoint p = [event locationInWindow];

NSLog(@"mouseDragged:%@", NSStringFromPoint(p));

currentPoint = [self convertPoint:p fromView:nil];

[self setNeedsDisplay:YES];


}


- (void)mouseUp:(NSEvent *)event

{

NSPoint p = [event locationInWindow];

NSLog(@"mouseUp:%@", NSStringFromPoint(p));

currentPoint = [self convertPoint:p fromView:nil];


[self setNeedsDisplay:YES];


}



#pragma mark Accessors




- (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);

}


@end
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/ardnopes%40yahoo.com

This email sent to [EMAIL PROTECTED]

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to