Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chat Bubble Cocoa

Tags:

macos

cocoa

chat

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...

like image 954
Alexandre Cassagne Avatar asked Feb 27 '23 19:02

Alexandre Cassagne


2 Answers

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.

like image 111
Chuck Avatar answered Mar 12 '23 05:03

Chuck


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

like image 43
mikecsh Avatar answered Mar 12 '23 04:03

mikecsh