home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9202 / tpw / pasdk / afterdar.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-08-17  |  12.0 KB  |  323 lines

  1. UNIT AfterDark;  {$A+,B-,D-,F-,G-,I+,L-,N-,R-,S-,V+,W+,X+}
  2.  
  3.  (* AFTERDAR.PAS - The AfterDark Interface Module
  4.   * Copyright (C) Richard R. Sands 1991
  5.   * Written by Richard R. Sands 04/91
  6.   * Version 1.01P
  7.   *
  8.   * MODULE() algorithm Copyright (C) Berkeley Systems 1991
  9.   *
  10.   * This unit is intended to perform most of the work for creating an
  11.   * AfterDark Screen Saver Module.  It provides the types and constants
  12.   * as described in AfterDark's C language SDK.  It also provides a
  13.   * Pascal object called TAfterDark which is the root of your
  14.   * application.  You must derive a new type from TAfterDark to perform
  15.   * something useful.
  16.   *
  17.   * You should call the ancestor object method at the start of
  18.   * any methods you override (eg. TAfterDark.DoInitialize), however, it is
  19.   * only required for the Init and DoBlank methods.  All methods (except
  20.   * the Init and Done methods) must return NOERROR (or an error code).
  21.   *
  22.   * Version History
  23.   *    1.00P - 04/04/91 - Initial Release
  24.   *    1.01P - 08/05/91 - Bug Fix: REAL was defined as an Operation System Mode
  25.   *                                so I changed to opREAL
  26.   *                       Added the GameMode constant for Game Support      
  27.   *)
  28.  
  29. INTERFACE
  30.  
  31.   USES WinTypes;
  32.  
  33. CONST
  34.    VERSION    = 100;  { 1.00 }
  35.  
  36.    { ---- ERROR RETURN CODES ---- }
  37.    NOERROR    = 0;  { NO ERROR, MODULE IS OK }
  38.    MEM_ERROR  = 1;  { NOT ENOUGH MEMORY, MODULE MUST CLOSE }
  39.    RESTART_ME = 3;  { REQUEST FOR AD TO REINITIALIZE ME }
  40.    WAKE_UP    = 5;  { REQUEST FOR AD TO WAKE }
  41.    USER_ERROR = 7;  { MODULE ERROR DESCRIBED BY USER-DEFINED STRING }
  42.    GAME_MODE  = 14; { RETURNS GAME MODE }
  43.  
  44.    { ---- PALETTE REQUEST RETURN CODES ---- }
  45.    HSV_PAL    = 10;  { SMOOTH HUE/SATURATION VALUES }
  46.    RGB_PAL    = 11;  { GENERIC RED-GREEN-BLUE PALETTE }
  47.    WHITE_PAL  = 12;  { SHADES OF GREY }
  48.    PRIMARY_PAL= 13;  { PRIMARY COLOURS }
  49.  
  50.    SAVER = 0;        { ---- SCREENSAVER MODES ---- }
  51.    DEMO  = 1;
  52.  
  53.    CPU_086 = 0;      { ---- PROCESSOR TYPE ---- }
  54.    CPU_186 = 1;
  55.    CPU_286 = 2;
  56.    CPU_386 = 3;
  57.    CPU_486 = 4;
  58.  
  59.    opREAL     = 0;     { ---- OPERATING MODE ---- }
  60.    opSTANDARD = 1;
  61.    opENHANCED = 2;
  62.  
  63.    byAFTERDARK  = 0; { ---- MODULE RUNNER ---- }
  64.    byRANDOMIZER = 1;
  65.  
  66. TYPE
  67.     ADSystem = Record
  68.        iOperatingMode,           { WINDOWS REAL, STANDARD, OR ENHANCED MODE }
  69.        iProcessorType:Integer;   { 8086, 80186, 80286, 80836, 80486         }
  70.        bCoProcessor:Bool;        { CO-PROCESSOR AVAILABLE                   }
  71.        ptScreenSize:TPoint;      { SIZE OF SCREEN                           }
  72.        iBitsPerPixel:Integer;    { COLOR RESOLUTION AVAILABLE               }
  73.        ptAspect,                 { RELATIVE X/Y ASPECT RATIO OF MONITOR     }
  74.        ptDotsPerInch:TPoint;     { NUMBER OF PIXELS PER INCH                }
  75.        iADVersion: Integer;      { VERSION OF AFTER DARK RUNNING            }
  76.        rDemoRect:TRect;          { RECT OF CONTROL PANEL (SCREEN 1)         }
  77.        iSaverMode:Integer;       { MODE FOR AFTER DARK, SAVER OR DEMO       }
  78.        hModuleInfo:THandle;      { HANDLE TO MODULE-SPECIFIC STRUCT         }
  79.        lpszErrorMessage:PChar;   { POINTER TO ERROR STRING                  }
  80.        hADWnd:HWnd;              { CONTROL PANEL WINDOW                     }
  81.        iRunner:Integer;          { WHO IS RUNNING MODULES, AD OR RANDOMIZER }
  82.     end;
  83.  
  84.     pAdSystem = ^ADSystem;
  85.  
  86.     AdModule = Record
  87.        hDrawRgn: HRGN; { REGION FOR MODULE TO DRAW INTO }
  88.        ptRgnSize : TPOINT; {SIZE OF DRAWING REGION }
  89.        iControlValue : Array[0..3] of Integer;  { CONTROL SETTINGS FOR MODULE }
  90.        iControlID    : Array[0..3] of Integer;  { IDS OF CONTROLS THAT MODULE WANTS }
  91.        hModule : THANDLE; { HANDLE TO THE MODULE DLL }
  92.        hPaletteAD : HPALETTE; { HANDLE TO CURRENT PALETTE (IF ANY) }
  93.        lpLogPaletteAD: LPHANDLE; { POINTER TO CURRENT PALETTE (IF ANY) }
  94.     end;
  95.     pAdModule = ^AdModule;
  96.  
  97. TYPE
  98.     PAfterDark = ^TAfterDark;
  99.     TAfterDark = object
  100.       { See AfterDark SDK documentation for use of these next variables }
  101.       DC: hDC;                { Provided Display Context }
  102.       lpSystemAD: pAdSystem;  { Pointer to AD System Param Block }
  103.       lpModule  : pAdModule;  { Pointer to Module's Parameters }
  104.  
  105.       { If you override these routines, you must call the ancestor
  106.     routines (eg. TAfterDark.Init) }
  107.       constructor Init;
  108.  
  109.       { This is called when the module is being unloaded. }
  110.       destructor  Done; virtual;
  111.  
  112.       { See AfterDark SDK documentation for use of these next routines }
  113.       function DoPreInitialize:Integer; virtual;
  114.       function DoInitialize:Integer;    virtual;
  115.       function DoBlank: Integer;        virtual;
  116.       function DoDrawFrame: Integer;    virtual;
  117.       function DoClose: Integer;        virtual;
  118.       function DoSelected: Integer;     virtual;
  119.       function DoAbout:Integer;         virtual;
  120.  
  121.       { These routines are the Control Handlers.  There use is similar
  122.     to the way the SDK DoButtonMessage() worked except the
  123.     iControlValue[] is passed to the actual routine }
  124.  
  125.       function DoButtonMessage1(Value:Integer):Integer; virtual;
  126.       function DoButtonMessage2(Value:Integer):Integer; virtual;
  127.       function DoButtonMessage3(Value:Integer):Integer; virtual;
  128.       function DoButtonMessage4(Value:Integer):Integer; virtual;
  129.     end;
  130.  
  131. function Module(iMessage:Integer; hDrawDC:hDC; AdSystem:THandle):Integer; EXPORT;
  132.   { For Export Only.  ╗ You Must Export This In Your Module ½ }
  133.  
  134. IMPLEMENTATION
  135.  
  136. USES
  137.    WinProcs;
  138.  
  139. CONST
  140.    { ---- CONTROL MESSAGES ---- }
  141.    PREINITIALIZE = 12;  { MODULE IS ABOUT TO GO TO SLEEP }
  142.    INITIALIZE    = 0;   { INITIALIZE VARIABLES }
  143.    BLANK         = 1;   { BLANK SCREEN }
  144.    DRAWFRAME     = 2;   { DRAW A FRAME OF ANIMATION }
  145.    CLOSE         = 3;   { FREE MEM, CLOSE MODULE }
  146.    MODULESELECTED= 5;   { MODULE IS SELECTED IN CONTROL PANEL }
  147.    ABOUT         = 6;   { MODULE'S ABOUT INFO IS BEING SHOWN }
  148.    BUTTONMESSAGE = 7;   { A CONTROL HAS BEEN CLICKED }
  149.  
  150. VAR
  151.    App : PAfterDark;
  152.    SaveExit  : Pointer;    { Exit Routine for DLL }
  153.    hSystem   : THandle;    { HANDLE TO AD SYSTEM PARAM BLOCK }
  154.    hLibInst  : THandle;    { SDK Type: HANDLE }
  155.  
  156. { ------------------------------------------------------------------------ }
  157. { Screen Saver Routines - These get changed                                }
  158. { ------------------------------------------------------------------------ }
  159. constructor TAfterDark.Init;
  160.   { Setup the object }
  161.   begin
  162.      App := @Self
  163.   end;
  164.  
  165. { ------------------------------------------------------------------------ }
  166. destructor TAfterDark.Done;
  167.   { Destroy the object }
  168.   begin
  169.   end;
  170.  
  171. { ------------------------------------------------------------------------ }
  172. function TAfterDark.DoPreInitialize:Integer;
  173.   { MODULE ABOUT TO GO TO SLEEP (PULL DOWN DLOGS, ETC.) }
  174.   begin
  175.      DoPreInitialize := NOERROR
  176.   end;
  177.  
  178. { ------------------------------------------------------------------------ }
  179. { MODULE INITIALIZATION ROUTINE                                            }
  180. { ------------------------------------------------------------------------ }
  181. function TAfterDark.DoInitialize:Integer;
  182.   begin
  183.      DoInitialize := NOERROR
  184.   end;
  185.  
  186. { ------------------------------------------------------------------------ }
  187. { MODULE SCREEN BLANKING ROUTINE                                           }
  188. { ------------------------------------------------------------------------ }
  189. function TAfterDark.DoBlank: Integer;
  190.   begin
  191.      { Get the Current Button Values }
  192.      DoButtonMessage1(lpModule^.iControlValue[0]);
  193.      DoButtonMessage2(lpModule^.iControlValue[1]);
  194.      DoButtonMessage3(lpModule^.iControlValue[2]);
  195.      DoButtonMessage4(lpModule^.iControlValue[3]);
  196.      DoBlank := NOERROR
  197.   end;
  198.  
  199. { ------------------------------------------------------------------------ }
  200. { MODULE GRAPHICS ROUTINE                                                  }
  201. { ------------------------------------------------------------------------ }
  202. function TAfterDark.DoDrawFrame: Integer;
  203.   begin
  204.      DoDrawFrame := NOERROR
  205.   end;
  206.  
  207. { ------------------------------------------------------------------------ }
  208. { CLOSE MODULE, FREE USED MEMORY, ETC..                                    }
  209. { ------------------------------------------------------------------------ }
  210. function TAfterDark.DoClose: Integer;
  211.   begin
  212.      DoClose := NOERROR
  213.   end;
  214.  
  215. { ------------------------------------------------------------------------ }
  216. { MODULE IS SELECTED                                                       }
  217. { ------------------------------------------------------------------------ }
  218. function TAfterDark.DoSelected: Integer;
  219.   begin
  220.      DoSelected := NOERROR
  221.   end;
  222.  
  223. { ------------------------------------------------------------------------ }
  224. { MODULE'S ABOUT INFO SELECTED                                             }
  225. { ------------------------------------------------------------------------ }
  226. function TAfterDark.DoAbout:Integer;
  227.   begin
  228.      DoAbout := NOERROR
  229.   end;
  230.  
  231. { ------------------------------------------------------------------------ }
  232. { BUTTON CLICKED ON A MODULE CONTROL                                       }
  233. { ------------------------------------------------------------------------ }
  234. function TAfterDark.DoButtonMessage1(Value:Integer):Integer;
  235.   begin
  236.      DoButtonMessage1 := NOERROR
  237.   end;
  238.  
  239. { ------------------------------------------------------------------------ }
  240. function TAfterDark.DoButtonMessage2(Value:Integer):Integer;
  241.   begin
  242.      DoButtonMessage2 := NOERROR
  243.   end;
  244.  
  245. { ------------------------------------------------------------------------ }
  246. function TAfterDark.DoButtonMessage3(Value:Integer):Integer;
  247.   begin
  248.      DoButtonMessage3 := NOERROR
  249.   end;
  250.  
  251. { ------------------------------------------------------------------------ }
  252. function TAfterDark.DoButtonMessage4(Value:Integer):Integer;
  253.   begin
  254.      DoButtonMessage4 := NOERROR
  255.   end;
  256.  
  257. { ------------------------------------------------------------------------ }
  258. { SYSTEM ROUTINES                                                          }
  259. { ------------------------------------------------------------------------ }
  260. Procedure LibExit; { aka. WEP() in SDK } FAR;
  261.   begin
  262.      App^.Done;
  263.      ExitProc := SaveExit
  264.   end;
  265.  
  266. { ------------------------------------------------------------------------ }
  267. { MASTER ROUTER FOR MODULE                                                 }
  268. { ------------------------------------------------------------------------ }
  269. function Module(iMessage:Integer; hDrawDC:hDC; AdSystem:THandle):Integer;
  270.   const
  271.      lTime:Longint=0;
  272.   var
  273.      iError, i:Integer;
  274.   begin
  275.      App^.DC := hDrawDC;
  276.      hSystem := AdSystem;
  277.      App^.lpSystemAD := GlobalLock(hSystem);  { Keep pointer safe... }
  278.      if App^.lpSystemAD <> NIL then
  279.      begin
  280.     App^.lpModule := GlobalLock(App^.lpSystemAD^.hModuleInfo);
  281.     if App^.lpModule <> NIL then
  282.     begin
  283.        case iMessage of
  284.          PREINITIALIZE:
  285.          iError := App^.DoPreinitialize;
  286.          INITIALIZE:
  287.            begin
  288.                randomize;
  289.                iError := App^.DoInitialize;
  290.            end;
  291.          BLANK:
  292.            iError := App^.DoBlank;
  293.          DRAWFRAME:
  294.            iError := App^.DoDrawFrame;
  295.          CLOSE :
  296.            iError := App^.DoClose;
  297.          MODULESELECTED:
  298.            begin
  299.                App^.lpModule^.hModule := hLibInst;
  300.                for i:=0 to 3 do
  301.                App^.lpModule^.iControlID[i] := i+1;
  302.                iError := App^.DoSelected
  303.            end;
  304.          ABOUT:
  305.            iError := App^.DoAbout;
  306.          BUTTONMESSAGE+0: iError := App^.DoButtonMessage1(App^.lpModule^.iControlValue[0]);
  307.          BUTTONMESSAGE+1: iError := App^.DoButtonMessage2(App^.lpModule^.iControlValue[1]);
  308.          BUTTONMESSAGE+2: iError := App^.DoButtonMessage3(App^.lpModule^.iControlValue[2]);
  309.          BUTTONMESSAGE+3: iError := App^.DoButtonMessage4(App^.lpModule^.iControlValue[3]);
  310.        end;
  311.        GlobalUnlock(App^.lpSystemAD^.hModuleInfo)
  312.     end;
  313.     GlobalUnlock(hSystem)
  314.      end
  315.   end;
  316.  
  317. { ------------------------------------------------------------------------ }
  318. BEGIN
  319.    hLibInst := hInstance;
  320.    SaveExit := ExitProc;
  321.    ExitProc := @LibExit
  322. END.
  323.