home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / prpascal / windmngr.lzh / WINDODEF.PAS < prev   
Pascal/Delphi Source File  |  1986-01-13  |  20KB  |  486 lines

  1. {$I VAR.INC}
  2. {$I WINDMNGR.INC}
  3. {$C-}
  4. {$I-}
  5.  
  6. var Screen_real: Array[1..4000] of byte absolute $B800:$0000;
  7.     temp_screen: Array[1..4000] of byte;
  8.     Windows: Array[1..8] of Record
  9.                   UpperLeftX,UpperLeftY,LowerRightX,LowerRightY,
  10.                   ForeGround,BackGround,FrameType,color: Integer;
  11.                   Title: String[80];
  12.              end;
  13.     saved,yestitle,stored:boolean;
  14.     wintitle:string[80];
  15.     title_color:integer;
  16.  
  17. Procedure Window_Title2(Name: Maxstr; color,i,j:integer);
  18.  
  19. var m, k, l: integer;
  20.  
  21. begin
  22.      l:=3;
  23.      color:=color+(j*16);
  24.      temp_screen[(((windows[i].upperlefty)*160)+(windows[i].upperleftx*2))+l]:=$5b;
  25.      for m:=1 to length(Name) do
  26.              begin
  27.                   k:=(((windows[i].upperlefty)*160)+(windows[i].upperleftx*2))+l+1;
  28.                   temp_Screen[k+1]:=ord(copy(Name,m,1));
  29.                   temp_Screen[k+2]:=Color;
  30.                   l:=l+2
  31.              end;
  32.      temp_Screen[k+3]:=$5d
  33. end;
  34.  
  35. { Thats all.. }
  36.  
  37. Procedure Writexy2(long_string:maxstr; xcoord,ycoord,color: integer);
  38.  
  39. { This procedure Draws whatever you want, wherever you want, by changing the
  40.   value of Screen in the variable declaration, it can draw a "Picture" any-
  41.   were in memory. This allows for the Speed of the window making process..}
  42.  
  43. var str_len, real_pos, scr_pos: integer;
  44.  
  45. begin
  46. {$I-}
  47.      str_len:=length(long_string); { So I know how much to write }
  48.      Scr_pos:=0;
  49.  
  50.      { The next 8 lines write the string in every "even" location in memory
  51.        and ever odd location gets the attribute with determines how the
  52.        string is displayed on the screen}
  53.      for real_pos:=1 to str_len do
  54.                  if scr_pos < 4001 then
  55.                        begin
  56.                             scr_pos:=((xcoord*2)-1)+(ycoord*160);
  57.                             temp_screen[scr_pos]:=ord(copy(long_string,real_pos,1));
  58.                             temp_screen[scr_pos+1]:=color;
  59.                             xcoord:=xcoord+1;
  60.                        end
  61. {$I+}
  62. end;
  63.  
  64. Procedure Clrtemp;
  65. var i:integer;
  66. begin
  67.      for i:=1 to 4000 do temp_screen[i]:=$00
  68. end;
  69.  
  70. Procedure Store_File;
  71. var outfile: text;
  72.     ch: char;
  73.     i,j: integer;
  74. begin
  75.      Assign(outfile,'DEFS.INC');
  76.      rewrite(outfile);
  77.      Writeln(outfile,'Procedure Select_Window(Win_Num: Integer);');
  78.      Write(outfile,'Const Windows: Array[1..9,1..8] of integer =(');
  79.      for i:=1 to 8 do
  80.               writeln(outfile,'(',Windows[i].UpperleftX,',',
  81.                                   Windows[i].Upperlefty,',',
  82.                                   Windows[i].Lowerrightx,',',
  83.                                   Windows[i].Lowerrighty,',',
  84.                                   Windows[i].Foreground,',',
  85.                                   Windows[i].Background,',',
  86.                                   Windows[i].Frametype,',',
  87.                                   Windows[i].Color,
  88.                               '),');
  89.      Writeln(outfile,'(0,0,0,0,0,0,0,0));');
  90.      writeln(outfile,' ');
  91.      Write(outfile,'  Title:Array[1..9] of string[80] = (');
  92.      for i:=1 to 8 do
  93.               if windows[i].title <> '' then writeln(outfile,'''',windows[i].title,'''',',')
  94.               else writeln(outfile,'''''',',');
  95.      Writeln(outfile,''''');');
  96.      writeln(outfile,' ');
  97.      writeln(outfile,'Begin');
  98.      Writeln(outfile,'     If (windows[win_num,3] > 0) and (Win_num > Stack_top) then');
  99.      Writeln(outfile,'        Begin');
  100.      Writeln(outfile,'            Add_Window(Windows[Win_Num,1],');
  101.      Writeln(Outfile,'                       Windows[Win_Num,2],');
  102.      Writeln(Outfile,'                       Windows[Win_Num,3],');
  103.      Writeln(Outfile,'                       Windows[Win_Num,4],');
  104.      Writeln(Outfile,'                       Windows[Win_Num,5],');
  105.      Writeln(Outfile,'                       Windows[Win_Num,6],');
  106.      Writeln(Outfile,'                       Windows[Win_Num,7]);');
  107.      Writeln(Outfile,'     If Title[win_num] <> '''' then');
  108.      Writeln(Outfile,'            Window_Title(Title[Win_num],Windows[Win_Num,8])');
  109.      Writeln(Outfile,'     end');
  110.      Writeln(Outfile,'     else');
  111.      Writeln(Outfile,'         If windows[Win_num,4] > 0 then');
  112.      Writeln(Outfile,'                begin');
  113.      Writeln(Outfile,'                     Imig[Last_window_num].w1:=wherex;');
  114.      Writeln(Outfile,'                     Imig[Last_window_num].w2:=wherey;');
  115.      Writeln(Outfile,'                     Window(1,1,80,25);');
  116.      Writeln(Outfile,'                     GotoXY(1,1);');
  117.      Writeln(Outfile,'                     Window(Imig[Win_num].x1,Imig[Win_num].y1,');
  118.      Writeln(Outfile,'                            Imig[Win_num].x2,Imig[Win_num].y2);');
  119.      Writeln(Outfile,'                     Textcolor(Imig[win_num].c1+(Imig[win_num].b1*16));');
  120.      Writeln(Outfile,'                     GotoXY(1,1);');
  121.      Writeln(Outfile,'                     GotoXY(Imig[win_num].w1,Imig[win_num].w2);');
  122.      Writeln(Outfile,'                     Last_Window_Num:=Win_Num');
  123.      Writeln(Outfile,'                End');
  124.      Writeln(outfile,'End;');
  125.      Close(outfile);
  126.      Saved:=true;
  127. end;
  128.  
  129.  
  130.  
  131. Procedure Frame2(WindowType, UpperLeftX, UpperLeftY, LowerRightX, LowerRightY, color: Integer);
  132.  
  133. { This procedure draws the window frame in another part of memory. }
  134. var i: integer;
  135. begin
  136.      WriteXY2(chr(Fc[WindowType,1]),UpperLeftX, UpperLeftY,color);
  137.      for i:=UpperLeftX+1 to LowerRightX-1 do WriteXY2(chr(Fc[WindowType,2]),i,UpperleftY,color);
  138.      WriteXY2(chr(Fc[WindowType,3]),i+1,UpperleftY,color);
  139.      for i:=UpperLeftY+1 to LowerRightY-1 do
  140.          begin
  141.               WriteXY2(chr(Fc[WindowType,4]),UpperLeftX , i,color);
  142.               WriteXY2(chr(Fc[WindowType,4]),LowerRightX, i,color);
  143.          end;
  144.      WriteXY2(chr(Fc[WindowType,5]),UpperLeftX, LowerRightY, color);
  145.     for i:=UpperLeftX+1 to LowerRightX-1 do WriteXY2(chr(Fc[WindowType,6]),i,LowerrightY,color);
  146.      WriteXY2(chr(Fc[WindowType,7]),i+1,LowerRightY,color);
  147. end  { Frame 2};
  148.  
  149. Procedure GetChar(VAR Ch: Char; VAR Extended: Boolean);
  150. Type
  151.  Registers = Record
  152.               AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer;
  153.              End;
  154. Var
  155.  Reg: Registers;
  156.  AL:  Integer;
  157. Begin
  158. Ch:=#0; Extended:=False;
  159. If KeyPressed Then
  160.  Begin
  161.  Reg.Ax:=$0800;                { -Set AH as $8 for Dos Function call      }
  162.  Intr($21,Reg);                { -Calls Interupt $21 for Dos Fucntion call}
  163.  AL:=(Reg.AX AND $00FF);       { -Derive AL from AX                       }
  164.  Ch:=Chr(AL);                  { -Set Ch to character to AL               }
  165.  If Ch=#0 then
  166.   Begin                       { Routine to get extended character scan code }
  167.   Reg.Ax:=$0800;
  168.   Intr($21,Reg);
  169.   Ch:=Chr((Reg.AX AND $00FF));
  170.   Extended:=True;
  171.   End;
  172.  End;
  173. End;
  174.  
  175. Procedure Beep;
  176. begin
  177.      Sound(1500);
  178.      delay(10);
  179.      Nosound
  180. end;
  181.  
  182. Procedure color_Frame(win, Foreground, Background: Integer);
  183. var i,j,k,color: Integer;
  184. begin
  185.      if background < 8 then color:=foreground+(Background*16);
  186.      k:=1;
  187.      for j:=(Windows[win].UpperLefty) to Windows[win].LowerRighty do
  188.          for i:=(Windows[win].Upperleftx) to (Windows[win].Lowerrightx) do
  189.              begin
  190.                   k:=(j*160)+(i*2);
  191.                   temp_screen[k]:=Color;
  192.              end;
  193.      end;
  194.  
  195. Procedure Edit_window;
  196.  
  197. var i,j,k,ux,uy,lx,ly,f,c1,b1: Integer;
  198.     Ch: Char;
  199.     Extended,saved: Boolean;
  200.     x11,y11,x22,y22,forg,bak:string[3];
  201.  
  202. begin
  203.      yestitle:=false;
  204.      Add_Window(0,0,80,25,15,0,5);
  205.      Normvideo;
  206.      Window(1,1,80,25);
  207.      repeat
  208.            gotoxy(1,1);
  209.            Clrscr;
  210.            textcolor(1);
  211.            Write(' Edit Window #(1-8): ');
  212.            textcolor(7);
  213.            read(i);
  214.      until (i<9) and (i>0);
  215.      if windows[i].title <> '' then yestitle:=true;
  216.      if windows[i].frametype=0 then
  217.            begin
  218.                 Windows[i].Upperleftx:=5;
  219.                 Windows[i].Upperlefty:=5;
  220.                 Windows[i].Lowerrightx:=10;
  221.                 Windows[i].Lowerrighty:=10;
  222.                 Windows[i].Foreground:=15;
  223.                 Windows[i].Frametype:=1;
  224.                 Windows[i].Background:=7;
  225.                 Windows[i].Foreground:=1;
  226.            end;
  227.      repeat
  228.            Clrtemp;
  229.            Str(windows[i].upperleftx,x11);
  230.            Str(windows[i].upperlefty,y11);
  231.            Str(windows[i].lowerrightx,x22);
  232.            str(windows[i].lowerrighty,y22);
  233.            Str(windows[i].foreground,forg);
  234.            Str(windows[i].background,bak);
  235.            if length(x11) < 2 then x11:='0'+x11;
  236.            if length(y11) < 2 then y11:='0'+y11;
  237.            if length(x22) < 2 then x22:='0'+x22;
  238.            if length(y22) < 2 then y22:='0'+y22;
  239.            if (length(forg)<2) then forg:='0'+forg;
  240.            if (length(forg)<3) then forg:='0'+forg;
  241.            Writexy2('  STATUS   X1:'+X11+' Y1:'+Y11+'   X2:'+X22+' Y2:'+Y22+'     FOREGROUND:'+FORG+'  BACKGROUND:'+BAK,0,0,7
  242.                    );
  243.            Writexy2(' 1=Expand-X  2=Expand-Y 3=Frame Type 4=Foreground 5=background 6=Title',1,1,14);
  244.            Writexy2(' 10=Exit to Main Menu, Use cursor keys to move window',1,2,14);
  245.            Frame2(Windows[i].frametype,Windows[i].Upperleftx,
  246.                   Windows[i].Upperlefty,Windows[i].LowerRightx,
  247.                   Windows[i].Lowerrighty,Windows[i].foreground);
  248.            Color_frame(i,Windows[i].foreground,windows[i].background);
  249.            if yestitle then Window_title2(windows[i].title,windows[i].color,i,windows[i].background);
  250.            move(temp_screen,screen_real,4000);
  251.            beep;
  252.            repeat
  253.                  repeat until keypressed;
  254.                  Getchar(ch, extended);
  255.            Until ord(ch) in [59,60,61,62,63,64,72,77,67,80,75,68];
  256.            saved:=false;
  257.            if extended then case ord(ch) of
  258.                           64:begin
  259.                                   yestitle:=true;
  260.                                   gotoxy(1,1);
  261.                                   write('                                                                              ');
  262.                                   textcolor(1);
  263.                                   gotoxy(1,1);
  264.                                   write('Enter Window title: ');
  265.                                   textcolor(7);
  266.                                   readln(wintitle);
  267.                                   gotoxy(1,1);
  268.                                   write('                                                                 ');
  269.                                   gotoxy(1,1);
  270.                                   textcolor(1);
  271.                                   write('Enter color of title: ');
  272.                                   textcolor(7);
  273.                                   readln(title_color);
  274.                                   windows[i].color:=Title_color;
  275.                                   windows[i].title:=wintitle;
  276.                              end;
  277.                           59:windows[i].LowerRightX:=Windows[i].LowerRightX+1;
  278.                           60:Windows[i].LowerRightY:=Windows[i].LowerRightY+1;
  279.                           61:begin
  280.                                   Windows[i].Frametype:=Windows[i].Frametype+1;
  281.                                   if Windows[i].Frametype > 4
  282.                                          then Windows[i].Frametype:=1
  283.                              end;
  284.                           62:begin
  285.                                   clrtemp;
  286.                                   gotoxy(1,1);
  287.                                   write('                                                                              ');
  288.                                   gotoxy(1,1);
  289.                                   textcolor(1);
  290.                                   Write(' Enter new Foreground Color (0-255): ');
  291.                                   textcolor(7);
  292.                                   repeat
  293.                                         readln(Windows[i].Foreground)
  294.                                   until Windows[i].Foreground < 256;
  295.                              end;
  296.                           77:begin
  297.                                 if Windows[i].LowerRightX<80 then begin
  298.                                   Windows[i].Upperleftx:=Windows[i].Upperleftx+1;
  299.                                   Windows[i].Lowerrightx:=Windows[i].lowerrightx+1;
  300.                                 end
  301.                                 else beep
  302.                              end;
  303.                           72:Begin
  304.                                 if windows[i].upperlefty>0 then begin
  305.                                   Windows[i].LowerRightY:=Windows[i].Lowerrighty-1;
  306.                                   Windows[i].Upperlefty:=Windows[i].Upperlefty-1;
  307.                                 end
  308.                                 else beep
  309.                              end;
  310.                           63:begin
  311.                               repeat
  312.                                   move(screen_real,temp_screen,4000);
  313.                                   gotoxy(1,1);
  314.                                   write('                                                                              ');
  315.                                   gotoxy(1,1);
  316.                                   textcolor(1);
  317.                                   Write('Enter New Background Color (0-8): ');
  318.                                   textcolor(7);
  319.                                   readln(Windows[i].background);
  320.                               until windows[i].background < 8;
  321.                               end;
  322.                          80:Begin
  323.                                 if windows[i].lowerrighty<24 then begin
  324.                                   Windows[i].LowerRightY:=Windows[i].Lowerrighty+1;
  325.                                   Windows[i].Upperlefty:=Windows[i].Upperlefty+1;
  326.                                 end
  327.                                 else beep
  328.                              end;
  329.                            75:begin
  330.                                 if windows[i].Upperleftx>1 then begin
  331.                                   Windows[i].Upperleftx:=Windows[i].Upperleftx-1;
  332.                                   Windows[i].Lowerrightx:=Windows[i].lowerrightx-1;
  333.                                 end
  334.                                 else beep
  335.                               end;
  336.                    end;
  337.      until ord(ch)=68;
  338.      stored:=false;
  339.      Remove(1);
  340. end;
  341.  
  342. Procedure Show_all;
  343. var ii: Integer;
  344. begin
  345.      Add_Window(1,1,80,25,15,0,0);
  346.      NormVideo;
  347.      Window(1,1,80,25);
  348.      repeat
  349.            GotoXY(1,1);
  350.            GotoXY(1,1);
  351.            Textcolor(1);
  352.            Writeln('Display Window');
  353.            Write('Number <0=Main Menu>: ');
  354.            textcolor(7);
  355.            readln(ii);
  356.            if ii<9 then
  357.            if (ii>0) and (windows[ii].Upperleftx > 0) then
  358.                begin
  359.                    with windows[ii] do
  360.                         begin
  361.                              Add_Window(Upperleftx,Upperlefty,LowerRightX,LowerRightY,FOreground,Background,frametype);
  362.                              Window_title(title,color)
  363.                         end
  364.                end
  365.            else
  366.                If ii>0 then
  367.                    begin
  368.                         gotoxy(1,1);
  369.                         Write('                                                                ');
  370.                         gotoxy(1,1);
  371.                         textcolor(1);
  372.                         Write('Window not defined!');
  373.                         delay(3000)
  374.                    end;
  375.            Gotoxy(1,1);
  376.            Write('                                                                ');
  377.     Normvideo;
  378.     window(1,1,80,25);
  379.     Until ii=0;
  380.     Remove(Stack_top-1);
  381. end;
  382.  
  383.  
  384.  
  385. var ch: Char;
  386.     extended: Boolean;
  387.     i: integer;
  388.  
  389. begin
  390.      Stored:=true;
  391.      Scrn_Off;
  392.      Set_page($01);
  393.      Initialize;
  394.      for i:=1 to 4000 do screen_real[i]:=00;
  395.      ClrScr;
  396.      saved:=true;
  397.      for i:=1 to 8 do
  398.          begin
  399.               windows[i].Upperleftx:=0;
  400.               windows[i].upperlefty:=0;
  401.               windows[i].lowerrightx:=0;
  402.               windows[i].lowerrighty:=0;
  403.               windows[i].foreground:=0;
  404.               windows[i].background:=0;
  405.               windows[i].frametype:=0;
  406.               windows[i].color:=0
  407.          end;
  408.      gotoxy(17,3);
  409.      Textcolor(15);
  410.      Writeln('THE WINDOW MANAGER/EDITOR SYSTEM WINDOW EDITOR');
  411.      gotoxy(17,5);
  412.      Textcolor(7);
  413.      Writeln('              (C) Copyright 1985');
  414.      gotoxy(17,6);
  415.      Writeln('                      by');
  416.      gotoxy(17,7);
  417.      Writeln('                 Jim Everingham');
  418.      Add_window(5,10,75,20,0,0,2);
  419.      gotoxy(10,2);
  420.      Writeln(' Options:');
  421.      writeln('                   <1> Edit/Configure window file');
  422.      writeln('                   <2> Save Definitions to disk file');
  423.      writeln('                   <3> Clear Defined Window');
  424.      writeln('                   <4> Display defined windows simultaneously');
  425.      writeln('                   <5> Exit to sytem');
  426.      Color_Window(0,4);
  427.      Scrn_on;
  428.      Set_page($00);
  429.      For I:=1 to 8 do
  430.                begin
  431.                           windows[i].Upperleftx:=0;
  432.                           windows[i].upperlefty:=0;
  433.                           windows[i].lowerrightx:=0;
  434.                           windows[i].lowerrighty:=0;
  435.                           windows[i].foreground:=0;
  436.                           windows[i].background:=0;
  437.                           windows[i].frametype:=0;
  438.                           Windows[i].Title:='';
  439.                 end;
  440.      Window_Title(' Main Menu ',128+(4*16));
  441.      beep;
  442.      repeat
  443.            repeat
  444.                  repeat until keypressed;
  445.                  read(kbd,ch);
  446.                  beep;
  447.            until ch in ['1'..'5'];
  448.            case ch of
  449.                 '1': Edit_window;
  450.                 '2': Store_file;
  451.                 '4': Show_All;
  452.                 '5': begin
  453.                           normvideo;
  454.                           Add_Window(1,1,80,25,1,0,5);
  455.                           clrscr;
  456.                           if not stored then
  457.                                  begin
  458.                                       Write('File not saved.  Are you sure you want to abort?');
  459.                                       read(kbd,ch);
  460.                                       if upcase(ch)='Y' then halt
  461.                                       else remove(1);
  462.                                  end
  463.                          else halt
  464.                      end;
  465.                 '3': begin
  466.                           Add_window(1,1,80,25,15,0,5);
  467.                           clrscr;
  468.                           textcolor(1);
  469.                           Write('Clear Window number: ');
  470.                           textcolor(7);
  471.                           repeat
  472.                                 readln(i);
  473.                           until (i<8) and (i>0);
  474.                           windows[i].Upperleftx:=0;
  475.                           windows[i].upperlefty:=0;
  476.                           windows[i].lowerrightx:=0;
  477.                           windows[i].lowerrighty:=0;
  478.                           windows[i].foreground:=0;
  479.                           windows[i].background:=0;
  480.                           windows[i].frametype:=0;
  481.                           Windows[i].Title:='';
  482.                           Remove(1);
  483.                     end;
  484.            end;
  485.     until true=false;
  486. end.