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