Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | display | |
Module | plotter | |
Tool | pgplotwidget |
The function returns an index which you can use to deactivate the callback.
At present, the events for which you may set a callback are:
The callback functions take a single argument, which will be a record of the type described in the manual. Or of course you could just pass in the callback function:
callback := function(rec) {print rec;}to discover the record structure. Note that to follow a drag you merely follow the motion after a button down and before a button up.
include 'pgplotwidget.g' f := frame(); pg := pgplotwidget(f); pos := [dragging=F]; # Drag starts downcallback := function(rec) { global pos; pos := [dragging=T, xlast=rec.world[1], ylast=rec.world[2]]; } # Draw the new line segment if we are dragging motioncallback := function(rec) { global pos; if (pos.dragging) { x := rec.world[1]; y := rec.world[2]; pg.line([pos.xlast, x], [pos.ylast, y]); pos.xlast := x; pos.ylast := y; } } # Drag ends upcallback := function(rec) { global pos; pos.dragging := F; } pg.env(0, 1, 0, 1, 0, -1); pg.setcallback('button', downcallback); pg.setcallback('motion', motioncallback); pg.setcallback('buttonup', upcallback); pg.message('Start scribbling! Drag the mouse with a button');The amount of code could have been reduced somewhat by having only one callback for both button and buttonup, and using the ``ButtonPress'' field of the record to distinguish up from down events.
name | events for which to call supply callback | ||
Allowed: | motion,key,button,button[1-3],buttonup | ||
callback | function to call on event | ||
Allowed: | single argument function |