aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UImage.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-30 13:24:28 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-30 13:24:28 +0000
commit85094b44de1f7a1a9bd710b162670fdb0a02a9a8 (patch)
tree3369951e5093a987b0fd98f9ea3119de22676f24 /Game/Code/Classes/UImage.pas
parent731dec0d29e29a5d30e728616bcb5aa35c7c75ea (diff)
downloadusdx-85094b44de1f7a1a9bd710b162670fdb0a02a9a8.tar.gz
usdx-85094b44de1f7a1a9bd710b162670fdb0a02a9a8.tar.xz
usdx-85094b44de1f7a1a9bd710b162670fdb0a02a9a8.zip
- title-bar icon working again in windowed mode
- moved LoadImage to UImage.pas - added RWopsFromStream() to get an SDL RWops handle from a TStream - removed some German comments git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1041 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UImage.pas66
1 files changed, 66 insertions, 0 deletions
diff --git a/Game/Code/Classes/UImage.pas b/Game/Code/Classes/UImage.pas
index 640e5202..d0a9d0d8 100644
--- a/Game/Code/Classes/UImage.pas
+++ b/Game/Code/Classes/UImage.pas
@@ -107,6 +107,8 @@ function WriteBMPImage(const FileName: string; Surface: PSDL_Surface): boolean;
function WriteJPGImage(const FileName: string; Surface: PSDL_Surface; Quality: integer): boolean;
{$ENDIF}
+function LoadImage(const Identifier: string): PSDL_Surface;
+
implementation
uses
@@ -130,6 +132,8 @@ uses
png,
{$ENDIF}
zlib,
+ sdl_image,
+ UCommon,
ULog;
function IsRGBSurface(pixelFmt: PSDL_PixelFormat): boolean;
@@ -700,4 +704,66 @@ end;
{$ENDIF}
+(*
+ * Loads an image from the given file or resource
+ *)
+function LoadImage(const Identifier: string): PSDL_Surface;
+var
+ TexRWops: PSDL_RWops;
+ TexStream: TStream;
+ FileName: string;
+begin
+ Result := nil;
+ TexRWops := nil;
+
+ if Identifier = '' then
+ exit;
+
+ //Log.LogStatus( Identifier, 'LoadImage' );
+
+ FileName := Identifier;
+
+ if (FileExistsInsensitive(FileName)) then
+ begin
+ // load from file
+ //Log.LogStatus( 'Is File ( Loading : '+FileName+')', ' LoadImage' );
+ try
+ Result := IMG_Load(PChar(FileName));
+ //Log.LogStatus( ' '+inttostr( integer( Result ) ), ' LoadImage' );
+ except
+ Log.LogError('Could not load from file "'+FileName+'"', 'TTextureUnit.LoadImage');
+ Exit;
+ end;
+ end
+ else
+ begin
+ //Log.LogStatus( 'IS Resource, because file does not exist.('+Identifier+')', ' LoadImage' );
+
+ TexStream := GetResourceStream(Identifier, 'TEX');
+ if (not assigned(TexStream)) then
+ begin
+ Log.LogError( 'Invalid file or resource "'+ Identifier+'"', 'TTextureUnit.LoadImage');
+ Exit;
+ end;
+
+ TexRWops := RWopsFromStream(TexStream);
+ if (TexRWops = nil) then
+ begin
+ Log.LogError( 'Could not assign resource "'+Identifier+'"', 'TTextureUnit.LoadImage');
+ TexStream.Free();
+ Exit;
+ end;
+
+ //Log.LogStatus( 'resource Assigned....' , Identifier);
+ try
+ Result := IMG_Load_RW(TexRWops, 0);
+ except
+ Log.LogError( 'Could not read resource "'+Identifier+'"', 'TTextureUnit.LoadImage');
+ end;
+
+ SDL_FreeRW(TexRWops);
+ TexStream.Free();
+ end;
+end;
+
end.