Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 91213ddcfbe7f54821d42c2d9e091326 > files > 3046

gap-system-packages-4.4.12-5mdv2010.0.i586.rpm

<html><head><title>[xgap] 7.2 Mouse Events</title></head>
<body text="#000000" bgcolor="#ffffff">
[<a href = "C007S000.htm">Up</a>] [<a href ="C007S001.htm">Previous</a>] [<a href ="C007S003.htm">Next</a>] [<a href = "theindex.htm">Index</a>]
<h1>7.2 Mouse Events</h1><p>
<p>
When a mouse event occurs, this is communicated to <font face="Gill Sans,Helvetica,Arial">GAP</font> via a function
call which in turn triggers a callback. As described in <a href="C006S001.htm#SSEC1">GraphicSheet</a> to
<a href="C006S001.htm#SSEC8">CtrlRightPBDown</a> the following callback keys are predefined as reactions
on mouse events: <code>LeftPBDown</code>, <code>RightPBDown</code>, <code>ShiftLeftPBDown</code>,
<code>ShiftRightPBDown</code>, <code>CtrlLeftPBDown</code>, <code>CtrlRightPBDown</code>.
<p>
Note that when your function gets called, the mouse button will still be
pressed. So it can react and for example wait for the release. There is an 
easy way to find out about the state of the mouse buttons after the event:
<p>
<a name = "SSEC1"></a>
<li><code>WcQueryPointer( </code><var>id</var><code> ) F</code>
<p>
<var>id</var> must be a <code>WindowId</code> of an XGAP sheet. This function returns a
vector of four integers. The first two are the coordinates of the mouse 
pointer relative to the XGAP sheet. Values outside the window are 
represented by <var>-1</var>. The third element is a number where the pressed      
buttons are coded. If no mouse button is pressed, the value is zero.
<code>BUTTONS.left</code> is added to the value, if the left mouse button is pressed
and <code>BUTTONS.right</code> is added, if the right mouse button is pressed. The
fourth value codes the state of the shift and control. Here the values
<code>BUTTONS.shift</code> and <code>BUTTONS.ctrl</code> are used.
<p>
This function is used in
<p>
<a name = "SSEC2"></a>
<li><code>Drag( </code><var>sheet</var><code>, </code><var>x</var><code>, </code><var>y</var><code>, </code><var>bt</var><code>, </code><var>func</var><code> ) O</code>
<p>
Call this function when a button event has occurred, so the button <var>bt</var>
is still pressed. It waits until the user releases the mouse button and
calls <var>func</var> for every change of the mouse position with the new x and
y position as two integer parameters. You can implement a dragging
procedure in this way as in the following example: (we assume that a
<code>LeftPBDown</code> event just occurred and x and y contain the current mouse
pointer position):
<p>
<pre>
  storex := x;
  storey := y;
  box := Rectangle(sheet,x,y,0,0);
  if Drag(sheet,x,y,BUTTONS.left,
          function(x,y)
            local bx,by,bw,bh;
            if x &lt; storex then
              bx := x;
              bw := storex - x;
            else
              bx := storex;
              bw := x - storex;
            fi;
            if y &lt; storey then
              by := y;
              bh := storey - y;
            else
              by := storey;
              bh := y - storey;
            fi;
            if bx &lt;&gt; box!.x or by &lt;&gt; box!.y then
              Move(box,bx,by);
            fi;
            if bw &lt;&gt; box!.w or bh &lt;&gt; box!.h then
              Reshape(box,bw,bh);
            fi;
          end) then
    the box had at one time at least a certain size
    ... work with box ...
  else
    the box was never big enough, we do nothing
  fi;
  Delete(box);
</pre>
<p>
<p>
[<a href = "C007S000.htm">Up</a>] [<a href ="C007S001.htm">Previous</a>] [<a href ="C007S003.htm">Next</a>] [<a href = "theindex.htm">Index</a>]
<P>
<address>xgap manual<br>Mai 2003
</address></body></html>