XYPad

An XYPad is similar to a trackpad.  It is controlled by clicking and dragging a selector (tracker bubble) across the pad.

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

Function Description
XYPad(x1, y1, x2, y2, updateFunction, foreground, background, outline, outlineThickness, trackerRadius, crosshairsThickness) Creates an XYPad object.

  • x1 and y1 specify coordinates of top-left corner, x2 and y2 specify coordinates of bottom-right corner.
  • updateFunction specifies what to do when the bubble is moved.
  • foreground is the color of the bubble (default is Color.RED)
  • background is the color behind the bubble (default is Color.BLACK)
  • outline is the color of the outline (default is same as foreground)
  • outlineThickness is the of the control’s outline in pixels (default is 2)
  • trackerRadius is the radius of the tracker bubble in pixels (default is 10).
  • crosshairsThickness is the thickness of the tracker lines in pixels (default is the same as outlineThickness).

You can create an XYPad as follows:

# function to specify what happens when tracker bubble is moved
def printPosition(x, y):
   print x, y   # replace this by whatever you want to do using x and y

trackpad = XYPad(100, 50, 200, 150, printPosition, Color.BLACK, Color.WHITE, Color.BLACK, 0)

display1.add(trackpad)

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

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