Re: NSBezierPath
Re: NSBezierPath
- Subject: Re: NSBezierPath
- From: Public Look <email@hidden>
- Date: Tue, 2 Dec 2003 10:03:51 -0500
Animation is accomplished by drawing graphics in changing positions as
time goes by.
When graphics are drawn, pixels in the graphics card's frame buffer are
changed. In order to create the illusion of animation, you must change
any previously drawn pixels back to their previous states (erase the
graphics) and then redraw the graphics at a new position.
If you are already drawing a stationary background behind your
animation, you can "erase" the animating graphics by simply redrawing
the background and thus changing the pixels back to their background
values.
If you are not drawing any background behind your animation, then some
other view is. Ultimately, the window's content view draws the striped
or metal background.
Cocoa's application kit already knows how to draw any part of any view
including nested views and super views all the way back to the window's
content view. All you have to do is call the -display,
-displayInRect:,-setNeedsDisplay, or -setNeedsDisplayInRect: methods,
and all appropriate views will be redrawn in the correct order to
produce the correct pixel values. Of course, this automatic redrawing
only works if views do all of their drawing within the -drawRect:
method. All of the variants of -display end up calling -drawRect: to
do actual drawing.
If you don't do your drawing within -drawRect:, then the automatic
redrawing will not work, and you will have situations in which
animation does not happen correctly. Whatever you draw may get
overdrawn my normal application kit drawing of nested views, etc.
Assuming you are drawing the needle of a gauge, store the
position/angle/or value of the needle. Each time the value of the
needle changes, call -setNeedsDisplay. Your drawRect: method will
automatically be called at the right time for you to draw the needle
based on the current value/position/angle or whatever. All of the
background views will have already drawn. All of the nested views will
draw after the needle.
You can use a timer to constantly change the needle's value and call
-setNeedsDisplay to cause continuous animation.
This is very very basic information, and I was reluctant to write this
type of detail before because I assumed that you would already know it.
I recommend that you investigate the many books on computer graphics
that are available. Armed with basic information about computer
graphics, I recommend that to read "Cocoa Programming" for its lengthy
section on graphics, views, etc.
On Dec 2, 2003, at 12:07 AM, Daniel Todd Currie wrote:
Since my view does not resize, this is of little concern to me... are
there other reasons I might want to use drawRect:? It seems to me
that it is easier the way i have done it, not having to use a subclass
and having access to instance variables, etc.
I'm not sure what you mean by "redrawing the background". There do
not seem to be any methods dealing with backgrounds in NSView, and I
have never drawn a background, let alone redrawn one. Could you
perhaps be more specific regarding the actual methods that I might use
to do as you suggest? thanks much
_______________________________________________
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.