home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 July / pcx23_9807.iso / PC-XUSER / PC-XUSER.16 / XVISION / XV2APP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-04-05  |  11.3 KB  |  436 lines

  1. Unit XV2APP;
  2.  
  3. INTERFACE
  4.  
  5. Uses Crt, Graph; {  Egyelôre még mindig Graph  unittal megy az XVision de  }
  6.                  {  nemsokára kicserélôdik a grafikus rész egy normálisra  }
  7.  
  8. Const
  9.   EvNothing    = 1;
  10.   EvMouseMove  = 2;
  11.   EvMouseDown  = 4;
  12.   EvMouseUp    = 8;
  13.   EvKeyDown    = 16;
  14.   EvMessage    = 32;
  15.   EvCommand    = 64;
  16.  
  17. Type
  18.   TEvent = record
  19.     What: Word;
  20.     case Word of
  21.       EvNothing: ();
  22.       EvCommand: (
  23.         Command: Word);
  24.       EvMouseUp, EvMouseDown, EvMouseMove: (
  25.         Buttons: Byte;
  26.         WhereX : Integer;
  27.         WhereY : Integer);
  28.       EvKeyDown: (
  29.         Shift  : Byte;
  30.         case Integer of
  31.           0: (KeyCode: Word);
  32.           1: (CharCode: Char;
  33.               ScanCode: Byte));
  34.       EvMessage: (
  35.         InfoPtr: Pointer);
  36.   end;
  37.   PView=^TView;          { Ez lesz az alapobjetkum, amelyikbôl mindegyik   }
  38.   TView=Object           { másik objektum is származik                     }
  39.     Prev, Next: PView;   { Az elôzô és a következô objektum                }
  40.     Owner: PView;        { Az objektum tulajdonosa                         }
  41.     Child, LChild: PView;{ A fa egyel lejjebbi szintje                     }
  42.     Options: Word;       { Az objektum általános beállításai               }
  43.     X, Y, W, H: Integer; { A képernyôelem mérete és relatív pozíciója      }
  44.     EventMask: Word;     { Azoknak az eseményeknek a listája, melyeket kér }
  45.                          { a képenyôelem                                   }
  46.     TabNum: Integer;     { A tabulátorszám                                 }
  47.     Constructor Init(ax, ay, aw, ah: Integer);
  48.                                        { Az alapobjektum Init konstruktora }
  49.     Procedure Insert(P: PView); Virtual;
  50.                        { Ezzel lehet objektumot beilleszteni az objektumra }
  51.     Procedure HandleEvent(var Event: TEvent); Virtual;
  52.                              { Ez hívódik meg, ha az objektum eseménzt kap }
  53.     Procedure Draw; Virtual;                { Az objektum rajzoló metódusa }
  54.     Procedure DrawIt; Virtual;              { Az objektum rajzoló metódusa }
  55.     Procedure DrawView; Virtual;
  56.                           { Az objektumot és minden "gyermekét" kirajzolja }
  57.     Procedure GetVideoArea(var xx,yy: Integer);
  58.                           { Az objektum abszolut koordinátáival tér vissza }
  59.   End;
  60.   PApplication=^TApplication;
  61.   TApplication=Object(TView) { Ez lesz az alapobjektum, ez fogja "mozgatni"}
  62.                              { a rendszert                                 }
  63.     Constructor Init;
  64.     Procedure SetGraphMode; Virtual; { A grafikus módba kapcsoló rutin     }
  65.     Procedure Draw; Virtual;                { Az objektum rajzoló metódusa }
  66.     Procedure Run; Virtual;                       { Ez indítja a rendszert }
  67.     Procedure Execute(Def: PView); Virtual;      { Ez várja az eseményeket }
  68.   End;
  69.  
  70. Function HiMouseX: Word;      { Egér X koordinátájának lekérdezése         }
  71. Function HiMouseY: Word;      { Egér Y koordinátájának lekérdezése         }
  72. Function buttons: Byte;       { Lekérdezi az egérgombok állapotát          }
  73. procedure mouse_show;         { Egér megjelenítése                         }
  74. procedure mouse_hide;         { Egér elrejtése                             }
  75. Function  IsInArea(X,Y,XX,YY,WW,HH: Integer): Boolean;
  76. { Megadja, hogy X és Y az XX,YY,WW,HH által meghatározott téglalapban van-e}
  77. Procedure SetFocus(P: PView); { 'P' fókuszálttá tétele                     }
  78.  
  79. Var
  80.   Application: PView;         { A fában legfelsô objektum címe             }
  81.   Exiting: Boolean;           { Ha igaz, akkor végetér a program           }
  82.  
  83. IMPLEMENTATION
  84.  
  85. Var                                      { Belsô globális változók         }
  86.   MouseInstalled: Boolean;    { Ha az értéke igaz akkor van egér           }
  87.   MouseShown: Boolean;   { Ha az értéke igaz akkor látható az egér         }
  88.   OldX,OldY: Integer;    { Az egér régi pozícióját tartalmazó változók     }
  89.   OldButtons: Byte;
  90.  
  91. (******************************************************************)
  92. (*  Alapvetô egérkezelô rutinok                                   *)
  93. (******************************************************************)
  94.  
  95. Function HiMouseX: Word;      { Egér X koordinátájának lekérdezése }
  96. Var
  97.   resl: Word;
  98. Begin
  99.   Asm
  100.     cmp MouseInstalled,0
  101.     je @@nomouse
  102.     mov ax,03h
  103.     int 33h
  104.     mov ResL, CX
  105.     jmp @@exit
  106.   @@nomouse:
  107.     MOV ResL, 0
  108.   @@exit:
  109.   End;
  110.   HiMouseX:=ResL;
  111. End;
  112.  
  113. Function HiMouseY: Word;      { Egér X koordinátájának lekérdezése }
  114. Var
  115.   resl: Word;
  116. Begin
  117.   Asm
  118.     cmp MouseInstalled,0
  119.     je @@nomouse
  120.     mov ax,03h
  121.     int 33h
  122.     mov ResL, DX
  123.     jmp @@exit
  124.   @@nomouse:
  125.     MOV ResL, 0
  126.   @@exit:
  127.   End;
  128.   HiMouseY:=ResL;
  129. End;
  130.  
  131. Function buttons: Byte; Assembler;       { Lekérdezi az egérgombok }
  132. Asm                                                    { állapotát }
  133.   cmp MouseInstalled,0
  134.   je @@nomouse
  135.   mov bx, 0
  136.   mov ax,03h
  137.   int 33h
  138.   mov ax,bx
  139.   jmp @@exit
  140. @@nomouse:
  141.   MOV ax,0
  142. @@exit:
  143. End;
  144.  
  145. procedure mouse_show; assembler;              { Egér megjelenítése }
  146.  asm
  147.  cmp mouseshown,1 ; je @@exit
  148.  cmp mouseinstalled,1 ; jne @@exit
  149.  mov ax,01h
  150.  int 33h
  151.  mov mouseshown,1
  152. @@exit:
  153.  end;
  154.  
  155. procedure mouse_hide;assembler;                 { Egér eltⁿntetése }
  156.  asm
  157.  cmp mouseshown,1 ; jne @@exit
  158.  cmp mouseinstalled,1 ; jne @@exit;
  159.  mov ax,02h
  160.  int 33h
  161.  mov mouseshown,0
  162. @@exit:
  163. end;
  164.  
  165. Function IsInArea(X,Y,XX,YY,WW,HH: Integer): Boolean;
  166. Begin
  167.   IsInArea:=False;
  168.   if (((X>=XX) and (X<=XX+WW)) and
  169.       ((Y>=YY) and (Y<=YY+HH))) then IsInArea:=True;
  170. End;
  171.  
  172. {-------------------------------------------------------------------------}
  173. {  Åltalános célú rutinok                                                 }
  174. {-------------------------------------------------------------------------}
  175. Procedure SetFocus(P: PView);
  176. Begin
  177.   While ((P<>Application) and (P<>Nil)) do
  178.   Begin
  179.     if ((P^.TabNum<>-1) and (P^.Prev<>Nil)) then
  180.     Begin
  181.       if P^.Next<>Nil then P^.Next^.Prev:=P^.Prev Else P^.Owner^.LChild:=P^.Owner^.LChild^.Prev;
  182.       if P^.Prev<>Nil then P^.Prev^.Next:=P^.Next Else P^.Owner^.Child:=P^.Owner^.Child^.Next;
  183.       P^.Next:=P^.Owner^.Child;
  184.       P^.Prev:=Nil;
  185.       P^.Owner^.Child^.Prev:=P;
  186.       P^.Owner^.Child:=P;
  187.       P^.DrawView;
  188.     End;
  189.     P:=P^.Owner;
  190.   End;
  191. End;
  192.  
  193. Procedure GetEvent(Var E: TEvent);       { Az eseményfigyelô rutin }
  194.  Function Shiftpress:Byte; Assembler;{ 1: RShift  2:LShift  3:Both }
  195.  Asm
  196.    XOR  AX, AX
  197.    MOV  AH, 02h
  198.    INT  16h
  199.    AND  AX, 3
  200.  End;
  201. Var
  202.   EX,EY: Word;
  203.   b1: byte;
  204.   ch: Char;
  205.   cb: Byte;
  206. Begin
  207.   E.What:=EvNothing;
  208.   if Keypressed then
  209.   Begin
  210.     E.What:=EvKeyDown;
  211.     E.Shift:=ShiftPress;
  212.     ch:=Readkey;
  213.     if ch=#0 then E.KeyCode:=Ord(Readkey)*256 else
  214.     Begin
  215.       E.KeyCode:=ord(ch);
  216.       E.CharCode:=ch;
  217.     End;
  218.   End;
  219.   EX:=HiMouseX;
  220.   EY:=HiMouseY;
  221.   E.Buttons:=Buttons;
  222.   b1:=buttons;
  223.   if ((OldX<>EX) or (OldY<>EY)) then
  224.   Begin
  225.     E.What:=EvMouseMove;
  226.     E.WhereX:=EX;
  227.     E.WhereY:=EY;
  228.   End;
  229.   if (((b1 and 1)<>0) and ((OldButtons and 1)=0)) or
  230.      (((b1 and 2)<>0) and ((OldButtons and 2)=0)) then
  231.   Begin
  232.     E.What:=EvMouseDown;
  233.     E.WhereX:=EX;
  234.     E.WhereY:=EY;
  235.   End;
  236.   if (((b1 and 1)=0) and ((OldButtons and 1)<>0)) or
  237.      (((b1 and 2)=0) and ((OldButtons and 2)<>0)) then
  238.   Begin
  239.     E.What:=EvMouseUp;
  240.     E.WhereX:=EX;
  241.     E.WhereY:=EY;
  242.   End;
  243.   OldX:=EX;
  244.   OldY:=EY;
  245.   OldButtons:=b1;
  246. End;
  247.  
  248. {-------------------------------------------------------------------------}
  249. {  A TView objektum                                                       }
  250. {-------------------------------------------------------------------------}
  251.  
  252. Constructor TView.Init(ax, ay, aw, ah: Integer);
  253. Begin
  254.   X:=AX; Y:=AY; W:=AW; H:=AH;
  255.   Options:=0;
  256.   TabNum:=0;
  257.   EventMask:=evMouseDown+evMouseUp;
  258.   Prev:=Nil; Next:=Nil; Child:=Nil; LChild:=Nil; Owner:=Nil;
  259. End;
  260.  
  261. Procedure TView.Insert(P: PView);
  262. Var
  263.   MaxNum: Integer;
  264.   Q: PView;
  265. Begin
  266.   P^.Owner:=@Self;
  267.   if Child<>Nil then    { Beillesztés a rendszerbe }
  268.   Begin
  269.     Child^.Prev:=P;
  270.     P^.Next:=Child;
  271.     Child:=P;
  272.   End
  273.   Else
  274.   Begin
  275.     Child:=P;
  276.     LChild:=P;
  277.   End;
  278.   if P^.TabNum<>-1 then
  279.   Begin
  280.     Q:=Child;
  281.     MaxNum:=0;
  282.     While Q<>Nil do
  283.     Begin
  284.       if Q^.TabNum>MaxNum then MaxNum:=TabNum;
  285.       Q:=Q^.Next;
  286.     End;
  287.     P^.TabNum:=MaxNum+1;
  288.   End;
  289.   P^.DrawView;
  290. End;
  291.  
  292. Procedure TView.HandleEvent(var Event: TEvent);
  293. Begin
  294. End;
  295.  
  296. Procedure TView.Draw;
  297. Begin
  298. End;
  299.  
  300. Procedure TView.DrawIt;
  301. Var
  302.   P: PView;
  303.   xx,yy: Integer;
  304. Begin
  305.   P:=@Self;
  306.   While ((P<>Nil) and (P<>Application)) do
  307.   Begin
  308.     P:=P^.Owner;
  309.   End;
  310.   if P=Application then
  311.   Begin
  312.     Mouse_Hide;
  313.     GetVideoArea(xx,yy);
  314.     SetViewPort(xx,yy,xx+w,yy+h,True);
  315.                   { Csak az objektumnak megadott területre lehet rajzolni }
  316.     Draw;
  317.     Mouse_Show;
  318.   End;
  319. End;
  320.  
  321. Procedure TView.DrawView;
  322. Var
  323.   P: PView;
  324.   xx,yy: Integer;
  325. Begin
  326.   DrawIt;
  327.   P:=@Self;
  328.   P:=LChild;
  329.   While P<>Nil do
  330.   Begin
  331. {   P^.DrawIt;}
  332.     P^{.LChild^}.DrawView;
  333.     P:=P^.Prev;
  334.   End;
  335. End;
  336.  
  337. Procedure TView.GetVideoArea(var xx,yy: Integer);
  338. Var
  339.   P: PView;
  340. Begin
  341.   P:=@Self;
  342.   xx:=0;
  343.   yy:=0;
  344.   While P<>Nil do
  345.   Begin
  346.     xx:=xx+P^.X;
  347.     yy:=yy+P^.Y;
  348.     P:=P^.Owner;
  349.   End;
  350. End;
  351.  
  352. {-------------------------------------------------------------------------}
  353. {  A TApplication                                                         }
  354. {-------------------------------------------------------------------------}
  355. Constructor TApplication.Init;
  356. Begin
  357.   MouseInstalled:=False; MouseShown:=False;
  358.   Exiting:=False;
  359.   Application:=@Self;
  360.   WriteLn('XVISION2> Rendszerelemek azonosítása...');
  361.   Asm                                         { Az egér vizsgálata }
  362.     MOV AX, 0
  363.     INT 33h
  364.     CMP AX, 0 ; JE @@Exit;
  365.     MOV BYTE(MouseInstalled), 1
  366.   @@Exit:
  367.   End;
  368.   WriteLn('XVISION2> Åtkapcsolás grafikus módba...');
  369.   SetGraphMode;
  370.   Inherited Init(0,0,GetMaxX, GetMaxY);
  371.   Mouse_Show;
  372.   DrawIt;
  373. End;
  374.  
  375. Procedure TApplication.SetGraphMode;
  376. Var
  377.   driver,mode: Integer;
  378. Begin
  379.   driver:=VGA;
  380.   mode  :=VGAHi;
  381.   InitGraph(driver, mode, 'D:\BP\BGI\');
  382. End;
  383.  
  384. Procedure TApplication.Draw;
  385. Begin
  386.   SetFillStyle(1,7);
  387.   Bar(0,0,w,h);
  388. End;
  389.  
  390. Procedure TApplication.Run;
  391. Begin
  392.   Execute(@Self);
  393. End;
  394.  
  395. Procedure TApplication.Execute;
  396. Var
  397.   E: TEvent;
  398.   P,Q: PView;
  399.   xx,yy: Integer;
  400. Begin
  401.   Repeat
  402.     GetEvent(E);
  403.     Case E.What of
  404.     EvMouseMove,
  405.     EvMouseDown,
  406.     EvMouseUp  :Begin
  407.                   P:=Def; Q:=Nil;
  408.                   While (P<>Nil) do
  409.                   Begin
  410.                     P^.GetVideoArea(xx,yy);
  411.                     if IsInArea(E.WhereX, E.WhereY, xx, yy, P^.W, P^.H) then
  412.                     Begin
  413.                       Q:=P;
  414.                       P:=P^.Child;
  415.                     End
  416.                     Else
  417.                     Begin
  418.                       P:=P^.Next;
  419.                     End;
  420.                   End;
  421.                   if Q<>Nil then
  422.                   Begin
  423.                     if (Q^.EventMask and E.What)<>0 then
  424.                     Begin
  425.                       SetFocus(Q);
  426.                       Q^.HandleEvent(E);
  427.                     End;
  428.                   End;
  429.                 End;
  430.     EvKeyDown:  Begin
  431.                 End;
  432.     End;
  433.   Until Exiting;
  434. End;
  435.  
  436. End.