Re: Drawing onto NSImageView subclass (Newbie)
Re: Drawing onto NSImageView subclass (Newbie)
- Subject: Re: Drawing onto NSImageView subclass (Newbie)
- From: Alan Cook <email@hidden>
- Date: Mon, 9 Feb 2004 18:26:34 -0800 (PST)
Hi Jens,
That makes sense now. Don't know why I never thought of that. I guess
the permanence of the dots without an image there, threw me off. I
think I'll use your NSPoint wrapper, and I'll making a Location object
containing the descriptive information specific to my app. Now that
that problem is solved I can work on the rest of the algorithms. (I'll
code it a little tonight and hopefully finish tomorrow, anyway.)
Actually, for the wrapper, some hints on something faster would be most
appreciated. I'll try to learn as I go, and come back here if I get
hung up.
Thanks,
Alan Cook
--- Jens Bauer <email@hidden> wrote:
>
Hi Alan,
>
>
You're only drawing one point in your drawing code.
>
>
Why you see more than one point, when you specify an image, is
>
because
>
the image erases the point first.
>
>
You should remember all the points you want to draw, in some kind of
>
buffer.
>
You could use an array of points (you can't just add a NSPoint to a
>
NSArray, because NSPoint is not a subclass of NSObject, it's just a
>
plain structure).
>
>
This would probably work, but would be slow if you're going to add
>
many
>
points:
{snip}
>
There's a more complicated way, which is *way* faster, and uses less
>
memory. Let me know, if this isn't good enough, and I'll spend some
>
time on coming up with a solution.
>
>
...So in short: Create a NSMutableArray in your -initWithFrame for
>
your
>
view...
>
pointArray = [[NSMutableArray array] retain];
>
>
...and in your mouseDown, you add the point by...
>
pt = [[MyPoint alloc] initWithPoint:center];
>
[pointArray addObject:pt];
>
...in your drawRect, you could iterate through all these points and
>
draw each of them by...
>
count = [pointArray count];
>
for(i = 0; i < count; i++)
>
{
>
[self addPoint:[[pointArray objectAtIndex] point]];
>
}
>
...and remember in your dealloc...
>
[pointArray release];
>
...That should do it.
{snip}
>
Love,
>
Jens
>
__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
_______________________________________________
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.