• 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: Converting an NSString to a series of NSImages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting an NSString to a series of NSImages?


  • Subject: Re: Converting an NSString to a series of NSImages?
  • From: Marco Binder <email@hidden>
  • Date: Thu, 19 Sep 2002 20:05:53 +0200

Hi Albert!

i dont want to appear rude, but I would really recommend you to read a good introductory tutorial on Objective-C and Cocoa. If you can afford it, get Aaron Hillegass' "Cocoa Programming for Mac OS X"- it4s a great step by step introduction to the whole topic. A good start for object oriented programming and the Objective C langage is provided by Apple at "file://localhost/Developer/Documentation/Cocoa/ObjectiveC/index.html". "The Vermont Recipes" by Bill Cheeseman (also posting on this list), to be found at http://www.stepwise.com/Articles/VermontRecipes/index.html , are also a nice starting point.

But since I guess you want to achieve something critical soon, let4s get back to your problem:

// Implement the function getRectFor:(unichar) to return the rect of the appropriate
// letter from your alphabetImage (e.g. "A" => NSMakeRect(0,0,32,32);)

I don't really understand how to do this...would it look something like this?:

- (void) getRectFor:(unichar) {
"A" => NSMakeRect(0,0,32,32);
//Continue with rest of alphabet
}

No! Again: you should really try to get fit with ObjC... First: the return type should be (NSRect*). Then you have to assign a name for the argument, e.g. (unichar) testChar. Then, I only used "A" => ... to give you an idea, what your function should do. Its no operator or anything. The, of course, you have to return the rect, so you main method can work with it.


That is my thought of how it should look. Let me know if that is how to do it. Also, the NSMakeRect has four digets. This is the top, left, bottom and right values in pixels right? So if the B character was right next to A I would put:

"B" => NSMakeRect(0,32,32,64);

into the getRectFor action, correct?

Wrong again, sorry. first, let me mention, that you find documentation to virtually everything that starts with "NS" on your hard-drive in Apples developer documentation. There you can read, that NSMakeRect takes four float values: origin.x, origin.y (x- and y-coordinates of the lower left corner of your rect) and size.width as well as size.height. So, for your purpose, it will always be

NSMakeRect(32*x,0,32,32)

where x is the index of your character. So, for A it would be (given "A" is your first letter), as mentioned, NSMakeRect(0,0,32,32). For "D" then (given its your 4th letter) it would be NSMakeRect(96,0,32,32)!

Then you have to return the NSRect.

So:

- (NSRect*) getRectFor:(unichar) testChar {
int i = getIndexOfThisCharacterWithinMyAlphabetImage(testChar);
// You ll have to do that yourself, I dont know your alphabetImage. You can for example have
// your alphabet in one string and then see at what index it hold testChar. Take that index as i

NSRect rightRect = NSMakeRect((32*i,0,32,32);
return rightRect;
}

That would be a possible implementation of the method.


Hope that helps you out! I know you'll make it from here on. And: do some tutorials or read a book, it really makes things easier!


marco


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.

References: 
 >Converting an NSString to a series of NSImages? (From: Albert Atkinson <email@hidden>)

  • Prev by Date: Re: How to determine a toolbar's size?
  • Next by Date: Re: [newbie] translating mouse location in an NSImageView
  • Previous by thread: Re: Converting an NSString to a series of NSImages?
  • Next by thread: How to take a screen shot
  • Index(es):
    • Date
    • Thread