[Kde-games-devel] Colour fonts
Troy Corbin Jr.
kde-games-devel@mail.kde.org
Thu, 16 Jan 2003 05:30:19 -0600
On Wednesday 15 January 2003 06:34 pm, Johnny Andersson wrote:
> Let's say I'm making a game for KDE and I want fonts with colours, and
> perhaps an outline to make it readable no matter what is behind it. I s=
till
> want the game to support all languages, so shipping it with a bitmap fo=
nt
> isn't an option.
>
> Would it be considered OK practise to render the characters that's goin=
g to
> be used to an offscreen bitmap, (using regular QT text output functions=
),
> manipulate it, and then use custom text routines to show it?
Are you talking about using that QPixmap strictly for the fonts only, and=
then=20
using a QPainter or bitblt to copy the text onto your widget? This is=20
possible, but I think it would only be useful if your font effects are so=
=20
complicated that they can't be rendered in real time. Something simple, l=
ike=20
a color font with a dropshadow, could easily be done in real time.
For example:
( assume pic is your doublebuffer )
QPainter painter;
QString text;
text =3D i18n("My test text");
painter.begin( pic );
painter.setFont( KGlobalSettings::fixedFont() );
painter.setPen( QColor( 0, 0, 0 ) );
painter.drawText( 3, 3, 256, 256, Qt::AlignRight | Qt::AlignBottom, text =
);
painter.setPen( QColor( 64, 255, 64 ) );
painter.drawText( 2, 2, 256, 256, Qt::AlignRight | Qt::AlignBottom, text =
);
painter.end();
This was taken almost straight from my game if you want to see it in acti=
on.=20
It gives you a green font with a black drop-shadow, and your text is stil=
l=20
i18n.
The method you mentioned is perfect for animated effects. For example, st=
art=20
with a transparent pixmap. Draw your text onto it, but draw it close to t=
he=20
bottom. Display it. Now apply an effect on the pixmap, like=20
KIconEffect::semiTransparent( QPixmap ). Draw your text again, but a litt=
le=20
higher. Rinse, repeat. You'll get a nice moving bit of text with a fading=
=20
tail. This would be perfect for score-up displays.
> Is there another way? Also, perhaps this could be adressed in a more
> general way since I'm sure many games and entertainment apps could bene=
fit
> from "happier" fonts.
I hope you're starting to think of some other nifty ways to display that =
text.=20
Perhaps we should compile a list of text effect and the ways to display t=
hem=20
using Qt and KDE? :-)
--=20
Troy Corbin Jr.
tcorbin@users.sf.net
http://knights.sf.net