VFader
Create a vertical fader the user can drag up and down.
Faders are drawn between a starting point (x1, y1) and an ending point (x2, y2).
There are two types of faders, a horizontal fader (HFader) and a vertical fader (VFader).
Creating a VFader
You can create a VFader using the following functions:
VFader(x1, y1, x2, y2)
VFader(x1, y1, x2, y2, minValue, maxValue, startValue, action, foregroundColor, backgroundColor, outlineColor, thickness, 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. |
minValue |
int |
0 |
The smallest value the fader can take. |
maxValue |
int |
999 |
The largest value the fader can take. |
startValue |
int or float |
None |
The fader's starting value. Defaults to halfway between minValue and maxValue. |
action |
function |
None |
The function to call when the fader moves; it receives the new value. |
foregroundColor |
Color |
Color.RED |
The color of the filled level. |
backgroundColor |
Color |
Color.BLACK |
The color behind the level. |
outlineColor |
Color |
Color.BLACK |
The outline color. |
thickness |
int |
3 |
The outline thickness, in pixels. |
rotation |
int or float |
0 |
How far to turn the fader, in degrees, counter-clockwise. |
visibility |
int |
100 |
How visible the fader is, from 0 (invisible) to 100 (fully visible). |
For example,
simpleFader.py
# simpleFader.py
# Creates a VFader and prints its value when it changes.
from gui import *
d = Display()
# function to specify what happens when fader is moved
def printValue(value):
print(value) # replace this with whatever action needs to happen
fader = VFader(25, 5, 45, 80, 0, 100, 50, printValue)
d.add(fader)
Once created, you can add it to a Display using the Display's add() function.
Functions
Once a VFader vfader has been created, the following functions are available:
| Function | Description |
|---|---|
vfader.setValue(newValue) |
Set the object's value. |
vfader.getValue() |
Return the object's current value. |
Position
| Function | Description |
|---|---|
vfader.getPosition() |
Return the object's position, the top-left corner of its bounding box. |
vfader.getX() |
Return the object's horizontal position. |
vfader.getY() |
Return the object's vertical position. |
vfader.getCenter() |
Return the object's center point. |
vfader.getCenterX() |
Return the object's horizontal center. |
vfader.getCenterY() |
Return the object's vertical center. |
vfader.setPosition(x, y) |
Move the object so the top-left corner of its bounding box sits at the given point. |
vfader.setX(x) |
Set the object's horizontal position. |
vfader.setY(y) |
Set the object's vertical position. |
vfader.setCenter(x, y) |
Move the object so its center sits at the given point. |
vfader.setCenterX(x) |
Set the object's horizontal center. |
vfader.setCenterY(y) |
Set the object's vertical center. |
vfader.move(x, y) |
Move the object to a new position. |
Size
| Function | Description |
|---|---|
vfader.getSize() |
Return the object's width and height. |
vfader.getWidth() |
Return the object's width. |
vfader.getHeight() |
Return the object's height. |
vfader.setSize(width, height) |
Set the object's width and height. |
vfader.setWidth(width) |
Set the object's width. |
vfader.setHeight(height) |
Set the object's height. |
Rotation
| Function | Description |
|---|---|
vfader.getRotation() |
Return how far the object is turned. |
vfader.setRotation(rotation) |
Turn the object to a given angle. |
vfader.rotate(angle) |
Turn the object by an additional angle. |
Visibility
| Function | Description |
|---|---|
vfader.getVisibility() |
Return how visible the object is. |
vfader.setVisibility(visibility) |
Set how visible the object is. |
Information
| Function | Description |
|---|---|
vfader.getEndpoints() |
Return the object's four corners. |
vfader.getBoundingBox() |
Return the smallest upright box that surrounds the object. |
vfader.getGroup() |
Return the Group this object belongs to. |
vfader.getDisplay() |
Return the Display this object is on. |
vfader.setToolTipText() |
Set the hover text shown over the object. |
Hit Testing
| Function | Description |
|---|---|
vfader.contains(x, y) |
Report whether a point lies inside the object. |
vfader.intersects(other) |
Report whether this object overlaps another. |
vfader.encloses(other) |
Report whether this object completely contains another. |
Events
| Function | Description |
|---|---|
vfader.onMouseClick(action) |
Set up a function to call when the mouse is clicked on this object. |
vfader.onMouseDown(action) |
Set up a function to call when the mouse vfader is pressed on this object. |
vfader.onMouseUp(action) |
Set up a function to call when the mouse vfader is released over this object. |
vfader.onMouseMove(action) |
Set up a function to call when the mouse moves over this object. |
vfader.onMouseDrag(action) |
Set up a function to call when the mouse is dragged over this object. |
vfader.onMouseEnter(action) |
Set up a function to call when the mouse moves onto this object. |
vfader.onMouseExit(action) |
Set up a function to call when the mouse moves off this object. |
vfader.onKeyType(action) |
Set up a function to call when a key is typed (pressed and released). |
vfader.onKeyDown(action) |
Set up a function to call when a key is pressed down. |
vfader.onKeyUp(action) |
Set up a function to call when a key is released. |