home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip Hitware 10
/
Chip_Hitware_Vol_10.iso
/
chiphit
/
multmedi
/
95licht
/
install.dll
/
1001
/
1
/
CRAWLER.DPR
< prev
next >
Wrap
Text File
|
1997-02-02
|
14KB
|
514 lines
{$A+,B-,C-,D+,E-,F-,G+,H-,I-,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{ $MINSTACKSIZE $00004000}
{ $MAXSTACKSIZE $00100000}
{$IMAGEBASE $02000000}
{$APPTYPE GUI}
library Crawler;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
View-Project Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the DELPHIMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using DELPHIMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
{ SysUtils,
Classes;}
WinTypes,
Messages,
{ SysUtils,}
LGDAPI,
LGDUTI
{$ifdef USESOUNDS}
, iSounds
{$endif}
;
{$ifdef ENGLISH}
{$r se_crawl.res}
{$else}
{$r ss_crawl.res}
{$endif}
const HELPFILE = 'LGD95.HLP';
HELPKEY:array[0..31]of char = 'Crawler';
const AppName = 'LGD_Crawler';
var
cxClient, cyClient: integer;
fPalette: boolean;
const MAXTAIL = 100;
MAXWORM = 50;
__MAXTAIL:integer = 20;
__MAXWORM:integer = 20;
__TURBO: integer = 0;
type
TPosition = record
x, y: integer;
end;
TailType = record
head, tail: integer;
TailPos: array [1..MAXTAIL] of TPosition;
end;
CrawlerType = record
xPos, yPos: integer;
Dir: integer;
l, m, d: TColorRef;
Tail: TailType;
end;
var Crawlers: array [1..MAXWORM] of CrawlerType;
{$ifdef USESOUNDS}
cSoundTime:integer;
{$endif}
Procedure MoveTo (dc: hdc; xPos, yPos: integer);
begin
MoveToEx (dc, xPos, yPos, NIL);
end;
Procedure DrawSegment (dc:hdc; xPos, yPos: integer; l,m,d: TColorRef);
var x, y: integer;
lb:TLogBrush;
Brush: hBrush;
Pen: hPen;
begin
dec (xPos, 3); { adresse des mittelpunkts ⁿbergeben }
dec (yPos, 3); { received address of center }
lb.lbStyle := bs_Solid;
lb.lbColor := m;
lb.lbHatch := 0;
Brush := CreateBrushIndirect (lb);
Brush := SelectObject (dc, Brush);
Pen := SelectObject (dc, GetStockObject (NULL_PEN));
Rectangle (dc, xPos + 2, yPos + 2, xPos + 8, yPos + 8);
DeleteObject (SelectObject (dc, Brush));
Pen := SelectObject (dc, CreatePen (ps_Solid, 1, l));
MoveTo (dc, xPos + 1, yPos + 6);
LineTo (dc, xPos + 1, yPos + 1);
LineTo (dc, xPos + 8, yPos + 1);
MoveTo (dc, xPos, yPos + 2);
LineTo (dc, xPos, yPos + 7);
MoveTo (dc, xPos + 2, yPos);
LineTo (dc, xPos + 7, yPos);
DeleteObject (SelectObject (dc, Pen));
Pen := SelectObject (dc, CreatePen (ps_Solid, 1, d));
MoveTo (dc, xPos + 1, yPos + 7);
LineTo (dc, xPos + 7, yPos + 7);
LineTo (dc, xPos + 7, yPos + 1);
MoveTo (dc, xPos + 2, yPos + 8);
LineTo (dc, xPos + 7, yPos + 8);
MoveTo (dc, xPos + 8, yPos + 2);
LineTo (dc, xPos + 8, yPos + 7);
DeleteObject (SelectObject (dc, Pen));
end;
Procedure InitCrawlers;
var i, j: integer;
begin
for j := 1 to __MAXWORM do
with Crawlers [j] do
begin
for i := 1 to __MAXTAIL do
begin
Tail.TailPos [i].x := -17;
Tail.TailPos [i].y := -17;
end;
xPos := random (cxClient);
yPos := random (cyClient);
dir := random (16 * 4);
Tail.tail := 1;
Tail.head := __MAXTAIL;
if fPalette {(pif <> nil)} then
begin
i := random (7);
l := PaletteIndex (ColorIndexesColorScales [i * 8 + 7]);
m := PaletteIndex (ColorIndexesColorScales [i * 8 + 5]);
d := PaletteIndex (ColorIndexesColorScales [i * 8 + 3]);
end
else
begin
i := random (7);
case i of
0: begin
l := RGB (255, 255, 255); { grau / grey}
m := RGB (192, 192, 192);
d := RGB (128, 128, 128);
end;
1: begin
l := RGB (255, 255, 0); { gelb / yellow }
m := RGB (192, 192, 0);
d := RGB (128, 128, 0);
end;
2: begin
l := RGB (0, 255, 255); { cyan }
m := RGB (0, 192, 192);
d := RGB (0, 128, 128);
end;
3: begin
l := RGB (0, 0, 255); { blau / blue }
m := RGB (0, 0, 192);
d := RGB (0, 0, 128);
end;
4: begin
l := RGB (255, 0, 0); { rot / red}
m := RGB (192, 0, 0);
d := RGB (128, 0, 0);
end;
5: begin
l := RGB (255, 0, 255); { magenta }
m := RGB (192, 0, 192);
d := RGB (128, 0, 128);
end;
6: begin
l := RGB (0, 255, 0); { grⁿn / green }
m := RGB (0, 192, 0);
d := RGB (0, 128, 0);
end;
end; { german and english share the same roots ... }
end;
end;
end;
Procedure MoveCrawlers (dc: hDC);
var i,j:integer;
begin
for i := 1 to __MAXWORM do
with Crawlers [i] do
begin
DrawSegment (dc, Tail.TailPos [Tail.Tail].x, Tail.TailPos [Tail.Tail].y, 0, 0, 0);
DrawSegment (dc, xPos, yPos, l, m, d);
Tail.TailPos [Tail.Head].x := xPos;
Tail.TailPos [Tail.Head].y := yPos;
inc (Tail.Head);
if Tail.Head > __MAXTAIL then
Tail.Head := 1;
inc (Tail.Tail);
if Tail.Tail > __MAXTAIL then
Tail.Tail := 1;
case Dir div 4 of
0: begin inc (xPos, 6); end;
1: begin inc (xPos, 4); inc (yPos, 2); end;
2: begin inc (xPos, 3); inc (yPos, 3); end;
3: begin inc (xPos, 2); inc (yPos, 4); end;
4: begin inc (yPos, 6); end;
5: begin dec (xPos, 2); inc (yPos, 4); end;
6: begin dec (xPos, 3); inc (yPos, 3); end;
7: begin dec (xPos, 4); inc (yPos, 2); end;
8: begin dec (xPos, 6); end;
9: begin dec (xPos, 4); dec (yPos, 2); end;
10: begin dec (xPos, 3); dec (yPos, 3); end;
11: begin dec (xPos, 2); dec (yPos, 4); end;
12: begin dec (yPos, 6); end;
13: begin inc (xPos, 2); dec (yPos, 4); end;
14: begin inc (xPos, 3); dec (yPos, 3); end;
15: begin inc (xPos, 4); dec (yPos, 2); end;
end;
j := integer (random (5)) - 2;
dir := dir + j;
if xPos >= cxClient then
begin
xPos := cxClient-1;
dir := 8 * 4;
end;
if xPos < 0 then
begin
xPos := 0;
dir := 0;
end;
if yPos >= cyClient then
begin
yPos := cyClient -1;
dir := 12 * 4;
end;
if yPos < 0 then
begin
yPos := 0;
dir := 4 * 4;
end;
dir := dir and 63;
end;
end;
Procedure ReadProfile (var mdModuleData: TModuleData);
var p: Pointer;
i: integer;
begin
with mdModuleData.pms^ do
begin
LgdRegOpenKey (p, sCallerName, sSaverName);
LgdRegGetInteger (p, appname, 'Worms', '10', __MAXWORM);
LgdRegGetInteger (p, appname, 'Length', '10', __MAXTAIL);
LgdRegGetInteger (p, appname, 'Delay', '20', __TURBO);
LgdRegCloseKey (p);
end;
(*
__MAXWORM := GetPrivateProfileInt (appname, 'Anzahl', 10, Ini);
__MAXTAIL := GetPrivateProfileInt (appname, 'LΣnge', 10, Ini);
__TURBO := GetPrivateProfileInt (appname, 'lDelay', 20, Ini);
*)
end;
Procedure WriteProfile (var mdModuleData: TModuleData);
var p: Pointer;
s:string;
begin
with mdModuleData.pms^ do
begin
LgdRegOpenKey (p, sCallerName, sSaverName);
LgdRegSetInteger (p, appname, 'Worms', __MAXWORM);
LgdRegSetInteger (p, appname, 'Length', __MAXTAIL);
LgdRegSetInteger (p, appname, 'Delay', __TURBO);
LgdRegCloseKey (p);
end;
(*
str (__MAXWORM, s);
s := s + #0;
WritePrivateProfileString (AppName, 'Anzahl', @s[1], Ini);
str (__MAXTAIL, s);
s := s + #0;
WritePrivateProfileString (AppName, 'LΣnge', @s[1], Ini);
str (__TURBO, s);
s := s + #0;
WritePrivateProfileString (AppName, 'lDelay', @s[1], Ini);
*)
end;
function Options(Dialog: HWnd; Message, WParam: Word;
LParam: Longint): Bool; stdcall; export;
var trans: bool;
begin
Options := True;
case Message of
wm_InitDialog:
begin
{ fLocalHelp := FALSE;}
SetDlgItemInt (Dialog, 103, __MAXWORM, FALSE);
SetDlgItemInt (Dialog, 104, __MAXTAIL, FALSE);
SetDlgItemInt (Dialog, 105, __TURBO, FALSE);
{$ifdef USESOUNDS}
if THSndVersion > 0 then
ShowWindow (GetDlgItem (dialog, 199), sw_normal);
{$endif}
Exit;
end;
wm_Command:
if (WParam = 1) or (WParam = id_Cancel) then
begin
if (wParam = 1) then
begin
{ *** Note: I changed the prototype for GetDlgItemInt in
Windows.Pas to make it compatible with Delphi 1.0 / BP 7.
Remove the address operator @ if you don't want to change
Windows.Pas. The old style was more logical ... }
__MAXWORM := GetDlgItemInt (Dialog, 103, @trans, FALSE);
__MAXTAIL := GetDlgItemInt (Dialog, 104, @trans, FALSE);
__TURBO := GetDlgItemInt (Dialog, 105, @trans, FALSE);
if __MAXTAIL < 2 then
__MAXTAIL := 2
else if __MAXTAIL > MAXTAIL then
__MAXTAIL := MAXTAIL;
if __MAXWORM < 1 then
__MAXWORM := 1
else if __MAXWORM > MAXWORM then
__MAXWORM := MAXWORM;
if __TURBO < 0 then
__TURBO := 0
else if __TURBO > 9999 then
__TURBO := 9999;
end;
{ if fLocalHelp then
WinHelp (Dialog, HelpFile, help_Quit, 0);}
EndDialog(Dialog, ord (wParam = id_OK));
Exit;
end
else if (wParam = 102) or (wParam = ID_HELPKEY_F1) then
begin
WinHelp (GetParent (dialog), HELPFILE, HELP_KEY, LongInt (@HELPKEY));
{ WinHelp (dialog, HELPFILE, help_Key, LONGINT (@HELPTEXT));
fLocalHelp := TRUE;}
exit;
end
{$ifdef USESOUNDS}
else if (wParam = 199) then
begin
THSndOptions (AppName, dialog);
end
{$endif}
;
end;
Options := False;
end;
{ requests information about screen saver }
Function ScrInfo (var lisInfo: TLgdInfoStruct): bool; stdcall; export;
begin
ScrInfo := FALSE;
with lisInfo do
begin
if cBytes < sizeof (lisInfo) then
exit;
if cMagic <> lMagic then
exit;
afSaverFlags := {SCR_LEAVESBLANK + SCR_MUSTHAVENONBLANK +}
{SCR_CONFIGDIALOG +} SCR_HELPAVAILABLE;
{$ifdef ENGLISH}
StrCopy (@strTitle[1], 'CCrawler');
StrCopy (@strInfo[1], 'Crawler Screen Saver'#10#10+
'Sample of a simple screen saver module for'#10+
'95 Lights Go Down'#10#10+
'Delphi Source Code included!');
{$else}
StrCopy (@strTitle[1], 'CCrawler');
StrCopy (@strInfo[1], 'Crawler Bildschirmschoner'#10#10+
'Beispiel eines einfachen Bildschirmschoners fⁿr '#10+
'95 Lichter gehen aus'#10#10#+
'Der Delphi Quelltext liegt bei!');
{$endif}
StrCopy (@strHelpFile[1], HELPFILE);
StrCopy (@strHelpKey[1], HELPKEY);
end;
ScrInfo := TRUE;
end;
{ display information about screen saver }
Function ScrAbout (hwndParent: HWND): bool; stdcall; export;
begin
ScrAbout := TRUE;
LgdAboutBox (hwndParent, 0,
'Crawler',
'⌐ 1992-97 Thomas H÷vel Software'#10+
'Saturnstr. 45, 53842 Troisdorf, Germany'#10+
'All Rights reserved!',
{$ifdef SHARE}
FALSE,
{$else}
TRUE,
{$endif}
3);
{ MessageBox (hwndParent, 'Hello, World!', 'About', mb_ok);}
end;
{ these functions are called to execute the screen saver }
{ init screen saver - should save pointer to structure }
Function ScrInit (var mdModuleData: TModuleData): bool; stdcall; export;
begin
with mdModuleData.pms^ do
begin
ReadProfile (mdModuleData);
fSupportsIdleFunction := TRUE;
lTimerDelay := 1000; { max. speed }
lCallDelay := __TURBO;
cxClient := cxScreen;
cyClient := cyScreen;
fPalette := pss^.iBPP >= 8;
end;
{$ifdef USESOUNDS}
cSoundTime := 5 + random (5);
{$endif}
ScrInit := TRUE;
Randomize;
InitCrawlers;
end;
Procedure ScrDone (var mdModuleData: TModuleData); stdcall; export;
begin
end;
Procedure ScrIdle (var mdModuleData: TModuleData); stdcall; export;
{ called at maximum rate if requested by saver }
var dc: hdc;
x, y: integer;
hpalOld: HPalette;
begin
with mdModuleData.pms^ do
begin
dc := GetDC (hwndSaver);
if pss^.iBPP >= 8 then
begin
hpalOld := SelectPalette (dc, pss^.hpalModule, FALSE);
RealizePalette (dc);
end;
MoveCrawlers (dc);
if pss^.iBPP >= 8 then
begin
SelectPalette (dc, hpalOld, FALSE);
end;
ReleaseDC (hwndSaver, dc);
end;
end;
Procedure ScrTimer (var mdModuleData: TModuleData); stdcall; export;
{ called by timer with selected interval }
var dc: hdc;
x, y: integer;
begin
{$ifdef USESOUNDS}
with mdModuleData.pms^ do
begin
dec (cSoundTime);
if cSoundTime < 0 then
begin
THSndRandom (AppName, FALSE);
cSoundTime := 10 + random (10);
end;
end;
{$endif}
(*
with mdModuleData.pms^ do
begin
dc := GetDC (hwndSaver);
x := random (cxScreen);
y := random (cyScreen);
SetPixel (dc, x-1, y, RGB (192, 192, 192));
SetPixel (dc, x+1, y, RGB (192, 192, 192));
SetPixel (dc, x, y-1, RGB (192, 192, 192));
SetPixel (dc, x, y+1, RGB (192, 192, 192));
SetPixel (dc, x, y, RGB (255, 255, 255));
ReleaseDC (hwndSaver, dc);
end;
*)
end;
{ display configuration dialog }
Function ScrConfig (var mdModuleData: TModuleData; hwndParent: HWND): integer; stdcall; export;
var Proc: TFarProc;
i: integer;
begin
ReadProfile (mdModuleData);
Proc := MakeProcInstance(@Options, HInstance);
i := DialogBox(HInstance, 'OPTIONBOX', hwndParent, Proc);
FreeProcInstance(Proc);
if i > 0 then
WriteProfile (mdModuleData);
ScrConfig := i;
end;
exports
ScrInfo index 11,
ScrAbout index 12,
ScrInit index 13,
ScrDone index 14,
ScrIdle index 15,
ScrTimer index 16,
ScrConfig index 17;
begin { library }
end.