TGradText

Version 1.0 - Harm: harmdog@ne.uswest.net
2/98 - Initial release to the public

This component is free.  Use it as you see fit.

DisClaimer:

No warranty.  Not intended for internal use.  May be hazardous to your
code.  The author is not responsible, and never has been.  Use at your
own risk.  For demonstration purposes only.

Description:

TGradText is a poor man's way of creating gradient filled text. It has
a couple of quirks, as listed below.  It only looks good with 16 or 24
bit color.  It's a descendant of TGraphicControl.  It has no Events, and 
very few properties:

 o - BeginColor - starting color of the gradient
 o - EndColor   - ending color of the gradient
 o - GradientStyle - five gradients to choose from
 o - Lines - lines of text

Word-Wrapping

GradText is capable of multi-line text.  Even if only one Line is
entered in the 'Lines' property, it will wrap the text if there are several
words.  To get all of the text on one line, adjust the width of the control
by grabbing a handle and dragging to widen, or increase the width in the
object inspector.  Adjusting the height has no effect, other than to cause
a re-paint.  If more than one Line is specified in the 'Lines' property,
GradText will honor the line break.  Adjusting the width will not eliminate
the hard line break.  To allow GradText to decide where to break for new
lines, make sure there is only one line in the 'Lines' property, then adjust
the width until the text appears the way you want it.
 
How it works:

Bitmap masking

Two internal bitmaps are used; bmB and bmT (Background and Text).  They
are defined as Transparent := TRUE.  bmT transparent color is black, for
the text, and bmB transparent color is white.  bmB is painted with a
gradient. bmT is first filled with white, then the Caption is applied in
Black, creating a Mask. bmT is then drawn on the canvas of bmB, which
results in the bmB gradient being overlayed with white except where the
text is, so the underlying gradient shows through.  bmB is then drawn onto
the canvas of the TGraphicControl, which results in a transparent label
except for the text, which still has the underlying gradient shining through.

Overall, it's a fairly useless component.  It does demonstrate how to use the
DrawText API to do multi-line text, which is how you could make buttons, labels,
etc with multi line.  The hardest part of this was figuring out how to get the
'Lines' property editor to work.  As with most of my work, this was a 'Learning'
project, I hope someone out there can benefit from it. 

Quirks:

  If you have the PLUS! package installed and the 'Smooth edges of screen fonts'
option of the PLUS! settings is checked, some true-type fonts don't look so
good.  Unchecking this setting improves the appearance of the GradText in
most cases.

  Some true-type fonts just don't look so good.  Also, because of the nature of
fonts, the horizontal gradient types look best.  The verticals often don't
capture the extremes of color because of the capital letters and descenders.

  Because white is used as the transparent color, specifying clWhite for the
Begin or EndColor will leave a little transparent line in your GradText.  To
circumvent this, use a color like $00FAFAFA, which is slightly off-white.

  If you want to change the text programatically, you can use the 'Caption' property,
which is not available at design time.  You must remember that GradText will word-wrap
everything it can within the existing Width of the control, so that changing the
text within an application may cause undesired results, like extending beyond the
bottom of the form.  You can adjust the width, but GradText will only stretch as far
as the widest line of text.

  Fonts that are specified in the Object Inspector may look good at design time,
but if they're not available on the machine at run-time will be replaced with
the default Font.  What I'm trying to say is that your 'Lucida Calligraphy' font
may look great on your machine, but when you put your program on a different
machine that doesn't have that font installed Windows will substitute MS Sans
Serif, or whatever the default is on that machine.  It is best to stick with the
standard fonts that come with Win95, like MS Sans Serif, Arial, etc. if you plan
on sharing any applications that use GradText.    

Installation:

  Unzip the files.  Put the Gradtext.Pas and Gradtext.Dcr files in a
folder together.  Start Delphi.  Select Component|Install Component...
Do a browse and find the folder where you put the two files.  Click OK.
By default, the component will be installed on the Samples tab of the 
Component Palette.  Edit the Gradtext.Pas and change the Register
procedure if you prefer another location.   