Hi, DaniWeb Subscribers!

I need to learn Cocoa with XTools quickly. I am reading Apple's Obj-C Prog Language manual and another book on Cocoa programming. I also looked at the examples provided by the ADC. I am still overwhelmed. I'd like to get the most simple example of the following (no frills, whistles, or bells):

Open a new window, draw a red circle in it, and when a mouse click occurs within the circle region, the program stops and is done. -- This way I'd have a framework I can build on.

Can anyone at least point me in a direction that I can work on this? Any recommended books, documentation, already existing source code?

Thanks for your patience and help!

boploog

Recommended Answers

All 5 Replies

>I need to learn Cocoa with XTools quickly.
Don't rush. You can't speed up learning. However, if you already know a language such as C or C++, the learning process will be significantly faster because Objective C is based on C, but with object-oriented capabilities thrown in. So my advice, take it easy, and you won't be overwhelmed.

Now, a word of warning - I haven't used Cocoa very much, so I'm not really sure what I'm doing here. :-) I'll just throw in a few suggestions.

I assume you can figure out enough to get a window open, if not, look for a "hello world" Cocoa application. There's one that exists somewhere in Apple's documentation.

Regarding the circle: this should meet your needs.
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/chapter_6_section_5.html

For the clicking part, take a look at this:
http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/chapter_5_section_3.html

What you need to do is calculate which points lie in the circle you drew using trig, then decide if the location of the click is within the circle.

Of particular interest is this line:

NSPoint curPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];

I think it's pretty self-explanatory.

Hi, joeprogrammer!

Many thanks for your quick and friendly reply!

I am embarrassed to admit that I have been using C, some C++ (and much earlier various versions of BASIC and Pascal) but the jump to Cocoa with XTools still seems like a mystery to me.

I have used Metrowerks Codewarrior for years and it was sufficient for what I needed it to do (I am a psychologist and am running all my experiments on "home-made" programs). But with OS X, the simple function GetNewCWindow hasn't been working anymore and no one seems to have an answer. Or no one thinks it's worthwhile to figure out the glitch because I should switch to Cocoa. And here the problem starts: I have not been able to find the equivalent of a "Hello World" program for cocoa and XTools. So I got stuck at the level to just open a window, which was the problem to start with when I tried to solve the glitch with the GetNewCWindow call.

I'll work my way through your suggestions (articles in particular and continue looking for an example provided by ADC). The time pressure comes in because programming is only a secondary aspect of my job but all else depends on it.

In any case, your friendly help was most appreciated! Thanks!

Member Avatar for iamthwee

If speed isn't critical I would seriously consider using this

I am embarrassed to admit that I have been using C, some C++ (and much earlier various versions of BASIC and Pascal) but the jump to Cocoa with XTools still seems like a mystery to me.

There's no need to be embarrassed. Knowing C or C++ means you don't have to learn the concepts of OOP programming all over again, but the syntax in Objective C, as you have already noticed, is very different and it takes some time to get used to.

But with OS X, the simple function GetNewCWindow hasn't been working anymore and no one seems to have an answer.

You probably shouldn't be using that function anyway, since you're using Cocoa, use the Cocoa methods to do things. For setting a window's background color, see this.

I have not been able to find the equivalent of a "Hello World" program for cocoa and XTools. So I got stuck at the level to just open a window, which was the problem to start with when I tried to solve the glitch with the GetNewCWindow call.

OK, start by creating a blank window Cocoa project if you haven't already; this will be your base for the "Hello World" program. In the New Project window of Xcode, make sure you choose "Cocoa Application".

Hmm... I can't seem to find the Hello World tutorial that exists in the official Apple documentation. Oh well, you'll just have to use something like this:
http://en.wikibooks.org/wiki/Programming_Mac_OS_X_with_Cocoa_for_beginners/First_Cocoa_program_-_Hello_World

This is probably too late already, but an excellent book which teaches the fundamental concepts of programming in OS X is Beginning Mac OS X Programming by Michael Trent and Drew McCormack. It covers Cocoa, Carbon, how to use many of the tools provided with the Apple Developer Tools, as well as covering a bit of some of the other ways to build applications in OS X.

I wish you the best of luck on learning how to do this.

Hello, joeprogrammer!

You have been most helpful and friendly. Even though I have "Cocoa Programming for Mac OS X" by Aaron Hillegrass, I'll order the book you suggested, too. In combination with the wikibooks.org, I feel confident that I'll be able to tackle the issue!

Thanks a million!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.