Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
Hi,

Sorry, for stupid question. I can't to draw line in NSView control.
Requirements are next:
- I have NSView and NSButton controls on the window.
- When I click button line should draw in the NSView control.

What should I type in my pushButtonAction ?

I allready typed:
- (IBAction) pushButtonAction: (id)sender {

NSGraphicsContext* theContext = [NSGraphicsContext currentContext];
}

I use Xcode 3.1 and Leopard 10.5.6
Thanks in advance.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
First lock the view before drawing into it: [myView lock]. Then use NSBezierPath to describe the line (see NSBezierPath docs for this) and then [myPath stroke] method to draw the line into the view. Finally, unlock the view when done: [myView unlock]. You shouldn't need to get the context for this, when you lock the view it'll be the current context. There are other ways of doing it (using Quartz for example), but this is probably the most Cocoa-like way.
 

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
Ok.
I can't understood how to get pointer to my View for lock, unlock etc :(
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
Ok.
I can't understood how to get pointer to my View for lock, unlock etc :(
You need to declare an outlet for the view, probably in your application controller object's .h file, something like:

Code:
IBOutlet NSView *myView;

IBOutlet is a special keyword that tells Xcode that you intend to link this object to something in Interface Builder. Once you have done that, in Interface Builder, Control-drag from your app controller object to the view and link it to "myView", or whatever you're calling it. Now when you specify myView (or whatever) in your code, it'll refer to the view you drew and linked to in IB.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.