home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / TCYBER.ZIP / CYFONT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-15  |  36KB  |  1,351 lines

  1. {
  2. Turbo Vision CyberTools 1.0
  3. (C) 1994 Steve Goldsmith
  4. All Rights Reserved
  5.  
  6. CyberFont application shows how to use fonts, graphics, sprites, bit map
  7. animation, PCX images and DAC palettes.  Borland Pascal 7.x or Turbo Pascal
  8. 7.x and Turbo Vision 2.x are required to compile.
  9.  
  10. Set IDE directories to
  11.  
  12. \BP\UNITS;
  13. \BP\EXAMPLES\DOS\TVDEMO;
  14. \BP\EXAMPLES\DOS\TVFM;
  15.  
  16. These path names are BP 7.x defaults.  If you changed any of these then use
  17. the correct paths in Options|Directories...  See APP.INC for global compiler
  18. switches.
  19. }
  20.  
  21. program CyberFont;
  22.  
  23. {$I APP.INC}
  24. {$X+}
  25.  
  26. uses
  27.  
  28.   Dos,                           {bp units}
  29.   Memory, Drivers, Objects,      {tv units}
  30.   Views, Menus, Dialogs,
  31.   App, MsgBox, StdDlg, ColorSel,
  32.   Gadgets, AsciiTab, HelpFile,   {tvdemo units}
  33.   ViewText,                      {tvfm units}
  34.   CFHelp, CFCmds,                {cybertools units}
  35.   VGA, VGACGFil, CFSprite, ChrPCX,
  36.   CFDlgs;
  37.  
  38. const
  39.  
  40.   appDocName  = 'CYBER.DOC';  {doc file name}
  41.   appCfgName  = 'CYFONT.CFG'; {config stream file name}
  42.   appHelpName = 'CFHELP.HLP'; {help file name}
  43.   appExeName  = 'CYFONT.EXE'; {name used to locate .exe for older dos}
  44.   appCfgHeaderLen = 10;       {header used by config stream}
  45.   appCfgHeader : string[appCfgHeaderLen] = 'CYBERFONT'#26;
  46.   appViewDocBuf = 8192;       {buffer size for viewing doc file}
  47.  
  48.   appChrWidth8  = $01;        {set app options bit to 1 to select option}
  49.   appPageMode   = $02;
  50.   app8Colors    = $04;
  51.   appAniBitMap  = $08;
  52.   appHelpInUse  = $8000;      {used by help system}
  53.   appScrOpts    = $0f;        {mask of just screen options}
  54.  
  55.   appGraphWinX = 32; {x = 32*8 = 256 pixels}
  56.   appGraphWinY = 8;  {y = 8*16 = 128 pixels}
  57.  
  58.   CSysColor = #$00#$00#$00; {app palette additions for tv system stuff}
  59.   CSysPal   = #144#145#146;
  60.  
  61. type
  62.  
  63.   TCyberFont = object (TApplication)
  64.     FontTable1,
  65.     FontTable2,
  66.     AniTable : byte;
  67.     FrameDelay : integer;
  68.     AppOptions,
  69.     PageOfs,
  70.     DefChrHeight : word;
  71.     BiosTimer,
  72.     TickDelay : longint;
  73.     Page : pointer;
  74.     DefFont : vgaChrTablePtr;
  75.     DacPalette : vgaPalette;
  76.     ScrData : ScrOptsData;
  77.     Clock : PClockView;
  78.     Heap : PHeapView;
  79.     constructor Init;
  80.     destructor Done; virtual;
  81.     procedure SetCustomScreen;
  82.     procedure FlipPage;
  83.     procedure ClearDeskTop;
  84.     procedure Idle; virtual;
  85.     procedure AboutBox;
  86.     function SelectFile (Title : string; WildCard : PathStr; ReadFlag : boolean) : PathStr;
  87.     procedure LoadFontTable (ChrData : pointer;
  88.                              ChrTable, ChrHeight :byte;
  89.                              StartChr, NumChrs : word);
  90.     function SaveFontTable (ChrTable, ChrHeight :byte;
  91.                             StartChr, NumChrs : word) : vgaChrTablePtr;
  92.     procedure LoadChrFile (F : PathStr; ChrTbl : byte);
  93.     procedure SaveChrFile (F : PathStr);
  94.     procedure GraphicsWin (T : string);
  95.     procedure RestoreDesktop (F : PathStr);
  96.     procedure SaveDeskTop (F : PathStr);
  97.     procedure GetEvent (var Event : TEvent); virtual;
  98.     function GetPalette : PPalette; virtual;
  99.     procedure HandleEvent (var Event : TEvent); virtual;
  100.     procedure InitDeskTop; virtual;
  101.     procedure InitMenuBar; virtual;
  102.     procedure InitStatusLine; virtual;
  103.     procedure OutOfMemory; virtual;
  104.     procedure LoadDesktop (var S : TStream);
  105.     procedure StoreDesktop (var S : TStream);
  106.   end;
  107.  
  108. constructor TCyberFont.Init;
  109.  
  110. var
  111.  
  112.   R :TRect;
  113.  
  114. begin
  115.   LowMemSize := 4095; {65520 byte safety pool needed to do dos shell safely}
  116.   inherited Init;
  117.   RegisterObjects;    {register stuff for stream access}
  118.   RegisterViews;
  119.   RegisterMenus;
  120.   RegisterDialogs;
  121.   RegisterApp;
  122.   RegisterAsciiTab;
  123.   RegisterHelpFile;
  124.   R.Assign (71,0,79,1);
  125.   Clock := New (PClockView,Init (R)); {gadgets included with tvdemo}
  126.   Insert (Clock);
  127.   R.Assign (64,0,70,1);
  128.   Heap := New (PHeapView,Init(R));
  129.   Insert (Heap);
  130.   RestoreDesktop (appCfgName); {load config stream}
  131.   AniTable := 1;               {start font 2 table animation with table 1}
  132.   FrameDelay := ScrData.Delay; {frame delay in 1/18 seconds}
  133.   Randomize                    {animation dialogs use random numbers}
  134. end;
  135.  
  136. destructor TCyberFont.Done;
  137.  
  138. begin
  139.   if DefFont <> nil then      {dispose default font}
  140.     FreeMem (DefFont,vgaMaxChrs*DefChrHeight);
  141.   FadeOutDAC;                 {fade to black}
  142.   SetVideoMode (StartUpMode); {this resets all the custom stuff with bios}
  143.   inherited Done
  144. end;
  145.  
  146. procedure TCyberFont.SetCustomScreen;
  147.  
  148. begin
  149.   HideMouse;
  150.   if AppOptions and appPageMode = 0 then
  151.     SetPage (vgaPageOfsLoc[0]); {screen page 0 for non page flipping displays}
  152.   if AppOptions and app8Colors = app8Colors then
  153.     SetAttrCont (vgaAttrCPEnable,$07)  {use 8 colors}
  154.   else
  155.     SetAttrCont (vgaAttrCPEnable,$0f); {use 16 colors}
  156.   if AppOptions and appChrWidth8 = appChrWidth8 then
  157.   begin
  158.     if IsChrWidth9 then
  159.       SetChrWidth8 {640 x 400 screen}
  160.   end
  161.   else
  162.   begin
  163.     if not IsChrWidth9 then
  164.       SetChrWidth9 {720 x 400 screen}
  165.   end;
  166.   FontMapSelect (vgaChrTableMap1[FontTable1],
  167.   vgaChrTableMap2[FontTable2]);    {select font tables}
  168.   SetDACBlock (@DacPalette,0,256); {set 256 color palette}
  169.   asm                 {new mouse cursor mask that looks right}
  170.     mov     ax,0ah    {when mouse is over graphic characters}
  171.     mov     bx,00h
  172.     mov     cx,0ffffh {and mask}
  173.     mov     dx,7700h  {xor mask}
  174.     int     33h       {mouse interrupt}
  175.   end;
  176.   ShowMouse
  177. end;
  178.  
  179. procedure TCyberFont.FlipPage;
  180.  
  181. begin {copy screen page 0 to new non-visiable page and flip to new page}
  182.   CopyScrMem (ScreenBuffer,Page,vgaScrSize25);
  183.   SetPage (PageOfs);
  184.   if PageOfs = vgaPageOfsLoc[1] then
  185.   begin
  186.     PageOfs := vgaPageOfsLoc[2];
  187.     Page := vgaPageLoc[2]
  188.   end
  189.   else
  190.   begin
  191.     PageOfs := vgaPageOfsLoc[1];
  192.     Page := vgaPageLoc[1]
  193.   end;
  194.   WaitVertSync {wait for vga vert sync before drawing anything}
  195. end;
  196.  
  197. procedure TCyberFont.ClearDeskTop;
  198.  
  199. procedure CloseDlg (P : PView); far;
  200.  
  201. begin
  202.   Message (P,evCommand,cmClose,nil)
  203. end;
  204.  
  205. begin
  206.   Desktop^.ForEach (@CloseDlg)
  207. end;
  208.  
  209. procedure TCyberFont.Idle;
  210.  
  211. function IsTileable (P : PView) : Boolean; far;
  212.  
  213. begin
  214.   IsTileable := (P^.Options and ofTileable <> 0) and
  215.   (P^.State and sfVisible <> 0);
  216. end;
  217.  
  218. function IsThere (P : PView) : Boolean; far;
  219.  
  220. begin
  221.   IsThere := (P^.State and sfActive = sfActive)
  222. end;
  223.  
  224. function IsModal (P : PView) : Boolean; far;
  225.  
  226. begin
  227.   IsModal := (P^.State and sfModal = sfModal)
  228. end;
  229.  
  230. procedure AniMsg (P: PView); far;
  231.  
  232. begin
  233.   Message (P,evBroadcast,cmAnimate,nil)
  234. end;
  235.  
  236. begin
  237.   inherited Idle;
  238.   BiosTimer := longint (Ptr (Seg0040,$6c)^); {read time from bios area}
  239.   Clock^.Update; {update tvdemo gadgets}
  240.   Heap^.Update;
  241.   if Desktop^.FirstThat (@IsThere) <> nil then {see if anything is}
  242.   begin                                        {on the desk top}
  243.     EnableCommands ([cmCloseAll]);
  244.     if Desktop^.FirstThat (@IsTileable) <> nil then {see if any tileable}
  245.       EnableCommands ([cmTile,cmCascade])           {windows are on the}
  246.     else                                            {desk top}
  247.       DisableCommands ([cmTile,cmCascade]);
  248.     Desktop^.ForEach (@AniMsg) {update all animation dialogs}
  249.   end
  250.   else
  251.     DisableCommands ([cmCloseAll,cmTile,cmCascade]);
  252.   if (Desktop^.FirstThat (@IsModal) <> nil)
  253.   or (AppOptions and appHelpInUse = appHelpInUse) then   {see if a modal dialog}
  254.     DisableCommands ([cmQuit,cmRestoreDef,cmScreenOpts]) {is on the desk top}
  255.   else
  256.     EnableCommands ([cmQuit,cmRestoreDef,cmScreenOpts]);
  257.   if AppOptions and appPageMode = appPageMode then
  258.     FlipPage; {if page mode is enabled then flip page each idle cycle}
  259.   if (AppOptions and appAniBitMap = appAniBitMap) and
  260.   (BiosTimer <> TickDelay) then {see if we are ready to display next frame}
  261.   begin
  262.     TickDelay := BiosTimer;     {reset tick delay to equal bios time}
  263.     Dec (FrameDelay);           {count down ticks}
  264.     if FrameDelay = 0 then      {see if counted down to zero}
  265.     begin                       {display next frame}
  266.       FontMapSelect (vgaChrTableMap1[FontTable1],vgaChrTableMap2[AniTable]);
  267.       Inc (AniTable);
  268.       if AniTable = vgaMaxChrTables then {see if last frame reached}
  269.         AniTable := 1;                   {yes, then restart at 1}
  270.       FrameDelay := ScrData.Delay        {reset frame delay}
  271.     end
  272.   end
  273. end;
  274.  
  275. procedure TCyberFont.AboutBox;
  276.  
  277. begin
  278.   MessageBox(
  279.     #3'Turbo Vision CyberTools 1.0'#13+
  280.     #3'(C) 1994 Steve Goldsmith'#13+
  281. {$IFDEF DPMI}
  282.     #3'CyberFont »> PROTECTED <«',
  283. {$ELSE}
  284.     #3'CyberFont »> REAL <«',
  285. {$ENDIF}
  286.     nil, mfInformation or mfOKButton)
  287. end;
  288.  
  289. function TCyberFont.SelectFile (Title : string; WildCard : PathStr; ReadFlag : boolean) : PathStr;
  290.  
  291. var
  292.  
  293.   F : file;
  294.  
  295. begin
  296.   HelpCtx := hcFOFileOpenDBox;
  297.   if ExecuteDialog (New (PFileDialog,Init (WildCard,Title,
  298.     '~N~ame',fdOkButton,100)),@WildCard) <> cmCancel then
  299.   begin
  300.     if ReadFlag then
  301.       SelectFile := WildCard
  302.     else
  303.     begin
  304.       Assign (F,WildCard);
  305.       {$I-} Reset (F); {$I+}
  306.       if IoResult = 0 then {see if file exists before writes}
  307.       begin
  308.         {$I-} Close (F); {$I+}
  309.         if MessageBox (WildCard+' already exists.  Erase and continue?',
  310.         nil,mfConfirmation or mfYesNoCancel) = cmYes then
  311.           SelectFile := WildCard
  312.         else
  313.           SelectFile := ''
  314.       end
  315.       else
  316.         SelectFile := WildCard
  317.     end
  318.   end
  319.   else
  320.     SelectFile := '';
  321.   HelpCtx := hcNoContext
  322. end;
  323.  
  324. procedure TCyberFont.LoadFontTable (ChrData : pointer;
  325.                                        ChrTable, ChrHeight :byte;
  326.                                        StartChr, NumChrs : word);
  327.  
  328. begin
  329.   HideMouse;
  330.   AccessFontMem;
  331.   SetRamTable (StartChr,NumChrs,ChrHeight,ChrData,vgaChrTableLoc[ChrTable]);
  332.   AccessScreenMem;
  333.   ShowMouse
  334. end;
  335.  
  336. function TCyberFont.SaveFontTable (ChrTable, ChrHeight :byte;
  337.                                       StartChr, NumChrs : word) : vgaChrTablePtr;
  338.  
  339. begin
  340.   HideMouse;
  341.   AccessFontMem;
  342.   SaveFontTable :=
  343.   GetRamTable (StartChr,NumChrs,ChrHeight,vgaChrTableLoc [ChrTable]);
  344.   AccessScreenMem;
  345.   ShowMouse
  346. end;
  347.  
  348. procedure TCyberFont.LoadChrFile (F : PathStr; ChrTbl : byte);
  349.  
  350. var
  351.  
  352.   ChrFile : TChrGenFile;
  353.  
  354. begin {load .cgf file and use bios to store in table}
  355.   ChrFile.Init;
  356.   ChrFile.OpenRead (F);
  357.   if (ChrFile.IoError = 0) and
  358.   (ChrFile.Header.Height = DefChrHeight) then
  359.   begin
  360.     ChrFile.ReadChrTable;
  361.     LoadFontTable (
  362.     ChrFile.ChrTablePtr,ChrTbl,ChrFile.Header.Height,
  363.     ChrFile.Header.StartChr,ChrFile.Header.TotalChrs)
  364.   end
  365.   else
  366.     MessageBox (#3'Problem reading font file.',nil,mfOkButton+mfError);
  367.   ChrFile.FreeChrTable;
  368.   ChrFile.Done
  369. end;
  370.  
  371. procedure TCyberFont.SaveChrFile (F : PathStr);
  372.  
  373. var
  374.  
  375.   ChrFile : TChrGenFile;
  376.  
  377. begin {save .cgf file from table}
  378.   ChrFile.Init;
  379.   HideMouse;
  380.   AccessFontMem;
  381.   ChrFile.GetFontTable (FontTable1,0,vgaMaxChrs,DefChrHeight);
  382.   AccessScreenMem;
  383.   ShowMouse;
  384.   ChrFile.OpenWrite (F);
  385.   if ChrFile.IoError = 0 then
  386.     ChrFile.WriteChrTable
  387.   else
  388.     MessageBox (#3'Problem writing font file.',nil,mfOkButton+mfError);
  389.   ChrFile.FreeChrTable;
  390.   ChrFile.Done
  391. end;
  392.  
  393. procedure TCyberFont.GraphicsWin (T : string);
  394.  
  395. var
  396.  
  397.   P : PChrSetDlg;
  398.  
  399. function IsThere (P : PView) : Boolean; far;
  400.  
  401. begin {see if view is a chr set dialog}
  402.   IsThere := (TypeOf (P^) = TypeOf (TChrSetDlg))
  403. end;
  404.  
  405. begin
  406.   PView (P) := Desktop^.FirstThat (@IsThere);
  407.   if P <> nil then {if on screen then close}
  408.   begin
  409.     if PChrSetDlg (P)^.Title <> nil then
  410.       DisposeStr (PChrSetDlg (P)^.Title);
  411.     PChrSetDlg (P)^.Title := NewStr (T);
  412.     PChrSetDlg (P)^.Frame^.DrawView;
  413.     PChrSetDlg (P)^.MakeFirst;
  414.   end
  415.   else
  416.   begin
  417.     P := New(PChrSetDlg,Init (T,appGraphWinX,appGraphWinY));
  418.     P^.Options := P^.Options or ofCentered;
  419.     P^.HelpCtx := hcGraphicsWindow;
  420.     InsertWindow (P)
  421.   end
  422. end;
  423.  
  424. procedure TCyberFont.RestoreDesktop (F : PathStr);
  425.  
  426. var
  427.  
  428.   I : byte;
  429.   S : PStream;
  430.   Signature : string[appCfgHeaderLen];
  431.  
  432. begin
  433.   S := New (PBufStream,Init (F,stOpenRead,1024));
  434.   if LowMemory then OutOfMemory
  435.   else
  436.     if S^.Status <> stOk then
  437.     begin
  438.       MessageBox (#3'Unable to open file.',nil,mfOkButton+mfError)
  439.     end
  440.     else
  441.     begin
  442.       Signature[0] := Char (appCfgHeaderLen);
  443.       S^.Read (Signature[1],appCfgHeaderLen);
  444.       if Signature = appCfgHeader then {see if signature is right}
  445.       begin
  446.         S^.Read (AppOptions,SizeOf (AppOptions)); {read data from stream}
  447.         S^.Read (DefChrHeight,SizeOf (DefChrHeight));
  448.         S^.Read (ScrData.Delay,SizeOf (ScrData.Delay));
  449.         if DefFont = nil then
  450.           DefFont := MemAlloc (DefChrHeight*vgaMaxChrs);
  451.         HideMouse; {no screen writes during font mem access}
  452.         AccessFontMem;
  453.         for I := 0 to 7 do
  454.         begin
  455.           S^.Read (DefFont^,DefChrHeight*vgaMaxChrs);
  456.           SetRamTable (0,vgaMaxChrs,DefChrHeight,DefFont,vgaChrTableLoc[I])
  457.         end;
  458.         AccessScreenMem;
  459.         ShowMouse;
  460.         S^.Read (FontTable1,SizeOf (FontTable1));
  461.         S^.Read (FontTable2,SizeOf (FontTable2));
  462.         S^.Read (DacPalette,SizeOf (DacPalette));
  463.         LoadDesktop (S^);
  464.         LoadIndexes (S^);
  465.         ShadowAttr := GetColor (144);   {tv shadow color}
  466.         SysColorAttr := (GetColor (145) shl 8) or GetColor (145); {tv system error color}
  467.         ErrorAttr := GetColor (146);    {tv palette index error color}
  468.         if DefFont <> nil then
  469.         begin
  470.           FreeMem (DefFont,DefChrHeight*vgaMaxChrs);
  471.           DefFont := SaveFontTable (FontTable1,DefChrHeight,0,vgaMaxChrs)
  472.         end;
  473.         SetCustomScreen;
  474.         Application^.ReDraw; {draw app with new config}
  475.         GraphicsWin ('');    {say hello with graphic window}
  476.         if S^.Status <> stOk then
  477.           MessageBox (#3'Stream error.',nil,mfOkButton+mfError);
  478.       end
  479.       else
  480.         MessageBox (#3'Invalid configuration format.',nil,mfOkButton+mfError)
  481.     end;
  482.   Dispose (S,Done)
  483. end;
  484.  
  485. procedure TCyberFont.SaveDesktop (F : PathStr);
  486.  
  487. var
  488.  
  489.   I : byte;
  490.   CfgFile : File;
  491.   S : PStream;
  492.   SFont : vgaChrTablePtr;
  493.  
  494. begin
  495.   S := New(PBufStream,Init (F,stCreate,1024));
  496.   if not LowMemory and (S^.Status = stOk) then
  497.   begin
  498.     S^.Write (appCfgHeader[1],appCfgHeaderLen); {write stream data}
  499.     S^.Write (AppOptions,SizeOf (AppOptions));
  500.     S^.Write (DefChrHeight,SizeOf (DefChrHeight));
  501.     S^.Write (ScrData.Delay,SizeOf (ScrData.Delay));
  502.     HideMouse; {no screen write during font mem access}
  503.     AccessFontMem;
  504.     for I := 0 to 7 do {save all 8 vga font tables}
  505.     begin
  506.       SFont := GetRamTable (0,vgaMaxChrs,DefChrHeight,vgaChrTableLoc[I]);
  507.       S^.Write (SFont^,DefChrHeight*vgaMaxChrs);
  508.       if SFont <> nil then
  509.         FreeMem (SFont,DefChrHeight*vgaMaxChrs)
  510.     end;
  511.     AccessScreenMem;
  512.     ShowMouse;
  513.     S^.Write (FontTable1,SizeOf (FontTable1));
  514.     S^.Write (FontTable2,SizeOf (FontTable2));
  515.     GetDACBlock (@DacPalette,0,256);
  516.     S^.Write(DacPalette,SizeOf (DacPalette));
  517.     StoreDesktop (S^);
  518.     StoreIndexes (S^);
  519.     if S^.Status <> stOk then
  520.     begin {if stream error then delete file}
  521.       MessageBox (#3'Could not create stream.',nil,mfOkButton+mfError);
  522.       Dispose (S,Done);
  523.       Assign (CfgFile,F);
  524.       {$I-} Erase (CfgFile) {$I+};
  525.       Exit
  526.     end
  527.   end;
  528.   Dispose (S,Done)
  529. end;
  530.  
  531. procedure TCyberFont.GetEvent (var Event : TEvent);
  532.  
  533. function CalcHelpName : PathStr;
  534.  
  535. var
  536.  
  537.   EXEName : PathStr;
  538.   Dir : DirStr;
  539.   Name : NameStr;
  540.   Ext : ExtStr;
  541.  
  542. begin
  543.   if Lo (DosVersion) >= 3 then
  544.     EXEName := ParamStr (0)
  545.   else
  546.     EXEName := FSearch (appExeName, GetEnv ('PATH'));
  547.   FSplit (EXEName, Dir, Name, Ext);
  548.   if Dir[Length (Dir)] = '\' then
  549.     Dec (Dir[0]);
  550.   CalcHelpName := FSearch (appHelpName, Dir);
  551. end;
  552.  
  553. var
  554.  
  555.   W : PWindow;
  556.   HFile : PHelpFile;
  557.   HelpStrm : PDosStream;
  558.  
  559. begin
  560.   inherited GetEvent (Event);
  561.   case Event.What of
  562.     evCommand:
  563.       if (Event.Command = cmHelp) and (AppOptions and appHelpInUse = 0) then
  564.       begin {process help command if not in use}
  565.         AppOptions := AppOptions or appHelpInUse; {help's in use}
  566.         HelpStrm := New (PDosStream, Init (CalcHelpName, stOpenRead));
  567.         HFile := New (PHelpFile, Init (HelpStrm));
  568.         if HelpStrm^.Status <> stOk then
  569.         begin
  570.           MessageBox (#3'Could not open help file.', nil, mfError + mfOkButton);
  571.           Dispose (HFile, Done);
  572.         end
  573.         else
  574.         begin
  575.           W := New (PHelpWindow,Init (HFile, GetHelpCtx));
  576.           if ValidView (W) <> nil then
  577.           begin
  578.             DisableCommands ([cmHelp]);
  579.             ExecView (W);
  580.             Dispose (W, Done);
  581.             EnableCommands ([cmHelp])
  582.           end;
  583.           ClearEvent (Event)
  584.         end;
  585.         AppOptions := AppOptions and not appHelpInUse
  586.       end;
  587.     evMouseDown:
  588.       if Event.Buttons <> 1 then
  589.         Event.What := evNothing
  590.   end
  591. end;
  592.  
  593. function TCyberFont.GetPalette: PPalette;
  594.  
  595. const
  596.  
  597.   CNewColor = CAppColor+CHelpColor+CAniColor+CGraphColor+CSysColor;
  598.   CNewBlackWhite = CAppBlackWhite+CHelpBlackWhite+CAniColor+CGraphColor+CSysColor;
  599.   CNewMonochrome = CAppMonochrome+CHelpMonochrome+CAniColor+CGraphColor+CSysColor;
  600.   P: array[apColor..apMonochrome] of string[Length (CNewColor)] =
  601.   (CNewColor, CNewBlackWhite, CNewMonochrome);
  602.  
  603. begin {add additional entries to the normal application palettes}
  604.   GetPalette := @P[AppPalette];
  605. end;
  606.  
  607. procedure TCyberFont.HandleEvent (var Event: TEvent);
  608.  
  609. procedure LoadFontFile;
  610.  
  611. var
  612.  
  613.   F : PathStr;
  614.  
  615. begin
  616.   F := SelectFile ('Load Font','*.CGF',true);
  617.   if F <> '' then
  618.     LoadChrFile (F,FontTable1)
  619. end;
  620.  
  621. procedure SaveFontFile;
  622.  
  623. var
  624.  
  625.   F : PathStr;
  626.  
  627. begin
  628.   F := SelectFile ('Save Font','*.CGF',false);
  629.   if F <> '' then
  630.     SaveChrFile (F)
  631. end;
  632.  
  633. procedure LoadPCXFile;
  634.  
  635. var
  636.  
  637.   F : PathStr;
  638.  
  639. begin
  640.   F := SelectFile ('Load PCX','*.PCX',true);
  641.   if F <> '' then
  642.   begin
  643.     HideMouse; {no screen writes during font mem access}
  644.     if PCXToChrTable (F,appGraphWinX,appGraphWinY,DefChrHeight,vgaChrTableLoc[FontTable2]) then
  645.     begin
  646.       ShowMouse;
  647.       GraphicsWin (F)
  648.     end
  649.     else
  650.     begin
  651.       ShowMouse;
  652.       MessageBox (#3'Problem reading PCX file.',nil,mfOkButton+mfError)
  653.     end
  654.   end
  655. end;
  656.  
  657. procedure SavePCXFile;
  658.  
  659. var
  660.  
  661.   F : PathStr;
  662.  
  663. begin
  664.   F := SelectFile ('Save PCX','*.PCX',false);
  665.   if F <> '' then
  666.   begin
  667.     HideMouse; {no screen writes during font mem access}
  668.     if not ChrTableToPCX (F,appGraphWinX,appGraphWinY,DefChrHeight,vgaChrTableLoc[FontTable2]) then
  669.     begin
  670.       ShowMouse;
  671.       MessageBox (#3'Problem writing PCX file.',nil,mfOkButton+mfError);
  672.     end
  673.     else
  674.       ShowMouse
  675.   end
  676. end;
  677.  
  678. procedure ChangeDir;
  679.  
  680. var
  681.  
  682.   D: PChDirDialog;
  683.  
  684. begin
  685.   D := New (PChDirDialog,Init (cdNormal,101));
  686.   D^.HelpCtx := hcFCChDirDBox;
  687.   ExecuteDialog (D,nil)
  688. end;
  689.  
  690. procedure ShellToDos;
  691.  
  692. var
  693.  
  694.   SaveFont : vgaChrTablePtr;
  695.  
  696. begin
  697.   SaveFont := SaveFontTable (FontTable1,DefChrHeight,0,vgaMaxChrs); {save current font}
  698.   if (not LowMemory) and (SaveFont <> nil) then
  699.   begin
  700.     SetVideoMode (StartUpMode);  {reset custom setup using bios}
  701.     DosShell
  702.   end
  703.   else
  704.     OutOfMemory;
  705.   if SaveFont <> nil then
  706.   begin {restore font}
  707.     LoadFontTable (SaveFont,FontTable1,DefChrHeight,0,vgaMaxChrs);
  708.     FreeMem (SaveFont,DefChrHeight*vgaMaxChrs);
  709.     SetCustomScreen;
  710.     ShowMouse
  711.   end
  712. end;
  713.  
  714. procedure ViewTextFile (FileName : PathStr);
  715.  
  716. var
  717.  
  718.   T : PTextWindow;
  719.   R : TRect;
  720.  
  721. begin
  722.   GetExtent (R);
  723.   R.Grow (-5,-4);
  724.   T := New(PTextWindow, Init(R, FileName));
  725.   T^.Options := T^.Options or ofCentered;
  726.   T^.HelpCtx := hcViewDoc;
  727.   InsertWindow (T)
  728. end;
  729.  
  730. procedure DelayTicks (T : word);
  731.  
  732. var
  733.  
  734.   Ticks : word;
  735.   CurTime : longint;
  736.   BiosTimer : longint absolute $40:$6c;
  737.  
  738. begin
  739.   Ticks := 0;
  740.   CurTime := BiosTimer;
  741.   repeat
  742.     if CurTime <> BiosTimer then
  743.     begin
  744.       CurTime := BiosTimer;
  745.       Inc (Ticks)
  746.     end
  747.   until Ticks = T;
  748. end;
  749.  
  750. procedure ClearGraphWin;
  751.  
  752. var
  753.  
  754.   I : integer;
  755.   ChrTablePtr : vgaChrTablePtr;
  756.  
  757. begin
  758.   GraphicsWin ('');
  759.   ChrTablePtr := vgaChrTableLoc[FontTable2];
  760.   HIdeMouse;
  761.   AccessFontMem;
  762.   for I := 0 to vgaChrTableSize-1 do {clear font table mem}
  763.     ChrTablePtr^[I] := 0;
  764.   AccessScreenMem;
  765.   ShowMouse
  766. end;
  767.  
  768. procedure Lines1;
  769.  
  770. var
  771.  
  772.   I : integer;
  773.  
  774. begin
  775.   GraphicsWin ('Lines 1');
  776.   HideMouse;
  777.   AccessFontMem;
  778.   for I := 0 to 31 do
  779.   begin
  780.     DrawTableLine (0,0,I*8+7,127,
  781.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true);
  782.     DrawTableLine (255,0,255-(I*8+7),127,
  783.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true)
  784.   end;
  785.   AccessScreenMem;
  786.   ShowMouse
  787. end;
  788.  
  789. procedure Lines2;
  790.  
  791. var
  792.  
  793.   I : integer;
  794.  
  795. begin
  796.   GraphicsWin ('Lines 2');
  797.   HideMouse;
  798.   AccessFontMem;
  799.   for I := 1 to 50 do
  800.     DrawTableLine (Random (256),Random (128),Random (256),Random (128),
  801.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true);
  802.   AccessScreenMem;
  803.   ShowMouse
  804. end;
  805.  
  806. procedure Ellipses1;
  807.  
  808. var
  809.  
  810.   I : integer;
  811.  
  812. begin
  813.   GraphicsWin ('Ellipses 1');
  814.   HideMouse;
  815.   AccessFontMem;
  816.   for I := 1 to 20 do
  817.   begin
  818.     DrawTableEllipse (I*4,I*3,I*2,I*3,
  819.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true);
  820.     DrawTableEllipse (255-I*4,I*3,I*2,I*3,
  821.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true)
  822.   end;
  823.   AccessScreenMem;
  824.   ShowMouse
  825. end;
  826.  
  827. procedure Ellipses2;
  828.  
  829. var
  830.  
  831.   I : integer;
  832.  
  833. begin
  834.   GraphicsWin ('Ellipses 2');
  835.   HideMouse;
  836.   AccessFontMem;
  837.   for I := 0 to 31  do
  838.     DrawTableEllipse (127,63,I*3,I*2,appGraphWinX,DefChrHeight,
  839.     vgaChrTableLoc[FontTable2],true);
  840.   AccessScreenMem;
  841.   ShowMouse
  842. end;
  843.  
  844. procedure Ellipses3;
  845.  
  846. var
  847.  
  848.   I : integer;
  849.  
  850. begin
  851.   GraphicsWin ('Ellipses 3');
  852.   HideMouse;
  853.   AccessFontMem;
  854.   for I := 1 to 12 do
  855.     DrawTableEllipse (Random (192)+32,Random (64)+32,Random (30)+2,Random (30)+2,
  856.     appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],true);
  857.   AccessScreenMem;
  858.   ShowMouse
  859. end;
  860.  
  861. procedure DrawTableRect (X1,Y1,X2,Y2 : integer; PixOn : boolean);
  862.  
  863. begin
  864.   DrawTableLine (X1,Y1,X2,Y1,
  865.   appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],PixOn);
  866.   DrawTableLine (X1,Y2,X2,Y2,
  867.   appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],PixOn);
  868.   DrawTableLine (X1,Y1,X1,Y2,
  869.   appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],PixOn);
  870.   DrawTableLine (X2,Y1,X2,Y2,
  871.   appGraphWinX,DefChrHeight,vgaChrTableLoc[FontTable2],PixOn);
  872. end;
  873.  
  874. procedure Rectangles1;
  875.  
  876. var
  877.  
  878.   I : integer;
  879.  
  880.  
  881. begin
  882.   GraphicsWin ('Rectangles 1');
  883.   HideMouse;
  884.   AccessFontMem;
  885.   for I := 0 to 31 do
  886.     DrawTableRect (127-I*3,63-I*2,127+I*3,63+I*2,true);
  887.   AccessScreenMem;
  888.   ShowMouse
  889. end;
  890.  
  891. procedure Rectangles2;
  892.  
  893. var
  894.  
  895.   I : integer;
  896.  
  897. begin
  898.   GraphicsWin ('Rectangles 2');
  899.   HideMouse;
  900.   AccessFontMem;
  901.   for I := 1 to 8 do
  902.     DrawTableRect (Random (128),Random (64),Random (128)+128,Random (64)+64,true);
  903.   AccessScreenMem;
  904.   ShowMouse
  905. end;
  906.  
  907. procedure AsciiTab;
  908.  
  909. var
  910.  
  911.   P : PAsciiChart;
  912.  
  913. begin
  914.   P := New (PAsciiChart,Init);
  915.   P^.Options := P^.Options or ofCentered;
  916.   P^.HelpCtx := hcAsciiTable;
  917.   InsertWindow (P)
  918. end;
  919.  
  920. procedure InvadersDialog;
  921.  
  922. var
  923.  
  924.   P : PAniDlg;
  925.  
  926. begin
  927.   P := New (PAniDlg,Init ('Invaders'));
  928.   P^.MoveTo (Random (40)+1,Random (11)+1);
  929.   P^.HelpCtx := hcInvaders;
  930.   InsertWindow (P)
  931. end;
  932.  
  933. procedure UfoDialog;
  934.  
  935. var
  936.  
  937.   P : PUfoDlg;
  938.  
  939. begin
  940.   P := New (PUfoDlg,Init ('UFO Bomber'));
  941.   P^.MoveTo (Random (40)+1,Random (11)+1);
  942.   P^.HelpCtx := hcUFOBomber;
  943.   InsertWindow (P)
  944. end;
  945.  
  946. procedure ShipDialog;
  947.  
  948. var
  949.  
  950.   P : PShipDlg;
  951.  
  952. begin
  953.   P := New (PShipDlg,Init ('Base Ship'));
  954.   P^.MoveTo (Random (40)+1,Random (11)+1);
  955.   P^.HelpCtx := hcBaseShip;
  956.   InsertWindow (P)
  957. end;
  958.  
  959. procedure RestoreDefFont;
  960.  
  961. begin
  962.   if (DefFont <> nil) and {restore default font loaded by config}
  963.   (DefChrHeight = BiosGetChrHeight) then
  964.     LoadFontTable (DefFont,FontTable1,DefChrHeight,0,vgaMaxChrs)
  965. end;
  966.  
  967. procedure ScreenOptions;
  968.  
  969. var
  970.  
  971.   D : PScrOptsDlg;
  972.  
  973. begin
  974.   with ScrData do
  975.   begin
  976.     SMode := AppOptions and appScrOpts; {use only screen options}
  977.     FontMapVal (GetSeqCont (vgaSeqChrMapSel),byte (FntTbl1),byte (FntTbl2));
  978.     D := New (PScrOptsDlg,Init);
  979.     D^.Options := D^.Options or ofCentered;
  980.     D^.HelpCtx := hcScreen;
  981.     if ExecuteDialog (D,@ScrData) <> cmCancel then
  982.     begin
  983.       AppOptions := (AppOptions and not appScrOpts)
  984.       or SMode; {clear all scr opts bits and set bits returned from dialog}
  985.       FontTable1 := FntTbl1;
  986.       FontTable2 := FntTbl2;
  987.       FrameDelay := Delay;
  988.       SetCustomScreen {set screen with new settings}
  989.     end
  990.   end
  991. end;
  992.  
  993. procedure Colors;
  994.  
  995. {custom color items}
  996. function DlgColorItems (Palette: Word; const Next: PColorItem) : PColorItem;
  997.  
  998. const
  999.  
  1000.   COffset : array[dpBlueDialog..dpGrayDialog] of Byte = (64, 96, 32);
  1001.  
  1002. var
  1003.  
  1004.   Offset : Byte;
  1005.  
  1006. begin
  1007.   Offset := COffset[Palette];
  1008.   DlgColorItems :=
  1009.     ColorItem ('Frame passive',     Offset,
  1010.     ColorItem ('Frame active',      Offset + 1,
  1011.     ColorItem ('Frame icons',       Offset + 2,
  1012.     ColorItem ('Scroll bar page',   Offset + 3,
  1013.     ColorItem ('Scroll bar icons',  Offset + 4,
  1014.     ColorItem ('Static text',       Offset + 5,
  1015.  
  1016.     ColorItem ('Label normal',      Offset + 6,
  1017.     ColorItem ('Label selected',    Offset + 7,
  1018.     ColorItem ('Label shortcut',    Offset + 8,
  1019.  
  1020.     ColorItem ('Button normal',     Offset + 9,
  1021.     ColorItem ('Button default',    Offset + 10,
  1022.     ColorItem ('Button selected',   Offset + 11,
  1023.     ColorItem ('Button disabled',   Offset + 12,
  1024.     ColorItem ('Button shortcut',   Offset + 13,
  1025.     ColorItem ('Button shadow',     Offset + 14,
  1026.  
  1027.     ColorItem ('Cluster normal',    Offset + 15,
  1028.     ColorItem ('Cluster selected',  Offset + 16,
  1029.     ColorItem ('Cluster shortcut',  Offset + 17,
  1030.  
  1031.     ColorItem ('Input normal',      Offset + 18,
  1032.     ColorItem ('Input selected',    Offset + 19,
  1033.     ColorItem ('Input arrow',       Offset + 20,
  1034.  
  1035.     ColorItem ('History button',    Offset + 21,
  1036.     ColorItem ('History sides',     Offset + 22,
  1037.     ColorItem ('History bar page',  Offset + 23,
  1038.     ColorItem ('History bar icons', Offset + 24,
  1039.  
  1040.     ColorItem ('List normal',       Offset + 25,
  1041.     ColorItem ('List focused',      Offset + 26,
  1042.     ColorItem ('List selected',     Offset + 27,
  1043.     ColorItem ('List divider',      Offset + 28,
  1044.  
  1045.     ColorItem('Information pane',  Offset + 29,
  1046.     Next))))))))))))))))))))))))))))));
  1047. end;
  1048.  
  1049. function HelpColorItems(const Next: PColorItem): PColorItem;
  1050.  
  1051. begin
  1052.   HelpColorItems :=
  1053.     ColorItem ('Frame passive',     128,
  1054.     ColorItem ('Frame active',      129,
  1055.     ColorItem ('Frame icons',       130,
  1056.     ColorItem ('Scroll bar page',   131,
  1057.     ColorItem ('Scroll bar icons',  132,
  1058.     ColorItem ('Normal text',       133,
  1059.     ColorItem ('Key word',          134,
  1060.     ColorItem ('Select key word',   135,
  1061.     Next))))))))
  1062. end;
  1063.  
  1064. function AniColorItems (const Next: PColorItem) : PColorItem;
  1065.  
  1066. begin
  1067.   AniColorItems :=
  1068.     ColorItem ('Background',       136,
  1069.     ColorItem ('Invaders',         137,
  1070.     ColorItem ('UFO',              138,
  1071.     ColorItem ('UFO bomb',         139,
  1072.     ColorItem ('UFO bomb explode', 140,
  1073.     ColorItem ('Base ship',        141,
  1074.     ColorItem ('Base ship shot',   142,
  1075.     ColorItem ('PCX graphics',     143,
  1076.     Next))))))))
  1077. end;
  1078.  
  1079. function SysColorItems (const Next: PColorItem) : PColorItem;
  1080.  
  1081. begin
  1082.   SysColorItems :=
  1083.     ColorItem ('Shadow',       144,
  1084.     ColorItem ('System error', 145,
  1085.     ColorItem ('Index error',  146,
  1086.     Next)))
  1087. end;
  1088.  
  1089. var
  1090.  
  1091.   D : PColorDialog;
  1092.  
  1093. begin
  1094.   D := New (PColorDialog,Init ('',
  1095.   ColorGroup ('Desktop',     DesktopColorItems(nil),
  1096.   ColorGroup ('Menus',       MenuColorItems(nil),
  1097.   ColorGroup ('Gray Windows',WindowColorItems(wpGrayWindow,nil),
  1098.   ColorGroup ('Blue Windows',WindowColorItems(wpBlueWindow,nil),
  1099.   ColorGroup ('Cyan Windows',WindowColorItems(wpCyanWindow,nil),
  1100.   ColorGroup ('Gray Dialogs',DlgColorItems(dpGrayDialog,nil),
  1101.   ColorGroup ('Blue Dialogs',DlgColorItems(dpBlueDialog,nil),
  1102.   ColorGroup ('Cyan Dialogs',DlgColorItems(dpCyanDialog,nil),
  1103.   ColorGroup ('Help',        HelpColorItems(nil),
  1104.   ColorGroup ('Animation',   AniColorItems(nil),
  1105.   ColorGroup ('System',      SysColorItems(nil),
  1106.   nil)))))))))))));
  1107.   D^.HelpCtx := hcOCColorsDBox;
  1108.   if ExecuteDialog (D,Application^.GetPalette) <> cmCancel then
  1109.   begin
  1110.     DoneMemory; {dispose all group buffers}
  1111.     ReDraw;     {redraw application with new palette}
  1112.     ShadowAttr := GetColor (144);   {tv shadow color}
  1113.     SysColorAttr := (GetColor (145) shl 8) or GetColor (145); {tv system error color}
  1114.     ErrorAttr := GetColor (146)     {tv palette index error color}
  1115.   end
  1116. end;
  1117.  
  1118. procedure AdjustPalette;
  1119.  
  1120. var
  1121.  
  1122.   D : PPalDlg;
  1123.  
  1124. begin
  1125.   D := New (PPalDlg,Init);
  1126.   D^.Options := D^.Options or ofCentered;
  1127.   D^.HelpCtx := hcAdjustPalette;
  1128.   if ExecuteDialog (D,nil) <> cmCancel then
  1129.     GetDACBlock (@DacPalette,0,256)
  1130. end;
  1131.  
  1132. procedure LoadConfigFile;
  1133.  
  1134. var
  1135.  
  1136.   F : PathStr;
  1137.  
  1138. begin
  1139.   F := SelectFile ('Load Config Stream','*.CFG',true);
  1140.   if F <> '' then
  1141.     RestoreDeskTop (F)
  1142. end;
  1143.  
  1144. procedure SaveConfigFile;
  1145.  
  1146. var
  1147.  
  1148.   F : PathStr;
  1149.  
  1150. begin
  1151.   F := SelectFile ('Save Config Stream','*.CFG',false);
  1152.   if F <> '' then
  1153.     SaveDeskTop (F)
  1154. end;
  1155.  
  1156. procedure TileableOnTop (P : PView); far;
  1157.  
  1158. begin {force all oftileable windows to top}
  1159.   if (P^.Options and ofTileable = ofTileable) then
  1160.     P^.MakeFirst
  1161. end;
  1162.  
  1163. begin
  1164.   if (Event.What = evCommand) and
  1165.   ((Event.Command = cmCascade) or
  1166.   (Event.Command = cmTile)) then {seperate oftileable windows from nontileable ones}
  1167.     Desktop^.ForEach (@TileableOnTop);
  1168.   inherited HandleEvent (Event);
  1169.   case Event.What of
  1170.     evCommand:
  1171.       begin
  1172.         case Event.Command of {process commands}
  1173.           cmLoadFont    : LoadFontFile;
  1174.           cmSaveFont    : SaveFontFIle;
  1175.           cmLoadPCX     : LoadPCXFile;
  1176.           cmSavePCX     : SavePCXFile;
  1177.           cmChangeDir   : ChangeDir;
  1178.           cmShellToDos  : ShellToDos;
  1179.           cmViewDoc     : ViewTextFile (appDocName);
  1180.           cmAbout       : AboutBox;
  1181.           cmLines1      : Lines1;
  1182.           cmLines2      : Lines2;
  1183.           cmEllipses1    : Ellipses1;
  1184.           cmEllipses2    : Ellipses2;
  1185.           cmEllipses3    : Ellipses3;
  1186.           cmRectangles1 : Rectangles1;
  1187.           cmRectangles2 : Rectangles2;
  1188.           cmClrGraphWin : ClearGraphWin;
  1189.           cmAsciiTab    : AsciiTab;
  1190.           cmInvaders    : InvadersDialog;
  1191.           cmUfo         : UfoDialog;
  1192.           cmShip        : ShipDialog;
  1193.           cmCloseAll    : ClearDeskTop;
  1194.           cmRestoreDef  : RestoreDefFont;
  1195.           cmScreenOpts  : ScreenOptions;
  1196.           cmColors      : Colors;
  1197.           cmAdjPal      : AdjustPalette;
  1198.           cmSaveConfig  : SaveConfigFile;
  1199.           cmLoadConfig  : LoadConfigFile
  1200.         else
  1201.           Exit
  1202.         end;
  1203.         ClearEvent (Event)
  1204.       end
  1205.   end
  1206. end;
  1207.  
  1208. procedure TCyberFont.InitDeskTop;
  1209.  
  1210. begin {set defaults}
  1211.   inherited InitDeskTop;
  1212.   DeskTop^.Background^.Pattern := '▒';
  1213.   Page := vgaPageLoc[1];
  1214.   PageOfs := vgaPageOfsLoc[1];
  1215.   DefChrHeight := BiosGetChrHeight;
  1216.   GetDACBlock (@DacPalette,0,256) {save current vga palette}
  1217. end;
  1218.  
  1219. procedure TCyberFont.InitMenuBar;
  1220.  
  1221. var
  1222.  
  1223.   R : TRect;
  1224.  
  1225. begin
  1226.   GetExtent (R);
  1227.   R.B.Y := R.A.Y+1;
  1228.   MenuBar := New (PMenuBar,Init (R,NewMenu (
  1229.     NewSubMenu ('~F~ile',hcFile,NewMenu (
  1230.     NewSubMenu ('~F~ont',hcFile,NewMenu (
  1231.       NewItem ('~L~oad...','',kbNoKey,cmLoadFont,hcLoadFont,
  1232.       NewItem ('~S~ave...','',kbNoKey,cmSaveFont,hcSaveFont,
  1233.       nil))),
  1234.     NewSubMenu ('~P~CX',hcFile,NewMenu (
  1235.       NewItem ('~L~oad...','',kbNoKey,cmLoadPCX,hcLoadPCX,
  1236.       NewItem ('~S~ave...','',kbNoKey,cmSavePCX,hcSavePCX,
  1237.       nil))),
  1238.       NewLine (
  1239.       NewItem ('~C~hange dir...','',kbNoKey,cmChangeDir,hcChangeDir,
  1240.       NewItem ('~D~os shell','F9',kbF9,cmShellToDos,hcDosShell,
  1241.       NewItem ('~V~iew doc','',kbNoKey,cmViewDoc,hcViewDoc,
  1242.       NewItem ('~A~bout','',kbNoKey,cmAbout,hcAbout,
  1243.       NewLine (
  1244.       NewItem ('E~x~it','Alt-X',kbAltX,cmQuit,hcExit,
  1245.       nil)))))))))),
  1246.     NewSubMenu ('~G~raphics',hcGraphics,NewMenu (
  1247.       NewSubMenu ('~L~ines',hcLines,NewMenu (
  1248.         NewItem ('Lines ~1~','',kbNoKey,cmLines1,hcLines,
  1249.         NewItem ('Lines ~2~','',kbNoKey,cmLines2,hcLines,
  1250.         nil))),
  1251.       NewSubMenu ('~E~llipses',hcEllipses,NewMenu (
  1252.         NewItem ('Ellipses ~1~','',kbNoKey,cmEllipses1,hcEllipses,
  1253.         NewItem ('Ellipses ~2~','',kbNoKey,cmEllipses2,hcEllipses,
  1254.         NewItem ('Ellipses ~3~','',kbNoKey,cmEllipses3,hcEllipses,
  1255.         nil)))),
  1256.       NewSubMenu ('~R~ectangles',hcRectangles,NewMenu (
  1257.         NewItem ('Rectangles ~1~','',kbNoKey,cmRectangles1,hcRectangles,
  1258.         NewItem ('Rectangles ~2~','',kbNoKey,cmRectangles2,hcRectangles,
  1259.         nil))),
  1260.       NewItem ('Clear ~g~raphics window','',kbNoKey,cmClrGraphWin,hcClearGraphWin,
  1261.       nil))))),
  1262.     NewSubMenu ('~A~nimation',hcAnimation,NewMenu (
  1263.       NewItem ('~A~SCII chart','',kbNoKey,cmAsciiTab,hcAsciiTable,
  1264.       NewItem ('~I~nvaders','F4',kbF4,cmInvaders,hcInvaders,
  1265.       NewItem ('~U~FO bomber','',kbNoKey,cmUfo,hcUFOBomber,
  1266.       NewItem ('~B~ase ship','',kbNoKey,cmShip,hcBaseShip,
  1267.       nil))))),
  1268.     NewSubMenu('~W~indow',hcWindows,NewMenu(
  1269.       StdWindowMenuItems(
  1270.       nil)),
  1271.     NewSubMenu ('~O~ptions',hcOptions,NewMenu (
  1272.       NewItem ('~D~efault font','Alt-D',kbNoKey,cmRestoreDef,hcDefaultFont,
  1273.       NewItem ('Scree~n~...','Alt-S',kbNoKey,cmScreenOpts,hcScreen,
  1274.       NewItem ('~C~olors...','',kbNoKey,cmColors,hcOColors,
  1275.       NewItem ('~A~djust Palette...','',kbNoKey,cmAdjPal,hcAdjustPalette,
  1276.       NewLine (
  1277.       NewItem ('~L~oad config','',kbNoKey,cmLoadConfig,hcLoadConfig,
  1278.       NewItem ('~S~ave config','',kbNoKey,cmSaveConfig,hcSaveConfig,
  1279.       nil)))))))),nil))))))))
  1280. end;
  1281.  
  1282. procedure TCyberFont.InitStatusLine;
  1283.  
  1284. var
  1285.  
  1286.   R : TRect;
  1287.  
  1288. begin
  1289.   GetExtent (R);
  1290.   R.A.Y := R.B.Y-1;
  1291.   StatusLine := New (PStatusLine,Init(R,
  1292.     NewStatusDef (0,$FFFF,
  1293.       NewStatusKey ('~F1~ Help', kbF1, cmHelp,
  1294.       NewStatusKey ('~Alt-F3~ Close',kbAltF3,cmClose,
  1295.       NewStatusKey ('~Alt-D~ Default font',kbAltD,cmRestoreDef,
  1296.       NewStatusKey ('~Alt-S~ Screen',kbAltS,cmScreenOpts,
  1297.       NewStatusKey ('~Alt-X~ Exit',kbAltX,cmQuit,
  1298.       NewStatusKey ('',kbCtrlF5,cmResize,
  1299.       NewStatusKey ('',kbF10,cmMenu,
  1300.       nil))))))),nil)))
  1301. end;
  1302.  
  1303. procedure TCyberFont.OutOfMemory;
  1304.  
  1305. begin
  1306.   MessageBox (#3'Not enough memory available to complete operation.  Try closing some windows!',
  1307.   nil,mfError+mfOkButton)
  1308. end;
  1309.  
  1310. procedure TCyberFont.LoadDesktop (var S : TStream);
  1311.  
  1312. var
  1313.  
  1314.   Pal : PString;
  1315.  
  1316. begin
  1317.   Pal := S.ReadStr;
  1318.   if Pal <> nil then
  1319.   begin
  1320.     Application^.GetPalette^ := Pal^;
  1321.     DoneMemory;
  1322.     DisposeStr (Pal)
  1323.   end
  1324. end;
  1325.  
  1326. procedure TCyberFont.StoreDesktop(var S: TStream);
  1327.  
  1328. var
  1329.  
  1330.   Pal: PString;
  1331.  
  1332. begin
  1333.   Pal := @Application^.GetPalette^;
  1334.   S.WriteStr (Pal)
  1335. end;
  1336.  
  1337. var
  1338.  
  1339.   CFApp : TCyberFont;
  1340.  
  1341. begin
  1342.   if VGACardActive then
  1343.   begin
  1344.     CFApp.Init;
  1345.     CFApp.Run;
  1346.     CFApp.Done
  1347.   end
  1348.   else
  1349.     PrintStr (#13#10'VGA display required to run CyberFont!'#13#10);
  1350. end.
  1351.