• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSRect, views....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRect, views....


  • Subject: Re: NSRect, views....
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Wed, 27 Aug 2003 11:36:53 +0100

On Wednesday, August 27, 2003, at 08:02 am, April Gendill wrote:

Because I do not understand the coordinate system or how to define an NSRect i do not know how to do this.

1. Co-ordinate system. The normal Mac OS X (Quartz) co-ordinate system looks like this:

: : : : : : :
5 +---+---+---+---+---+---+ ..
| | | | | | |
4 +---+---+---+---+---+---+ ..
| | | | | | |
3 +---+---+---+---+---+---+ ..
| | | | | | |
2 +---+---+---+---+---+---+ ..
| | | | | | |
1 +---+---+---+---+---+---+ ..
| | | | | | |
0 +---+---+---+---+---+---+ ..
0 1 2 3 4 5 6

Notice that the co-ordinates correspond to the *grid* and *not* to the pixels (so the centre of the bottom-left pixel has coordinates 0.5, 0.5). Notice also that the co-ordinates increase in the upward direction.

If the view you are working in is flipped (see NSView's -isFlipped method), then the co-ordinate space looks like this instead:

0 1 2 3 4 5 6
0 +---+---+---+---+---+---+ ..
| | | | | | |
1 +---+---+---+---+---+---+ ..
| | | | | | |
2 +---+---+---+---+---+---+ ..
| | | | | | |
3 +---+---+---+---+---+---+ ..
| | | | | | |
4 +---+---+---+---+---+---+ ..
| | | | | | |
5 +---+---+---+---+---+---+ ..
: : : : : : :

2. Defining NSRects is easy. NSRect is just a structure containing an NSPoint and an NSSize:

typedef struct _NSRect {
NSPoint origin;
NSSize size;
} NSRect;

so if you want you can just access the members of the structure (similarly with NSPoint and NSSize). However, Cocoa provides some convenience functions that you can use instead (for example, NSMakeRect()); see the Foundation documentation for more information (I find it easiest to use AppKiDo for this sort of thing).

When laying-out views, you probably want to use NSDivideRect() rather than doing the calculations by hand.

Note that NSRect doesn't have any special significance to the GUI... it isn't even an object. If you want to place a view in a superview, you need to use -addSubview: on the superview, then -setFrame: on the subview (or some combination of -setFrameOrigin: and -setFrameSize:).

Kind regards,

Alastair.
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSRect, views....
      • From: April Gendill <email@hidden>
References: 
 >NSRect, views.... (From: April Gendill <email@hidden>)

  • Prev by Date: Re: Slow converting index color to RGB
  • Next by Date: Re: Slow converting index color to RGB
  • Previous by thread: NSRect, views....
  • Next by thread: Re: NSRect, views....
  • Index(es):
    • Date
    • Thread