• 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, Third Edition, Chapter 18
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hillegass, Third Edition, Chapter 18


  • Subject: Re: Hillegass, Third Edition, Chapter 18
  • From: Aron Nopanen <email@hidden>
  • Date: Tue, 15 Jul 2008 18:30:17 +1200

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

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

_______________________________________________

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, Third Edition, Chapter 18 (From: "Jon Buys" <email@hidden>)

  • Prev by Date: Re: Questions about Core Data and SQLite
  • Next by Date: Re: Hillegass, Third Edition, Chapter 18
  • Previous by thread: Hillegass, Third Edition, Chapter 18
  • Next by thread: Re: Hillegass, Third Edition, Chapter 18
  • Index(es):
    • Date
    • Thread