- Updated Vampyre Imaging Lib
- Added font rendering - Added height display in flat mode
This commit is contained in:
+341
-415
@@ -1,5 +1,5 @@
|
||||
{
|
||||
$Id: ImagingUtility.pas 128 2008-07-23 11:57:36Z galfar $
|
||||
$Id: ImagingUtility.pas 175 2009-10-06 11:55:15Z galfar $
|
||||
Vampyre Imaging Library
|
||||
by Marek Mauder
|
||||
http://imaginglib.sourceforge.net
|
||||
@@ -56,9 +56,10 @@ type
|
||||
TBooleanArray = array[0..MaxInt - 1] of Boolean;
|
||||
PBooleanArray = ^TBooleanArray;
|
||||
|
||||
TDynByteArray = array of Byte;
|
||||
TDynIntegerArray = array of Integer;
|
||||
TDynBooleanArray = array of Boolean;
|
||||
|
||||
|
||||
TWordRec = packed record
|
||||
case Integer of
|
||||
0: (WordValue: Word);
|
||||
@@ -98,23 +99,24 @@ type
|
||||
end;
|
||||
PFloatHelper = ^TFloatHelper;
|
||||
|
||||
TChar2 = array[0..1] of Char;
|
||||
TChar3 = array[0..2] of Char;
|
||||
TChar4 = array[0..3] of Char;
|
||||
TChar8 = array[0..7] of Char;
|
||||
TChar2 = array[0..1] of AnsiChar;
|
||||
TChar3 = array[0..2] of AnsiChar;
|
||||
TChar4 = array[0..3] of AnsiChar;
|
||||
TChar8 = array[0..7] of AnsiChar;
|
||||
TChar16 = array[0..15] of AnsiChar;
|
||||
|
||||
{ Options for BuildFileList function:
|
||||
flFullNames - file names in result will have full path names
|
||||
(ExtractFileDir(Path) + FileName)
|
||||
flRelNames - file names in result will have names relative to
|
||||
ExtractFileDir(Path) dir
|
||||
flRecursive - adds files in subdirectories found in Path.}
|
||||
TFileListOption = (flFullNames, flRelNames, flRecursive);
|
||||
TFileListOptions = set of TFileListOption;
|
||||
flFullNames - file names in result will have full path names
|
||||
(ExtractFileDir(Path) + FileName)
|
||||
flRelNames - file names in result will have names relative to
|
||||
ExtractFileDir(Path) dir
|
||||
flRecursive - adds files in subdirectories found in Path.}
|
||||
TFileListOption = (flFullNames, flRelNames, flRecursive);
|
||||
TFileListOptions = set of TFileListOption;
|
||||
|
||||
|
||||
{ Frees class instance and sets its reference to nil.}
|
||||
procedure FreeAndNil(var Obj);
|
||||
procedure FreeAndNil(var Obj);
|
||||
{ Frees pointer and sets it to nil.}
|
||||
procedure FreeMemNil(var P); {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
{ Replacement of standard System.FreeMem procedure which checks if P is nil
|
||||
@@ -135,32 +137,35 @@ function GetAppExe: string;
|
||||
path delimiter at the end.}
|
||||
function GetAppDir: string;
|
||||
{ Returns True if FileName matches given Mask with optional case sensitivity.
|
||||
Mask can contain ? and * special characters: ? matches
|
||||
one character, * matches zero or more characters.}
|
||||
Mask can contain ? and * special characters: ? matches
|
||||
one character, * matches zero or more characters.}
|
||||
function MatchFileNameMask(const FileName, Mask: string; CaseSensitive: Boolean = False): Boolean;
|
||||
{ This function fills Files string list with names of files found
|
||||
with FindFirst/FindNext functions (See details on Path/Atrr here).
|
||||
- BuildFileList('c:\*.*', faAnyFile, List, [flRecursive]) returns
|
||||
list of all files (only name.ext - no path) on C drive
|
||||
- BuildFileList('d:\*.*', faDirectory, List, [flFullNames]) returns
|
||||
list of all directories (d:\dirxxx) in root of D drive.}
|
||||
function BuildFileList(Path: string; Attr: LongInt; Files: TStrings;
|
||||
Options: TFileListOptions = []): Boolean;
|
||||
{ Similar to RTL's Pos function but with optional Offset where search will start.
|
||||
This function is in the RTL StrUtils unit but }
|
||||
function PosEx(const SubStr, S: string; Offset: LongInt = 1): LongInt;
|
||||
{ Same as PosEx but without case sensitivity.}
|
||||
function PosNoCase(const SubStr, S: string; Offset: LongInt = 1): LongInt; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
{ Returns a sub-string from S which is followed by
|
||||
Sep separator and deletes the sub-string from S including the separator.}
|
||||
function StrToken(var S: string; Sep: Char): string;
|
||||
{ Same as StrToken but searches from the end of S string.}
|
||||
function StrTokenEnd(var S: string; Sep: Char): string;
|
||||
{ Returns string representation of integer number (with digit grouping).}
|
||||
function IntToStrFmt(const I: Int64): string;
|
||||
{ Returns string representation of float number (with digit grouping).}
|
||||
function FloatToStrFmt(const F: Double; Precision: Integer = 2): string;
|
||||
|
||||
with FindFirst/FindNext functions (See details on Path/Atrr here).
|
||||
- BuildFileList('c:\*.*', faAnyFile, List, [flRecursive]) returns
|
||||
list of all files (only name.ext - no path) on C drive
|
||||
- BuildFileList('d:\*.*', faDirectory, List, [flFullNames]) returns
|
||||
list of all directories (d:\dirxxx) in root of D drive.}
|
||||
function BuildFileList(Path: string; Attr: LongInt; Files: TStrings;
|
||||
Options: TFileListOptions = []): Boolean;
|
||||
{ Similar to RTL's Pos function but with optional Offset where search will start.
|
||||
This function is in the RTL StrUtils unit but }
|
||||
function PosEx(const SubStr, S: string; Offset: LongInt = 1): LongInt;
|
||||
{ Same as PosEx but without case sensitivity.}
|
||||
function PosNoCase(const SubStr, S: string; Offset: LongInt = 1): LongInt; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
{ Returns a sub-string from S which is followed by
|
||||
Sep separator and deletes the sub-string from S including the separator.}
|
||||
function StrToken(var S: string; Sep: Char): string;
|
||||
{ Same as StrToken but searches from the end of S string.}
|
||||
function StrTokenEnd(var S: string; Sep: Char): string;
|
||||
{ Fills instance of TStrings with tokens from string S where tokens are separated by
|
||||
one of Seps characters.}
|
||||
procedure StrTokensToList(const S: string; Sep: Char; Tokens: TStrings);
|
||||
{ Returns string representation of integer number (with digit grouping).}
|
||||
function IntToStrFmt(const I: Int64): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
{ Returns string representation of float number (with digit grouping).}
|
||||
function FloatToStrFmt(const F: Double; Precision: Integer = 2): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
|
||||
{ Clamps integer value to range <Min, Max>}
|
||||
function ClampInt(Number: LongInt; Min, Max: LongInt): LongInt; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||
{ Clamps float value to range <Min, Max>}
|
||||
@@ -397,7 +402,7 @@ end;
|
||||
|
||||
function GetTimeMilliseconds: Int64;
|
||||
begin
|
||||
Result := GetTimeMicroseconds div 1000;
|
||||
Result := GetTimeMicroseconds div 1000;
|
||||
end;
|
||||
|
||||
function GetFileExt(const FileName: string): string;
|
||||
@@ -439,359 +444,275 @@ begin
|
||||
end;
|
||||
|
||||
function MatchFileNameMask(const FileName, Mask: string; CaseSensitive: Boolean): Boolean;
|
||||
var
|
||||
MaskLen, KeyLen : LongInt;
|
||||
|
||||
function CharMatch(A, B: Char): Boolean;
|
||||
begin
|
||||
if CaseSensitive then
|
||||
Result := A = B
|
||||
else
|
||||
Result := UpCase(A) = UpCase(B);
|
||||
end;
|
||||
|
||||
function MatchAt(MaskPos, KeyPos: LongInt): Boolean;
|
||||
begin
|
||||
while (MaskPos <= MaskLen) and (KeyPos <= KeyLen) do
|
||||
begin
|
||||
case Mask[MaskPos] of
|
||||
'?' :
|
||||
begin
|
||||
Inc(MaskPos);
|
||||
Inc(KeyPos);
|
||||
end;
|
||||
'*' :
|
||||
begin
|
||||
while (MaskPos <= MaskLen) and (Mask[MaskPos] = '*') do
|
||||
Inc(MaskPos);
|
||||
if MaskPos > MaskLen then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
repeat
|
||||
if MatchAt(MaskPos, KeyPos) then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
Inc(KeyPos);
|
||||
until KeyPos > KeyLen;
|
||||
Result := False;
|
||||
Exit;
|
||||
end;
|
||||
else
|
||||
if not CharMatch(Mask[MaskPos], FileName[KeyPos]) then
|
||||
begin
|
||||
Result := False;
|
||||
Exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Inc(MaskPos);
|
||||
Inc(KeyPos);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
while (MaskPos <= MaskLen) and (Mask[MaskPos] in ['?', '*']) do
|
||||
Inc(MaskPos);
|
||||
if (MaskPos <= MaskLen) or (KeyPos <= KeyLen) then
|
||||
begin
|
||||
Result := False;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
begin
|
||||
MaskLen := Length(Mask);
|
||||
KeyLen := Length(FileName);
|
||||
if MaskLen = 0 then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
Result := MatchAt(1, 1);
|
||||
var
|
||||
MaskLen, KeyLen : LongInt;
|
||||
|
||||
function CharMatch(A, B: Char): Boolean;
|
||||
begin
|
||||
if CaseSensitive then
|
||||
Result := A = B
|
||||
else
|
||||
Result := AnsiUpperCase (A) = AnsiUpperCase (B);
|
||||
end;
|
||||
|
||||
function MatchAt(MaskPos, KeyPos: LongInt): Boolean;
|
||||
begin
|
||||
while (MaskPos <= MaskLen) and (KeyPos <= KeyLen) do
|
||||
begin
|
||||
case Mask[MaskPos] of
|
||||
'?' :
|
||||
begin
|
||||
Inc(MaskPos);
|
||||
Inc(KeyPos);
|
||||
end;
|
||||
'*' :
|
||||
begin
|
||||
while (MaskPos <= MaskLen) and (Mask[MaskPos] = '*') do
|
||||
Inc(MaskPos);
|
||||
if MaskPos > MaskLen then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
repeat
|
||||
if MatchAt(MaskPos, KeyPos) then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
Inc(KeyPos);
|
||||
until KeyPos > KeyLen;
|
||||
Result := False;
|
||||
Exit;
|
||||
end;
|
||||
else
|
||||
if not CharMatch(Mask[MaskPos], FileName[KeyPos]) then
|
||||
begin
|
||||
Result := False;
|
||||
Exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Inc(MaskPos);
|
||||
Inc(KeyPos);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
while (MaskPos <= MaskLen) and (Mask[MaskPos] in ['?', '*']) do
|
||||
Inc(MaskPos);
|
||||
if (MaskPos <= MaskLen) or (KeyPos <= KeyLen) then
|
||||
begin
|
||||
Result := False;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
begin
|
||||
MaskLen := Length(Mask);
|
||||
KeyLen := Length(FileName);
|
||||
if MaskLen = 0 then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
Result := MatchAt(1, 1);
|
||||
end;
|
||||
|
||||
function BuildFileList(Path: string; Attr: LongInt;
|
||||
Files: TStrings; Options: TFileListOptions): Boolean;
|
||||
var
|
||||
FileMask: string;
|
||||
RootDir: string;
|
||||
Folders: TStringList;
|
||||
CurrentItem: LongInt;
|
||||
Counter: LongInt;
|
||||
LocAttr: LongInt;
|
||||
|
||||
procedure BuildFolderList;
|
||||
var
|
||||
FindInfo: TSearchRec;
|
||||
Rslt: LongInt;
|
||||
begin
|
||||
Counter := Folders.Count - 1;
|
||||
CurrentItem := 0;
|
||||
while CurrentItem <= Counter do
|
||||
begin
|
||||
// Searching for subfolders
|
||||
Rslt := SysUtils.FindFirst(Folders[CurrentItem] + '*', faDirectory, FindInfo);
|
||||
try
|
||||
while Rslt = 0 do
|
||||
begin
|
||||
if (FindInfo.Name <> '.') and (FindInfo.Name <> '..') and
|
||||
(FindInfo.Attr and faDirectory = faDirectory) then
|
||||
Folders.Add(Folders[CurrentItem] + FindInfo.Name + PathDelim);
|
||||
Rslt := SysUtils.FindNext(FindInfo);
|
||||
end;
|
||||
finally
|
||||
SysUtils.FindClose(FindInfo);
|
||||
end;
|
||||
Counter := Folders.Count - 1;
|
||||
Inc(CurrentItem);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure FillFileList(CurrentCounter: LongInt);
|
||||
var
|
||||
FindInfo: TSearchRec;
|
||||
Res: LongInt;
|
||||
CurrentFolder: string;
|
||||
begin
|
||||
CurrentFolder := Folders[CurrentCounter];
|
||||
Res := SysUtils.FindFirst(CurrentFolder + FileMask, LocAttr, FindInfo);
|
||||
if flRelNames in Options then
|
||||
CurrentFolder := ExtractRelativePath(RootDir, CurrentFolder);
|
||||
try
|
||||
while Res = 0 do
|
||||
begin
|
||||
if (FindInfo.Name <> '.') and (FindInfo.Name <> '..') then
|
||||
begin
|
||||
if (flFullNames in Options) or (flRelNames in Options) then
|
||||
Files.Add(CurrentFolder + FindInfo.Name)
|
||||
else
|
||||
Files.Add(FindInfo.Name);
|
||||
end;
|
||||
Res := SysUtils.FindNext(FindInfo);
|
||||
end;
|
||||
finally
|
||||
SysUtils.FindClose(FindInfo);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
FileMask := ExtractFileName(Path);
|
||||
RootDir := ExtractFilePath(Path);
|
||||
Folders := TStringList.Create;
|
||||
Folders.Add(RootDir);
|
||||
Files.Clear;
|
||||
{$IFDEF DCC}
|
||||
{$WARN SYMBOL_PLATFORM OFF}
|
||||
{$ENDIF}
|
||||
if Attr = faAnyFile then
|
||||
LocAttr := faSysFile or faHidden or faArchive or faReadOnly
|
||||
else
|
||||
LocAttr := Attr;
|
||||
{$IFDEF DCC}
|
||||
{$WARN SYMBOL_PLATFORM ON}
|
||||
{$ENDIF}
|
||||
// Here's the recursive search for nested folders
|
||||
if flRecursive in Options then
|
||||
BuildFolderList;
|
||||
if Attr <> faDirectory then
|
||||
for Counter := 0 to Folders.Count - 1 do
|
||||
FillFileList(Counter)
|
||||
else
|
||||
Files.AddStrings(Folders);
|
||||
Folders.Free;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function PosEx(const SubStr, S: string; Offset: LongInt = 1): LongInt;
|
||||
{$IFDEF USE_ASM}
|
||||
asm
|
||||
// The Original ASM Code is (C) Fastcode project.
|
||||
test eax, eax
|
||||
jz @Nil
|
||||
test edx, edx
|
||||
jz @Nil
|
||||
dec ecx
|
||||
jl @Nil
|
||||
|
||||
push esi
|
||||
push ebx
|
||||
|
||||
mov esi, [edx-4] //Length(Str)
|
||||
mov ebx, [eax-4] //Length(Substr)
|
||||
sub esi, ecx //effective length of Str
|
||||
add edx, ecx //addr of the first char at starting position
|
||||
cmp esi, ebx
|
||||
jl @Past //jump if EffectiveLength(Str)<Length(Substr)
|
||||
test ebx, ebx
|
||||
jle @Past //jump if Length(Substr)<=0
|
||||
|
||||
add esp, -12
|
||||
add ebx, -1 //Length(Substr)-1
|
||||
add esi, edx //addr of the terminator
|
||||
add edx, ebx //addr of the last char at starting position
|
||||
mov [esp+8], esi //save addr of the terminator
|
||||
add eax, ebx //addr of the last char of Substr
|
||||
sub ecx, edx //-@Str[Length(Substr)]
|
||||
neg ebx //-(Length(Substr)-1)
|
||||
mov [esp+4], ecx //save -@Str[Length(Substr)]
|
||||
mov [esp], ebx //save -(Length(Substr)-1)
|
||||
movzx ecx, byte ptr [eax] //the last char of Substr
|
||||
|
||||
@Loop:
|
||||
cmp cl, [edx]
|
||||
jz @Test0
|
||||
@AfterTest0:
|
||||
cmp cl, [edx+1]
|
||||
jz @TestT
|
||||
@AfterTestT:
|
||||
add edx, 4
|
||||
cmp edx, [esp+8]
|
||||
jb @Continue
|
||||
@EndLoop:
|
||||
add edx, -2
|
||||
cmp edx, [esp+8]
|
||||
jb @Loop
|
||||
@Exit:
|
||||
add esp, 12
|
||||
@Past:
|
||||
pop ebx
|
||||
pop esi
|
||||
@Nil:
|
||||
xor eax, eax
|
||||
ret
|
||||
@Continue:
|
||||
cmp cl, [edx-2]
|
||||
jz @Test2
|
||||
cmp cl, [edx-1]
|
||||
jnz @Loop
|
||||
@Test1:
|
||||
add edx, 1
|
||||
@Test2:
|
||||
add edx, -2
|
||||
@Test0:
|
||||
add edx, -1
|
||||
@TestT:
|
||||
mov esi, [esp]
|
||||
test esi, esi
|
||||
jz @Found
|
||||
@String:
|
||||
movzx ebx, word ptr [esi+eax]
|
||||
cmp bx, word ptr [esi+edx+1]
|
||||
jnz @AfterTestT
|
||||
cmp esi, -2
|
||||
jge @Found
|
||||
movzx ebx, word ptr [esi+eax+2]
|
||||
cmp bx, word ptr [esi+edx+3]
|
||||
jnz @AfterTestT
|
||||
add esi, 4
|
||||
jl @String
|
||||
@Found:
|
||||
mov eax, [esp+4]
|
||||
add edx, 2
|
||||
|
||||
cmp edx, [esp+8]
|
||||
ja @Exit
|
||||
|
||||
add esp, 12
|
||||
add eax, edx
|
||||
pop ebx
|
||||
pop esi
|
||||
end;
|
||||
{$ELSE}
|
||||
var
|
||||
I, X: LongInt;
|
||||
Len, LenSubStr: LongInt;
|
||||
begin
|
||||
I := Offset;
|
||||
LenSubStr := Length(SubStr);
|
||||
Len := Length(S) - LenSubStr + 1;
|
||||
while I <= Len do
|
||||
begin
|
||||
if S[I] = SubStr[1] then
|
||||
begin
|
||||
X := 1;
|
||||
while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
|
||||
Inc(X);
|
||||
if (X = LenSubStr) then
|
||||
begin
|
||||
Result := I;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
Inc(I);
|
||||
end;
|
||||
Result := 0;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function PosNoCase(const SubStr, S: string; Offset: LongInt): LongInt;
|
||||
begin
|
||||
Result := PosEx(LowerCase(SubStr), LowerCase(S), Offset);
|
||||
end;
|
||||
|
||||
function StrToken(var S: string; Sep: Char): string;
|
||||
var
|
||||
I: LongInt;
|
||||
begin
|
||||
I := Pos(Sep, S);
|
||||
if I <> 0 then
|
||||
begin
|
||||
Result := Copy(S, 1, I - 1);
|
||||
Delete(S, 1, I);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := S;
|
||||
S := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
function StrTokenEnd(var S: string; Sep: Char): string;
|
||||
var
|
||||
I, J: LongInt;
|
||||
begin
|
||||
J := 0;
|
||||
I := Pos(Sep, S);
|
||||
while I <> 0 do
|
||||
begin
|
||||
J := I;
|
||||
I := PosEx(Sep, S, J + 1);
|
||||
end;
|
||||
if J <> 0 then
|
||||
begin
|
||||
Result := Copy(S, J + 1, MaxInt);
|
||||
Delete(S, J, MaxInt);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := S;
|
||||
S := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
function IntToStrFmt(const I: Int64): string;
|
||||
begin
|
||||
Result := Format('%.0n', [I * 1.0]);
|
||||
end;
|
||||
|
||||
function FloatToStrFmt(const F: Double; Precision: Integer): string;
|
||||
begin
|
||||
Result := Format('%.' + IntToStr(Precision) + 'n', [F]);
|
||||
end;
|
||||
|
||||
Files: TStrings; Options: TFileListOptions): Boolean;
|
||||
var
|
||||
FileMask: string;
|
||||
RootDir: string;
|
||||
Folders: TStringList;
|
||||
CurrentItem: LongInt;
|
||||
Counter: LongInt;
|
||||
LocAttr: LongInt;
|
||||
|
||||
procedure BuildFolderList;
|
||||
var
|
||||
FindInfo: TSearchRec;
|
||||
Rslt: LongInt;
|
||||
begin
|
||||
Counter := Folders.Count - 1;
|
||||
CurrentItem := 0;
|
||||
while CurrentItem <= Counter do
|
||||
begin
|
||||
// Searching for subfolders
|
||||
Rslt := SysUtils.FindFirst(Folders[CurrentItem] + '*', faDirectory, FindInfo);
|
||||
try
|
||||
while Rslt = 0 do
|
||||
begin
|
||||
if (FindInfo.Name <> '.') and (FindInfo.Name <> '..') and
|
||||
(FindInfo.Attr and faDirectory = faDirectory) then
|
||||
Folders.Add(Folders[CurrentItem] + FindInfo.Name + PathDelim);
|
||||
Rslt := SysUtils.FindNext(FindInfo);
|
||||
end;
|
||||
finally
|
||||
SysUtils.FindClose(FindInfo);
|
||||
end;
|
||||
Counter := Folders.Count - 1;
|
||||
Inc(CurrentItem);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure FillFileList(CurrentCounter: LongInt);
|
||||
var
|
||||
FindInfo: TSearchRec;
|
||||
Res: LongInt;
|
||||
CurrentFolder: string;
|
||||
begin
|
||||
CurrentFolder := Folders[CurrentCounter];
|
||||
Res := SysUtils.FindFirst(CurrentFolder + FileMask, LocAttr, FindInfo);
|
||||
if flRelNames in Options then
|
||||
CurrentFolder := ExtractRelativePath(RootDir, CurrentFolder);
|
||||
try
|
||||
while Res = 0 do
|
||||
begin
|
||||
if (FindInfo.Name <> '.') and (FindInfo.Name <> '..') then
|
||||
begin
|
||||
if (flFullNames in Options) or (flRelNames in Options) then
|
||||
Files.Add(CurrentFolder + FindInfo.Name)
|
||||
else
|
||||
Files.Add(FindInfo.Name);
|
||||
end;
|
||||
Res := SysUtils.FindNext(FindInfo);
|
||||
end;
|
||||
finally
|
||||
SysUtils.FindClose(FindInfo);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
FileMask := ExtractFileName(Path);
|
||||
RootDir := ExtractFilePath(Path);
|
||||
Folders := TStringList.Create;
|
||||
Folders.Add(RootDir);
|
||||
Files.Clear;
|
||||
{$IFDEF DCC}
|
||||
{$WARN SYMBOL_PLATFORM OFF}
|
||||
{$ENDIF}
|
||||
if Attr = faAnyFile then
|
||||
LocAttr := faSysFile or faHidden or faArchive or faReadOnly
|
||||
else
|
||||
LocAttr := Attr;
|
||||
{$IFDEF DCC}
|
||||
{$WARN SYMBOL_PLATFORM ON}
|
||||
{$ENDIF}
|
||||
// Here's the recursive search for nested folders
|
||||
if flRecursive in Options then
|
||||
BuildFolderList;
|
||||
if Attr <> faDirectory then
|
||||
for Counter := 0 to Folders.Count - 1 do
|
||||
FillFileList(Counter)
|
||||
else
|
||||
Files.AddStrings(Folders);
|
||||
Folders.Free;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function PosEx(const SubStr, S: string; Offset: LongInt = 1): LongInt;
|
||||
var
|
||||
I, X: LongInt;
|
||||
Len, LenSubStr: LongInt;
|
||||
begin
|
||||
I := Offset;
|
||||
LenSubStr := Length(SubStr);
|
||||
Len := Length(S) - LenSubStr + 1;
|
||||
while I <= Len do
|
||||
begin
|
||||
if S[I] = SubStr[1] then
|
||||
begin
|
||||
X := 1;
|
||||
while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
|
||||
Inc(X);
|
||||
if (X = LenSubStr) then
|
||||
begin
|
||||
Result := I;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
Inc(I);
|
||||
end;
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function PosNoCase(const SubStr, S: string; Offset: LongInt): LongInt;
|
||||
begin
|
||||
Result := PosEx(AnsiLowerCase(SubStr), AnsiLowerCase(S), Offset);
|
||||
end;
|
||||
|
||||
function StrToken(var S: string; Sep: Char): string;
|
||||
var
|
||||
I: LongInt;
|
||||
begin
|
||||
I := Pos(Sep, S);
|
||||
if I <> 0 then
|
||||
begin
|
||||
Result := Copy(S, 1, I - 1);
|
||||
Delete(S, 1, I);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := S;
|
||||
S := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
function StrTokenEnd(var S: string; Sep: Char): string;
|
||||
var
|
||||
I, J: LongInt;
|
||||
begin
|
||||
J := 0;
|
||||
I := Pos(Sep, S);
|
||||
while I <> 0 do
|
||||
begin
|
||||
J := I;
|
||||
I := PosEx(Sep, S, J + 1);
|
||||
end;
|
||||
if J <> 0 then
|
||||
begin
|
||||
Result := Copy(S, J + 1, MaxInt);
|
||||
Delete(S, J, MaxInt);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := S;
|
||||
S := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure StrTokensToList(const S: string; Sep: Char; Tokens: TStrings);
|
||||
var
|
||||
Token, Str: string;
|
||||
begin
|
||||
Tokens.Clear;
|
||||
Str := S;
|
||||
while Str <> '' do
|
||||
begin
|
||||
Token := StrToken(Str, Sep);
|
||||
Tokens.Add(Token);
|
||||
end;
|
||||
end;
|
||||
|
||||
function IntToStrFmt(const I: Int64): string;
|
||||
begin
|
||||
Result := Format('%.0n', [I * 1.0]);
|
||||
end;
|
||||
|
||||
function FloatToStrFmt(const F: Double; Precision: Integer): string;
|
||||
begin
|
||||
Result := Format('%.' + IntToStr(Precision) + 'n', [F]);
|
||||
end;
|
||||
|
||||
function ClampInt(Number: LongInt; Min, Max: LongInt): LongInt;
|
||||
begin
|
||||
Result := Number;
|
||||
if Result < Min then
|
||||
Result := Min
|
||||
else
|
||||
if Result > Max then
|
||||
else if Result > Max then
|
||||
Result := Max;
|
||||
end;
|
||||
|
||||
@@ -800,8 +721,7 @@ begin
|
||||
Result := Number;
|
||||
if Result < Min then
|
||||
Result := Min
|
||||
else
|
||||
if Result > Max then
|
||||
else if Result > Max then
|
||||
Result := Max;
|
||||
end;
|
||||
|
||||
@@ -831,7 +751,7 @@ end;
|
||||
function NextPow2(Num: LongInt): LongInt;
|
||||
begin
|
||||
Result := Num and -Num;
|
||||
while (Result < Num) do
|
||||
while Result < Num do
|
||||
Result := Result shl 1;
|
||||
end;
|
||||
|
||||
@@ -957,18 +877,18 @@ end;
|
||||
|
||||
function Iff(Condition: Boolean; TruePart, FalsePart: Pointer): Pointer;
|
||||
begin
|
||||
if Condition then
|
||||
if Condition then
|
||||
Result := TruePart
|
||||
else
|
||||
Result := FalsePart;
|
||||
Result := FalsePart;
|
||||
end;
|
||||
|
||||
function Iff(Condition: Boolean; const TruePart, FalsePart: Int64): Int64;
|
||||
begin
|
||||
if Condition then
|
||||
if Condition then
|
||||
Result := TruePart
|
||||
else
|
||||
Result := FalsePart;
|
||||
Result := FalsePart;
|
||||
end;
|
||||
|
||||
function IffFloat(Condition: Boolean; TruePart, FalsePart: Single): Single;
|
||||
@@ -1062,8 +982,8 @@ end;
|
||||
function MulDiv(Number, Numerator, Denominator: Word): Word;
|
||||
{$IF Defined(USE_ASM) and (not Defined(USE_INLINE))}
|
||||
asm
|
||||
MUL DX
|
||||
DIV CX
|
||||
MUL DX
|
||||
DIV CX
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
@@ -1075,8 +995,8 @@ function IsLittleEndian: Boolean;
|
||||
var
|
||||
W: Word;
|
||||
begin
|
||||
W := $00FF;
|
||||
Result := PByte(@W)^ = $FF;
|
||||
W := $00FF;
|
||||
Result := PByte(@W)^ = $FF;
|
||||
end;
|
||||
|
||||
function SwapEndianWord(Value: Word): Word;
|
||||
@@ -1334,12 +1254,12 @@ begin
|
||||
end;
|
||||
|
||||
function GetVolumeLevelCount(Depth, MipMaps: LongInt): LongInt;
|
||||
var
|
||||
I: LongInt;
|
||||
begin
|
||||
Result := Depth;
|
||||
for I := 1 to MipMaps - 1 do
|
||||
Inc(Result, ClampInt(Depth shr I, 1, Depth));
|
||||
var
|
||||
I: LongInt;
|
||||
begin
|
||||
Result := Depth;
|
||||
for I := 1 to MipMaps - 1 do
|
||||
Inc(Result, ClampInt(Depth shr I, 1, Depth));
|
||||
end;
|
||||
|
||||
function BoundsToRect(X, Y, Width, Height: LongInt): TRect;
|
||||
@@ -1488,27 +1408,27 @@ begin
|
||||
end;
|
||||
|
||||
function RectInRect(const R1, R2: TRect): Boolean;
|
||||
begin
|
||||
Result:=
|
||||
(R1.Left >= R2.Left) and
|
||||
(R1.Top >= R2.Top) and
|
||||
(R1.Right <= R2.Right) and
|
||||
(R1.Bottom <= R2.Bottom);
|
||||
begin
|
||||
Result:=
|
||||
(R1.Left >= R2.Left) and
|
||||
(R1.Top >= R2.Top) and
|
||||
(R1.Right <= R2.Right) and
|
||||
(R1.Bottom <= R2.Bottom);
|
||||
end;
|
||||
|
||||
function RectIntersects(const R1, R2: TRect): Boolean;
|
||||
begin
|
||||
Result :=
|
||||
not (R1.Left > R2.Right) and
|
||||
not (R1.Top > R2.Bottom) and
|
||||
not (R1.Right < R2.Left) and
|
||||
not (R1.Bottom < R2.Top);
|
||||
end;
|
||||
Result :=
|
||||
not (R1.Left > R2.Right) and
|
||||
not (R1.Top > R2.Bottom) and
|
||||
not (R1.Right < R2.Left) and
|
||||
not (R1.Bottom < R2.Top);
|
||||
end;
|
||||
|
||||
function FormatExceptMsg(const Msg: string; const Args: array of const): string;
|
||||
begin
|
||||
Result := Format(Msg + SLineBreak + 'Message: ' + GetExceptObject.Message, Args);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DebugMsg(const Msg: string; const Args: array of const);
|
||||
var
|
||||
@@ -1552,6 +1472,12 @@ initialization
|
||||
-- TODOS ----------------------------------------------------
|
||||
- nothing now
|
||||
|
||||
-- 0.26.1 Changes/Bug Fixes -----------------------------------
|
||||
- Some formatting changes.
|
||||
- Changed some string functions to work with localized strings.
|
||||
- ASM version of PosEx had bugs, removed it.
|
||||
- Added StrTokensToList function.
|
||||
|
||||
-- 0.25.0 Changes/Bug Fixes -----------------------------------
|
||||
- Fixed error in ClipCopyBounds which was causing ... bad clipping!
|
||||
|
||||
@@ -1561,7 +1487,7 @@ initialization
|
||||
|
||||
-- 0.23 Changes/Bug Fixes -----------------------------------
|
||||
- Added RectInRect and RectIntersects functions
|
||||
- Added some string utils: StrToken, StrTokenEnd, PosEx, PosNoCase.
|
||||
- Added some string utils: StrToken, StrTokenEnd, PosEx, PosNoCase.
|
||||
- Moved BuildFileList here from DemoUtils.
|
||||
|
||||
-- 0.21 Changes/Bug Fixes -----------------------------------
|
||||
|
||||
Reference in New Issue
Block a user