Re: From Carbon to Cocoa
Re: From Carbon to Cocoa
- Subject: Re: From Carbon to Cocoa
- From: Scott Thompson <email@hidden>
- Date: Tue, 20 Jul 2004 15:22:06 -0500
On Jul 20, 2004, at 2:57 PM, Tim Conkling wrote:
As a new Cocoa developer, I'm having a bit of difficulty figuring out
how to do things the Cocoa way -- my brain is stuck in Carbon-land.
Trying to figure out how to programatically make an NSWindow visible,
for example, took me a long time -- I was looking for methods like
show:, makeVisible:, setVisible:, etc, until I finally stumbled on
makeKeyAndOrderFront:, which does what I want (well, it displays the
window) but has a name that confuses the heck out of me.
Welcome to the club. I too am a fugitive from Carbon-land :-)
"Make Key" means that that window will be the window with the keyboard
focus. "Order Front" means put it in the front of the window list
(make it the first window in the window "order"). A window can also be
"ordered out" which means that it's not displayed on the screen.
I'm wondering if someone has taken it upon themselves to write a
"Cocoa for Carbon Programmers" guide that describes the Cocoa method
of doing common things like displaying a window. Apple's Cocoa
documentation is great, but all of a sudden I feel like I did back
when I was first learning the Toolbox -- that is, it's hard for me to
even know where to look to find information on basic tasks.
Get one of the "intro to cocoa" books and run through the demos they
ask you to construct. They will get you familiar with the basics.
Specifically, I'm currently trying to figure out the relationship
between NSWindows, NSViews, and CGContexts so that I can use Quartz
APIs (also new to me; I'm used to QD) to draw things into a window.
NSWindow is like a Carbon WindowRef.
NSView is a rectangular drawing area within an NSWindow that knows how
to respond to events as well.
Cocoa maintains a single CGContext which is the "current CGContext"...
much like QuickDraw's current port.
However, most of the Cocoa drawing I've done, I don't draw directly
into CGContexts. More often what happens is I will use NSBezierPath to
construct a path and then use the path inside of a call to one of my
view's "drawRect:" methods.
To wit:
@impelmentation MyStupidView
- (void) drawRect: (NSRect)
{
[NSGraphicsContext saveGraphicsState];
NSBezierPath *linePath = [NSBeizerPath bezierPath];
[linePath moveToPoint: NSMakePoint(0,0)];
[linePath lineToPoint: NSMakePoint(100, 100)];
[linePath setLineWidth: 2.0];
[linePath stroke];
[NSGraphicsContext restoreGraphicsState];
}
@end // MyStupidView
(I don't know that that "code" will complie, but you should be able to
get the gist of it).
Scott
_______________________________________________
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.