42 lines
1.2 KiB
Ada
42 lines
1.2 KiB
Ada
with SDL.Video.Rectangles;
|
|
with SDL.TTFs;
|
|
use type SDL.TTFs.Font_Measurements;
|
|
with Video.Integer_Geometry;
|
|
use Video.Integer_Geometry;
|
|
|
|
package body Video.SDL2.Surfaces.TTFs is
|
|
|
|
function Extent (
|
|
Target : TTF_on_Surface;
|
|
Text : String)
|
|
return Texts.Text_Extent
|
|
is
|
|
Sizes : constant SDL.Sizes := Target.Typeface.Size_Latin_1 (Text);
|
|
Ascent : constant SDL.TTFs.Font_Measurements := Target.Typeface.Ascent;
|
|
Extent : constant Texts.Text_Extent := (
|
|
Bounds => Rectangles.From_SDL (SDL.Video.Rectangles.Rectangle'(
|
|
X => Interfaces.C.int (-Ascent),
|
|
Y => 0,
|
|
Width => Sizes.Width,
|
|
Height => Sizes.Height)),
|
|
Advance => Rectangles.From_SDL ((X => Sizes.Width, Y => 0))
|
|
);
|
|
begin
|
|
return Extent;
|
|
end Extent;
|
|
|
|
procedure Write (
|
|
Target : in out TTF_on_Surface;
|
|
A : in Integer_Geometry.Point;
|
|
Text : in String)
|
|
is
|
|
Extent : Texts.Text_Extent := Target.Extent (Text);
|
|
Src : SDL_Surface;
|
|
begin
|
|
Src.Data := Target.Typeface.Render_Solid (Text => Text, Colour => Target.Foreground);
|
|
Target.Target.Paste (
|
|
A => A + (Extent.Bounds.X.First, Extent.Bounds.Y.First),
|
|
Source => Src);
|
|
end Write;
|
|
|
|
end Video.SDL2.Surfaces.TTFs; |