home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / amouse10.zip / DEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-14  |  12KB  |  278 lines

  1. {▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  2. {▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ Demo ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  3. {▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  4. {▒  This  is  a simple  DEMO  program that shows   general mouse function,  ▒}
  5. {▒  and demonstrates basic mouse programming using the aRmouse unit. Easy!  ▒}
  6. {▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒}
  7. {$R-,L-,D-,S-,E-,A+,N-,G-,F-}
  8. uses aRmouse,crt,dos;
  9.  
  10. const
  11.     push             = true;
  12.     release          = false;
  13.     Esc              = #27;
  14.     Enter            = #13;
  15.     main             = 1;
  16.     pressed          = 2;
  17.     nopressed        = 3;
  18.     BlackAndWhite    : boolean = false;
  19.     NoArrow          : boolean = false;
  20.     color            : array [false..true,main..nopressed] of integer=(
  21.                        (Lightcyan,LightGray,LightCyan),(LightGray,White,LightGray));
  22.     BackGround       : integer = Blue;
  23.  
  24. var ch               : char;
  25.     i                : integer;
  26.     x,y              : byte;
  27.     who              : EventStatus;
  28.     s                : string;
  29.     CurrentArrow     : ImageArrowName;
  30.  
  31. {$i Demo.inc}        { <-Service Rutine : Time, SetCursor, NormalCursor,
  32.                                            Atr,  HiddenCursor}
  33.  
  34.  
  35. procedure Button( n : integer; status : boolean);
  36.  {-Draw Button n=1 - left; n=2 - centr; n=3 - right status=push/release}
  37.  
  38. procedure WriteXY(s:string;x,y:integer);
  39. begin
  40.  Gotoxy(x,y);
  41.  Write(s);
  42. end;
  43.  
  44. var
  45.   x     : integer;
  46. begin
  47.  if NumberOfButtons=3 then x:=28+(n-1)*6
  48.  else if n=1 then x:=30 else x:=38;
  49.  if Status=Release then
  50.  begin
  51.   Atr(color[BlackAndWhite,NoPressed],BackGround);
  52.    writeXY('┌───┐',x,6);
  53.    writeXY('│███│',x,7);
  54.    writeXY('│███│',x,8);
  55.    writeXY('│███│',x,9);
  56.    writeXY('└───┘',x,10);
  57.  end
  58.  else
  59.  begin
  60.    Atr(color[BlackAndWhite,Pressed],BackGround);
  61.    writeXY('▄▄▄▄▄',x,6);
  62.    writeXY('▌▄▄▄▐',x,7);
  63.    writeXY('▌███▐',x,8);
  64.    writeXY('▌▀▀▀▐',x,9);
  65.    writeXY('▀▀▀▀▀',x,10);
  66.  end;
  67.   Atr(color[BlackAndWhite,Main],BackGround);
  68. end;
  69.  
  70. Procedure PushButton(status : EventStatus);
  71.   {-Draw Pushed Button}
  72. begin
  73.   if ord(Status) and 1 = 1 then Button(1,Push);
  74.   if ord(Status) and 2 = 2 then Button(3,Push);
  75.   if ord(Status) and 4 = 4 then Button(2,Push);
  76. end;
  77.  
  78. Procedure ReleaseButtons;
  79.    {-Draw all release Button}
  80. var I     : integer;
  81. begin
  82.   if MouseReady then for i :=1 to 3 do Button(i,Release);
  83. end;
  84.  
  85.  
  86. Procedure DemoImageArrow;
  87. begin
  88.    if (WhereArrowy>4)and(WhereArrowy<6) then
  89.       if WhereArrowx>73 then SelectNotPressedImage(DragArrowR) else
  90.       if WhereArrowx>69 then SelectNotPressedImage(DragArrowL) else
  91.       if WhereArrowx>65 then SelectNotPressedImage(ClockArrow) else
  92.       if WhereArrowx>61 then SelectNotPressedImage(HandArrow) else
  93.       if WhereArrowx>57 then SelectNotPressedImage(Hand1Arrow) else
  94.       if WhereArrowx>53 then SelectNotPressedImage(Hand3Arrow) else
  95.       if WhereArrowx>49 then SelectNotPressedImage(NormalArrow);
  96.    if (WhereArrowy>6)and(WhereArrowy<9) then
  97.       if WhereArrowx>73 then SelectNotPressedImage(Clock2Arrow) else
  98.       if WhereArrowx>69 then SelectNotPressedImage(DragArrow) else
  99.       if WhereArrowx>65 then SelectNotPressedImage(PencilArrow) else
  100.       if WhereArrowx>61 then SelectNotPressedImage(FootArrow) else
  101.       if WhereArrowx>57 then SelectNotPressedImage(Big2Arrow) else
  102.       if WhereArrowx>53 then SelectNotPressedImage(SightArrow) else
  103.       if WhereArrowx>49 then SelectNotPressedImage(PlusArrow);
  104. end;
  105.  
  106. Procedure SetImageArrow;
  107. begin
  108.    if (WhereArrowy>4)and(WhereArrowy<6) then
  109.       if WhereArrowx>73 then CurrentArrow:=DragArrowR else
  110.       if WhereArrowx>69 then CurrentArrow:=DragArrowL else
  111.       if WhereArrowx>65 then CurrentArrow:=ClockArrow else
  112.       if WhereArrowx>61 then CurrentArrow:=HandArrow else
  113.       if WhereArrowx>57 then CurrentArrow:=Hand1Arrow else
  114.       if WhereArrowx>53 then CurrentArrow:=Hand3Arrow else
  115.       if WhereArrowx>49 then CurrentArrow:=NormalArrow;
  116.    if (WhereArrowy>6)and(WhereArrowy<9) then
  117.       if WhereArrowx>73 then CurrentArrow:=Clock2Arrow else
  118.       if WhereArrowx>69 then CurrentArrow:=DragArrow else
  119.       if WhereArrowx>65 then CurrentArrow:=PencilArrow else
  120.       if WhereArrowx>61 then CurrentArrow:=FootArrow else
  121.       if WhereArrowx>57 then CurrentArrow:=Big2Arrow else
  122.       if WhereArrowx>53 then CurrentArrow:=SightArrow else
  123.       if WhereArrowx>49 then CurrentArrow:=PlusArrow;
  124. end;
  125.  
  126.  
  127. procedure DemoImage;
  128.    {-This procidure demo arrow image }
  129. begin
  130.   if (WhereArrowx>49)and(WhereArrowx<77)and(WhereArrowy>4)and(WhereArrowy<9) then DemoImageArrow
  131.   else SelectNotPressedImage(CurrentArrow);
  132. end;
  133.  
  134.  
  135. procedure SelectImage;
  136.    {-This procidure select new arrow image }
  137. begin
  138.   if (WhereArrowx>49)and(WhereArrowx<77)and(WhereArrowy>4)and(WhereArrowy<9) then SetImageArrow;
  139. end;
  140.  
  141. {$F+}
  142. Procedure ShowTime;
  143.    {-This procidure work into procedure GetEvent until
  144.      mouse button released}
  145. begin
  146.  textcolor(color[BlackAndWhite,NoPressed]);
  147.  Time;
  148.  PushButton(CurrentStatus);
  149. end;
  150. {$F-}
  151.  
  152. {$F+}
  153. procedure ShowTimeAndSwitchImage;
  154.    {-This procidure work into procedure GetEvent while not
  155.      mouse button released}
  156. begin
  157.  textcolor(color[BlackAndWhite,Pressed]);
  158.  Time;
  159.  textcolor(color[BlackAndWhite,Main]);
  160.  DemoImage;
  161. end;
  162. {$F-}
  163.  
  164. Procedure DrawScreen;
  165.    {-Draw Screen Image}
  166. begin
  167.   gotoxy(1,2);
  168.   Atr(color[BlackAndWhite,Main],BackGround);
  169.   writeln(' DEMO of available mouse functions    The C O L L E C T I O N  of arrows. Press');
  170.   writeln('                                  ╔╩╗ double click of left  button  for select.');
  171.   writeln('                                  ╠═╣           ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ');
  172.   writeln('                         ╔════════╩═╩════════╗  █   █   █   █   █   █   █   █ ');
  173.   writeln('                         ║                   ║  █▄▄▄█▄▄▄█▄▄▄█▄▄▄█▄▄▄█▄▄▄█▄▄▄█ ');
  174.   writeln('                         ║                   ║  █▀▀▀█▀▀▀█▀▀▀█▀▀▀█▀▀▀█▀▀▀█▀▀▀█ ');
  175.   writeln('                         ║                   ║  █   █   █   █   █   █   █   █ ');
  176.   writeln('                         ║                   ║  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ');
  177.   writeln('   Double click = ENTER─>║                   ║<───── One click    = ESC');
  178.   If not MouseReady then
  179.    writeln('                         ║MOUSE NOT INSTALLED║       Double click = #127')
  180.   else
  181.    writeln('                         ║                   ║       Double click = #127');
  182.   if (NumberOfButtons=2)or(NumberOfButtons=0) then
  183.   begin
  184.    writeln('                         ║                   ║');
  185.    writeln('                         ║                   ║');
  186.    writeln('                         ║                   ║');
  187.    writeln('                         ║                   ║');
  188.   end
  189.   else
  190.   begin
  191.    writeln('                         ║         ^         ║');
  192.    writeln('                         ║         │         ║');
  193.    writeln('                         ║Double click = #255║');
  194.    writeln('                         ║ for center button ║');
  195.   end;
  196.   If not AMouse then
  197.    writeln('                         ║ NO GRAPHIC EFFECT ║')
  198.   else
  199.    writeln('                         ║                   ║');
  200.   writeln('                         ╚═══════════════════╝');
  201.   writeln('                      Press any key or mouse button');
  202.   writeln;
  203.   writeln('  Pressing of Button results in character under cursor and X,Y positions');
  204.   writeln('  Pressing of any KBD key results in Mouse to  be  sleeping  until  move');
  205.   writeln('                      Press KBD Key <Esc> for EXIT');
  206.   Atr(color[BlackAndWhite,Main],BackGround);
  207.   ReleaseButtons;
  208. end;
  209.  
  210. {░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░}
  211. {░░░░█████████████████████████████████████████████████████████████████████░░░░}
  212. {░░░░█               MAIN PROGRAMM for DEMO ARMOUSE UNIT                 █░░░░}
  213. {░░░░█████████████████████████████████████████████████████████████████████░░░░}
  214. {░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░}
  215.  
  216. begin                             { Unit ArMouse initiate Arrow before }
  217.   for i:=1 to paramcount do
  218.   begin
  219.     if paramstr(i) = '/b' then begin
  220.                             BlackAndWhite:=true;
  221.                             BackGround:=Black;
  222.                           end
  223.     else if paramstr(i) = '/n' then begin
  224.                                       NoArrow:=true;
  225.                                       AMouse:=false;
  226.                                      end
  227.          else if paramstr(i) = '/e' then begin
  228.                                       DoneArrowMouse;
  229.                                       SwitchToEGA:=true;
  230.                                       ReInitArrowMouse;
  231.                                       if NoArrow then AMouse:=False;
  232.                                     end
  233.               else begin
  234.                      writeln('Syntax : demo [/b] [/n] [/e]');
  235.                      halt;
  236.                    end;
  237.   end;
  238.   CurrentArrow:=NormalArrow;      { Select image for demo             }
  239.   Atr(color[BlackAndWhite,Main],BackGround);
  240.                                   { Set Attribute                     }
  241.   Window(1,1,80,24);
  242.   ClrScr;
  243.   Window(1,1,80,25);              { Prepare Screen                    }
  244.   HiddenCursor;                   { Set Key Board cursor invisible    }
  245.   DrawScreen;                     { Draw MOUSE and text               }
  246.   repeat                          { Main Cycle                        }
  247.  
  248.     who:=GetEvent(ch, x, y, ShowTimeAndSwitchImage, ShowTime);
  249.  
  250.                                   { While not Event work 2 procedures }
  251.                                   { 1) ShowTimeAndSwitchImage         }
  252.                                   {    (until button not pressed)     }
  253.                                   { 2) ShowTime                       }
  254.                                   {    (while all button not released)}
  255.    case who of
  256.      Left_Button                  : s:= 'LeftButtonPressed           ';
  257.      Right_Button                 : s:= 'RightButtonPressed          ';
  258.      Both_Button                  : s:= 'BothButtonsPressed          ';
  259.      Center_Button                : s:= 'CenterButtonPressed         ';
  260.      Left_Center_Button           : s:= 'LeftAndCenterButtonsPressed ';
  261.      Right_Center_Button          : s:= 'RightAndCenterButtonsPressed';
  262.      All3_Button                  : s:= 'All3ButtonsPressed          ';
  263.      KBD_Key                      : s:= 'KBDKeyPressed               ';
  264.      KBD_Special_Key              : s:= 'KBDSpecialKeyPressed        ';
  265.    end;                           { Who pressed for write             }
  266.    ReleaseButtons;                { Draw Released Buttons             }
  267.    if (ch=Enter) and (Who=Left_Button) then SelectImage;
  268.                                   { Select image arrow if double click}
  269.    GoToXY(1,23);
  270.    Atr(color[BlackAndWhite,Main],BackGround);
  271.    if (ch=Enter)or(ch=#255)  then write(' ',s,' Character under cursor/KBD=[#',ord(ch),'] x=',x,' y=',y,'  ')
  272.    else  Write(' ',s,' Character under cursor/KBD=[',ch,'] x=',x,' y=',y,'    ');
  273.                                   { Write result to last line         }
  274.   until (ch=Esc)and(who=KBD_Key);{ End Main Cycle}
  275.   DoneArrowMouse;                 { Disable Event Handler at all..}
  276.   NormalCursor;                   { Set cursor visible            }
  277. end.
  278.