XYPad

An XYPad can be drawn on a display and used to control the parameters being given to a particular function via the location of the selector, which is controlled by clicking and dragging to move the selector across the pad. The x and y values of the selector’s location can be used to control another function.

An XYPad is specified by two diagonal corners, the function to call when the user interacts with it, its various colors (background, foreground, and outline) and outline thickness.

To create an XYPad, you must have a display to draw it on.

d = Display()

When creating a new XYPad object, you need to store it in a variable (or other memory location) to be able to use it later.

Function Description
XYPad(x1, y1, x2, y2, updateFunction, foreground, background, thickness) Creates an XYPad.  x1 and y1 specify coordinates of one corner, x2 and y2 specify coordinates of the diagonal corner. updateFunction (default is None) is the function that this XYPad calls when the selector is moved. foreground is the color of the XYPad  selector  and outline (default is red), background is the color behind it (default is black), and thickness specifies the thickness in pixels of the selector lines (default is 3).

You can create an XYPad as follows:

xy = XYPad(100, 50, 200, 150, None, Color.BLACK, Color.WHITE, 1)

and add it to the display:

d.add(xy)

Once an XYPad has been created, the following functions are available:

Function Description
xy.getPosition() Returns the current x and y coordinates of the XYPad, relative to the XYPad (top left corner is 0,0).
xy.setPosition(newX, newY) Sets the current position of the XYPad’s selector.