What do you think about to add some useful text to the AsphyreFonts.pas? Here's 2 overloaded methods to draw rotated text.
(Thanks to CHaser for it)
Code:
procedure TAsphyreFont.DisplayText(const Pos: TPoint2; const Text: WideString;
Alpha: Single; CenterOffset : TPoint2; Angle:single);
var
CharNo: Integer;
uCode : Integer;
xPos : Single;
Style : PFontStyle;
Entry : PLetterEntry;
Image : TAsphyreImage;
Canvas: TAsphyreCanvas;
iAlpha: Integer;
DrawPos : TPoint2;
DrawSize: TPoint2;
Colors : TColor2;
begin
if (FOwner.Images = nil)or(FOwner.Canvas = nil) then Exit;
Image:= FOwner.Images[FImageIndex];
if (Image = nil) then Exit;
Canvas:= FOwner.Canvas;
// -> Start processing text.
xPos := Pos.x;
CharNo:= 1;
iAlpha:= MinMax2(Round(Alpha * 255.0), 0, 255);
while (CharNo <= Length(Text)) do
begin
// -> Check if there are any tags in the text.
if (ParseTag(Text, CharNo, False)) then Continue;
// -> Retreive letter, its numerical code, and the current style.
uCode:= Word(Text[CharNo]);
Entry:= @Entries[uCode];
Style:= PeekStyle();
// -> Check whether the letter has its drawing information.
if (Entry.Size.x < 1)or(Entry.Size.y < 1)or(Style = nil) then
begin
Inc(CharNo);
xPos:= xPos + FWhitespace * FScale;
Continue;
end;
if (Style = nil) then Continue;
// -> Include leading space.
xPos:= xPos + Entry.Leading * FScale;
// -> Compute drawing position and size.
DrawPos.x := xPos;
DrawPos.y := Pos.y + (Entry.Top * FScale);
DrawSize.x:= Entry.Size.x * FScale;
DrawSize.y:= Entry.Size.y * FScale;
// -> Interpolate drawing colors.
Colors[0]:= cLerp(Style.Colors[0], Style.Colors[1], Entry.Top / FFontSize.y);
Colors[1]:= cLerp(Style.Colors[0], Style.Colors[1],
(Entry.Top + Entry.Size.y) / FFontSize.y);
// -> Display the letter.
Canvas.UseImagePx(Image, pxBounds4(Entry.Pos.x, Entry.Pos.y,
Entry.Size.x, Entry.Size.y));
if angle=0 then
Canvas.TexMap(
pBounds4(DrawPos.x, DrawPos.y, DrawSize.x, DrawSize.y),
cColorAlpha4(Colors[0], Colors[0], Colors[1], Colors[1],
iAlpha, iAlpha, iAlpha, iAlpha))
else
Canvas.TexMap(
pRotate4se(DrawPos, DrawSize, Pos - DrawPos + CenterOffset, Angle, 1),
cColorAlpha4(Colors[0], Colors[0], Colors[1], Colors[1],
iAlpha, iAlpha, iAlpha, iAlpha));
// -> Keep going horizontally.
Inc(CharNo);
xPos:= xPos + (Entry.Size.x + Entry.Trailing + FKerning) * FScale;
end;
end;
procedure TAsphyreFont.TextOut(const Pos: TPoint2; const Text: WideString;
const Colors: TColor2; CenterOffset: TPoint2; Angle: single; Alpha:single=1);
begin
ClearStyles();
PushStyle(Colors, 0);
DisplayText(Pos, Text, Alpha, CenterOffset, Angle);
ClearStyles();
end;