From c4eae67bc403eb26af8a1c91f9eb67dc92a8b4b6 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Tue, 5 Feb 2008 11:40:45 +0000 Subject: updated to latest version of JEDI SDL JEDI-SDL v1.0 Final RC ( 2008-01-29 05:46 ) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@811 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdl_ttf.pas | 68 +++++++- .../lib/JEDI-SDL/SDL_ttf/Pas/sdltruetypefont.pas | 180 ++++++++++++++++++--- 2 files changed, 215 insertions(+), 33 deletions(-) (limited to 'Game/Code/lib/JEDI-SDL/SDL_ttf') diff --git a/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdl_ttf.pas b/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdl_ttf.pas index eea69719..88966f82 100644 --- a/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdl_ttf.pas +++ b/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdl_ttf.pas @@ -1,6 +1,6 @@ unit sdl_ttf; { - $Id: sdl_ttf.pas,v 1.10 2005/01/02 19:07:32 savage Exp $ + $Id: sdl_ttf.pas,v 1.19 2007/12/05 22:54:20 savage Exp $ } {******************************************************************************} @@ -87,6 +87,33 @@ unit sdl_ttf; { } { $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 ) @@ -124,7 +151,17 @@ unit sdl_ttf; {$I jedi-sdl.inc} -{$ALIGN ON} +{ + 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 @@ -133,7 +170,7 @@ uses gpc, {$ENDIF} -{$IFDEF WIN32} +{$IFDEF WINDOWS} {$IFNDEF __GPC__} Windows, {$ENDIF} @@ -141,20 +178,25 @@ uses sdl; const -{$IFDEF WIN32} +{$IFDEF WINDOWS} SDLttfLibName = 'SDL_ttf.dll'; {$ENDIF} {$IFDEF UNIX} {$IFDEF DARWIN} - SDLttfLibName = 'libSDL_ttf.dylib'; + SDLttfLibName = 'libSDL_ttf-2.0.0.dylib'; {$ELSE} - SDLttfLibName = 'libSDL_ttf.so'; + {$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 *} @@ -162,7 +204,7 @@ const {$EXTERNALSYM SDL_TTF_MAJOR_VERSION} SDL_TTF_MINOR_VERSION = 0; {$EXTERNALSYM SDL_TTF_MINOR_VERSION} - SDL_TTF_PATCHLEVEL = 7; + SDL_TTF_PATCHLEVEL = 9; {$EXTERNALSYM SDL_TTF_PATCHLEVEL} // Backwards compatibility @@ -314,8 +356,10 @@ cdecl; external {$IFDEF __GPC__}name 'TTF_SizeUNICODE'{$ELSE} SDLttfLibName{$END } 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; @@ -448,4 +492,14 @@ 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-SDL/SDL_ttf/Pas/sdltruetypefont.pas b/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdltruetypefont.pas index 4b53ddd9..a0f25e12 100644 --- a/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdltruetypefont.pas +++ b/Game/Code/lib/JEDI-SDL/SDL_ttf/Pas/sdltruetypefont.pas @@ -1,6 +1,6 @@ unit sdltruetypefont; { - $Id: sdltruetypefont.pas,v 1.1 2004/09/30 22:39:50 savage Exp $ + $Id: sdltruetypefont.pas,v 1.5 2005/05/26 21:22:28 savage Exp $ } {******************************************************************************} @@ -62,6 +62,21 @@ unit sdltruetypefont; { 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. @@ -93,6 +108,7 @@ type FFontFile : string; FFontSize : integer; procedure PrepareFont; + protected public @@ -100,6 +116,7 @@ type 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; @@ -131,7 +148,7 @@ begin FForeGroundColour.r := 0; FForeGroundColour.g := 0; FForeGroundColour.b := 0; - FRenderType := rtUTF8; + FRenderType := rtUnicode; if ( TTF_Init >= 0 ) then begin FFontFile := aFontFile; @@ -265,26 +282,31 @@ begin else begin dec( i ); - strChopped := Copy( strChopped, 0, i ); - if TTF_SizeText( FFont, PChar( string( strChopped ) ), textw, texth ) = 0 then + if TTF_SizeText( FFont, PChar( string( Copy( strChopped, 0, i ) ) ), textw, texth ) = 0 then begin if ( textw < aWidth ) - and ( texth < aHeight ) then + and ( texth < aHeight ) then begin SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - strChopped := Copy( aText, i + 2, Length( aText ) - ( i - 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 - SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - break; + 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 @@ -310,26 +332,31 @@ begin else begin dec( i ); - strChopped := Copy( strChopped, 0, i ); - if TTF_SizeUTF8( FFont, PChar( string( strChopped ) ), textw, texth ) = 0 then + if TTF_SizeUTF8( FFont, PChar( string( Copy( strChopped, 0, i ) ) ), textw, texth ) = 0 then begin if ( textw < aWidth ) - and ( texth < aHeight ) then + and ( texth < aHeight ) then begin SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - strChopped := Copy( aText, i + 2, Length( aText ) - ( i - 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 - SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - break; + 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 @@ -355,21 +382,25 @@ begin else begin dec( i ); - strChopped := Copy( strChopped, 0, i ); - if TTF_SizeUNICODE( FFont, PUInt16( strChopped ), textw, texth ) = 0 then + if TTF_SizeUNICODE( FFont, PUInt16( Copy( strChopped, 0, i ) ), textw, texth ) = 0 then begin if ( textw < aWidth ) - and ( texth < aHeight ) then + and ( texth < aHeight ) then begin SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - strChopped := Copy( aText, i + 2, Length( aText ) - ( i - 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 - SetLength( strlist, Length( strlist ) + 1 ); - strlist[ Length( strlist ) - 1 ] := strChopped; - break; + 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; @@ -411,6 +442,103 @@ begin 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; -- cgit v1.2.3