home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Pascal / HISOFTPASCAL2,0-1.DMS / in.adf / HSPascal / AmigaDemos / MouseDemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-05-14  |  2.8 KB  |  85 lines

  1. {--------------------------------------------------------------------------
  2.  
  3.                      HighSpeed Pascal for the Amiga
  4.  
  5.                           MOUSE TRACKING DEMO
  6.  
  7.                   Programmed by Martin Eskildsen 1991
  8.  
  9.                   Copyright (c) 1991 by D-House I ApS
  10.                          All rights reserved
  11.  
  12.  
  13.   Version : Date (dd.mm.yy) : Comment
  14.   -----------------------------------
  15.     1.00 : 22.07.91 : First version
  16.     1.01 : 13.08.91 : Uses Init.LegalPosition
  17.     1.02 : 17.09.91 : Uses new libraries
  18.     1.03 : 06.11.91 : Final for first release
  19.     1.10 : 22.04.92 : Updated to use correct unsigned types, Wait() fixed
  20.  
  21. --------------------------------------------------------------------------}
  22.  
  23. program MouseDemo;
  24.  
  25. uses Init, Intuition, Exec, Graphics;
  26.  
  27. procedure DrawLoop;
  28. var
  29.   dummy    : longint;
  30.   Imessage : pIntuiMessage;   { The messages sent to this program }
  31.   class    : long;            { Message class }
  32.   code     : word;            { Message code }
  33.   quit     : boolean;         { TRUE = done showing menu }
  34.   drawing  : boolean;         { TRUE = we are drawing }
  35.   x, y     : integer;         { Mouse (x,y) }
  36.  
  37. begin
  38.   quit := FALSE;                       { Not done yet }
  39.   drawing := FALSE;                    { Not drawing at entry }
  40.   Move_(OutputWindow^.RPort, 2,10);    { Move to upper left of work area }
  41.   repeat
  42.     dummy := Wait(BitMask(OutputWindow^.UserPort^.MP_SIGBIT));
  43.                                         { Wait for something to happen }
  44.  
  45.     Imessage := pIntuiMessage(GetMsg(OutputWindow^.UserPort));
  46.                                         { Find out what }
  47.     while Imessage <> NIL do begin
  48.       class := Imessage^.class;         { Save for later use }
  49.       code  := Imessage^.code;
  50.       x     := Imessage^.MouseX;
  51.       y     := Imessage^.MouseY;
  52.       ReplyMsg(pMessage(Imessage));     { Accept this message }
  53.       case class of
  54.         MOUSEBUTTONS : begin
  55.                          drawing := code = SELECTDOWN;
  56.                          if drawing and LegalPosition(x, y) then
  57.                            Move_(OutputWindow^.RPort, x, y)
  58.                        end;
  59.         MOUSEMOVE    : if drawing and LegalPosition(x, y) then
  60.                          Draw(OutputWindow^.RPort, x, y);
  61.         CLOSEWINDOW_ : quit := TRUE
  62.       end;
  63.       Imessage := pIntuiMessage(GetMsg(OutputWindow^.UserPort)) { Get next }
  64.     end;
  65.   until quit
  66. end;
  67.  
  68. begin
  69.   if PrepareEnvironment('Mouse Tracking') then begin
  70.  
  71.     Message('First, a window to draw in');
  72.     with OutputWinDef do begin            { Tell Intuition that we want }
  73.       IDCMPflags := IDCMPflags or MOUSEBUTTONS or MOUSEMOVE;
  74.       Flags := Flags or REPORTMOUSE_
  75.     end;
  76.     OpenOutputWindow;
  77.  
  78.     Inform('Ready! Press left mouse button to draw; Close gadget to end');
  79.     DrawLoop;
  80.  
  81.     CloseOutputWindow;
  82.     CloseDown
  83.   end
  84. end.
  85.