aboutsummaryrefslogtreecommitdiffstats
path: root/src/base
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-09-12 09:51:33 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-09-12 09:51:33 +0000
commitabf47ddd1fe77287136535e2d05ada48b99b8e1f (patch)
treec7bb68f38c381d1f84dd542de882cca079b9b4b2 /src/base
parentb8e1a9b524f0922329c5307b0396f78a3dc2b44f (diff)
downloadusdx-abf47ddd1fe77287136535e2d05ada48b99b8e1f.tar.gz
usdx-abf47ddd1fe77287136535e2d05ada48b99b8e1f.tar.xz
usdx-abf47ddd1fe77287136535e2d05ada48b99b8e1f.zip
- Windows resources (.rc) reduced to the icon
- Texture resource names are now directly written to resources.inc - Fonts are no resources anymore. They are moved to game/fonts and can be changed to support multiple charsets (until the TTF part is finished). Fonts are registered in fonts/fonts.in git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1367 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/base')
-rw-r--r--src/base/TextGL.pas93
-rw-r--r--src/base/UCommon.pas101
-rw-r--r--src/base/UMain.pas4
3 files changed, 103 insertions, 95 deletions
diff --git a/src/base/TextGL.pas b/src/base/TextGL.pas
index f7b3ac95..f02a261c 100644
--- a/src/base/TextGL.pas
+++ b/src/base/TextGL.pas
@@ -12,7 +12,6 @@ uses
gl,
SDL,
UTexture,
- Classes,
// SDL_ttf,
ULog;
@@ -73,81 +72,101 @@ uses
UMain,
UCommon,
SysUtils,
+ IniFiles,
+ Classes,
UGraphic;
var
// Colours for the reflection
TempColor: array[0..3] of GLfloat;
-procedure LoadBitmapFontInfo(aID : integer; const aType, aResourceName: string);
+{**
+ * Load font info.
+ * FontFile is the name of the image (.png) not the data (.dat) file
+ *}
+procedure LoadFontInfo(FontID: integer; const FontFile: string);
var
- stream: TStream;
+ Stream: TFileStream;
+ DatFile: string;
begin
- stream := GetResourceStream(aResourceName, aType);
- if (not assigned(stream)) then
- begin
- Log.LogError('Unknown font['+ inttostr(aID) +': '+aType+']', 'loadfont');
- Exit;
- end;
+ DatFile := ChangeFileExt(FontFile, '.dat');
+ FillChar(Fonts[FontID].Width[0], Length(Fonts[FontID].Width), 0);
+
+ Stream := nil;
try
- stream.Read(Fonts[ aID ].Width, 256);
+ Stream := TFileStream.Create(DatFile, fmOpenRead);
+ Stream.Read(Fonts[FontID].Width, 256);
except
- Log.LogError('Error while reading font['+ inttostr(aID) +': '+aType+']', 'loadfont');
+ Log.LogError('Error while reading font['+ inttostr(FontID) +']', 'LoadFontInfo');
end;
- stream.Free;
+ Stream.Free;
end;
// Builds bitmap fonts
procedure BuildFont;
var
Count: integer;
+ FontIni: TMemIniFile;
+ FontFile: string; // filename of the image (with .png/... ending)
begin
ActFont := 0;
- SetLength(Fonts, 5);
- Fonts[0].Tex := Texture.LoadTexture(true, 'Font', TEXTURE_TYPE_TRANSPARENT, 0);
+ SetLength(Fonts, 4);
+ FontIni := TMemIniFile.Create(FontPath + 'fonts.ini');
+
+ // Normal
+
+ FontFile := FontPath + FontIni.ReadString('Normal', 'File', '');
+
+ Fonts[0].Tex := Texture.LoadTexture(true, FontFile, TEXTURE_TYPE_TRANSPARENT, 0);
Fonts[0].Tex.H := 30;
Fonts[0].AspectW := 0.9;
Fonts[0].Outline := 0;
- Fonts[1].Tex := Texture.LoadTexture(true, 'FontB', TEXTURE_TYPE_TRANSPARENT, 0);
+ LoadFontInfo(0, FontFile);
+
+ // Bold
+
+ FontFile := FontPath + FontIni.ReadString('Bold', 'File', '');
+
+ Fonts[1].Tex := Texture.LoadTexture(true, FontFile, TEXTURE_TYPE_TRANSPARENT, 0);
Fonts[1].Tex.H := 30;
Fonts[1].AspectW := 1;
Fonts[1].Outline := 0;
- Fonts[2].Tex := Texture.LoadTexture(true, 'FontO', TEXTURE_TYPE_TRANSPARENT, 0);
+ LoadFontInfo(1, FontFile);
+ for Count := 0 to 255 do
+ Fonts[1].Width[Count] := Fonts[1].Width[Count] div 2;
+
+ // Outline1
+
+ FontFile := FontPath + FontIni.ReadString('Outline1', 'File', '');
+
+ Fonts[2].Tex := Texture.LoadTexture(true, FontFile, TEXTURE_TYPE_TRANSPARENT, 0);
Fonts[2].Tex.H := 30;
Fonts[2].AspectW := 0.95;
Fonts[2].Outline := 5;
- Fonts[3].Tex := Texture.LoadTexture(true, 'FontO2', TEXTURE_TYPE_TRANSPARENT, 0);
- Fonts[3].Tex.H := 30;
- Fonts[3].AspectW := 0.95;
- Fonts[3].Outline := 4;
+ LoadFontInfo(2, FontFile);
+ for Count := 0 to 255 do
+ Fonts[2].Width[Count] := Fonts[2].Width[Count] div 2 + 2;
-{ Fonts[4].Tex := Texture.LoadTexture('FontO', TEXTURE_TYPE_TRANSPARENT, 0); // for score screen
- Fonts[4].Tex.H := 30;
- Fonts[4].AspectW := 0.95;
- Fonts[4].Done := -1;
- Fonts[4].Outline := 5;}
+ // Outline2
- // load font info
- LoadBitmapFontInfo( 0, 'FNT', 'Font');
- LoadBitmapFontInfo( 1, 'FNT', 'FontB');
- LoadBitmapFontInfo( 2, 'FNT', 'FontO');
- LoadBitmapFontInfo( 3, 'FNT', 'FontO2');
+ FontFile := FontPath + FontIni.ReadString('Outline2', 'File', '');
- for Count := 0 to 255 do
- Fonts[1].Width[Count] := Fonts[1].Width[Count] div 2;
-
- for Count := 0 to 255 do
- Fonts[2].Width[Count] := Fonts[2].Width[Count] div 2 + 2;
+ Fonts[3].Tex := Texture.LoadTexture(true, FontFile, TEXTURE_TYPE_TRANSPARENT, 0);
+ Fonts[3].Tex.H := 30;
+ Fonts[3].AspectW := 0.95;
+ Fonts[3].Outline := 4;
+ LoadFontInfo(3, FontFile);
for Count := 0 to 255 do
Fonts[3].Width[Count] := Fonts[3].Width[Count] + 1;
-{ for Count := 0 to 255 do
- Fonts[4].Width[Count] := Fonts[4].Width[Count] div 2 + 2;}
+
+ // close ini-file
+ FontIni.Free;
// enable blending by default
for Count := 0 to High(Fonts) do
diff --git a/src/base/UCommon.pas b/src/base/UCommon.pas
index 38a68d84..3f41dae6 100644
--- a/src/base/UCommon.pas
+++ b/src/base/UCommon.pas
@@ -306,87 +306,74 @@ begin
end;
-{$IFDEF Unix}
- // include resource-file info (stored in the constant array "resources")
- {$I ../resource.inc}
-{$ENDIF}
+// include resource-file info (stored in the constant array "resources")
+{$I ../resource.inc}
function GetResourceStream(const aName, aType: string): TStream;
-{$IFDEF Unix}
var
ResIndex: integer;
Filename: string;
-{$ENDIF}
begin
Result := nil;
- {$IFDEF Unix}
for ResIndex := 0 to High(resources) do
begin
- if (resources[ResIndex][0] = aName ) and
- (resources[ResIndex][1] = aType ) then
+ if (Resources[ResIndex][0] = aName ) then
begin
try
- Filename := ResourcesPath + resources[ResIndex][2];
+ Filename := ResourcesPath + Resources[ResIndex][1];
Result := TFileStream.Create(Filename, fmOpenRead);
except
- Log.LogError('Failed to open: "'+ resources[ResIndex][2] +'"', 'GetResourceStream');
+ Log.LogError('Failed to open: "'+ resources[ResIndex][1] +'"', 'GetResourceStream');
end;
- exit;
+ Exit;
end;
end;
- {$ELSE}
- try
- Result := TResourceStream.Create(HInstance, aName , PChar(aType));
- except
- Log.LogError('Invalid resource: "'+ aType + ':' + aName +'"', 'GetResourceStream');
- end;
- {$ENDIF}
end;
// +++++++++++++++++++++ helpers for RWOpsFromStream() +++++++++++++++
- function SdlStreamSeek( context : PSDL_RWops; offset : Integer; whence : Integer ) : integer; cdecl;
- var
- stream : TStream;
- origin : Word;
- begin
- stream := TStream( context.unknown );
- if ( stream = nil ) then
- raise EInvalidContainer.Create( 'SDLStreamSeek on nil' );
- case whence of
- 0 : origin := soFromBeginning; // Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
- 1 : origin := soFromCurrent; // Offset is from the current position in the resource. Seek moves to Position + Offset.
- 2 : origin := soFromEnd;
- else
- origin := soFromBeginning; // just in case
- end;
- Result := stream.Seek( offset, origin );
+function SdlStreamSeek( context : PSDL_RWops; offset : Integer; whence : Integer ) : integer; cdecl;
+var
+ stream : TStream;
+ origin : Word;
+begin
+ stream := TStream( context.unknown );
+ if ( stream = nil ) then
+ raise EInvalidContainer.Create( 'SDLStreamSeek on nil' );
+ case whence of
+ 0 : origin := soFromBeginning; // Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
+ 1 : origin := soFromCurrent; // Offset is from the current position in the resource. Seek moves to Position + Offset.
+ 2 : origin := soFromEnd;
+ else
+ origin := soFromBeginning; // just in case
end;
+ Result := stream.Seek( offset, origin );
+end;
- function SdlStreamRead( context : PSDL_RWops; Ptr : Pointer; size : Integer; maxnum: Integer ) : Integer; cdecl;
- var
- stream : TStream;
- begin
- stream := TStream( context.unknown );
- if ( stream = nil ) then
- raise EInvalidContainer.Create( 'SDLStreamRead on nil' );
- try
- Result := stream.read( Ptr^, Size * maxnum ) div size;
- except
- Result := -1;
- end;
+function SdlStreamRead( context : PSDL_RWops; Ptr : Pointer; size : Integer; maxnum: Integer ) : Integer; cdecl;
+var
+ stream : TStream;
+begin
+ stream := TStream( context.unknown );
+ if ( stream = nil ) then
+ raise EInvalidContainer.Create( 'SDLStreamRead on nil' );
+ try
+ Result := stream.read( Ptr^, Size * maxnum ) div size;
+ except
+ Result := -1;
end;
+end;
- function SDLStreamClose( context : PSDL_RWops ) : Integer; cdecl;
- var
- stream : TStream;
- begin
- stream := TStream( context.unknown );
- if ( stream = nil ) then
- raise EInvalidContainer.Create( 'SDLStreamClose on nil' );
- stream.Free;
- Result := 1;
- end;
+function SDLStreamClose( context : PSDL_RWops ) : Integer; cdecl;
+var
+ stream : TStream;
+begin
+ stream := TStream( context.unknown );
+ if ( stream = nil ) then
+ raise EInvalidContainer.Create( 'SDLStreamClose on nil' );
+ stream.Free;
+ Result := 1;
+end;
// -----------------------------------------------
(*
diff --git a/src/base/UMain.pas b/src/base/UMain.pas
index f9f56c3e..7d9886b6 100644
--- a/src/base/UMain.pas
+++ b/src/base/UMain.pas
@@ -77,6 +77,7 @@ var
LanguagesPath: string;
PluginPath: string;
VisualsPath: string;
+ FontPath: string;
ResourcesPath: string;
PlayListPath: string;
@@ -100,7 +101,7 @@ function FindPath(out PathResult: string; const RequestedPath: string; NeedsWrit
procedure InitializePaths;
procedure AddSongPath(const Path: string);
-Procedure Main;
+procedure Main;
procedure MainLoop;
procedure CheckEvents;
procedure Sing(Screen: TScreenSing);
@@ -1091,6 +1092,7 @@ begin
FindPath(LanguagesPath, Platform.GetGameSharedPath + 'languages', false);
FindPath(PluginPath, Platform.GetGameSharedPath + 'plugins', false);
FindPath(VisualsPath, Platform.GetGameSharedPath + 'visuals', false);
+ FindPath(FontPath, Platform.GetGameSharedPath + 'fonts', false);
FindPath(ResourcesPath, Platform.GetGameSharedPath + 'resources', false);
// Playlists are not shared as we need one directory to write too