Re: Drawing faster with NSImage???
Re: Drawing faster with NSImage???
- Subject: Re: Drawing faster with NSImage???
- From: Andre Lipinski <email@hidden>
- Date: Tue, 18 Dec 2001 23:58:48 -0500
On Monday, December 17, 2001, at 04:23 PM, Joshua Orr wrote:
On Monday, December 17, 2001, at 01:40 PM, Nat! wrote:
On Montag, Dezember 17, 2001, at 08:41 Uhr, Joshua D. Orr wrote:
I have a app that does a lot of drawing. I have been thinking if
I draw to
an NSImage and then when they scroll around, the just scroll around the
NSImage. When they change something I could recalculate the
NSImage. I am
trying to find the best way to do this, does anyone have any
suggestions?
You could make your drawing code a subclass of NSImageRep (not
NSBitmapImageRep I suppose) and do your drawing there. The NSImage
that owns that imageRep will automatically cache the drawing for
you. You may need to recache the NSImage (throw away the cache),
when something changed.
Cheers
Nat!
-----------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
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.
Right now I use a subclass of NSView to draw everything using
NSBezierPath's. Would this type of drawing work with NSImageRep and
NSImage? I also need to know where the user clicks in the NSView in the
window. Would NSImageRep user actions like that? I was originally
thinking I could somehow draw into a NSImage when something changed, and
then draw the NSImage into the NSView until I needed to redraw it.
Another question I just thought of: Could I just re-draw portions of the
NSImage, so I don't have to redraw the entire image when only something
small changed?
The ultimate thing I want to do is just somehow cache my drawing so that
when the user scrolls around the NSView, it does nto have to keep
redrawing all the lines, etc. with NSBezierPath's. I have looked all
over the docs, and it looks like doing it with an NSImage would be the
way to go, but I am now sure. Any suggestions would be helpful! If an
NSImage is the way to go, could someone just briefly tell me what would
the best way to go about would be?
- Mouse events will be gathered by NSView or NSImageView, both of which
you can draw into and cache using
initWithFocusedViewRect:
- You should use NSImageView and set the image to the one you draw into or
cache from above. when it's time to redisplay AppKit will take care of
displaying only the rectangles needed to get the job done.
You'll need to monitor scrolling from your scroll view or scrollers as
well as window resizing and make amendments to you image as needed. I
think you can set an origin for the image somewhere, not sure right now.
You're going to have to decide how much memory you want to use with this
method as it can become quite a burden. You may like to chop off older
parts of the image as the user scrolls. Furthermore, you still have to
draw everything once with this method AND draw that image on the screen.
It'll be intense.
You might want to just copy on scroll, see NSClipView. There's also cached
image rect's that you can use to replace stuff when moving the mouse & etc
around and other methods to just shift a view's contents while scrolling.
Andre.