home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / Samples / G_MOUS2A.ARJ / DEMO20.PAS next >
Encoding:
Pascal/Delphi Source File  |  1992-12-13  |  8.8 KB  |  241 lines

  1. Program Demo_Mouse_2;
  2.  
  3. (****************************************************************************)
  4. (*                                                                          *)
  5. (*                             Demo Program For                             *)
  6. (*                                 The Unit                                 *)
  7. (*                                 G_Mouse2                                 *)
  8. (*                                                                          *)
  9. (*                          By Jean-Laurent PRADEL                          *)
  10. (*                                                                          *)
  11. (****************************************************************************)
  12.  
  13. Uses Crt,Dos,Graph,G_Mouse2;
  14.  
  15. Var x, y, button, b : Integer;
  16.     SizeBox: Word;
  17.     P : Pointer;
  18.     i:integer;
  19.     Boite, Boite2, Boite3, ContBox : ^Box;
  20.     xcm, ycm, km : real;
  21.     Intkm, Frackm, textkm : String;
  22.  
  23.  
  24. Procedure Init;
  25.   Var GrD, GrM : Integer;
  26.   Begin
  27.     DetectGraph (GrD,GrM);
  28.     InitGraph (GrD,GrM,'c:\tp\bgi');
  29.     If Not TestMouse Then Begin
  30.       SetTextJustify (CenterText, CenterText);
  31.       SetTextStyle (DefaultFont, HorizDir, 5);
  32.       OutTextXY (Round (GetMaxX/2), Round (GetMaxY/2), 'You need a mouse driver !');
  33.       Repeat Until KeyPressed;
  34.       Halt;
  35.     End;
  36.     ChangeMouse(Arrow);
  37.     New (ContBox,Init (Round (GetMaxX/2), Round (GetMaxY/20*15), 0,0,9,3,1));
  38.     ContBox^.SetText (1,0,3,'Continue');
  39.   End;
  40.  
  41. Procedure Title;
  42.   Begin
  43.     SetColor (Random (14)+1);
  44.     SetTextStyle (1, HorizDir, 6);
  45.     SetTextJustify (CenterText, TopText);
  46.     OutTextXY (Round (GetMaxX/2), 5, 'UNIT MOUSE');
  47.     SetTextJustify (CenterText, BottomText);
  48.     OutTextXY (Round (GetMaxX/2), GetMaxY-5, 'DEMO');
  49.     SetTextJustify (LeftText, CenterText);
  50.     SetTextStyle(1, HorizDir, 3);
  51.     SetColor (15);
  52.     PutMouse (Round (GetMaxX/2), Round (GetMaxY/2));
  53.   End;
  54.  
  55. Begin
  56.   Init;
  57.   Title;
  58.   New (Boite,Init (Round (GetMaxX/2), Round (GetMaxY/2), 0,0,0,0,2));
  59.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'This unit allows you to show or hide');
  60.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'the mouse. This is usefull when you draw');
  61.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*6), 'on the background...');
  62.   Boite^.SetText (1,0,3,'Click to hide the mouse');
  63.   Boite^.Bill;
  64.   WaitButton (x,y,button);
  65.   Boite^.ChangeText (1,0,3,'Click to show the mouse');
  66.   Hide_Mouse;
  67.   WaitButton (x,y,button);
  68.   Show_Mouse;
  69.   Dispose (Boite,Done);
  70.   ContBox^.Bill;
  71.   ContBox^.Wait (Left);
  72.   Hide_Mouse;
  73.   ClearViewPort;
  74.  
  75.   Title;
  76.   New (Boite, Init (Round (GetMaxX/4), Round (GetMaxY/2), 120, 30,10,2,1));
  77.   New (Boite2, Init (Round (GetMaxX/2), Round (GetMaxY/2), 120, 30,10,2,1));
  78.   New (Boite3, Init (Round (GetMaxX/4*3), Round (GetMaxY/2), 120, 30,10,2,1));
  79.   Boite^.SetText(1,0,3,'Left');
  80.   Boite2^.SetText (1,0,3,'Center');
  81.   Boite3^.SetText (1,0,3,'Right');
  82.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'This unit allows you to create easily selection');
  83.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'boxes, and wait the user click one of them...');
  84.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*6), 'with the button you want...');
  85.   Boite^.Bill;
  86.   If KindOfMouse=3 Then Boite2^.Bill;
  87.   Boite3^.Bill;
  88.   ContBox^.Bill;
  89.   SetColor (12);
  90.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*12), 'Try at it on each of those boxes...');
  91.   Show_Mouse;
  92.   Repeat                                                         
  93.     If Boite^.TestButton (Left) Or Boite3^.TestButton (Right) Or
  94.       (Boite2^.TestButton (Middle) And (KindOfMouse=3)) Then Begin
  95.           Sound (1000);
  96.           Delay (100);
  97.           NoSound;
  98.     End;
  99.   Until ContBox^.Testbutton (Left);
  100.   Dispose (Boite,Done);
  101.   Dispose (Boite2,Done);
  102.   Dispose (Boite3,Done);
  103.   Hide_Mouse;
  104.   ClearViewPort;
  105.  
  106.   Title;
  107.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'This unit allows you to change the mouse cursor');
  108.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'There are 4 predefined cursors in constants and');
  109.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*6), 'you can define new cursor...in an easy way...');
  110.   SetColor(2);
  111.   SetTextJustify (CenterText, CenterText);
  112.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/2), 'Click right button to change the cursor');
  113.   ContBox^.Bill;
  114.   Show_Mouse;
  115.   i:=0;
  116.   Repeat
  117.     Waitbutton(x,y,button);
  118.     Case button Of
  119.       Right : Begin
  120.                 Inc (i);
  121.                 i:= i Mod 4;
  122.                 Case i Of
  123.                   0 : ChangeMouse (Arrow);
  124.                   1 : ChangeMouse (Target);
  125.                   2 : ChangeMouse (Bomb);
  126.                   3 : ChangeMouse (QuestionMark);
  127.                 End;
  128.               End;
  129.     End;
  130.   Until ContBox^.TestButton (Left);
  131.   Hide_Mouse;
  132.   ClearViewPort;
  133.  
  134.   Title;
  135.   SetTextJustify (LeftText, CenterText);
  136.   SetTextStyle(1, HorizDir, 3);
  137.   SetColor (15);
  138.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'This unit allows you to define a area out of');
  139.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'which the mouse can''t go...');
  140.   New (Boite, Init (Round(GetmaxX/2), Round(GetMaxY/2),300,100,14,8,2));
  141.   Show_Mouse;
  142.   PutMouse(0,0);
  143.   MouseLimits (Round(GetMaxX/2)-150,Round(GetMaxY/2)-50,Round(GetMaxX/2)+150,Round(GetMaxY/2)+50);
  144.   b:=0;
  145.   Repeat
  146.     Boite^.ChangeText (1,0,3,'Limited Area');
  147.     For i:=0 To 10000 Do Begin
  148.        MouseState (x,y,Button);
  149.        If button<>0 Then b:=button;
  150.     End;
  151.     Boite^.ChangeText (1,0,3,'Click To Continue');
  152.     For i:=0 To 10000 Do Begin
  153.        MouseState (x,y,Button);
  154.        If button<>0 Then b:=button;
  155.     End;
  156.   Until b<>0;
  157.   Dispose (Boite, Done);
  158.   UnLimitMouse;
  159.   Hide_Mouse;
  160.   ClearViewPort;
  161.  
  162.   Title;
  163.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'And just for fun, you could compute');
  164.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'how many (kilo)meters you make with...');
  165.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*6), 'your mouse !');
  166.   Show_Mouse;
  167.   ContBox^.Bill;
  168.   New (Boite, Init(Round(GetMaxX/2), Round(GetMaxY/2), 200, 30 ,15 ,0 ,14));
  169.   km:=0;
  170.   MouseRun (x,y);
  171.   Repeat
  172.     MouseRun (x,y);
  173.     If (x<>0) Or (y<>0) Then Begin
  174.       xcm := x/200*2.54;
  175.       ycm := y/200*2.54;
  176.       km := km + Sqrt (xcm*xcm+ycm*ycm);
  177.       Str (Round(Int(km)), Intkm);
  178.       Str (Round(Int(((km-Int(km))*100))), Frackm);
  179.       Textkm := Intkm+'.'+Frackm+' cm';
  180.       Boite^.ChangeText (1,0,3,Textkm);
  181.     End;
  182.   Until ContBox^.Testbutton (Left);
  183.   Dispose (boite,Done);
  184.   Hide_Mouse;
  185.   ClearViewPort;
  186.  
  187.   Title;
  188.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*4), 'New ! An object to define, move, modify');
  189.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*5), 'and test the boxes...This object accepts');
  190.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*6), 'news children with news procedures');
  191.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*7), 'For example, click on the green box and');
  192.   OutTextXY (Round (GetMaxX/15), Round (GetMaxY/20*8), 'move it with your mouse...');
  193.   New (Boite, Init (Round (GetMaxX/2), Round (GetMaxY/2), 100,30,12,2,2));
  194.   boite^.SetText (1,0,3,' ');
  195.   ContBox^.Bill;
  196.   Hide_Mouse;
  197.   ChangeMouse (Target);
  198.   With Boite^ Do Begin
  199.     SizeBox := ImageSize(Round(MidX-Width/2),Round(MidY-Height/2),Round(MidX+Width/2),Round(MidY+Height/2));
  200.     GetMem (P, SizeBox);
  201.     GetImage (Round(MidX-Width/2),Round(MidY-Height/2),Round(MidX+Width/2),Round(MidY+Height/2),P^);
  202.     Bill;
  203.     Repeat
  204.       If TestButton (Left) Then Begin
  205.         MouseState (x,y,button);
  206.         UnBill;
  207.         Hide_Mouse;
  208.         PutImage (Round(MidX-Width/2),Round(MidY-Height/2),P^,NormalPut);
  209.         Move (x,y);
  210.         GetImage (Round(MidX-Width/2),Round(MidY-Height/2),Round(MidX+Width/2),Round(MidY+Height/2),P^);
  211.         Show_Mouse;
  212.         Bill;
  213.       End;
  214.     Until ContBox^.TestButton (Left);
  215.   End;
  216.   Dispose (Boite,Done);
  217.   Dispose (ContBox,Done);
  218.   Dispose (P);
  219.   Hide_Mouse;
  220.   ChangeMouse (Bomb);
  221.   ClearViewPort;
  222.  
  223.   Title;
  224.   SetTextJustify (CenterText, CenterText);
  225.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/20*6), 'All in all, you''ll find 21 procedures, 2 functions,');
  226.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/20*7), 'few constants and types in the unit G_MOUSE2.TPU');
  227.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/20*8), 'All details are in the file G_Mouse2.TXT.');
  228.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/20*9), 'I wish you a lot of fun and nice new graphic');
  229.   OutTextXY (Round (GetMaxX/2), Round (GetMaxY/20*10), 'programs with your MOUSE...!');
  230.   Show_Mouse;
  231.   Repeat
  232.     x:=Random (GetMaxX);
  233.     y:=Random (GetMaxY);
  234.     PutMouse (x,y);
  235.     Delay (100);
  236.     MouseState (x,y,button);
  237.   Until button<>0;
  238.   Hide_Mouse;
  239.   ClearViewPort;
  240.   CloseGraph;
  241. End.