• 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: Rects and points...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rects and points...


  • Subject: Re: Rects and points...
  • From: Brendan Younger <email@hidden>
  • Date: Wed, 21 Nov 2001 00:04:21 -0500

On Tuesday, November 20, 2001, at 08:29 PM, John Hvrnkvist wrote:

On Wednesday, November 21, 2001, at 12:07 , Riccardo Santato wrote:

<snip>

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.

Just wanted to clarify: -drawRect: is used to draw within a given rectangle. I know the name is misleading, but it does not just draw a rectangle somewhere =). Core Graphics does that. Basically, all drawing within an NSView is implemented by the -drawRect: method. The rectangle passed is the dirty portion of the view so you don't have to redraw everything if only one part needs to be updated. Basically, the way Cocoa graphics works is thus:
NSWindow, NSView, NSControl, NSImage, etc. provide a object-oriented way to look at widgets, windows, and generic views. Each one of these classes actually performs its drawing by using the Core Graphics API, which is implemented in C for speed reasons. NSBezierPath uses Core Graphics too, but underneath the Obj-C level that you use.
The reason for having these object-based interface elements is quite simple. They haven't changed much since NeXTSTEP days (quite a feat considering the underlying graphics engine is entirely new) and can be pushed around, flipped, added and removed, very easily. And most importantly, you rarely have to write your own drawing code outside of graphics applications.
If you're looking for good tutorials, there are some on http://www.oreillynet.com/mac/.

Brendan Younger


  • Prev by Date: Re: Mutability
  • Next by Date: Re: Mutability
  • Previous by thread: Re: Rects and points...
  • Next by thread: Re: Laggy live scrolling in Cocoa
  • Index(es):
    • Date
    • Thread