NSView and setNeedsDisplayInRect:rect
NSView and setNeedsDisplayInRect:rect
- Subject: NSView and setNeedsDisplayInRect:rect
- From: email@hidden
- Date: Sun, 10 Nov 2002 02:51:03 +0100
Hello everybody!
I've been working on an application which should display a given
2D-vector. The app is rather simple and I use NSBezierPath to draw the
coordinate system as well as background and the vector. In the static
mode everything works just fine.
I then started experimenting with an NSTimer to animate a rotating
vector. In my first implementation i used the [vectorDisplay
setNeedsDisplay:YES] message to draw my custom NSView. This too worked
well, but I didn't get the performance I wanted. I then figured that I
could optimize my code by using the [vectorDisplay
setNeedsDisplayInRect:dirtyRect] since I then should be redrawing only
the updated part of the NSView. This however gave me some very
interesting (and not very welcome) graphical disorders which I don't
know how to treat.
In the first quarter of the coordinate system the vector is displayed
correctly, see picture:
http://homepage.mac.com/jontolof/.Pictures/VectorDisplay1.jpg
But when reaching the second quarter it seems like the updated
rectangle is very much wrong. See for yourself on the screenshot:
http://homepage.mac.com/jontolof/.Pictures/VectorDisplay2.jpg
Also when I use the Quarz debugger I get the following results:
http://homepage.mac.com/jontolof/.Pictures/VectorDisplayQuartz.jpg
...which is very strange because the dirtyRect that I send to the
setNeedsDisplayInRect:dirtyRect is an NSRect made by the origo and the
point of the vector.
This really bugs me and maybe I've misunderstood the entire
setNeedsDisplayInRect:dirtyRect - method, in that case, please help me
out.
In short, how do I get setNeedsDisplayInRect:dirtyRect to redraw but
the rectangle between the origo and the point of the vector?
Source code for those who find it helpful or interesting.
Thank you all in advance
/Jont Olof
/* JOLVectorView */
#import <Cocoa/Cocoa.h>
#import "Vector.h"
@interface JOLVectorView : NSView
{
NSBezierPath *path;
Vector *v;
}
- (void)updateVector:(Vector *)vector;
- (void)clearView;
@end
[demime 0.98b removed an attachment of type application/octet-stream which had a name of Vector.m]
//
// MyDocument.h
// VectorDisplay
//
// Created by Jont Olof on Thu Jan 01 1970.
// Copyright (c) 2002 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "JOLVectorView.h"
#import <math.h>
@class Vector;
@interface MyDocument : NSDocument
{
Vector *vector;
int count;
NSTimer *timer;
IBOutlet NSTextField *xField;
IBOutlet NSTextField *yField;
IBOutlet NSTextField *rField;
IBOutlet NSTextField *vField;
IBOutlet NSTextField *langdField;
IBOutlet NSTextField *angleField;
IBOutlet NSProgressIndicator *progressView;
IBOutlet NSView *vectorDisplay;
IBOutlet NSTextField *sliderValue;
}
- (IBAction)typeX:(id)sender;
- (IBAction)typeY:(id)sender;
- (IBAction)typeR:(id)sender;
- (IBAction)typeV:(id)sender;
- (IBAction)stopGo:(id)sender;
- (void)updateAngle:(NSTimer *)aTimer;
@end
//
// Vector.h
// VectorDisplay
//
// Created by Jont Olof on Thu Jan 01 1970.
// Copyright (c) 1970 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <math.h>
@interface Vector : NSObject
{
float x, y;
}
- (id)initVectorWithX:(float)initX andY:(float)initY;
- (float)getX;
- (void)setX:(float)newX;
- (float)getY;
- (void) setY:(float)newY;
- (float)langd;
@end
[demime 0.98b removed an attachment of type application/octet-stream which had a name of JOLVectorView.m]
[demime 0.98b removed an attachment of type application/octet-stream which had a name of MyDocument.m]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.