Re: NSRect, views....
Re: NSRect, views....
- Subject: Re: NSRect, views....
- From: Henry McGilton <email@hidden>
- Date: Wed, 27 Aug 2003 10:24:40 -0700
On Wednesday, August 27, 2003, at 08:13 AM, April Gendill wrote:
Oh, my...
This is no small affair...
Looks like I've opened a can of worms here.
By the way what is Appkido? is it a third party frame work? or a
information source or a typo?
AppKiDo is a third party documentation browser --- super application
for finding your way through the documentation BWOS. The name looks
like a word play on AikiDo to me.
any way... nssize, nsorigin... ok so I need to break out the pen and
paper and hit the books kinda hard i guess.
For a good overview of views, drawing, and coordinate systems, start
with this
document:
file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/DrawViews/index.html
paying special attention to the topic entitled "The View Hierarchy".
Then scan the topics from "Displaying a View" through "Transforming
Coordinate Systems in a View".
Then take a look at the Foundation Functions for 'Points', 'Sizes',
and 'Rects'. Also see the Foundation Types and Constants for
'NSPoint', 'NSSize', and 'NSRect'. And then see the Application Kit
Functions for 'Graphics', which describes drawing operations using
NSRects.
As far as I know, there is no such thing as a NSOrigin --- the origin
of a NSRect is a NSPoint.
The amount of stuff you have to learn is not nearly as imposing as
it appears. The imaging models and view hierarchies are built on a
few relatively simple ideas (like all good systems should be).
Simplifying enormously, the basic object into which you draw is a
NSView.
The position and size of a NSView within its super NSView is described
by
a NSRect(angle). A NSRect is defined by an origin (NSPoint) and a size
(NSSize).
Drawing rectangular areas within a NSView is trivial:
o make a NSRect,
o set a colour,
o call NSRectFill.
The most trivial example of which is to fill the entire NSView with
a colour (withing the drawRect method):
o set a colour,
o NSRectFill([self bounds]);
Drawing non-rectangular shapes within a NSView is done using
NSBezierPath. Changing the shape of the coordinate system within a
NSView is
done using NSAffineTransform, possibly in conjunction with NSBezierPath.
The subtle and not very well explained distinction between view frame
and
view bounds is explained with pictures in this document:
file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/DrawViews/index.html
A bit of history:
The default Cocoa coordinate system is a First Quadrant coordinate
system, with (0, 0) at the lower left, same as you learn in basic
school geometry and trigonometry at age twelve. This is historical:
The NextStep (and OpenStep) --- the ancestors of Cocoa imaging models
were based on the Display PostScript system imaging models, which were
in turn based on the PostScript (Page Description Language) imaging
models developed by Adobe. The founders of Adobe were mostly
mathematicians
(as opposed to computer propellor heads), so they went with a standard
First Quadrant Cartesian coordinate system.
Coming from a mathematics and electrical engineering background, the
PostScript/Cocoa imaging models seem perfectly reasonable to me, whereas
the common computer origin at upper left simply looks 'wrong' to me.
Best Wishes,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
|
===============================+============================
_______________________________________________
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.