XCode Design - How to create a map?
So I basically have a bunch of routes (think of 3D positions) and I'd like to draw them in a view.
I haven't actually done anything w/graphics before and was curious how I should even start thinking about doing this in XCode w/my Cocoa app.
Anyone have any suggestions?
Should I subclass NSView? Should I use OpenGL?
Thanks!
Edit: So I was able to subclass NSView, see here: http://groovyape.com/map.png
Is this the best way? (I realize it's only 2D, I'm afraid to try 3D heh). And what if i want to 开发者_高级运维allow people to click on the circles - how can I do this?
In your NSView subclass you can override the various mouse event handlers to do whatever you want:
- (void)mouseDown:(NSEvent *)event;
- (void)mouseDragged:(NSEvent *)event;
- (void)mouseUp:(NSEvent *)event;
Then you'll need a way to know where the circles are so you'll know when they've been clicked in. If you have a circle as an NSPoint and the radius then something like this will work
- (BOOL)isPoint:(NSPoint)click inCircleAtPoint:(NSPoint)centre withRadius:(float)r
{
float dx = click.x - centre.x;
float dy = click.y - centre.y;
// Get the distance from the click to the centre of the circle
float h = hypot (dx, dy);
// is the distance less than the radius?
return (h < r);
}
- (void)mouseDown:(NSEvent *)event
{
NSPoint clickPoint = [event locationInWindow];
if ([self isPoint:clickPoint inCircleAtPoint:mapPoint withRadius:5.0]) {
// Click was in point
}
}
精彩评论