Re: Rects and points...
Re: Rects and points...
- Subject: Re: Rects and points...
- From: John Hörnkvist <email@hidden>
- Date: Wed, 21 Nov 2001 02:29:30 +0100
On Wednesday, November 21, 2001, at 12:07 , Riccardo Santato wrote:
First of all , THANK YOU ALL !!!! :-))
You've been too kind for the lots of answers. The sad thing is that a
huge number of doubts raised into my head...
I think I had several problems in drawing this stupid thing just because
I really can't understand from the docs the meanings of the classes. If
you consider, my experiment was much greater than the real needs (I
involved convertPoint and many other things), as I was desperately
trying
to get a grip on those things :
1) I can't understand the differences, NOW , between Rects, Views,
Images
in the Cocoa environment...
An NSView is an object that represents a region in a window (or image)
where you can perform drawing. A view can have subviews.
An NSRect is a structure, not an object. A rectangle is just an origin
(as an NSPoint) and a size (as an NSSize).
An NSImage is an object that represents some data that can be drawn.
When you call "display" something like this happens:
[aView lockFocus]; // Now drawing goes to aView, and we use aView's
coordinate system.
[aView drawRect:[aView bounds]];
[aView unlockFocus]; // Reset the coordinates, device transforms, etc
2) I was trying to make the coordinates as much as view-relative as
possible. I figured a better way would have been to set them from the
origin of the view in a RELATIVE and not ABSOLUTE way. That's is also
the
cause I used the convertPoint routines...
When you've called lockFocus, the coordinate system has its origin in
your view.
3) In the first example Tom sent me, there was just one function, in the
later one several... but... HOW can Cocoa know which one is to call at a
desired time without using NSTimer things or mouse /keyboard / task
events ?!?
At the top of the runloop, it checks if there are any dirty views and
redraws them. It notices that a view is dirty when [aView
setNeedsDisplay:YES] or [aView setNeedsDisplayInRect:someRect] is called.
You need to call these when you want the view to be redrawn, but usually
it will be done automatically.
4) If a method like drawRect: is already present in the NSView class,
why
must I repeat it ?
Because you're the only one who nows what you want to draw. Often,
drawRect: is the one method you override in a view.
5) Why didn't Apple supplied GOOD step-by-step tutorials on graphic
handling, event handling, file handling and similar ?!?
In Cocoa you rarely have to bother with manual event handling. When you
do, you use NSRunLoop and NSEvent.
Pardon me, I'm a newcomer in Apple programming, as far as under AmigaOS
3.9 was much much more simple !! :-))
Unless things changed a lot after 3.0, they were nowhere near as
simple. :)
For an easier way of dealing with graphics, check the GraphicKit,
<
http://www,toastedmarshmallow.com/Frameworks>.
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com