Skip to content

Training the Mouse (in APL*PLUS/PC)

Vector 8:2, page 132

user interfaces system interfaces

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 132

In VECTOR 7.3 pp 130-135, Ray Cannon proposed some functions in APL*PLUS/PC to be able to use the mouse. These functions were very much welcome for me, but I slightly modified them as follows.

The mouse always works in pixels, that is the screen is divided in 200 lines of 640 columns even in text mode. In that case, the values jump by 8 (0 8 16 24 .... 632 and 0 8 .... 192). That is why Ray divides the cursor position values by 8 (MS∆Q MS∆QCU MS∆QR MS∆WIN MS∆CU:0.125 x or 8 x) to return 25 lines and 80 columns (1 character “boxes”).

But you can design different boxes. Suppose you have a menu bar at the top of the screen; it uses 8 pixel’s lines (one text line) and you have 10 entries (each 64 pixel’s columns). So the returned cursor position should always be 0 for the line and 0 1 2 .... or 9 for the columns (top left corner is 0 0). The modified functions allow to specify the size of the boxes. If two values are given they represent the y and x values (lines and columns), a single value will apply to both y and x. In text mode one will generally use 8 (as Ray did).

I have also introduced ⎕IO = 1 as local to the mouse functions. One could even go further by choosing the mouse shape and colour, but that is another story.

Finally I want to point out that I got some problems with the mouse in EGA graphic mode:

  1. the cursor moves down to line 200 but not to line 357 or so of the EGA mode,
  2. there is conflict with ⎕GWRITE and
  3. there is conflict with ⎕GPRINT. I haven’t seen version 10 of APL*PLUS/PC, so I do not know if these problems exist with the builtin mouse support.

The function GENERAL uses the modified mouse functions. barremenu provides a screen with a top line menu: Help File Exit System Do and two information boxes. Selection is done either by clicking with the mouse left button or by typing the first letter of the choice. The mouse window is restricted to the first line.

    ∇ GENERAL;a;b;dum;HFESD;⍙mouse
[1]     ⍝ Programme de cartographie climatique
[2]
[3]      ⎕IO←0
[4]
[5]     ⍝ Help, File, System and exec are called functions
[6]      HFESD← 5 6 ⍴'Help  File  →0    Systemexec  '
[7]
[8]  deb:
[9]      dum←0 ⎕POKE 254 ⍝ ⎕INKEY doesn't wait for input
[10]     MS∆INIT 0
[11]     0 0 1 80 MS∆WIN 7 8 ⍝ 7 8 is the size factor
[12]     0 0 25 80 ⎕WPUT barremenu
[13]     MS∆SHOW
[14]   x: ⍝ check the mouse and the keyboard
[15]     a←0 MS∆Q 24 64 ⋄ →((a[0]≠0)∧a[2]∊ 0 1 2 4 9)/go1
[16]     b←1↑⎕INKEY,'x' ⋄ b←⎕AV[b+¯32×97<b←⎕AV⍳b]
[17]     →(~b∊'HFESD')/x ⋄ →go2
[18]     →x
[19] go1:MS∆HIDE ⋄ ⍎,(0 1 2 4 9 =a[2])⌿HFESD ⋄ →deb
[20] go2:MS∆HIDE ⋄ ⍎,('HFESD'=b)⌿HFESD ⋄ →deb
    ∇
    ∇ MS∆INIT cu;rc
[1]  ⍝ Initialize mouse ... global ⍙mouse←1 if OK ... else 0
[2]  ⍝ cu is the cursor type ... 0=mouse block; 1=hardware
[3]   rc←0 ⎕INT 51 ⋄ ⍙mouse←0≠1↑rc ⋄ →⍙mouse↓0
[4]   →cu↓0 ⋄ rc← 10 1 ⎕INT 51
    ∇
    ∇ MS∆SHOW;r
[1]  ⍝ Show mouse cursor
[2]   →⍙mouse↓0 ⋄ r←1 ⎕INT 51
    ∇
    ∇ MS∆HIDE;r
[1]  ⍝ Hide mouse cursor
[2]   →⍙mouse↓0 ⋄ r←2 ⎕INT 51
    ∇
    ∇ pos MS∆WIN sf;xy;rc;size;⎕IO
[1]  ⍝ Set mouse window .... as per ⎕WIN i.e. offset,size
[2]  ⍝ sf is the size factor, sf[1] line, sf[2] column
[3]   ⎕IO←1 ⋄ →⍙mouse↓0
[4]   pos←4↑,pos
[5]  ⍝ set the window with a maximum of 639, 199
[6]   xy← 639 199 ⌊⌊⌽sf×2↑pos ⋄ size← 639 199 ⌊⌊⌽sf×2↓pos
[7]   rc←(7,0,xy[1],xy[1]+size[1])⎕INT 51
[8]   rc←(8,0,xy[2],xy[2]+size[2])⎕INT 51
    ∇
    ∇ pos MS∆CU sf;xy;rc;⎕IO
[1]  ⍝ Place mouse cursor at row,col
[2]  ⍝ sf is the size factor, sf[1] line, sf[2] column
[3]   ⎕IO←1 ⋄ →⍙mouse↓0
[4]   xy← 639 199 ⌊⌊⌽sf×2↑pos
[5]   rc←(4,0,xy)⎕INT 51
    ∇
    ∇ r←btn MS∆Q sf;rc;xy;ct;⎕IO
[1]  ⍝ Query number of presses and row/col for button <btn>
[2]  ⍝ btn←0 ... left, btn←1 ... right, btn←2 ... both together
[3]  ⍝ sf is the size factor, sf[1] line, sf[2] column
[4]   ⎕IO←1 ⋄ r←3⍴0 ⋄ →⍙mouse↓0
[5]   rc←(5,btn)⎕INT 51
[6]   ct←rc[2] ⋄ xy←rc[4 3] ⍝ note inversion of x, y
[7]   r←ct,⌊xy÷sf
    ∇
    ∇ r←MS∆QCU sf;rc;xy;⎕IO
[1]  ⍝ Query row/col for cursor
[2]  ⍝ sf is the size factor, sf[1] line, sf[2] column
[3]   ⎕IO←1 ⋄ r← 0 0 ⋄ →⍙mouse↓0
[4]   rc←3 ⎕INT 51
[5]   xy←rc[4 3] ⍝ note inversion of x, y
[6]   r←⌊xy÷sf
    ∇
    ∇ r←btn MS∆QR sf;rc;xy;ct;⎕IO
[1]  ⍝ Query number of releases and cursor row/col for <btn>
[2]  ⍝ btn←0 ... left, btn←1 ... right, btn←2 ... both together
[3]  ⍝ sf is the size factor, sf[1] line, sf[2] column
[4]   ⎕IO←1 ⋄ r←3⍴0 ⋄ →⍙mouse↓0
[5]   rc←(6,btn)⎕INT 51
[6]   ct←rc[2] ⋄ xy←rc[4 3] ⍝ note inversion of x, y
[7]   r←ct,⌊xy÷sf
    ∇