home *** CD-ROM | disk | FTP | other *** search
/ Chip: Shareware for Win 95 / Chip-Shareware-Win95.bin / ostatni / delphi / delphi2 / wowsrc.exe / CODESPOT.PAS < prev    next >
Pascal/Delphi Source File  |  1995-11-24  |  5KB  |  102 lines

  1. unit Codespot;
  2.  
  3. interface
  4.  
  5. Uses
  6.   WinProcs,
  7.   WinTypes,
  8.   Graphics,
  9.   IniFiles,
  10.   Classes;
  11.  
  12. Var
  13.   zx, zy      : Integer;                            { Screen Width and Height }
  14.   cx, cy      : Integer;                            { Spot Pos }
  15.   vx, vy, d   : integer;                            { Accel amd Width }
  16.   Desktop     : hBitmap;                            { Desktop bitmap }
  17.  
  18.  
  19. Procedure InitSpot;                                  { Inti routine }
  20. Procedure ReadSpotDefaults;                          { Read the spot defaults }
  21. Procedure DrawSpot;                                  { Draw It }
  22. Procedure FreeSpot;                                  { Free resources }
  23.  
  24. implementation
  25.  
  26. Uses
  27.   SSave,
  28.   Globals;
  29.  
  30. Procedure InitSpot;
  31. var
  32.   WinDC, MemDC: hDC;                                       { Local DC's }
  33.  
  34. begin
  35.   ReadSpotDefaults;                                        { Read Defaults }
  36.   zx := ScreenWd;                                          { get Width }
  37.   zy := ScreenHt;                                          { Get Height }
  38.   randomize;                                               { Ramdom init }
  39.   cx := random (zx div 2) + 1;                             { get starting x }
  40.   cy := random (zy div 2) + 1;                             { get starting y }
  41.   vx := -1 + 2 * random (2);                               { get speed: }
  42.   vy := -1 + 2 * random (2);                               { vx, vy = 1 or -1 }
  43.   d  := SpotSize;                                          { diameter }
  44.  
  45.   WinDC := GetDC (GetDeskTopWindow);                       { copy actual video RAM.. }
  46.   MemDC := CreateCompatibleDC (WinDC);                     { Get Compatible DC }
  47.   Desktop := CreateCompatibleBitmap (WinDC, zx, zy);       { Create the Bitmap }
  48.   SelectObject (MemDC, Desktop);                           { Select it }
  49.   BitBlt (MemDC, 0, 0, zx, zy, WinDC, 0, 0, SRCCOPY);      { Now copy the desktop }
  50.   DeleteDC (MemDC);                                        { Free it }
  51.   ReleaseDC (GetDeskTopWindow, WinDC);                     { Release the Desktop DC }
  52. End;
  53.  
  54. Procedure DrawSpot;                                        { Draw the spot light }
  55. var
  56.   WinDC, MemDC: hDC;                                       { Local DC's }
  57.   CircleRgn, BackGndRgn: hRgn;                             { Local Regions }
  58.  
  59. begin
  60.   WinDC := GetDC (Scrn.Handle);                            { Get Screen DC }
  61.   MemDC := CreateCompatibleDC (WinDC);                     { Get compat }
  62.   SelectObject (MemDC, Desktop);                           { get a DC with desktop bitmap }
  63.   if ((cx <= 0) or (cx+d >= zx)) then vx := -vx;           { bounce light at X edges }
  64.   if ((cy <= 0) or (cy+d >= zy)) then vy := -vy;           { bounce light at Y edges }
  65.   cx := cx+vx;                                             { calculate new X position }
  66.   cy := cy+vy;                                             { calculate new Y position }
  67.  
  68.   CircleRgn := CreateEllipticRgn (cx, cy, cx+d, cy+d);     { Build the "spotlight region"  }
  69.   BackGndRgn := CreateRectRgn (cx-2, cy-2,
  70.                                cx+d+2, cy+d+2);            { Get Region aroubnd Spot }
  71.   CombineRgn (BackGndRgn, BackGndRgn, CircleRgn,
  72.                    RGN_DIFF);                              { Get Combination }
  73.   FillRgn (WinDC, BackGndRgn,
  74.                           GetStockObject (black_brush));   { Fill it black }
  75.   SelectObject (WinDC, CircleRgn);                         { clipping region }
  76.   BitBlt (WinDC, 0, 0, zx, zy, MemDC, 0, 0, SRCCOPY);      { copy bitmap -> screen }
  77.   DeleteDC (MemDC);                                        { Release }
  78.   ReleaseDC (Scrn.Handle, WinDC);                          { Release }
  79.   DeleteObject (CircleRgn);                                { Drop Object }
  80.   DeleteObject (BackGndRgn);                               { Drop Object }
  81.   Delay(SpotSpeed);                                        { Delay if required }
  82. end;
  83.  
  84. Procedure FreeSpot;                                        { Free resources }
  85. Begin
  86.   DeleteObject (Desktop);                                  { Drop the desktop bitmap }
  87. End;
  88.  
  89. Procedure ReadSpotDefaults;                                { Read defaults }
  90. Var
  91.   Ini : TiniFile;                                          { The Ini file }
  92. Begin
  93.   Ini := TIniFile.Create('Wow.Ini');                   { Open the Ini File }
  94.   Apptitle := 'Screen Saver.Delphi Spot';                  { Set title }
  95.   PwdType := Ini.ReadInteger(AppTitle,'PwdType',0);        { Get the Password Type }
  96.   SpotSpeed := Ini.ReadInteger(AppTitle,'Speed',0);        { Get Delay in MS }
  97.   SpotSize := Ini.ReadInteger(AppTitle,'Size',100);        { Get the Size }
  98.   Pwd := Ini.ReadString('ScreenSaver','Password','');      { Read the Password, if any }
  99. End;
  100.  
  101. end.
  102.