At 17:38 +0200 28/1/09, Oleg Krupnov wrote:
I want to produce the effect of a text string fading out when it's too
long to be displayed in a rect. This kind of effect is used in many
apps.

One option is to draw the end of the string character by character with varying alphas.

Ie, instead of

Hello Cruel Wo...

draw

Hello Cruel Wo

then draw r at 75% alpha
then draw l at 50% alpha
then draw d at 25% alpha.

If you really want finer control, you could use a narrow clipping rect, which would also let you draw the entire string ten times with different alphs and different clipping rects, assuming that performance did not become a problem. The code would actually be pretty straight forward:

Clip to width -20
Draw string
Clip from width-20 to width -18
Draw string at Alpha 90%
Clip from width-18 to width-16
Draw string at Alpha 80%
...

Your code doesn't even have to consider if the string is long enough to need truncating.

Enjoy,
   Peter.

--
              Keyboard Maestro 3 Now Available!
   Now run macros from your iPhone with Keyboard Maestro Control!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to