home *** CD-ROM | disk | FTP | other *** search
- UNIT AfterDark; {$A+,B-,D-,F-,G-,I+,L-,N-,R-,S-,V+,W+,X+}
-
- (* AFTERDAR.PAS - The AfterDark Interface Module
- * Copyright (C) Richard R. Sands 1991
- * Written by Richard R. Sands 04/91
- * Version 1.01P
- *
- * MODULE() algorithm Copyright (C) Berkeley Systems 1991
- *
- * This unit is intended to perform most of the work for creating an
- * AfterDark Screen Saver Module. It provides the types and constants
- * as described in AfterDark's C language SDK. It also provides a
- * Pascal object called TAfterDark which is the root of your
- * application. You must derive a new type from TAfterDark to perform
- * something useful.
- *
- * You should call the ancestor object method at the start of
- * any methods you override (eg. TAfterDark.DoInitialize), however, it is
- * only required for the Init and DoBlank methods. All methods (except
- * the Init and Done methods) must return NOERROR (or an error code).
- *
- * Version History
- * 1.00P - 04/04/91 - Initial Release
- * 1.01P - 08/05/91 - Bug Fix: REAL was defined as an Operation System Mode
- * so I changed to opREAL
- * Added the GameMode constant for Game Support
- *)
-
- INTERFACE
-
- USES WinTypes;
-
- CONST
- VERSION = 100; { 1.00 }
-
- { ---- ERROR RETURN CODES ---- }
- NOERROR = 0; { NO ERROR, MODULE IS OK }
- MEM_ERROR = 1; { NOT ENOUGH MEMORY, MODULE MUST CLOSE }
- RESTART_ME = 3; { REQUEST FOR AD TO REINITIALIZE ME }
- WAKE_UP = 5; { REQUEST FOR AD TO WAKE }
- USER_ERROR = 7; { MODULE ERROR DESCRIBED BY USER-DEFINED STRING }
- GAME_MODE = 14; { RETURNS GAME MODE }
-
- { ---- PALETTE REQUEST RETURN CODES ---- }
- HSV_PAL = 10; { SMOOTH HUE/SATURATION VALUES }
- RGB_PAL = 11; { GENERIC RED-GREEN-BLUE PALETTE }
- WHITE_PAL = 12; { SHADES OF GREY }
- PRIMARY_PAL= 13; { PRIMARY COLOURS }
-
- SAVER = 0; { ---- SCREENSAVER MODES ---- }
- DEMO = 1;
-
- CPU_086 = 0; { ---- PROCESSOR TYPE ---- }
- CPU_186 = 1;
- CPU_286 = 2;
- CPU_386 = 3;
- CPU_486 = 4;
-
- opREAL = 0; { ---- OPERATING MODE ---- }
- opSTANDARD = 1;
- opENHANCED = 2;
-
- byAFTERDARK = 0; { ---- MODULE RUNNER ---- }
- byRANDOMIZER = 1;
-
- TYPE
- ADSystem = Record
- iOperatingMode, { WINDOWS REAL, STANDARD, OR ENHANCED MODE }
- iProcessorType:Integer; { 8086, 80186, 80286, 80836, 80486 }
- bCoProcessor:Bool; { CO-PROCESSOR AVAILABLE }
- ptScreenSize:TPoint; { SIZE OF SCREEN }
- iBitsPerPixel:Integer; { COLOR RESOLUTION AVAILABLE }
- ptAspect, { RELATIVE X/Y ASPECT RATIO OF MONITOR }
- ptDotsPerInch:TPoint; { NUMBER OF PIXELS PER INCH }
- iADVersion: Integer; { VERSION OF AFTER DARK RUNNING }
- rDemoRect:TRect; { RECT OF CONTROL PANEL (SCREEN 1) }
- iSaverMode:Integer; { MODE FOR AFTER DARK, SAVER OR DEMO }
- hModuleInfo:THandle; { HANDLE TO MODULE-SPECIFIC STRUCT }
- lpszErrorMessage:PChar; { POINTER TO ERROR STRING }
- hADWnd:HWnd; { CONTROL PANEL WINDOW }
- iRunner:Integer; { WHO IS RUNNING MODULES, AD OR RANDOMIZER }
- end;
-
- pAdSystem = ^ADSystem;
-
- AdModule = Record
- hDrawRgn: HRGN; { REGION FOR MODULE TO DRAW INTO }
- ptRgnSize : TPOINT; {SIZE OF DRAWING REGION }
- iControlValue : Array[0..3] of Integer; { CONTROL SETTINGS FOR MODULE }
- iControlID : Array[0..3] of Integer; { IDS OF CONTROLS THAT MODULE WANTS }
- hModule : THANDLE; { HANDLE TO THE MODULE DLL }
- hPaletteAD : HPALETTE; { HANDLE TO CURRENT PALETTE (IF ANY) }
- lpLogPaletteAD: LPHANDLE; { POINTER TO CURRENT PALETTE (IF ANY) }
- end;
- pAdModule = ^AdModule;
-
- TYPE
- PAfterDark = ^TAfterDark;
- TAfterDark = object
- { See AfterDark SDK documentation for use of these next variables }
- DC: hDC; { Provided Display Context }
- lpSystemAD: pAdSystem; { Pointer to AD System Param Block }
- lpModule : pAdModule; { Pointer to Module's Parameters }
-
- { If you override these routines, you must call the ancestor
- routines (eg. TAfterDark.Init) }
- constructor Init;
-
- { This is called when the module is being unloaded. }
- destructor Done; virtual;
-
- { See AfterDark SDK documentation for use of these next routines }
- function DoPreInitialize:Integer; virtual;
- function DoInitialize:Integer; virtual;
- function DoBlank: Integer; virtual;
- function DoDrawFrame: Integer; virtual;
- function DoClose: Integer; virtual;
- function DoSelected: Integer; virtual;
- function DoAbout:Integer; virtual;
-
- { These routines are the Control Handlers. There use is similar
- to the way the SDK DoButtonMessage() worked except the
- iControlValue[] is passed to the actual routine }
-
- function DoButtonMessage1(Value:Integer):Integer; virtual;
- function DoButtonMessage2(Value:Integer):Integer; virtual;
- function DoButtonMessage3(Value:Integer):Integer; virtual;
- function DoButtonMessage4(Value:Integer):Integer; virtual;
- end;
-
- function Module(iMessage:Integer; hDrawDC:hDC; AdSystem:THandle):Integer; EXPORT;
- { For Export Only. ╗ You Must Export This In Your Module ½ }
-
- IMPLEMENTATION
-
- USES
- WinProcs;
-
- CONST
- { ---- CONTROL MESSAGES ---- }
- PREINITIALIZE = 12; { MODULE IS ABOUT TO GO TO SLEEP }
- INITIALIZE = 0; { INITIALIZE VARIABLES }
- BLANK = 1; { BLANK SCREEN }
- DRAWFRAME = 2; { DRAW A FRAME OF ANIMATION }
- CLOSE = 3; { FREE MEM, CLOSE MODULE }
- MODULESELECTED= 5; { MODULE IS SELECTED IN CONTROL PANEL }
- ABOUT = 6; { MODULE'S ABOUT INFO IS BEING SHOWN }
- BUTTONMESSAGE = 7; { A CONTROL HAS BEEN CLICKED }
-
- VAR
- App : PAfterDark;
- SaveExit : Pointer; { Exit Routine for DLL }
- hSystem : THandle; { HANDLE TO AD SYSTEM PARAM BLOCK }
- hLibInst : THandle; { SDK Type: HANDLE }
-
- { ------------------------------------------------------------------------ }
- { Screen Saver Routines - These get changed }
- { ------------------------------------------------------------------------ }
- constructor TAfterDark.Init;
- { Setup the object }
- begin
- App := @Self
- end;
-
- { ------------------------------------------------------------------------ }
- destructor TAfterDark.Done;
- { Destroy the object }
- begin
- end;
-
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoPreInitialize:Integer;
- { MODULE ABOUT TO GO TO SLEEP (PULL DOWN DLOGS, ETC.) }
- begin
- DoPreInitialize := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { MODULE INITIALIZATION ROUTINE }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoInitialize:Integer;
- begin
- DoInitialize := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { MODULE SCREEN BLANKING ROUTINE }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoBlank: Integer;
- begin
- { Get the Current Button Values }
- DoButtonMessage1(lpModule^.iControlValue[0]);
- DoButtonMessage2(lpModule^.iControlValue[1]);
- DoButtonMessage3(lpModule^.iControlValue[2]);
- DoButtonMessage4(lpModule^.iControlValue[3]);
- DoBlank := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { MODULE GRAPHICS ROUTINE }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoDrawFrame: Integer;
- begin
- DoDrawFrame := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { CLOSE MODULE, FREE USED MEMORY, ETC.. }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoClose: Integer;
- begin
- DoClose := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { MODULE IS SELECTED }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoSelected: Integer;
- begin
- DoSelected := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { MODULE'S ABOUT INFO SELECTED }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoAbout:Integer;
- begin
- DoAbout := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { BUTTON CLICKED ON A MODULE CONTROL }
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoButtonMessage1(Value:Integer):Integer;
- begin
- DoButtonMessage1 := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoButtonMessage2(Value:Integer):Integer;
- begin
- DoButtonMessage2 := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoButtonMessage3(Value:Integer):Integer;
- begin
- DoButtonMessage3 := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- function TAfterDark.DoButtonMessage4(Value:Integer):Integer;
- begin
- DoButtonMessage4 := NOERROR
- end;
-
- { ------------------------------------------------------------------------ }
- { SYSTEM ROUTINES }
- { ------------------------------------------------------------------------ }
- Procedure LibExit; { aka. WEP() in SDK } FAR;
- begin
- App^.Done;
- ExitProc := SaveExit
- end;
-
- { ------------------------------------------------------------------------ }
- { MASTER ROUTER FOR MODULE }
- { ------------------------------------------------------------------------ }
- function Module(iMessage:Integer; hDrawDC:hDC; AdSystem:THandle):Integer;
- const
- lTime:Longint=0;
- var
- iError, i:Integer;
- begin
- App^.DC := hDrawDC;
- hSystem := AdSystem;
- App^.lpSystemAD := GlobalLock(hSystem); { Keep pointer safe... }
- if App^.lpSystemAD <> NIL then
- begin
- App^.lpModule := GlobalLock(App^.lpSystemAD^.hModuleInfo);
- if App^.lpModule <> NIL then
- begin
- case iMessage of
- PREINITIALIZE:
- iError := App^.DoPreinitialize;
- INITIALIZE:
- begin
- randomize;
- iError := App^.DoInitialize;
- end;
- BLANK:
- iError := App^.DoBlank;
- DRAWFRAME:
- iError := App^.DoDrawFrame;
- CLOSE :
- iError := App^.DoClose;
- MODULESELECTED:
- begin
- App^.lpModule^.hModule := hLibInst;
- for i:=0 to 3 do
- App^.lpModule^.iControlID[i] := i+1;
- iError := App^.DoSelected
- end;
- ABOUT:
- iError := App^.DoAbout;
- BUTTONMESSAGE+0: iError := App^.DoButtonMessage1(App^.lpModule^.iControlValue[0]);
- BUTTONMESSAGE+1: iError := App^.DoButtonMessage2(App^.lpModule^.iControlValue[1]);
- BUTTONMESSAGE+2: iError := App^.DoButtonMessage3(App^.lpModule^.iControlValue[2]);
- BUTTONMESSAGE+3: iError := App^.DoButtonMessage4(App^.lpModule^.iControlValue[3]);
- end;
- GlobalUnlock(App^.lpSystemAD^.hModuleInfo)
- end;
- GlobalUnlock(hSystem)
- end
- end;
-
- { ------------------------------------------------------------------------ }
- BEGIN
- hLibInst := hInstance;
- SaveExit := ExitProc;
- ExitProc := @LibExit
- END.
-