views:

281

answers:

2
+1  Q: 

Chat Bubble Cocoa

I have been trying to create a chat bubble for about a month now... (you know, like the one in iChat or Tweetie). At some point I found a thread that said that I could use Twitterfon's source... which I did. But I get stuck for a few reasons. Which ones? Apple didn't seem to implement all the methods needed for calculating the rect's size. E.g.: NSTextField doesn't implement a method that allows me to give an NSRect in order for it to calculate the best size. The fact is, Tweetie's bubble rects are always perfect. I dropped him a line asking how he did that, but I didn't get a reply. Although, I understand, because it is used in a commercial application. I thought that with the popularity of iPhone's SMS application (and iChat, or any app including chat bubbles), someone would probably made an implementation on OS X, and made it open source. I am not very experienced, and mainly I don't have time (school), so this is why I have been working on it for one month and have not found a solution.

If someone created the thing on Cocoa, would they please explain their solution for it ? Or even better, show some code...

Thanks

+5  A: 

The AppKit NSString Additions have methods to measure strings for drawing, and for more advanced purposes you can use NSLayoutManager. See the Text Layout Programming Guide for more info.

Chuck
Ok thanks. Do you know of any piece of code that demonstrates the implementation ? I've been looking everywhere
Alexandre Cassagne
Jerry Krinock's *NS(Attributed)String+Geometrics* category could be what you're looking for: http://www.sheepsystems.com/sourceCode/sourceStringGeometrics.html
Rob Keniger
Thanks irsk.i managed to do something that starts looking good with nslayoutmanager, but i have a problem that starts posing itself: if i have too much text in the chat bubble, the text starts lowering the margin in which it is supposed to draw. How do i fix this ? thanks again to those who helpedI'll try releasing the code when it's done
Alexandre Cassagne
A: 

Alternatively you could use WebKit and HTML/CSS. I believe this is how Adium achieve their IM message themes.

mikecsh