home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI10.ARJ / ictari.10 / C / EVNT_BUT / EVNT_BUT.TXT
Text File  |  1994-04-21  |  7KB  |  155 lines

  1.  
  2.                  Using the right mouse button with evnt_multi
  3.                  ============================================
  4.  
  5.     You will probably have noticed that very few applications for the Atari
  6.     make much use of the  right  mouse  button.  The  reason given was that
  7.     there was no simple way for a GEM  program  to do it. It turns out that
  8.     there has been a legal  way  to  do  it  all  along - Atari finally got
  9.     around to documenting it a couple of  years ago, but only to registered
  10.     developers.
  11.  
  12.     evnt_button
  13.     -----------
  14.  
  15.     Normally a GEM program  is  based  around  an  evnt_multi call, but for
  16.     simplicity I will stick to  evnt_button,  which  only waits for a mouse
  17.     button event. The parameters  are  much  the  same  but because it only
  18.     waits for one event, there are rather less of them :)
  19.  
  20.     In C it is
  21.  
  22.     int evnt_button( int maxclicks, int mask, int state,short *x, short *y,
  23.     short *button, short *kstate ) ;
  24.  
  25.     It takes three parameters, maxclicks  is  the  number of clicks to wait
  26.     for, mask is a  bitmap  showing  which  buttons  you  are interested in
  27.     (1=left, 2=right, 3=both) and state is  a  bitmap showing what state to
  28.     wait for. It returns the number of clicks that occurred, and puts the x
  29.     and y position of the  mouse  in  x  and  y,  the final button state in
  30.     button and the shift key state in kstate.
  31.  
  32.     The way it is normally used is to  pass  one in mask so that it ignores
  33.     the right button.
  34.  
  35.     Using the right button as a shift key
  36.     -------------------------------------
  37.  
  38.     The desktop and some other applications  use the right button to select
  39.     things in windows that aren't topped. You  have to hold the left button
  40.     down at the same time. To do this,  or  use the right mouse button as a
  41.     shift key like this in any other  way,  you  still use one in the mask,
  42.     but you check button afterwards to see if the right button was down
  43.  
  44.     evnt_button( 1, 0x01, 0x01, &x, &y, &button, &kstate ) ;
  45.                     ^        ^
  46.                     |        Wait for left button down
  47.                      Use left button, ignore right
  48.  
  49.     if( button & 0x02 )
  50.          /* right button down as well */
  51.     else
  52.          /* left button only */
  53.  
  54.     Waiting for a right button click
  55.     --------------------------------
  56.  
  57.     It is also possible to wait  for  a  right button click. For example if
  58.     you want to wait for the  right  button,  and don't care about the left
  59.     button,
  60.  
  61.     evnt_button( 1, 0x02, 0x02, &x, &y, &button, &kstate ) ;
  62.                     ^       ^
  63.                     |       Wait for right button down
  64.                     Use right button, ignore left
  65.  
  66.     If you want to wait for both  buttons  to  be down, or just the left or
  67.     just the right, you have to use three  for the mask (1+2) and the state
  68.     to wait for in state.
  69.  
  70.     evnt_button( 1, 0x03, 0x02, &x, &y, &button, &kstate ) ;
  71.                     ^       ^
  72.                     |       Wait for right down, left up
  73.                     Use both buttons
  74.  
  75.     evnt_button( 1, 0x03, 0x03, &x, &y, &button, &kstate ) ;
  76.                     ^       ^
  77.                     |       Wait for both to be down
  78.                     Use both buttons
  79.  
  80.     Waiting for either click
  81.     ------------------------
  82.  
  83.     You will notice that you can only  wait  for one state. There is no way
  84.     of saying 'Wait for left or right  button  click'. At least, not if you
  85.     believe the  documentation!  Here's  where  you  get  the  bit  not  in
  86.     textbooks :-
  87.  
  88.     First...
  89.  
  90.     A historical note
  91.     -----------------
  92.  
  93.     A method used by some older  programs,  and  in fact recommended in the
  94.     Lattice C manual, involves some clever messing around with vectors. You
  95.     use the VDI call vex_butv() to install a mouse button handler, and what
  96.     you do is that whatever click you  get  you  pretend it is a left click
  97.     and set a variable somewhere to show what sort it really is.
  98.  
  99.     Playing around with vectors like this  is  difficult in C and virtually
  100.     impossible in basic, but  there  is  a  more  serious problem with this
  101.     method. What happens if you are running multitos, and one program tries
  102.     this? All the other programs will also  be affected by your routine and
  103.     will get all their mouse clicks as left clicks.
  104.  
  105.     So Atari announced to developers  the  official  method that had always
  106.     worked and no one knew about.
  107.  
  108.     The bit you won't find in your manuals
  109.     --------------------------------------
  110.  
  111.     As well as  the  maximum  number  of  clicks  to  wait  for,  the first
  112.     parameter to evnt_button has another  purpose.  If  you add 0x100 to it
  113.     (this is 256 in decimal)  it  means  negate  the state requirement. For
  114.     example if the state is zero, it will  wait for the button state not to
  115.     be zero - ie for either button to be down
  116.  
  117.     evnt_button( 0x101, 0x03, 0x00, &x, &y, &button, &kstate ) ;
  118.                     ^   ^       ^
  119.                     |   |       Wait for NOT(no buttons down )
  120.                    |    Look at both buttons
  121.                    Negate state requirement, wait for one click
  122.  
  123.     If you are interested in mouse up events, then you have to wait for one
  124.     of the buttons to be pressed and  then  either wait for the state to be
  125.     zero, or wait for it NOT to be whatever it then is.
  126.  
  127.     evnt_button( 0x101, 0x03, 0x00, &x, &y, &button, &kstate ) ;
  128.     /* Right, now one or the other or both is down         */
  129.     evnt_button( 0x101, 0x03, button, &x, &y, &button, &kstate ) ;
  130.                           ^
  131.                           Wait for NOT( previous state )
  132.  
  133.     Summary
  134.     -------
  135.  
  136.     Using the right button  isn't  as  difficult  as  it's  made out to be.
  137.     Although all the examples I have done are in C, this should work in any
  138.     language that lets you call  GEM  directly,  such  as Hisoft Basic, GFA
  139.     Basic 3 or Assembly language (see also ASSEMBLY\EVNT_BUT folder).
  140.  
  141.     The information was originally released by Mike Fulton (Atari developer
  142.     support). Warwick Allison posted it onto the Usenet newsgroup with some
  143.     accompanying notes, and then Steve Taylor  posted a copy of his message
  144.     onto Turbonet (where I read it).
  145.  
  146.  
  147.                                        Mark Baker
  148.  
  149.     Email :                            mark.baker@mettav.royle.org
  150.  
  151.                                        Fidonet             2:254/108.17
  152.                                        Turbonet  100:1011/0.17
  153.                                        NeST                90;102/140.17
  154.                                        Atarinet  51:502/100.17
  155.