FROM : I. Savant
DATE : Thu Jun 12 19:39:16 2008
> I have recently started programming on Mac using Objective-C and Cocoa. I am coming from C++/C# world.
Recant, heretic! ;-)
> In first line, I was expecting something like [self setColor:[NSColor blackColor]]; (similar to this.color = NSColor.blackColor; in C#/C++)
> how NSColor object knows about where to set the color?
In all seriousness, you'll need to read the Cocoa Drawing Guide. The
answer to this quesiton is found there. NSColor's -set method tells
the current drawing context to use that color as the current drawing
color. All drawing actions will happen with that color because it's
set as the current color.
> In second line, NSRectFill(), I was expecting it to be called using square bracket [] notation. Again how this function knows where to fill the rectangle? There is no reference of NSView passed into the function?
Using brackets means you're sending an object a message:
[someObject message];
As you might guess, NSRectFill() is a standard c function.
Obviously, the signature gives you a good clue. Again, this applies to
the current graphics context (which knows what view currently has
focus, and therefore its bounds).
--
I.S.
DATE : Thu Jun 12 19:39:16 2008
> I have recently started programming on Mac using Objective-C and Cocoa. I am coming from C++/C# world.
Recant, heretic! ;-)
> In first line, I was expecting something like [self setColor:[NSColor blackColor]]; (similar to this.color = NSColor.blackColor; in C#/C++)
> how NSColor object knows about where to set the color?
In all seriousness, you'll need to read the Cocoa Drawing Guide. The
answer to this quesiton is found there. NSColor's -set method tells
the current drawing context to use that color as the current drawing
color. All drawing actions will happen with that color because it's
set as the current color.
> In second line, NSRectFill(), I was expecting it to be called using square bracket [] notation. Again how this function knows where to fill the rectangle? There is no reference of NSView passed into the function?
Using brackets means you're sending an object a message:
[someObject message];
As you might guess, NSRectFill() is a standard c function.
Obviously, the signature gives you a good clue. Again, this applies to
the current graphics context (which knows what view currently has
focus, and therefore its bounds).
--
I.S.
| Related mails | Author | Date |
|---|---|---|
| Vikas | Jun 12, 19:26 | |
| Randall Meadows | Jun 12, 19:31 | |
| Hamish Allan | Jun 12, 19:33 | |
| Shawn Erickson | Jun 12, 19:36 | |
| I. Savant | Jun 12, 19:39 | |
| Vikas | Jun 12, 19:54 | |
| Hamish Allan | Jun 12, 20:14 | |
| I. Savant | Jun 12, 20:20 | |
| Mike Abdullah | Jun 12, 20:26 | |
| Kyle Sluder | Jun 12, 20:28 | |
| Jens Alfke | Jun 12, 20:33 | |
| Andy Lee | Jun 12, 20:45 |






Cocoa mail archive

