Skip to content

XYPad

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

XYPads are drawn between a starting point (x1, y1) and an ending point (x2, y2). Its value is an (x, y) position within the pad.

Creating an XYPad

You can create an XYPad using the following functions:

xypad = XYPad(x1, y1, x2, y2)
XYPad(x1, y1, x2, y2, action, foregroundColor, backgroundColor, outlineColor, outlineThickness, trackerRadius, crosshairThickness, rotation, visibility)
Parameter Type Default Description
x1 int or float required The horizontal position of the top-left corner, in pixels.
y1 int or float required The vertical position of the top-left corner, in pixels.
x2 int or float required The horizontal position of the bottom-right corner, in pixels.
y2 int or float required The vertical position of the bottom-right corner, in pixels.
action function None The function to call when the tracker moves; it receives the new [x, y] value.
foregroundColor Color Color.RED The color of the tracker.
backgroundColor Color Color.BLACK The color behind the tracker.
outlineColor Color Color.CLEAR The outline color.
outlineThickness int 2 The outline thickness, in pixels.
trackerRadius int or float 10 The radius of the tracker, in pixels.
crosshairThickness int None The thickness of the crosshair lines, in pixels. Defaults to the outline thickness.
rotation int or float 0 How far to turn the pad, in degrees, counter-clockwise.
visibility int 100 How visible the pad is, from 0 (invisible) to 100 (fully visible).

For example,

simpleXYPad.py
# simpleXYPad.py
# Creates an XYPad and prints its value when it changes

from gui import *

d = Display()

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

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

Once created, you can add it to a Display using the Display's add() function.

Functions

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

Function Description
xypad.getValue() Return the tracker's position within the pad.
xypad.setValue(x, y) Set the tracker's position within the pad.

Position

Function Description
xypad.getPosition() Return the object's position, the top-left corner of its bounding box.
xypad.getX() Return the object's horizontal position.
xypad.getY() Return the object's vertical position.
xypad.getCenter() Return the object's center point.
xypad.getCenterX() Return the object's horizontal center.
xypad.getCenterY() Return the object's vertical center.
xypad.setPosition(x, y) Move the object so the top-left corner of its bounding box sits at the given point.
xypad.setX(x) Set the object's horizontal position.
xypad.setY(y) Set the object's vertical position.
xypad.setCenter(x, y) Move the object so its center sits at the given point.
xypad.setCenterX(x) Set the object's horizontal center.
xypad.setCenterY(y) Set the object's vertical center.
xypad.move(x, y) Move the object to a new position.

Size

Function Description
xypad.getSize() Return the object's width and height.
xypad.getWidth() Return the object's width.
xypad.getHeight() Return the object's height.
xypad.setSize(width, height) Set the object's width and height.
xypad.setWidth(width) Set the object's width.
xypad.setHeight(height) Set the object's height.

Rotation

Function Description
xypad.getRotation() Return how far the object is turned.
xypad.setRotation(rotation) Turn the object to a given angle.
xypad.rotate(angle) Turn the object by an additional angle.

Visibility

Function Description
xypad.getVisibility() Return how visible the object is.
xypad.setVisibility(visibility) Set how visible the object is.

Information

Function Description
xypad.getEndpoints() Return the object's four corners.
xypad.getBoundingBox() Return the smallest upright box that surrounds the object.
xypad.getGroup() Return the Group this object belongs to.
xypad.getDisplay() Return the Display this object is on.
xypad.setToolTipText() Set the hover text shown over the object.

Hit Testing

Function Description
xypad.contains(x, y) Report whether a point lies inside the object.
xypad.intersects(other) Report whether this object overlaps another.
xypad.encloses(other) Report whether this object completely contains another.

Events

Function Description
xypad.onMouseClick(action) Set up a function to call when the mouse is clicked on this object.
xypad.onMouseDown(action) Set up a function to call when the mouse xypad is pressed on this object.
xypad.onMouseUp(action) Set up a function to call when the mouse xypad is released over this object.
xypad.onMouseMove(action) Set up a function to call when the mouse moves over this object.
xypad.onMouseDrag(action) Set up a function to call when the mouse is dragged over this object.
xypad.onMouseEnter(action) Set up a function to call when the mouse moves onto this object.
xypad.onMouseExit(action) Set up a function to call when the mouse moves off this object.
xypad.onKeyType(action) Set up a function to call when a key is typed (pressed and released).
xypad.onKeyDown(action) Set up a function to call when a key is pressed down.
xypad.onKeyUp(action) Set up a function to call when a key is released.