home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / OMOUSE.ZIP / OMOUSE.DOC < prev    next >
Encoding:
Text File  |  1990-02-23  |  12.2 KB  |  431 lines

  1.     OMouse.TPU for TP 5.5
  2.     =====================
  3.  
  4.  
  5.     Thank you for downloading omouse.zip.  Omouse stands for
  6.     object mouse.  Compile and run omouse.dem with Turbo
  7.     Pascal 5.5 to see omouse in action.  When you want to
  8.     use a mouse in your next application simply include
  9.     omouse in the "uses" clause!
  10.  
  11.     For example:
  12.  
  13.         program MyNextApp;
  14.  
  15.             uses omouse;
  16.  
  17.  
  18.  
  19.             begin
  20.                 mouse.show;
  21.                 while (not mouse.LeftPressed) do;
  22.                 writeln('Mouse's left button pressed.')
  23.             end.
  24.  
  25.     All omouse coordinates are expressed in Turbo Pascal's
  26.     physical screen coordinates rather than the mouse's
  27.     virtual coordinates.  Be sure to call mouse.reset after
  28.     each video mode change to enable this feature!
  29.  
  30.     For example:
  31.  
  32.         program MyLastApp;
  33.  
  34.             uses graph, omouse;
  35.  
  36.             var driver, mode, error : integer;
  37.  
  38.             begin
  39.                 if not mouse.present then begin
  40.                     write('Mouse driver not installed ');
  41.                     write('or mouse not properly ');
  42.                     writeln('connected!');
  43.                     writeln('Press "enter" to halt.');
  44.                     halt;
  45.                     end;
  46.                 driver := detect;
  47.                 InitGraph(driver,mode,'');
  48.                 error := GraphResult;
  49.                 if error <> grOk then
  50.                     writeln('Graphics error: ',
  51.                         GraphErrorMsg(error))
  52.                 else begin
  53.                     mouse.reset;
  54.                     mouse.x := GetMaxX div 2;
  55.                     mouse.y := GetMaxY div 2;
  56.                     mouse.GotoXY;
  57.                     mouse.trap(mouse.x,mouse.y,
  58.                         GetMaxX,GetMaxY);
  59.                     OutText('Mouse trapped in lower ');
  60.                     OutText('right quadrant.')
  61.                     end;
  62.                 readln
  63.             end.
  64.  
  65.     Omouse has both initialization and exit code so you need
  66.     not worry about any messy details.  All of the mouse
  67.     driver functions are included as methods of the mouse
  68.     object.  If you look at the MM (Microsoft Mouse) object
  69.     code in the interface section of omouse, you can see the
  70.     data fields and methods.  Both are commented with
  71.     { MF?? } which tells you which (M)ouse (F)unction(s) are
  72.     operating on the data or being called.
  73.  
  74.     For example, consider the following code from the
  75.     interface section of omouse.pas :
  76.  
  77.         MM = object        {  Microsoft Mouse }
  78.  
  79.             { "var mouse : MM;" below must be the only instance! }
  80.  
  81.             { Exit chain procedure pointer; do not modify! }
  82.             ExitSave : pointer;
  83.  
  84.             { MF0, MF33 : Video mode at reset/SoftReset }
  85.             { Call reset after all video mode changes! }
  86.             { Do not modify! }
  87.             vmode : word;
  88.  
  89.             { MF0 : Set by reset }
  90.             Present : boolean;
  91.             Buttons : word;
  92.  
  93.             { MF3, MF5, MF6 : Button Status }
  94.             LeftPressed, RightPressed : boolean;
  95.  
  96.             { MF3, MF4 : Mouse Positon }
  97.             x, y : integer;
  98.             { X & Y are physical, not virtual coordinates! }
  99.             { Text modes upper left corner : 1,1 }
  100.             { Graphics modes upper left corner : 0,0 }
  101.  
  102.             ...
  103.  
  104.             procedure init;        { Don't call! }
  105.  
  106.         { Mouse driver function calls: }
  107.  
  108.             procedure reset;                { MF0 }
  109.             procedure show;                    { MF1 }
  110.             procedure hide;                 { MF2 }
  111.             procedure UpdateStatusInfo;     { MF3 }
  112.             procedure GotoXY;                { MF4 }
  113.             procedure UpdatePressInfo;        { MF5 }
  114.             procedure UpdateReleaseInfo;    { MF6 }
  115.             procedure trap                    { MF7, MF8 }
  116.                         (x1,y1,x2,y2 : integer);
  117.  
  118.             ...
  119.  
  120.             end;
  121.  
  122.         var mouse : MM;
  123.  
  124.  
  125.     In this example listing, you should find vmode and
  126.     thus deduce from the associated comments that
  127.     mouse.vmode is modified and/or referenced by mouse
  128.     functions #0 and #33.  Now find the "show" method.  This
  129.     implements Microsoft Mouse Driver function #1.  You may
  130.     be wondering what calling mouse.UpdateStatusInfo does
  131.     other than call mouse function #3.  The answer is that
  132.     it updates mouse.LeftPressed, mouse.RightPressed,
  133.     mouse.x, and mouse.y!  Can you see this by finding these
  134.     data fields and seeing that their associated comments
  135.     say that they are modified by mouse function #3?  I
  136.     should mention now, if you want to do any serious mouse
  137.     programming it would be a good idea to pick up
  138.  
  139.         "Microsoft Mouse Programmer's Reference."
  140.         Bellevue, Washington: Microsoft Press, 1989.
  141.  
  142.     This is the main reference I used in coding omouse.
  143.     Rather than repeat what is in this book or explain what
  144.     the mouse functions do, you should reference this book.
  145.     By using the book and reading the interface of omouse,
  146.     you will soon get the picture of what's going on.
  147.  
  148.     You will soon notice that the mouse methods don't
  149.     typically pass parameters but values are instead stored
  150.     directly in the mouse object's data fields.  The reason
  151.     I don't pass parameters is so you don't have to provide
  152.     variables to store them in.  Secondly, omouse has a
  153.     special method called AutoEventUpdate which is a
  154.     prewritten mouse event interrupt handler.  All you do is
  155.     call mouse.AutoEventUpdate and it updates the mouse's
  156.     data fields whenever a mouse event happens as specified
  157.     by mouse.EventMask (see p. 167 of the book).  The mask
  158.     is preconfigured to request an update whenever the mouse
  159.     moves, or a mouse button is pressed or released.  This
  160.     should satisfy most of your requirements.  If you need
  161.     something more sophisticed, you can use the code of
  162.     AutoEventHandler() to cookbook your interrupt handler!
  163.     But you'll have to register to get that secret.
  164.  
  165.     I tested the omouse unit with Microsoft Mouse driver
  166.     version 7.00 and Microsoft's second generation mouse.
  167.  
  168.     Compile and run omouse.dem with Turbo Pascal 5.5.
  169.     Peruse its source code to get some ideas about using
  170.     omouse.  You are going to have to dig alittle but you'll
  171.     get allot from omouse.  Play with the mouse.report in
  172.     the demo to see some of the data fields updated by the
  173.     automatic event handler.  Hey, this is shareware!  I
  174.     haven't found anyone willing to pay for 60 page manuals,
  175.     e.g. crtplus.zip, crtpls.zip, so I stopped writing them.
  176.     If you feel otherwise let me know.  Why not let me know
  177.     via email. Remember I need your support to do more!
  178.  
  179.     If you find omouse useful and are using it in your
  180.     applications, a registration fee of $7 is requested.
  181.     Upon registration you will be sent source code and the
  182.     latest examples programs on a DOS formatted 5 1/4" disk.
  183.  
  184.  
  185.     Thanks,
  186.  
  187.         John
  188.  
  189.     CIS id : 73757,2233
  190.  
  191.  
  192.     P.S.  Graphtxt is already available as shareware ($7) on
  193.     the BBS's and PolyList will be as soon as polylist.dem
  194.     and polylist.doc are finished, shareware ($7).  Be
  195.     sure to look for crtplus, shareware ($20); this is the
  196.     one with the 60 page manual!
  197.  
  198.  
  199.     Omouse.PAS interface section follows.
  200.     =====================================
  201.  
  202.  
  203. {
  204.  
  205.     omouse.pas
  206.     2-23-90
  207.     Microsoft mouse interrupt functions
  208.  
  209.     Copyright 1990
  210.     John W. Small
  211.     All rights reserved
  212.  
  213.     PSW / Power SoftWare
  214.     P.O. Box 10072
  215.     McLean, Virginia 22102 8072
  216.     (703) 759-3838
  217.  
  218.  
  219.     Works consulted:
  220.  
  221.     "Microsoft Mouse Programmer's Reference."
  222.         Bellevue, Washington: Microsoft Press, 1989.
  223.  
  224.     "Microsoft Mouse Programmer's Reference Guide."
  225.         Bellevue, Washington: Microsoft Press, 1986.
  226.  
  227. }
  228.  
  229. unit omouse;
  230.  
  231. interface
  232.  
  233.     uses DOS;
  234.  
  235.     const
  236.  
  237.         {
  238.             Mouse Events, for MM.CallMask, MM.AltCallMask,
  239.             MM.EventMask, and MM.EventFlags.
  240.         }
  241.  
  242.         Moved     =     1;
  243.         LeftP     =     2;
  244.         LeftR     =     4;
  245.         RightP     =     8;
  246.         RightR     =      16;
  247.         Shift    =      32;
  248.         Ctrl    =      64;
  249.         Alt        =     128;
  250.  
  251.         { Mouse Buttons }
  252.  
  253.         LeftB   =    1;
  254.         RightB    =    2;
  255.  
  256.  
  257.     type
  258.  
  259.         MouseTypes =
  260.             ( Unknown, Bus, Serial, InPort, PS2, HP );
  261.  
  262.         MouseLanguages = ( English, French, Dutch,
  263.             German, Swedish, Finnish, Spanish,
  264.             Portuguese, Italian );
  265.  
  266.         GraphicsCursorType = record
  267.             HorzHotSpot, VertHotSpot : shortint;
  268.             ScreenCursorMask : array[0..31] of word
  269.         end;
  270.  
  271.         MM = object        {  Microsoft Mouse }
  272.  
  273.             { "var mouse : MM;" below must be the only instance! }
  274.  
  275.             { Exit chain procedure pointer; do not modify! }
  276.             ExitSave : pointer;
  277.  
  278.             { MF0, MF33 : Video mode at reset/SoftReset }
  279.             { Call reset after all video mode changes! }
  280.             { Do not modify! }
  281.             vmode : word;
  282.  
  283.             { MF0 : Set by reset }
  284.             Present : boolean;
  285.             Buttons : word;
  286.  
  287.             { MF3, MF5, MF6 : Button Status }
  288.             LeftPressed, RightPressed : boolean;
  289.  
  290.             { MF3, MF4 : Mouse Positon }
  291.             x, y : integer;
  292.             { X & Y are physical, not virtual coordinates! }
  293.             { Text modes upper left corner : 1,1 }
  294.             { Graphics modes upper left corner : 0,0 }
  295.  
  296.             { User data area! }
  297.             UserX, UserY, UserLeft,
  298.             UserRight, UserCount : integer;
  299.  
  300.             { MF5 : Button Press Information }
  301.             LastLeftPressX, LastLeftPressY,
  302.             LeftPresses : integer;
  303.             LastRightPressX, LastRightPressY,
  304.             RightPresses : integer;
  305.             { X & Y are physical, not virtual coordinates! }
  306.  
  307.             { MF5, MF6 : Button Requested }
  308.             ButtonRequested : word;
  309.  
  310.             { MF6 : Button Release Information }
  311.             LastLeftReleaseX, LastLeftReleaseY,
  312.             LeftReleases : integer;
  313.             LastRightReleaseX, LastRightReleaseY,
  314.             RightReleases : integer;
  315.             { X & Y are physical, not virtual coordinates! }
  316.  
  317.             { MF11 : Mouse motion counters }
  318.             VertMickeys, HorzMickeys : word;
  319.  
  320.             { MF12, MF20 : Set/SwapInterrupt(s) mask/addr }
  321.             IntrProc : pointer; { See AutoEventHandler }
  322.             CallMask : word;
  323.             { Also used by AutoEventUpdate. }
  324.  
  325.             { Set by Mouse Event Handler. }
  326.             EventMask : word;
  327.             EventFlags : word;
  328.             EventCount : word;
  329.             EventMoved : word;
  330.             ClickTimeOut : longint;
  331.             LeftClickTime : longint;
  332.             LeftClicks : word;
  333.             RightClickTime : longint;
  334.             RightClicks : word;
  335.  
  336.             { MF21, MF22, MF23 : Used by save and restore }
  337.             { Do not modify! }
  338.             OrigState, State : pointer;
  339.             StateSize : word;
  340.  
  341.             { MF24, MF25 : Set/GetAltInterrupt mask/addr }
  342.             AltIntrProc : pointer; { See AutoEventHandler }
  343.             AltCallMask : word;
  344.             { MF25 can read those set by MF20! }
  345.  
  346.             { MF26, MF27 : Set/GetSensitivity }
  347.             HorzPercent, VertPercent, DoublePercent : word;
  348.  
  349.             { MF29, MF30 : Set/GetCRTpage }
  350.             CRTpage : word;
  351.  
  352.             { MF31, MF32 : Used by off/on, don't change! }
  353.             MouseIntrVector : pointer;
  354.  
  355.             { MF34, MF35 : Used by Get/SetLanguage  }
  356.             language : MouseLanguages;
  357.  
  358.             { MF36 : Set by driver }
  359.             DriverVersion : word;
  360.             IRQ : integer;
  361.             TypeRequired : MouseTypes;
  362.  
  363.  
  364.             procedure init;        { Don't call! }
  365.  
  366.         { Mouse driver function calls: }
  367.  
  368.             procedure reset;                { MF0 }
  369.             procedure show;                    { MF1 }
  370.             procedure hide;                 { MF2 }
  371.             procedure UpdateStatusInfo;     { MF3 }
  372.             procedure GotoXY;                { MF4 }
  373.             procedure UpdatePressInfo;        { MF5 }
  374.             procedure UpdateReleaseInfo;    { MF6 }
  375.             procedure trap                    { MF7, MF8 }
  376.                         (x1,y1,x2,y2 : integer);
  377.             procedure GraphicsCursor        { MF9 }
  378.                         (gc : GraphicsCursorType);
  379.             procedure SoftWareTextCursor    { MF10 }
  380.                         (scrMask, curMask : word);
  381.             procedure UpdateMotionInfo;        { MF11 }
  382.             procedure SetInterrupt;            { MF12 }
  383.             procedure LightPenOn;            { MF13 }
  384.             procedure LightPenOff;            { MF14 }
  385.             procedure speed                    { MF15 }
  386.                         (horz, vert : word);
  387.             procedure OffTrap                { MF16 }
  388.                         (x1, y1, x2, y2 : integer);
  389.             procedure DoubleSpeedThreshold    { MF19 }
  390.                         (mickeys : word);
  391.             procedure SwapInterrupts;        { MF20 }
  392.             procedure AutoEventUpdate;        { N/A  }
  393.             procedure save;                    { MF21, MF22 }
  394.             procedure restore;                { MF23 }
  395.             procedure SetAltInterrupt;        { MF24 }
  396.             procedure GetAltInterrupt;        { MF25 }
  397.             procedure ClrAltInterrupts;        { N/A  }
  398.             procedure SetSensitivity;        { MF26 }
  399.             procedure GetSensitivity;        { MF27 }
  400.             procedure SetInterruptRate        { MF28 }
  401.                         (rate : word);
  402.             procedure SetCRTpage;            { MF29 }
  403.             procedure GetCRTpage;            { MF30 }
  404.             procedure off;                    { MF31 }
  405.             procedure on;                    { MF32 }
  406.             procedure SoftReset;            { MF33 }
  407.             procedure SetLanguage;            { MF34 }
  408.             procedure GetLanguage;            { MF35 }
  409.             procedure driver;                { MF36 }
  410.  
  411.             {  Added features: }
  412.  
  413.             function  VirtualX  (XPhysical : integer) : integer;
  414.             function  PhysicalX (XVirtual  : integer) : integer;
  415.             function  VirtualY  (YPhysical : integer) : integer;
  416.             function  PhysicalY (YVirtual  : integer) : integer;
  417.  
  418.             procedure report;    { Text mode only! }
  419.  
  420.         end;
  421.  
  422.     var
  423.  
  424.         mouse : MM;
  425.  
  426.     { Do not call!  Use to cookbook your own if needed. }
  427.     procedure AutoEventHandler(PseudoFlags,CS,IP,
  428.                 ConditionMask,ButtonState,x,y,
  429.                 HorzMickeys,VertMickeys,
  430.                 DS,ES,BP: word); interrupt;
  431.