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

Hillegass, Third Edition, Chapter 18


  • Subject: Hillegass, Third Edition, Chapter 18
  • From: "Jon Buys" <email@hidden>
  • Date: Mon, 14 Jul 2008 22:53:52 -0500

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

  • Follow-Ups:
    • Re: Hillegass, Third Edition, Chapter 18
      • From: Antonio Nunes <email@hidden>
    • Re: Hillegass, Third Edition, Chapter 18
      • From: Aron Nopanen <email@hidden>
  • Prev by Date: Re: [Q] Any document that shows differences of Cocoa programming for Mac and for the iPhone/iPod touch?
  • Next by Date: Re: KVO notifications and threads
  • Previous by thread: Mouse events in NSTextFieldCell
  • Next by thread: Re: Hillegass, Third Edition, Chapter 18
  • Index(es):
    • Date
    • Thread