diff options
Diffstat (limited to '')
4 files changed, 2079 insertions, 0 deletions
diff --git a/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/GLFont/glfont.dpr b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/GLFont/glfont.dpr new file mode 100644 index 00000000..645d4b96 --- /dev/null +++ b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/GLFont/glfont.dpr @@ -0,0 +1,625 @@ +program glfont;
+{
+ glfont: An example of using the SDL_ttf library with OpenGL.
+ Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ The SDL_GL_* functions in this file are available in the public domain.
+ Sam Lantinga
+ slouken@libsdl.org
+}
+{ $Id: glfont.dpr,v 1.3 2005/05/23 22:35:39 savage Exp $ }
+{ A simple program to test the text rendering feature of the TTF library }
+uses
+ SysUtils,
+ sdl,
+ sdl_ttf,
+ gl;
+
+(* Undefine this if you want a flat cube instead of a rainbow cube *)
+{$DEFINE SHADED_CUBE}
+
+const
+ DEFAULT_PTSIZE = 18;
+ DEFAULT_TEXT = 'The quick brown fox jumped over the lazy dog';
+ NUM_COLORS = 256;
+ Usage = 'Usage: %s <font>.ttf [-solid] [-utf8 or -unicode] [-b] [-i] [-u] [-fgcol r g b] [-bgcol r g b] [-ptsize nn] [-text "message"]';
+ SCREEN_WIDTH = 640;
+ SCREEN_HEIGHT = 480;
+ SCREEN_BPP = 0;
+
+procedure ShutDownApplication( HaltStatus : integer );
+begin
+ TTF_Quit;
+ SDL_Quit;
+ Halt( HaltStatus );
+end;
+
+procedure SDL_GL_Enter2DMode;
+var
+ screen : PSDL_Surface;
+begin
+ screen := SDL_GetVideoSurface;
+ (* Note, there may be other things you need to change,
+ depending on how you have your OpenGL state set up.
+ *)
+ glPushAttrib( GL_ENABLE_BIT );
+ glDisable( GL_DEPTH_TEST );
+ glDisable( GL_CULL_FACE );
+ glEnable( GL_TEXTURE_2D );
+ glViewport( 0, 0, screen.w, screen.h );
+ glMatrixMode( GL_PROJECTION );
+ glPushMatrix;
+ glLoadIdentity;
+ glOrtho( 0.0, screen.w, screen.h, 0.0, 0.0, 1.0 );
+ glMatrixMode( GL_MODELVIEW );
+ glPushMatrix;
+ glLoadIdentity;
+ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
+end;
+
+procedure SDL_GL_Leave2DMode;
+begin
+ glMatrixMode( GL_MODELVIEW );
+ glPopMatrix;
+ glMatrixMode( GL_PROJECTION );
+ glPopMatrix;
+ glPopAttrib;
+end;
+(* Quick utility function for texture creation *)
+
+function power_of_two( input : integer ) : integer;
+var
+ value : integer;
+begin
+ value := 1;
+ while ( value < input ) do
+ begin
+ value := value shl 1;
+ end;
+ result := value;
+end;
+
+function SDL_GL_LoadTexture( surface : PSDL_Surface; var texcoord : array of GlFloat ) : GLuint;
+var
+ texture : GLuint;
+ w, h : integer;
+ image : PSDL_Surface;
+ area : TSDL_Rect;
+ saved_flags : Uint32;
+ saved_alpha : Uint8;
+begin
+ (* Use the surface width and height expanded to powers of 2 *)
+ w := power_of_two( surface.w );
+ h := power_of_two( surface.h );
+ texcoord[ 0 ] := 0.0; (* Min X *)
+ texcoord[ 1 ] := 0.0; (* Min Y *)
+ texcoord[ 2 ] := surface.w / w; (* Max X *)
+ texcoord[ 3 ] := surface.h / h; (* Max Y *)
+ image := SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ w, h,
+ 32,
+{$IFNDEF IA32} (* OpenGL RGBA masks *)
+ $000000FF,
+ $0000FF00,
+ $00FF0000,
+ $FF000000
+{$ELSE}
+ $FF000000,
+ $00FF0000,
+ $0000FF00,
+ $000000FF
+{$ENDIF}
+ );
+ if ( image = nil ) then
+ begin
+ result := 0;
+ exit;
+ end;
+ (* Save the alpha blending attributes *)
+ saved_flags := surface.flags and ( SDL_SRCALPHA or SDL_RLEACCELOK );
+ saved_alpha := surface.format.alpha;
+ if ( ( saved_flags and SDL_SRCALPHA ) = SDL_SRCALPHA ) then
+ begin
+ SDL_SetAlpha( surface, 0, 0 );
+ end;
+ (* Copy the surface into the GL texture image *)
+ area.x := 0;
+ area.y := 0;
+ area.w := surface.w;
+ area.h := surface.h;
+ SDL_BlitSurface( surface, @area, image, @area );
+ (* Restore the alpha blending attributes *)
+ if ( ( saved_flags and SDL_SRCALPHA ) = SDL_SRCALPHA ) then
+ begin
+ SDL_SetAlpha( surface, saved_flags, saved_alpha );
+ end;
+ (* Create an OpenGL texture for the image *)
+ glGenTextures( 1, @texture );
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexImage2D( GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ w, h,
+ 0,
+ GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ image.pixels );
+ SDL_FreeSurface( image ); (* No longer needed *)
+ result := texture;
+end;
+
+type
+ TRenderType = ( rtLatin1, rtUTF8, rtUnicode );
+
+var
+ //fontfile : string;
+ //gl_error : GLenum;
+ texture : GLuint;
+ x, y, w, h : integer;
+ //texcoord : array[ 0..4 ] of TGLfloat;
+ texMinX, texMinY : GLfloat;
+ texMaxX, texMaxY : GLfloat;
+ color : array[ 0..7, 0..2 ] of single = ( ( 1.0, 1.0, 0.0 ),
+ ( 1.0, 0.0, 0.0 ),
+ ( 0.0, 0.0, 0.0 ),
+ ( 0.0, 1.0, 0.0 ),
+ ( 0.0, 1.0, 1.0 ),
+ ( 1.0, 1.0, 1.0 ),
+ ( 1.0, 0.0, 1.0 ),
+ ( 0.0, 0.0, 1.0 ) );
+ cube : array[ 0..7, 0..2 ] of single = ( ( 0.5, 0.5, -0.5 ),
+ ( 0.5, -0.5, -0.5 ),
+ ( -0.5, -0.5, -0.5 ),
+ ( -0.5, 0.5, -0.5 ),
+ ( -0.5, 0.5, 0.5 ),
+ ( 0.5, 0.5, 0.5 ),
+ ( 0.5, -0.5, 0.5 ),
+ ( -0.5, -0.5, 0.5 ) );
+ screen : PSDL_Surface = nil;
+ font : PTTF_Font;
+ temp : PSDL_Surface = nil;
+ ptsize : integer = 0;
+ i : integer;
+ done : Boolean = false;
+ //rdiff, gdiff, bdiff : integer;
+ //colors : array[ 0..NUM_COLORS - 1 ] of TSDL_Color;
+ white : TSDL_Color = ( r : $FF; g : $FF; b : $FF; unused : 0 );
+ black : TSDL_Color = ( r : $00; g : $00; b : $00; unused : 0 );
+ forecol : TSDL_Color;
+ backcol : TSDL_Color;
+ //dstrect : TSDL_Rect;
+ event : TSDL_Event;
+ rendersolid : Boolean = false;
+ renderstyle : integer = TTF_STYLE_NORMAL;
+ rendertype : TRenderType = rtLatin1;
+ dump : Boolean;
+ message : string;
+ glyph : PSDL_Surface = nil;
+ r, g, b : integer;
+ outname : string;
+ //texcoord : array[ 0..3 ] of TGLfloat;
+ aspect : single;
+
+procedure CreateTextTexture;
+var
+ //screen : PSDL_Surface;
+ image : PSDL_Surface;
+ texcoord : array[ 0..3 ] of GlFloat;
+begin
+ //screen := SDL_GetVideoSurface;
+ if ( texture = 0 ) then
+ begin
+ case rendertype of
+ rtLatin1 :
+ begin
+ if ( rendersolid ) then
+ begin
+ image := TTF_RenderText_Solid( font, PChar( message ), forecol );
+ end
+ else
+ begin
+ image := TTF_RenderText_Shaded( font, PChar( message ), forecol, backcol );
+ end;
+ end;
+
+ rtUTF8 :
+ begin
+ if ( rendersolid ) then
+ begin
+ image := TTF_RenderUTF8_Solid( font, PChar( message ), forecol );
+ end
+ else
+ begin
+ image := TTF_RenderUTF8_Shaded( font, PChar( message ), forecol, backcol );
+ end;
+ end;
+
+ rtUNICODE :
+ begin
+ { This doesn't actually work because you can't pass UNICODE text in via command line, AFAIK, but...}
+ {Uint16 unicode_text[BUFSIZ];
+ int index;
+ for index := 0 to Lneght(message) do
+ begin
+ unicode_text[index] := ((Uint8 *)message)[0];
+ unicode_text[index] := unicode_text[index] shl 8;
+ unicode_text[index] := unicode_text[index] or ((Uint8 *)message)[1];
+ message := message + 2;
+ end;
+ if ( rendersolid ) then
+ begin
+ text := TTF_RenderUNICODE_Solid(font, unicode_text, @forecol);
+ end
+ else
+ begin
+ text := TTF_RenderUNICODE_Shaded( font, unicode_text, @forecol, @backcol);
+ end;}
+ end;
+ else
+ begin
+ image := nil;
+ { This shouldn't happen }
+ end;
+ end;
+
+ if ( image = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn't render text: %s', [SDL_GetError]);
+ TTF_CloseFont( font );
+ ShutDownApplication( 2 );
+ end;
+
+
+ w := image.w;
+ h := image.h;
+ (* Convert the image into an OpenGL texture *)
+ texture := SDL_GL_LoadTexture( image, texcoord );
+ (* Make texture coordinates easy to understand *)
+ texMinX := texcoord[ 0 ];
+ texMinY := texcoord[ 1 ];
+ texMaxX := texcoord[ 2 ];
+ texMaxY := texcoord[ 3 ];
+ (* We don't need the original image anymore *)
+ SDL_FreeSurface( image );
+ (* Make sure that the texture conversion is okay *)
+ if ( texture = 0 ) then
+ begin
+ exit;
+ end;
+ end;
+end;
+
+procedure DrawTextTexture;
+begin
+ (* Show the image on the screen *)
+ SDL_GL_Enter2DMode;
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glBegin( GL_TRIANGLE_STRIP );
+ glTexCoord2f( texMinX, texMinY );
+ glVertex2i( x, y );
+ glTexCoord2f( texMaxX, texMinY );
+ glVertex2i( x + w, y );
+ glTexCoord2f( texMinX, texMaxY );
+ glVertex2i( x, y + h );
+ glTexCoord2f( texMaxX, texMaxY );
+ glVertex2i( x + w, y + h );
+ glEnd;
+ SDL_GL_Leave2DMode;
+end;
+
+begin
+ { Default is black and white }
+ forecol := black;
+ backcol := white;
+
+ for i := 1 to ParamCount - 1 do
+ begin
+ if ( ParamStr( i ) = '-solid' ) then
+ begin
+ rendersolid := true;
+ end
+ else if ( ParamStr( i ) = '-utf8' ) then
+ begin
+ rendertype := rtUTF8;
+ end
+ else if ( ParamStr( i ) = '-unicode' ) then
+ begin
+ rendertype := rtUnicode;
+ end
+ else if ( ParamStr( i ) = '-b' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_BOLD;
+ end
+ else if ( ParamStr( i ) = '-i' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_ITALIC;
+ end
+ else if ( ParamStr( i ) = '-u' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_UNDERLINE;
+ end
+ else if ( ParamStr( i ) = '-dump' ) then
+ begin
+ dump := true;
+ end
+ else if ( ParamStr( i ) = '-fgcol' ) then
+ begin
+ try
+ r := StrToInt( ParamStr( i + 1 ) );
+ g := StrToInt( ParamStr( i + 2 ) );
+ b := StrToInt( ParamStr( i + 3 ) );
+ except
+ ShutDownApplication( 1 )
+ end;
+ forecol.r := r;
+ forecol.g := g;
+ forecol.b := b;
+ end
+ else if ( ParamStr( i ) = '-bgcol' ) then
+ begin
+ try
+ r := StrToInt( ParamStr( i + 1 ) );
+ g := StrToInt( ParamStr( i + 2 ) );
+ b := StrToInt( ParamStr( i + 3 ) );
+ except
+ ShutDownApplication( 1 )
+ end;
+ forecol.r := r;
+ forecol.g := g;
+ forecol.b := b;
+ end
+ else if ( ParamStr( i ) = '-ptsize' ) then
+ begin
+ ptsize := StrToInt( ParamStr( i + 1 ) );
+ end
+ else if ( ParamStr( i ) = '-text' ) then
+ begin
+ message := ParamStr( i + 1 );
+ end
+ else
+ begin
+ //fprintf(stderr, Usage, argv0);
+ end;
+ end;
+
+ { Check usage }
+ {if ( ! argv[ 0 ] ) {
+ fprintf(stderr, Usage, argv0);
+ return(1);
+ }
+
+ { Initialize SDL }
+ if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then
+ begin
+ //fprintf(stderr, 'Couldn't initialize SDL: %s',SDL_GetError);
+ SDL_Quit;
+ end;
+
+ { Initialize the TTF library }
+ if ( TTF_Init < 0 ) then
+ begin
+ //fprintf(stderr, 'Couldn't initialize TTF: %s',SDL_GetError);
+ SDL_Quit;
+ end;
+ //atexit( TTF_Quit );
+ { Open the font file with the requested point size }
+ if ( ptsize = 0 ) then
+ begin
+ //i := 2;
+ ptsize := DEFAULT_PTSIZE;
+ end
+ else
+ begin
+ //i := 3;
+ end;
+
+ font := TTF_OpenFont( PChar( ParamStr( 1 ) ), ptsize );
+ if ( font = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn''t load %d pt font from %s: %s',[ptsize, ParamStr(0), SDL_GetError]);
+ ShutDownApplication( 2 )
+ end;
+
+ TTF_SetFontStyle( font, renderstyle );
+
+ if ( dump ) then
+ begin
+ for i := 48 to 122 do
+ begin
+ glyph := TTF_RenderGlyph_Shaded( font, i, forecol, backcol );
+ if ( glyph <> nil ) then
+ begin
+ outname := 'glyph-' + IntToStr( i ) + '.bmp';
+ SDL_SaveBMP( glyph, PChar( outname ) );
+ end;
+ end;
+ ShutDownApplication( 0 );
+ exit;
+ end;
+
+ { Set a 640x480x8 video mode }
+ screen := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL );
+ if ( screen = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn''t set 640x480 OpenGL mode: %s', SDL_GetError);
+ ShutDownApplication( 2 );
+ end;
+
+ // Set the window manager title bar
+ SDL_WM_SetCaption( 'JEDI-SDL 3D TTF Demo', 'glfont' );
+
+ { Render and center the message }
+ if ( message = '' ) then
+ begin
+ message := DEFAULT_TEXT;
+ end;
+
+ { Initialize the GL state }
+ glViewport( 0, 0, screen.w, screen.h );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity;
+ // This makes the cube rectangular on screen */
+ //glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
+ // This makes the cube equisided on screen */
+ aspect := 2.0 / ( screen.w / screen.h );
+ glOrtho( -2.0, 2.0, -aspect, aspect, -20.0, 20.0 );
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity;
+ glEnable( GL_DEPTH_TEST );
+ glDepthFunc( GL_LESS );
+ glShadeModel( GL_SMOOTH );
+
+ CreateTextTexture;
+
+ { Wait for a keystroke, and blit text on mouse press }
+ done := false;
+ while ( not done ) do
+ begin
+ while ( SDL_PollEvent( @event ) <> 0 ) do
+ begin
+ case event.type_ of
+ SDL_MOUSEBUTTONDOWN :
+ begin
+ x := event.motion.x - w div 2;
+ y := event.motion.y - h div 2;
+ end;
+
+ SDL_KEYDOWN, SDL_QUITEV :
+ begin
+ done := true;
+ end;
+ end;
+ end;
+
+ { Clear the screen }
+ glClearColor( 1.0, 1.0, 1.0, 1.0 );
+ glClear( GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT );
+ { Draw the spinning cube }
+ glBegin( GL_QUADS );
+{$IFDEF SHADED_CUBE}
+ glColor3fv( @color[ 0 ] );
+ glVertex3fv( @cube[ 0 ] );
+ glColor3fv( @color[ 1 ] );
+ glVertex3fv( @cube[ 1 ] );
+ glColor3fv( @color[ 2 ] );
+ glVertex3fv( @cube[ 2 ] );
+ glColor3fv( @color[ 3 ] );
+ glVertex3fv( @cube[ 3 ] );
+
+ glColor3fv( @color[ 3 ] );
+ glVertex3fv( @cube[ 3 ] );
+ glColor3fv( @color[ 4 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glColor3fv( @color[ 7 ] );
+ glVertex3fv( @cube[ 7 ] );
+ glColor3fv( @color[ 2 ] );
+ glVertex3fv( @cube[ 2 ] );
+
+ glColor3fv( @color[ 0 ] );
+ glVertex3fv( @cube[ 0 ] );
+ glColor3fv( @color[ 5 ] );
+ glVertex3fv( @cube[ 5 ] );
+ glColor3fv( @color[ 6 ] );
+ glVertex3fv( @cube[ 6 ] );
+ glColor3fv( @color[ 1 ] );
+ glVertex3fv( @cube[ 1 ] );
+
+ glColor3fv( @color[ 5 ] );
+ glVertex3fv( @cube[ 5 ] );
+ glColor3fv( @color[ 4 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glColor3fv( @color[ 7 ] );
+ glVertex3fv( @cube[ 7 ] );
+ glColor3fv( @color[ 6 ] );
+ glVertex3fv( @cube[ 6 ] );
+ glColor3fv( @color[ 5 ] );
+ glVertex3fv( @cube[ 5 ] );
+ glColor3fv( @color[ 0 ] );
+ glVertex3fv( @cube[ 0 ] );
+ glColor3fv( @color[ 3 ] );
+ glVertex3fv( @cube[ 3 ] );
+ glColor3fv( @color[ 4 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glColor3fv( @color[ 6 ] );
+ glVertex3fv( @cube[ 6 ] );
+ glColor3fv( @color[ 1 ] );
+ glVertex3fv( @cube[ 1 ] );
+ glColor3fv( @color[ 2 ] );
+ glVertex3fv( @cube[ 2 ] );
+ glColor3fv( @color[ 7 ] );
+ glVertex3fv( @cube[ 7 ] );
+{$ELSE} // flat cube
+ glColor3f( 1.0, 0.0, 0.0 );
+ glVertex3fv( @cube[ 0 ] );
+ glVertex3fv( @cube[ 1 ] );
+ glVertex3fv( @cube[ 2 ] );
+ glVertex3fv( @cube[ 3 ] );
+
+ glColor3f( 0.0, 1.0, 0.0 );
+ glVertex3fv( @cube[ 3 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glVertex3fv( @cube[ 7 ] );
+ glVertex3fv( @cube[ 2 ] );
+
+ glColor3f( 0.0, 0.0, 1.0 );
+ glVertex3fv( @cube[ 0 ] );
+ glVertex3fv( @cube[ 5 ] );
+ glVertex3fv( @cube[ 6 ] );
+ glVertex3fv( @cube[ 1 ] );
+
+ glColor3f( 0.0, 1.0, 1.0 );
+ glVertex3fv( @cube[ 5 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glVertex3fv( @cube[ 7 ] );
+ glVertex3fv( @cube[ 6 ] );
+ glColor3f( 1.0, 1.0, 0.0 );
+ glVertex3fv( @cube[ 5 ] );
+ glVertex3fv( @cube[ 0 ] );
+ glVertex3fv( @cube[ 3 ] );
+ glVertex3fv( @cube[ 4 ] );
+ glColor3f( 1.0, 0.0, 1.0 );
+ glVertex3fv( @cube[ 6 ] );
+ glVertex3fv( @cube[ 1 ] );
+ glVertex3fv( @cube[ 2 ] );
+ glVertex3fv( @cube[ 7 ] );
+{$ENDIF} (* SHADED_CUBE *)
+ glEnd;
+
+ { Rotate the cube }
+ glMatrixMode( GL_MODELVIEW );
+ glRotatef( 5.0, 1.0, 1.0, 1.0 );
+ { Show the text on the screen }
+ DrawTextTexture;
+ {SDL_GL_Enter2DMode;
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glBegin( GL_TRIANGLE_STRIP );
+ glTexCoord2f( texMinX, texMinY );
+ glVertex2i( x, y );
+ glTexCoord2f( texMaxX, texMinY );
+ glVertex2i( x + w, y );
+ glTexCoord2f( texMinX, texMaxY );
+ glVertex2i( x, y + h );
+ glTexCoord2f( texMaxX, texMaxY );
+ glVertex2i( x + w, y + h );
+ glEnd;
+ SDL_GL_Leave2DMode;}
+ { Swap the buffers so everything is visible }
+ SDL_GL_SwapBuffers;
+ end;
+ TTF_CloseFont( font );
+ ShutDownApplication( 0 );
+end.
+
diff --git a/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/ShowFont/showfont.dpr b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/ShowFont/showfont.dpr new file mode 100644 index 00000000..693c1b8c --- /dev/null +++ b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Demos/ShowFont/showfont.dpr @@ -0,0 +1,384 @@ +program showfont;
+{
+ showfont: An example of using the SDL_ttf library with 2D graphics.
+ Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Sam Lantinga slouken@libsdl.org
+}
+
+{
+$Id: showfont.dpr,v 1.3 2007/06/01 08:39:06 savage Exp $
+}
+
+{
+A simple program to test the text rendering feature of the TTF library
+}
+
+uses
+ SysUtils,
+ sdl,
+ sdl_ttf;
+
+const
+ DEFAULT_PTSIZE = 18;
+ DEFAULT_TEXT = 'The quick Pascal compiler jumped over the lazy C compiler';
+ NUM_COLORS = 256;
+ Usage = 'Usage: %s <font>.ttf [-solid] [-utf8 or -unicode] [-b] [-i] [-u] [-fgcol r g b] [-bgcol r g b] [-ptsize nn] [-text "message"]';
+ SCREEN_WIDTH = 640;
+ SCREEN_HEIGHT = 480;
+ SCREEN_BPP = 8;
+
+type
+ TRenderType = ( rtLatin1, rtUTF8, rtUnicode );
+
+procedure ShutDownApplication( HaltStatus : integer );
+begin
+ TTF_Quit;
+ SDL_Quit;
+ Halt( HaltStatus );
+end;
+
+var
+ screen : PSDL_Surface = nil;
+ font : PTTF_Font;
+ text : PSDL_Surface = nil;
+ temp : PSDL_Surface = nil;
+ ptsize : integer = 0;
+ i : integer;
+ done : Boolean = false;
+ rdiff, gdiff, bdiff : integer;
+ colors : array[ 0..NUM_COLORS - 1 ] of TSDL_Color;
+ white : TSDL_Color = ( r : $FF; g : $FF; b : $FF; unused : 0 );
+ black : TSDL_Color = ( r : $00; g : $00; b : $00; unused : 0 );
+ forecol : TSDL_Color;
+ backcol : TSDL_Color;
+ dstrect : TSDL_Rect;
+ event : TSDL_Event;
+ rendersolid : Boolean = false;
+ renderstyle : integer = TTF_STYLE_NORMAL;
+ rendertype : TRenderType = rtLatin1;
+ dump : Boolean;
+ message : WideString;
+ glyph : PSDL_Surface = nil;
+ r, g, b : integer;
+ outname : string;
+begin
+ { Look for special execution mode }
+ {dump := false;
+ { Look for special rendering types }
+ {rendersolid := false;
+ renderstyle := TTF_STYLE_NORMAL;
+ rendertype := rtLatin1;}
+
+ { Default is black and white }
+ forecol := black;
+ backcol := white;
+
+ for i := 1 to ParamCount do
+ begin
+ if ( ParamStr( i ) = '-solid' ) then
+ begin
+ rendersolid := true;
+ end
+ else if ( ParamStr( i ) = '-utf8' ) then
+ begin
+ rendertype := rtUTF8;
+ end
+ else if ( ParamStr( i ) = '-unicode' ) then
+ begin
+ rendertype := rtUnicode;
+ end
+ else if ( ParamStr( i ) = '-b' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_BOLD;
+ end
+ else if ( ParamStr( i ) = '-i' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_ITALIC;
+ end
+ else if ( ParamStr( i ) = '-u' ) then
+ begin
+ renderstyle := renderstyle or TTF_STYLE_UNDERLINE;
+ end
+ else if ( ParamStr( i ) = '-dump' ) then
+ begin
+ dump := true;
+ end
+ else if ( ParamStr( i ) = '-fgcol' ) then
+ begin
+ try
+ r := StrToInt( ParamStr( i + 1 ) );
+ g := StrToInt( ParamStr( i + 2 ) );
+ b := StrToInt( ParamStr( i + 3 ) );
+ except
+ ShutDownApplication( 1 )
+ end;
+ forecol.r := r;
+ forecol.g := g;
+ forecol.b := b;
+ end
+ else if ( ParamStr( i ) = '-bgcol' ) then
+ begin
+ try
+ r := StrToInt( ParamStr( i + 1 ) );
+ g := StrToInt( ParamStr( i + 2 ) );
+ b := StrToInt( ParamStr( i + 3 ) );
+ except
+ ShutDownApplication( 1 )
+ end;
+ forecol.r := r;
+ forecol.g := g;
+ forecol.b := b;
+ end
+ else if ( ParamStr( i ) = '-ptsize' ) then
+ begin
+ ptsize := StrToInt( ParamStr( i + 1 ) );
+ end
+ else if ( ParamStr( i ) = '-text' ) then
+ begin
+ message := WideString( ParamStr( i + 1 ) );
+ end
+ else
+ begin
+ //fprintf(stderr, Usage, argv0);
+ end;
+ end;
+
+ { Check usage }
+ {
+ if ( ! argv[0] ) then
+ begin
+ fprintf(stderr, Usage, argv0);
+ return(1);
+ end;
+ }
+
+ { Initialize SDL }
+ if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then
+ begin
+ //fprintf(stderr, 'Couldn''t initialize SDL: %s',SDL_GetError);
+ ShutDownApplication( 2 )
+ end;
+
+ //atexit(SDL_Quit);
+
+ { Initialize the TTF library }
+ if ( TTF_Init( ) < 0 ) then
+ begin
+ //fprintf(stderr, 'Couldn''t initialize TTF: %s',SDL_GetError);
+ ShutDownApplication( 2 )
+ end;
+
+ //atexit(TTF_Quit);
+
+ { Open the font file with the requested point size }
+ if ( ptsize = 0 ) then
+ begin
+ i := 2;
+ ptsize := DEFAULT_PTSIZE;
+ end
+ else
+ begin
+ i := 3;
+ end;
+
+ font := TTF_OpenFont( PChar( ParamStr( 1 ) ), ptsize );
+ if ( font = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn''t load %d pt font from %s: %s',[ptsize, ParamStr(0), SDL_GetError]);
+ ShutDownApplication( 2 )
+ end;
+
+ TTF_SetFontStyle( font, renderstyle );
+
+ if ( dump ) then
+ begin
+ for i := 48 to 123 do
+ begin
+ glyph := TTF_RenderGlyph_Shaded( font, i, forecol, backcol );
+ if ( glyph <> nil ) then
+ begin
+ //sprintf( outname, 'glyph-%d.bmp', i );
+ outname := 'glyph-' + IntToStr( i ) + '.bmp';
+ SDL_SaveBMP( glyph, PChar( outname ) );
+ end;
+ end;
+ ShutDownApplication( 0 );
+ exit;
+ end;
+
+ { Set a 640x480x8 video mode }
+ screen := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
+ if ( screen = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn't set 640x480x8 video mode: %s',[SDL_GetError]);
+ ShutDownApplication( 2 );
+ end;
+
+ // Set the window manager title bar
+ SDL_WM_SetCaption( 'JEDI-SDL 2D TTF Demo', 'showfont' );
+
+ { Set a palette that is good for the foreground colored text }
+ rdiff := backcol.r - forecol.r;
+ gdiff := backcol.g - forecol.g;
+ bdiff := backcol.b - forecol.b;
+
+ for i := 0 to NUM_COLORS - 1 do
+ begin
+ colors[ i ].r := forecol.r + ( i * rdiff ) div 4;
+ colors[ i ].g := forecol.g + ( i * gdiff ) div 4;
+ colors[ i ].b := forecol.b + ( i * bdiff ) div 4;
+ end;
+
+ SDL_SetColors( screen, @colors, 0, NUM_COLORS );
+
+ { Clear the background to background color }
+
+ SDL_FillRect( screen, nil, SDL_MapRGB( screen.format, backcol.r, backcol.g, backcol.b ) );
+
+ SDL_UpdateRect( screen, 0, 0, 0, 0 );
+
+ { Show which font file we're looking at }
+ //sprintf(string, 'Font file: %s', argv[0]);
+
+ { Render and center the message }
+ if message = '' then
+ begin
+ message := DEFAULT_TEXT;
+ end;
+
+ case rendertype of
+ rtLatin1 :
+ begin
+ if ( rendersolid ) then
+ begin
+ text := TTF_RenderText_Solid( font, PChar( string(message) ), forecol );
+ end
+ else
+ begin
+ text := TTF_RenderText_Shaded( font, PChar( string( message ) ), forecol, backcol );
+ end;
+ end;
+
+ rtUTF8 :
+ begin
+ if ( rendersolid ) then
+ begin
+ text := TTF_RenderUTF8_Solid( font, PChar( string( message ) ), forecol );
+ end
+ else
+ begin
+ text := TTF_RenderUTF8_Shaded( font, PChar( string( message ) ), forecol, backcol );
+ end;
+ end;
+
+ rtUnicode :
+ begin
+ { This doesn't actually work because you can't pass UNICODE text in via command line, AFAIK, but...}
+ {Uint16 unicode_text[BUFSIZ];
+ int index;}
+ {for index := 0 to Length(message) - 1 do
+ begin
+ unicode_text[index] := ((Uint8 *)message)[0];
+ unicode_text[index] := unicode_text[index] shl 8;
+ unicode_text[index] := unicode_text[index] or ((Uint8 *)message)[1];
+ message := message + 2;
+ end; }
+ if ( rendersolid ) then
+ begin
+ text := TTF_RenderUNICODE_Solid(font, PUInt16( message ), forecol);
+ end
+ else
+ begin
+ text := TTF_RenderUNICODE_Shaded( font, PUInt16( message ), forecol, backcol);
+ end;
+ end;
+ else
+ begin
+ text := nil;
+ { This shouldn't happen }
+ end;
+ end;
+
+ if ( text = nil ) then
+ begin
+ //fprintf(stderr, 'Couldn''t render text: %s', [SDL_GetError]);
+ TTF_CloseFont( font );
+ ShutDownApplication( 2 );
+ end;
+
+ dstrect.x := ( screen.w - text.w ) div 2;
+ dstrect.y := ( screen.h - text.h ) div 2;
+ dstrect.w := text.w;
+ dstrect.h := text.h;
+ //printf('Font is generally %d big, and string is %hd big', TTF_FontHeight(font), text.h);
+
+ { Blit the text surface }
+ if ( SDL_BlitSurface( text, nil, screen, @dstrect ) < 0 ) then
+ begin
+ //fprintf(stderr, 'Couldn't blit text to display: %s', [SDL_GetError]);
+ TTF_CloseFont( font );
+ ShutDownApplication( 2 );
+ end;
+
+ SDL_UpdateRect( screen, 0, 0, 0, 0 );
+ { Set the text colorkey and convert to display format }
+ if ( SDL_SetColorKey( text, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0 ) < 0 ) then
+ begin
+ //fprintf(stderr, 'Warning: Couldn't set text colorkey: %s', [SDL_GetError]);
+ end;
+
+ temp := SDL_DisplayFormat( text );
+ if ( temp <> nil ) then
+ begin
+ SDL_FreeSurface( text );
+ text := temp;
+
+ { Wait for a keystroke, and blit text on mouse press }
+ done := false;
+ while ( not done ) do
+ begin
+ while ( SDL_PollEvent( @event ) <> 0 ) do
+ begin
+ case ( event.type_ ) of
+ SDL_MOUSEBUTTONDOWN :
+ begin
+ dstrect.x := event.button.x - text.w div 2;
+ dstrect.y := event.button.y - text.h div 2;
+ dstrect.w := text.w;
+ dstrect.h := text.h;
+ if ( SDL_BlitSurface( text, nil, screen, @dstrect ) = 0 ) then
+ begin
+ SDL_UpdateRects( screen, 1, @dstrect );
+ end
+ else
+ begin
+ //fprintf(stderr, 'Couldn''t blit text to display: %s', [SDL_GetError]);
+ end;
+ end;
+
+ SDL_KEYDOWN, SDL_QUITEV :
+ begin
+ done := true;
+ end;
+
+ end;
+ end;
+ end;
+ end;
+ SDL_FreeSurface( text );
+ TTF_CloseFont( font );
+ ShutDownApplication( 0 );
+end.
+
diff --git a/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdl_ttf.pas b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdl_ttf.pas new file mode 100644 index 00000000..88966f82 --- /dev/null +++ b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdl_ttf.pas @@ -0,0 +1,505 @@ +unit sdl_ttf;
+{
+ $Id: sdl_ttf.pas,v 1.19 2007/12/05 22:54:20 savage Exp $
+
+}
+{******************************************************************************}
+{ }
+{ JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer }
+{ Conversion of the Simple DirectMedia Layer Headers }
+{ }
+{ Portions created by Sam Lantinga <slouken@devolution.com> are }
+{ Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga }
+{ 5635-34 Springhouse Dr. }
+{ Pleasanton, CA 94588 (USA) }
+{ }
+{ All Rights Reserved. }
+{ }
+{ The original files are : SDL_ttf.h }
+{ }
+{ The initial developer of this Pascal code was : }
+{ Dominqiue Louis <Dominique@SavageSoftware.com.au> }
+{ }
+{ Portions created by Dominqiue Louis are }
+{ Copyright (C) 2000 - 2001 Dominqiue Louis. }
+{ }
+{ }
+{ Contributor(s) }
+{ -------------- }
+{ Tom Jones <tigertomjones@gmx.de> His Project inspired this conversion }
+{ }
+{ Obtained through: }
+{ Joint Endeavour of Delphi Innovators ( Project JEDI ) }
+{ }
+{ You may retrieve the latest version of this file at the Project }
+{ JEDI home page, located at http://delphi-jedi.org }
+{ }
+{ The contents of this file are used with permission, subject to }
+{ the Mozilla Public License Version 1.1 (the "License"); you may }
+{ not use this file except in compliance with the License. You may }
+{ obtain a copy of the License at }
+{ http://www.mozilla.org/MPL/MPL-1.1.html }
+{ }
+{ Software distributed under the License is distributed on an }
+{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
+{ implied. See the License for the specific language governing }
+{ rights and limitations under the License. }
+{ }
+{ Description }
+{ ----------- }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ Requires }
+{ -------- }
+{ The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so }
+{ They are available from... }
+{ http://www.libsdl.org . }
+{ }
+{ Programming Notes }
+{ ----------------- }
+{ }
+{ }
+{ }
+{ }
+{ Revision History }
+{ ---------------- }
+{ December 08 2002 - DL : Fixed definition of TTF_RenderUnicode_Solid }
+{ }
+{ April 03 2003 - DL : Added jedi-sdl.inc include file to support more }
+{ Pascal compilers. Initial support is now included }
+{ for GnuPascal, VirtualPascal, TMT and obviously }
+{ continue support for Delphi Kylix and FreePascal. }
+{ }
+{ April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added}
+{ better TMT Pascal support and under instruction }
+{ from Prof. Abimbola Olowofoyeku (The African Chief),}
+{ I have added better Gnu Pascal support }
+{ }
+{ April 30 2003 - DL : under instruction from David Mears AKA }
+{ Jason Siletto, I have added FPC Linux support. }
+{ This was compiled with fpc 1.1, so remember to set }
+{ include file path. ie. -Fi/usr/share/fpcsrc/rtl/* }
+{ }
+{
+ $Log: sdl_ttf.pas,v $
+ Revision 1.19 2007/12/05 22:54:20 savage
+ Better Mac OS X support for Frameworks.
+
+ Revision 1.18 2007/06/01 11:16:33 savage
+ Added IFDEF UNIX for Workaround.
+
+ Revision 1.17 2007/06/01 08:38:21 savage
+ Added TTF_RenderText_Solid workaround as suggested by Michalis Kamburelis
+
+ Revision 1.16 2007/05/29 21:32:14 savage
+ Changes as suggested by Almindor for 64bit compatibility.
+
+ Revision 1.15 2007/05/20 20:32:45 savage
+ Initial Changes to Handle 64 Bits
+
+ Revision 1.14 2006/12/02 00:19:01 savage
+ Updated to latest version
+
+ Revision 1.13 2005/04/10 11:48:33 savage
+ Changes as suggested by Michalis, thanks.
+
+ Revision 1.12 2005/01/05 01:47:14 savage
+ Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively.
+
+ Revision 1.11 2005/01/04 23:14:57 savage
+ Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively.
+
+ Revision 1.10 2005/01/02 19:07:32 savage
+ Slight bug fix to use LongInt instead of Long ( Thanks Michalis Kamburelis )
+
+ Revision 1.9 2005/01/01 02:15:20 savage
+ Updated to v2.0.7
+
+ Revision 1.8 2004/10/07 21:02:32 savage
+ Fix for FPC
+
+ Revision 1.7 2004/09/30 22:39:50 savage
+ Added a true type font class which contains a wrap text function.
+ Changed the sdl_ttf.pas header to reflect the future of jedi-sdl.
+
+ Revision 1.6 2004/08/14 22:54:30 savage
+ Updated so that Library name defines are correctly defined for MacOS X.
+
+ Revision 1.5 2004/05/10 14:10:04 savage
+ Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ).
+
+ Revision 1.4 2004/04/13 09:32:08 savage
+ Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary.
+
+ Revision 1.3 2004/04/01 20:53:24 savage
+ Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site.
+
+ Revision 1.2 2004/03/30 20:23:28 savage
+ Tidied up use of UNIX compiler directive.
+
+ Revision 1.1 2004/02/16 22:16:40 savage
+ v1.0 changes
+
+
+}
+{******************************************************************************}
+
+{$I jedi-sdl.inc}
+
+{
+ Define this to workaround a known bug in some freetype versions.
+ The error manifests as TTF_RenderGlyph_Solid returning nil (error)
+ and error message (in SDL_Error) is
+ "Failed loading DPMSDisable: /usr/lib/libX11.so.6: undefined symbol: DPMSDisable"
+ See [http://lists.libsdl.org/pipermail/sdl-libsdl.org/2007-March/060459.html]
+}
+{$IFDEF UNIX}
+{$DEFINE Workaround_TTF_RenderText_Solid}
+{$ENDIF}
+
+
+interface
+
+uses
+{$IFDEF __GPC__}
+ gpc,
+{$ENDIF}
+
+{$IFDEF WINDOWS}
+ {$IFNDEF __GPC__}
+ Windows,
+ {$ENDIF}
+{$ENDIF}
+ sdl;
+
+const
+{$IFDEF WINDOWS}
+ SDLttfLibName = 'SDL_ttf.dll';
+{$ENDIF}
+
+{$IFDEF UNIX}
+{$IFDEF DARWIN}
+ SDLttfLibName = 'libSDL_ttf-2.0.0.dylib';
+{$ELSE}
+ {$IFDEF FPC}
+ SDLttfLibName = 'libSDL_ttf.so';
+ {$ELSE}
+ SDLttfLibName = 'libSDL_ttf-2.0.so.0';
+ {$ENDIF}
+{$ENDIF}
+{$ENDIF}
+
+{$IFDEF MACOS}
+ SDLttfLibName = 'SDL_ttf';
+ {$linklib libSDL_ttf}
+{$ENDIF}
+
+ {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
+ SDL_TTF_MAJOR_VERSION = 2;
+{$EXTERNALSYM SDL_TTF_MAJOR_VERSION}
+ SDL_TTF_MINOR_VERSION = 0;
+{$EXTERNALSYM SDL_TTF_MINOR_VERSION}
+ SDL_TTF_PATCHLEVEL = 9;
+{$EXTERNALSYM SDL_TTF_PATCHLEVEL}
+
+ // Backwards compatibility
+ TTF_MAJOR_VERSION = SDL_TTF_MAJOR_VERSION;
+ TTF_MINOR_VERSION = SDL_TTF_MINOR_VERSION;
+ TTF_PATCHLEVEL = SDL_TTF_PATCHLEVEL;
+
+{*
+ Set and retrieve the font style
+ This font style is implemented by modifying the font glyphs, and
+ doesn't reflect any inherent properties of the truetype font file.
+*}
+ TTF_STYLE_NORMAL = $00;
+ TTF_STYLE_BOLD = $01;
+ TTF_STYLE_ITALIC = $02;
+ TTF_STYLE_UNDERLINE = $04;
+
+// ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark)
+ UNICODE_BOM_NATIVE = $FEFF;
+ UNICODE_BOM_SWAPPED = $FFFE;
+
+type
+ PTTF_Font = ^TTTF_font;
+ TTTF_Font = record
+ end;
+
+{ This macro can be used to fill a version structure with the compile-time
+ version of the SDL_ttf library. }
+procedure SDL_TTF_VERSION( var X : TSDL_version );
+{$EXTERNALSYM SDL_TTF_VERSION}
+
+{ This function gets the version of the dynamically linked SDL_ttf library.
+ It should NOT be used to fill a version structure, instead you should use the
+ SDL_TTF_VERSION() macro. }
+function TTF_Linked_Version : PSDL_version;
+cdecl; external {$IFDEF __GPC__}name 'TTF_Linked_Version'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_Linked_Version}
+
+{ This function tells the library whether UNICODE text is generally
+ byteswapped. A UNICODE BOM character in a string will override
+ this setting for the remainder of that string.
+}
+procedure TTF_ByteSwappedUNICODE( swapped : integer );
+cdecl; external {$IFDEF __GPC__}name 'TTF_ByteSwappedUNICODE'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_ByteSwappedUNICODE}
+
+//returns 0 on succes, -1 if error occurs
+function TTF_Init : integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_Init'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_Init}
+
+{
+ Open a font file and create a font of the specified point size.
+ Some .fon fonts will have several sizes embedded in the file, so the
+ point size becomes the index of choosing which size. If the value
+ is too high, the last indexed size will be the default.
+}
+function TTF_OpenFont( const filename : Pchar; ptsize : integer ) : PTTF_Font;
+cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFont'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_OpenFont}
+
+function TTF_OpenFontIndex( const filename : Pchar; ptsize : integer; index : Longint ): PTTF_Font;
+cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontIndex'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_OpenFontIndex}
+
+function TTF_OpenFontRW( src : PSDL_RWops; freesrc : integer; ptsize : integer ): PTTF_Font;
+cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontRW'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_OpenFontRW}
+
+function TTF_OpenFontIndexRW( src : PSDL_RWops; freesrc : integer; ptsize : integer; index : Longint ): PTTF_Font;
+cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontIndexRW'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_OpenFontIndexRW}
+
+function TTF_GetFontStyle( font : PTTF_Font) : integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_GetFontStyle'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_GetFontStyle}
+
+procedure TTF_SetFontStyle( font : PTTF_Font; style : integer );
+cdecl; external {$IFDEF __GPC__}name 'TTF_SetFontStyle'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_SetFontStyle}
+
+{ Get the total height of the font - usually equal to point size }
+function TTF_FontHeight( font : PTTF_Font ) : Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontHeight'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontHeight}
+
+{ Get the offset from the baseline to the top of the font
+ This is a positive value, relative to the baseline.
+}
+function TTF_FontAscent( font : PTTF_Font ) : Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontAscent'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontAscent}
+{ Get the offset from the baseline to the bottom of the font
+ This is a negative value, relative to the baseline.
+}
+function TTF_FontDescent( font : PTTF_Font ) : Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontDescent'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontDescent}
+
+{ Get the recommended spacing between lines of text for this font }
+function TTF_FontLineSkip( font : PTTF_Font ): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontLineSkip'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontLineSkip}
+
+{ Get the number of faces of the font }
+function TTF_FontFaces( font : PTTF_Font ) : Longint;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaces'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontFaces}
+
+{ Get the font face attributes, if any }
+function TTF_FontFaceIsFixedWidth( font : PTTF_Font ): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceIsFixedWidth'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontFaceIsFixedWidth}
+
+function TTF_FontFaceFamilyName( font : PTTF_Font ): PChar;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceFamilyName'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontFaceFamilyName}
+
+function TTF_FontFaceStyleName( font : PTTF_Font ): PChar;
+cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceStyleName'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_FontFaceStyleName}
+
+{ Get the metrics (dimensions) of a glyph }
+function TTF_GlyphMetrics( font : PTTF_Font; ch : Uint16;
+ var minx : integer; var maxx : integer;
+ var miny : integer; var maxy : integer;
+ var advance : integer ): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_GlyphMetrics'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_GlyphMetrics}
+
+{ Get the dimensions of a rendered string of text }
+function TTF_SizeText( font : PTTF_Font; const text : PChar; var w : integer; var y : integer ): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_SizeText'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_SizeText}
+
+function TTF_SizeUTF8( font : PTTF_Font; const text : PChar; var w : integer; var y : integer): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_SizeUTF8'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_SizeUTF8}
+
+function TTF_SizeUNICODE( font : PTTF_Font; const text : PUint16; var w : integer; var y : integer): Integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_SizeUNICODE'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_SizeUNICODE}
+
+{ Create an 8-bit palettized surface and render the given text at
+ fast quality with the given font and color. The 0 pixel is the
+ colorkey, giving a transparent background, and the 1 pixel is set
+ to the text color.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderText_Solid( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color ): PSDL_Surface;
+{$IFNDEF Workaround_TTF_RenderText_Solid}
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderText_Solid}
+{$ENDIF}
+
+function TTF_RenderUTF8_Solid( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUTF8_Solid}
+
+function TTF_RenderUNICODE_Solid( font : PTTF_Font;
+ const text :PUint16; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUNICODE_Solid}
+
+{
+Create an 8-bit palettized surface and render the given glyph at
+ fast quality with the given font and color. The 0 pixel is the
+ colorkey, giving a transparent background, and the 1 pixel is set
+ to the text color. The glyph is rendered without any padding or
+ centering in the X direction, and aligned normally in the Y direction.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderGlyph_Solid( font : PTTF_Font;
+ ch : Uint16; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderGlyph_Solid}
+
+{ Create an 8-bit palettized surface and render the given text at
+ high quality with the given font and colors. The 0 pixel is background,
+ while other pixels have varying degrees of the foreground color.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderText_Shaded( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderText_Shaded}
+function TTF_RenderUTF8_Shaded( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUTF8_Shaded}
+function TTF_RenderUNICODE_Shaded( font : PTTF_Font;
+ const text : PUint16; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUNICODE_Shaded}
+
+{ Create an 8-bit palettized surface and render the given glyph at
+ high quality with the given font and colors. The 0 pixel is background,
+ while other pixels have varying degrees of the foreground color.
+ The glyph is rendered without any padding or centering in the X
+ direction, and aligned normally in the Y direction.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderGlyph_Shaded( font : PTTF_Font; ch : Uint16; fg : TSDL_Color;
+ bg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderGlyph_Shaded}
+
+{ Create a 32-bit ARGB surface and render the given text at high quality,
+ using alpha blending to dither the font with the given color.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderText_Blended( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderText_Blended}
+function TTF_RenderUTF8_Blended( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUTF8_Blended}
+function TTF_RenderUNICODE_Blended( font : PTTF_Font;
+ const text: PUint16; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderUNICODE_Blended}
+
+{ Create a 32-bit ARGB surface and render the given glyph at high quality,
+ using alpha blending to dither the font with the given color.
+ The glyph is rendered without any padding or centering in the X
+ direction, and aligned normally in the Y direction.
+ This function returns the new surface, or NULL if there was an error.
+}
+function TTF_RenderGlyph_Blended( font : PTTF_Font; ch : Uint16; fg : TSDL_Color ): PSDL_Surface;
+cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_RenderGlyph_Blended}
+
+{ For compatibility with previous versions, here are the old functions }
+{#define TTF_RenderText(font, text, fg, bg)
+ TTF_RenderText_Shaded(font, text, fg, bg)
+#define TTF_RenderUTF8(font, text, fg, bg)
+ TTF_RenderUTF8_Shaded(font, text, fg, bg)
+#define TTF_RenderUNICODE(font, text, fg, bg)
+ TTF_RenderUNICODE_Shaded(font, text, fg, bg)}
+
+{ Close an opened font file }
+procedure TTF_CloseFont( font : PTTF_Font );
+cdecl; external {$IFDEF __GPC__}name 'TTF_CloseFont'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_CloseFont}
+
+//De-initialize TTF engine
+procedure TTF_Quit;
+cdecl; external {$IFDEF __GPC__}name 'TTF_Quit'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_Quit}
+
+// Check if the TTF engine is initialized
+function TTF_WasInit : integer;
+cdecl; external {$IFDEF __GPC__}name 'TTF_WasInit'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
+{$EXTERNALSYM TTF_WasInit}
+
+// We'll use SDL for reporting errors
+procedure TTF_SetError( fmt : PChar );
+
+function TTF_GetError : PChar;
+
+implementation
+
+{$IFDEF __GPC__}
+ {$L 'sdl_ttf'} { link sdl_ttf.dll.a or libsdl_ttf.so or libsdl_ttf.a }
+{$ENDIF}
+
+procedure SDL_TTF_VERSION( var X : TSDL_version );
+begin
+ X.major := SDL_TTF_MAJOR_VERSION;
+ X.minor := SDL_TTF_MINOR_VERSION;
+ X.patch := SDL_TTF_PATCHLEVEL;
+end;
+
+procedure TTF_SetError( fmt : PChar );
+begin
+ SDL_SetError( fmt );
+end;
+
+function TTF_GetError : PChar;
+begin
+ result := SDL_GetError;
+end;
+
+{$IFDEF Workaround_TTF_RenderText_Solid}
+function TTF_RenderText_Solid( font : PTTF_Font;
+ const text : PChar; fg : TSDL_Color ): PSDL_Surface;
+const
+ Black: TSDL_Color = (r: 0; g: 0; b: 0; unused: 0);
+begin
+ Result := TTF_RenderText_Shaded(font, text, fg, Black);
+end;
+{$ENDIF Workaround_TTF_RenderText_Solid}
+
+end.
diff --git a/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdltruetypefont.pas b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdltruetypefont.pas new file mode 100644 index 00000000..a0f25e12 --- /dev/null +++ b/Game/Code/lib/JEDI-SDLv1.0/SDL_ttf/Pas/sdltruetypefont.pas @@ -0,0 +1,565 @@ +unit sdltruetypefont;
+{
+ $Id: sdltruetypefont.pas,v 1.5 2005/05/26 21:22:28 savage Exp $
+
+}
+{******************************************************************************}
+{ }
+{ JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer }
+{ Wrapper class for SDL_ttf }
+{ }
+{ The initial developer of this Pascal code was : }
+{ Dominqiue Louis <Dominique@SavageSoftware.com.au> }
+{ }
+{ Portions created by Dominqiue Louis are }
+{ Copyright (C) 2000 - 2001 Dominqiue Louis. }
+{ }
+{ }
+{ Contributor(s) }
+{ -------------- }
+{ }
+{ }
+{ Obtained through: }
+{ Joint Endeavour of Delphi Innovators ( Project JEDI ) }
+{ }
+{ You may retrieve the latest version of this file at the Project }
+{ JEDI home page, located at http://delphi-jedi.org }
+{ }
+{ The contents of this file are used with permission, subject to }
+{ the Mozilla Public License Version 1.1 (the "License"); you may }
+{ not use this file except in compliance with the License. You may }
+{ obtain a copy of the License at }
+{ http://www.mozilla.org/MPL/MPL-1.1.html }
+{ }
+{ Software distributed under the License is distributed on an }
+{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
+{ implied. See the License for the specific language governing }
+{ rights and limitations under the License. }
+{ }
+{ Description }
+{ ----------- }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ }
+{ Requires }
+{ -------- }
+{ The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so }
+{ They are available from... }
+{ http://www.libsdl.org . }
+{ }
+{ Programming Notes }
+{ ----------------- }
+{ }
+{ }
+{ }
+{ }
+{ Revision History }
+{ ---------------- }
+{ September 23 2004 - DL : Initial Creation }
+{
+ $Log: sdltruetypefont.pas,v $
+ Revision 1.5 2005/05/26 21:22:28 savage
+ Update to Input code.
+
+ Revision 1.1 2005/05/25 23:15:42 savage
+ Latest Changes
+
+ Revision 1.4 2005/05/25 22:55:01 savage
+ Added InputRect support.
+
+ Revision 1.3 2005/05/13 14:02:49 savage
+ Made it use UniCode rendering by default.
+
+ Revision 1.2 2005/05/13 11:37:52 savage
+ Improved wordwrapping algorithm
+
+ Revision 1.1 2004/09/30 22:39:50 savage
+ Added a true type font class which contains a wrap text function.
+ Changed the sdl_ttf.pas header to reflect the future of jedi-sdl.
+
+
+}
+{******************************************************************************}
+
+interface
+
+uses
+ sdl,
+ sdl_ttf;
+
+type
+ TRenderType = ( rtLatin1, rtUTF8, rtUnicode );
+ TSDLFontStyle = ( fsBold, fsItalic, fsUnderline, fsStrikeOut );
+
+ TSDLFontStyles = set of TSDLFontStyle;
+
+ TTrueTypeFont = class( TObject )
+ private
+ FFont : PTTF_Font;
+ FSolid : Boolean;
+ FBackGroundColour : TSDL_Color;
+ FForeGroundColour : TSDL_Color;
+ FRenderType : TRenderType;
+ FStyle : TSDLFontStyles;
+ FFontFile : string;
+ FFontSize : integer;
+ procedure PrepareFont;
+
+ protected
+
+ public
+ constructor Create( aFontFile : string; aRenderStyle : TSDLFontStyles = [ ]; aFontSize : integer = 14 );
+ destructor Destroy; override;
+ function DrawText( aText : WideString ) : PSDL_Surface; overload;
+ function DrawText( aText : WideString; aWidth, aHeight : Integer ) : PSDL_Surface; overload;
+ function Input(aDestination: PSDL_Surface; aX, aY, aWidth, aHeight: integer; var aText: string; aMaxChars: integer = 10 ): PSDL_Surface;
+ property BackGroundColour : TSDL_Color read FBackGroundColour write FBackGroundColour;
+ property ForeGroundColour : TSDL_Color read FForeGroundColour write FForeGroundColour;
+ property FontFile : string read FFontFile write FFontFile;
+ property RenderType : TRenderType read FRenderType write FRenderType;
+ property Solid : Boolean read FSolid write FSolid;
+ property Style : TSDLFontStyles read FStyle write FStyle;
+ property FontSize : integer read FFontSize write FFontSize;
+ end;
+
+
+implementation
+
+uses
+ SysUtils;
+
+{ TTrueTypeFont }
+
+constructor TTrueTypeFont.Create( aFontFile : string; aRenderStyle : TSDLFontStyles; aFontSize : integer );
+begin
+ inherited Create;
+ if FileExists( aFontFile ) then
+ begin
+ FStyle := aRenderStyle;
+ FFontSize := aFontSize;
+ FSolid := false;
+ FBackGroundColour.r := 255;
+ FBackGroundColour.g := 255;
+ FBackGroundColour.b := 255;
+ FForeGroundColour.r := 0;
+ FForeGroundColour.g := 0;
+ FForeGroundColour.b := 0;
+ FRenderType := rtUnicode;
+ if ( TTF_Init >= 0 ) then
+ begin
+ FFontFile := aFontFile;
+ end
+ else
+ raise Exception.Create( 'Failed to Initialiase SDL_TTF' );
+ end
+ else
+ raise Exception.Create( 'Font File does not exist' );
+end;
+
+destructor TTrueTypeFont.Destroy;
+begin
+ if FFont <> nil then
+ TTF_CloseFont( FFont );
+ TTF_Quit;
+ inherited;
+end;
+
+function TTrueTypeFont.DrawText( aText : WideString ) : PSDL_Surface;
+begin
+ PrepareFont;
+
+ result := nil;
+
+ case FRenderType of
+ rtLatin1 :
+ begin
+ if ( FSolid ) then
+ begin
+ result := TTF_RenderText_Solid( FFont, PChar( string( aText ) ), FForeGroundColour );
+ end
+ else
+ begin
+ result := TTF_RenderText_Shaded( FFont, PChar( string( aText ) ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+
+ rtUTF8 :
+ begin
+ if ( FSolid ) then
+ begin
+ result := TTF_RenderUTF8_Solid( FFont, PChar( string( aText ) ), FForeGroundColour );
+ end
+ else
+ begin
+ result := TTF_RenderUTF8_Shaded( FFont, PChar( string( aText ) ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+
+ rtUnicode :
+ begin
+ if ( FSolid ) then
+ begin
+ result := TTF_RenderUNICODE_Solid( FFont, PUInt16( aText ), FForeGroundColour );
+ end
+ else
+ begin
+ result := TTF_RenderUNICODE_Shaded( FFont, PUInt16( aText ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+ end;
+end;
+
+function TTrueTypeFont.DrawText( aText : WideString; aWidth, aHeight : Integer ) : PSDL_Surface;
+var
+ textw, texth, i, yPos : integer;
+ strChopped : WideString;
+ SurfaceList : array of PSDL_Surface;
+ strlist : array of WideString;
+ ReturnedSurface : PSDL_Surface;
+ BltRect : TSDL_Rect;
+begin
+ PrepareFont;
+
+ // Do an initial check to see if it already fits
+ case FRenderType of
+ rtLatin1 :
+ begin
+ if TTF_SizeText( FFont, PChar( string( aText ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ result := DrawText( aText );
+ exit;
+ end
+ end;
+ end;
+
+ rtUTF8 :
+ begin
+ if TTF_SizeUTF8( FFont, PChar( string( aText ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ result := DrawText( aText );
+ exit;
+ end
+ end;
+ end;
+
+ rtUnicode :
+ begin
+ if TTF_SizeUNICODE( FFont, PUInt16( aText ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ result := DrawText( aText );
+ exit;
+ end
+ end;
+ end;
+ end;
+
+ // Create the Surface we will be returning
+ ReturnedSurface := SDL_DisplayFormat( SDL_CreateRGBSurface( SDL_SRCCOLORKEY or SDL_RLEACCEL or SDL_HWACCEL, aWidth, aHeight, 16, 0, 0, 0, 0 ) );
+
+ // If we are still here there is some serious parsing to do
+ case FRenderType of
+ rtLatin1 :
+ begin
+ strChopped := aText;
+ i := Length( strChopped );
+ while ( i <> 0 ) do
+ begin
+ if ( string( strChopped[ i ] ) <> ' ' ) and ( Integer( string( strChopped[ i ] ) ) <> 13 ) then
+ dec( i )
+ else
+ begin
+ dec( i );
+ if TTF_SizeText( FFont, PChar( string( Copy( strChopped, 0, i ) ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ if TTF_SizeText( FFont, PChar( string( strChopped ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ end;
+ end;
+ end;
+ end;
+ end;
+ end;
+
+ SetLength( SurfaceList, Length( strlist ) );
+ for i := Low( strlist ) to High( strlist ) do
+ begin
+ if ( FSolid ) then
+ begin
+ SurfaceList[ i ] := TTF_RenderText_Solid( FFont, PChar( string( strlist[ i ] ) ), FForeGroundColour );
+ end
+ else
+ begin
+ SurfaceList[ i ] := TTF_RenderText_Shaded( FFont, PChar( string( strlist[ i ] ) ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+ end;
+
+ rtUTF8 :
+ begin
+ strChopped := aText;
+ i := Length( strChopped );
+ while ( i <> 0 ) do
+ begin
+ if ( string( strChopped[ i ] ) <> ' ' ) and ( Integer( string( strChopped[ i ] ) ) <> 13 ) then
+ dec( i )
+ else
+ begin
+ dec( i );
+ if TTF_SizeUTF8( FFont, PChar( string( Copy( strChopped, 0, i ) ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ if TTF_SizeUTF8( FFont, PChar( string( strChopped ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ end;
+ end;
+ end;
+ end;
+ end;
+ end;
+
+ SetLength( SurfaceList, Length( strlist ) );
+ for i := Low( strlist ) to High( strlist ) do
+ begin
+ if ( FSolid ) then
+ begin
+ SurfaceList[ i ] := TTF_RenderUTF8_Solid( FFont, PChar( string( strlist[ i ] ) ), FForeGroundColour );
+ end
+ else
+ begin
+ SurfaceList[ i ] := TTF_RenderUTF8_Shaded( FFont, PChar( string( strlist[ i ] ) ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+ end;
+
+ rtUnicode :
+ begin
+ strChopped := aText;
+ i := Length( strChopped );
+ while ( i <> 0 ) do
+ begin
+ if ( string( strChopped[ i ] ) <> ' ' ) and ( Integer( string( strChopped[ i ] ) ) <> 13 ) then
+ dec( i )
+ else
+ begin
+ dec( i );
+ if TTF_SizeUNICODE( FFont, PUInt16( Copy( strChopped, 0, i ) ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ if TTF_SizeUNICODE( FFont, PUInt16( strChopped ), textw, texth ) = 0 then
+ begin
+ if ( textw < aWidth )
+ and ( texth < aHeight ) then
+ begin
+ SetLength( strlist, Length( strlist ) + 1 );
+ strlist[ Length( strlist ) - 1 ] := Copy( strChopped, 0, i );
+ strChopped := Copy( strChopped, i + 2, Length( strChopped ) - ( i - 1 ) );
+ i := Length( strChopped );
+ end;
+ end;
+ end;
+ end;
+ end;
+ end;
+ SetLength( SurfaceList, Length( strlist ) );
+ for i := Low( strlist ) to High( strlist ) do
+ begin
+ if ( FSolid ) then
+ begin
+ SurfaceList[ i ] := TTF_RenderUNICODE_Solid( FFont, PUInt16( strlist[ i ] ), FForeGroundColour );
+ end
+ else
+ begin
+ SurfaceList[ i ] := TTF_RenderUNICODE_Shaded( FFont, PUInt16( strlist[ i ] ), FForeGroundColour, FBackGroundColour );
+ end;
+ end;
+ end;
+ end;
+
+ // Now Draw the SurfaceList onto the resulting Surface
+ yPos := 6;
+ for i := Low( SurfaceList ) to High( SurfaceList ) do
+ begin
+ BltRect.x := 6;
+ BltRect.y := yPos;
+ BltRect.w := SurfaceList[ i ].w;
+ BltRect.h := SurfaceList[ i ].h;
+ SDL_BlitSurface( SurfaceList[ i ], nil, ReturnedSurface, @BltRect );
+ yPos := yPos + TTF_FontHeight( FFont );
+ end;
+ result := ReturnedSurface;
+
+ for i := Low( SurfaceList ) to High( SurfaceList ) do
+ begin
+ SDL_FreeSurface( SurfaceList[ i ] );
+ end;
+ SetLength( SurfaceList, 0 );
+ SetLength( strlist, 0 );
+end;
+
+function TTrueTypeFont.Input(aDestination: PSDL_Surface; aX, aY, aWidth: integer; aHeight : integer; var aText : string; aMaxChars: integer): PSDL_Surface;
+var
+ event : TSDL_Event;
+ ch : integer;
+
+ BackSurface, TextSurface : PSDL_Surface;
+ rect : SDL_Rect;
+ textw, texth : integer;
+ Done : boolean;
+ PassedInText : string;
+begin
+ PassedInText := aText;
+
+ BackSurface := SDL_AllocSurface( aDestination.flags,
+ aDestination.w,
+ aDestination.h,
+ aDestination.format.BitsPerPixel,
+ aDestination.format.Rmask,
+ aDestination.format.Gmask,
+ aDestination.format.Bmask, 0 );
+
+ rect.x := aX;
+ rect.y := aY;
+ rect.w := aWidth;
+ rect.h := aHeight;
+
+ SDL_BlitSurface( aDestination, nil, BackSurface, nil );
+ SDL_FillRect( BackSurface, @rect, SDL_MapRGB( aDestination.format, 0, 0, 0 ) );
+
+ TextSurface := DrawText( aText + '|' );
+
+ // start input
+ SDL_EnableUNICODE( 1 );
+ Done := false;
+ while ( not Done ) and ( SDL_WaitEvent( @event ) > 0 ) do
+ begin
+ if event.type_ = SDL_KEYDOWN then
+ begin
+ ch := event.key.keysym.unicode;
+ case ch of
+ SDLK_RETURN :
+ begin
+ Done := true;
+ end;
+
+ SDLK_ESCAPE :
+ begin
+ aText := PassedInText;
+ Done := true;
+ end;
+
+ SDLK_BACKSPACE :
+ begin
+ if ( Length( aText ) > 0 ) then
+ begin
+ aText := Copy( aText, 0, Length( aText ) - 1 );
+ if TextSurface <> nil then
+ SDL_FreeSurface( TextSurface );
+ TextSurface := DrawText( aText + '|' );
+ end;
+ end;
+ else
+ begin
+ if Length( aText ) < aMaxChars then
+ begin
+ if ( chr( ch ) <> '' ) then
+ begin
+ aText := aText + chr( ch );
+
+ if ( aText <> '' )
+ and ( TTF_SizeUNICODE( FFont, PUInt16( aText ), textw, texth ) = 0 ) then
+ begin
+ if ( textw > aWidth ) then
+ aText := Copy( aText, 0, Length( aText ) - 1 );
+ end;
+
+ if TextSurface <> nil then
+ SDL_FreeSurface( TextSurface );
+ TextSurface := DrawText( aText + '|' );
+ end;
+ end;
+ end;
+ end;
+ end;
+ SDL_BlitSurface( BackSurface, nil, aDestination, nil );
+ SDL_BlitSurface( TextSurface, nil, aDestination, @rect );
+ SDL_Flip( aDestination );
+ end;
+
+ if TextSurface <> nil then
+ SDL_FreeSurface( TextSurface );
+ if aText <> '' then
+ TextSurface := DrawText( aText );
+ SDL_FreeSurface( BackSurface );
+ result := TextSurface;
+end;
+
+procedure TTrueTypeFont.PrepareFont;
+var
+ renderstyle : integer;
+begin
+ if FFont <> nil then
+ TTF_CloseFont( FFont );
+
+ FFont := TTF_OpenFont( PChar( FFontFile ), FFontSize );
+
+ renderstyle := TTF_STYLE_NORMAL;
+ if ( fsBold in FStyle ) then
+ renderstyle := renderstyle or TTF_STYLE_BOLD;
+
+ if ( fsItalic in FStyle ) then
+ renderstyle := renderstyle or TTF_STYLE_ITALIC;
+
+ if ( fsUnderline in FStyle ) then
+ renderstyle := renderstyle or TTF_STYLE_UNDERLINE;
+
+ TTF_SetFontStyle( FFont, renderstyle );
+end;
+
+end.
+
|