When a mouse event occurs, this is communicated to GAP via a function
call which in turn triggers a callback. As described in GraphicSheet to
CtrlRightPBDown the following callback keys are predefined as reactions
on mouse events: LeftPBDown
, RightPBDown
, ShiftLeftPBDown
,
ShiftRightPBDown
, CtrlLeftPBDown
, CtrlRightPBDown
.
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:
WcQueryPointer(
id ) F
id must be a WindowId
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 -1. The third element is a number where the pressed
buttons are coded. If no mouse button is pressed, the value is zero.
BUTTONS.left
is added to the value, if the left mouse button is pressed
and BUTTONS.right
is added, if the right mouse button is pressed. The
fourth value codes the state of the shift and control. Here the values
BUTTONS.shift
and BUTTONS.ctrl
are used.
This function is used in
Drag(
sheet,
x,
y,
bt,
func ) O
Call this function when a button event has occurred, so the button bt
is still pressed. It waits until the user releases the mouse button and
calls func 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
LeftPBDown
event just occurred and x and y contain the current mouse
pointer position):
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 < storex then bx := x; bw := storex - x; else bx := storex; bw := x - storex; fi; if y < storey then by := y; bh := storey - y; else by := storey; bh := y - storey; fi; if bx <> box!.x or by <> box!.y then Move(box,bx,by); fi; if bw <> box!.w or bh <> 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);
[Up] [Previous] [Next] [Index]
xgap manual