Skip to content

Cursor

The cursor is an input element and displays a slider inside a box.

Configure

Ensure the GUI library is included and initialised according to the configuration procedure.

cursor myCursor;

The constructor creates a cursor.

1
2
myCursor.dDefine(10, 10, 160, 50,
    0, 255);

dDefine() defines the cursor with vector coordinates.

The required parameters are

  • The first line specifies the vector coordinates: top-left coordinates x-y then width and height in pixels;

  • The second line defines the range of the values, with minimum and maximum, both as signed 32-bit integers.

By default, the cursor is horizontal and enabled according to the GUI setting.

Then,

myCursor.setOption(optionHorizontal);
myCursor.setState(stateEnabled);
myCursor.setValue(value);

setOption() defines the orientation:

  • optionHorizontal or false for horizontal orientation;
  • optionVertical or true of vertical orientation.

Default is false for horizontal orientation.

setState() defines whether touch is enabled for the element.

Select

  • stateDisabled or false for touch disabled;
  • stateEnabled or true for touch enabled.

Default is false for touch disabled.

setValue() sets the initial value of the cursor element, with a signed 32-bit integer.

The element checks the value is within the defined range, and replaces it with the minimal value if is inferior or the maximal value if it is superior.

Use

myCursor.draw();
bool result = myCursor.check();
int32_t value = myCursor.getValue();

draw() displays the cursor.

check() polls the touch controller and returns true is the cursor is pressed.

An optional parameter defines the mode:

  • modeNormal or false for normal mode;
  • modeInstant or true for instant mode.

Default mode is normal mode.

In normal mode, the element raises the event when the finger is released from the element. Additionally, the element goes through a cinematic sequence.

Start, press, move, release

In instant mode, the element raises the event when the finger touches the element. No cinematic sequence is performed.

Start, press

getValue() gets the value of the cursor element, as a signed 32-bit integer.

Example

This is the core of the code from example GUI_Cursor.ino.

void displayCursor()
{
    myScreen.setOrientation(myOrientation);
    uint16_t x, y, dx, dy;
    int32_t value = 128;

    x = myScreen.screenSizeX();
    y = myScreen.screenSizeY();
    dx = x / 5;
    dy = y / 5;

    myGUI.delegatePartial(false);

    dLabel(0, 0, x, dy, "Cursor", myColours.black, myColours.white, -1, 1, fontLarge);

    text myText;
    myText.dDefine(0, dy, x, dy, 0, 0, fontMedium);

    cursor myCursor;
    myCursor.dDefine(dx, dy * 3, dx * 3, dy, 0, 255);
    myCursor.setOption(optionHorizontal);
    myCursor.setState(stateEnabled);
    myCursor.setValue(value);
    myCursor.draw();

    myText.draw(formatString("%i", value));
    myText.draw();

    drawNext();
    myScreen.flushFast();

    myGUI.delegatePartial(true);
    while (!checkNext())
    {
        if (myCursor.check())
        {
            value = myCursor.getValue();
            myText.draw(formatString("%i", value));
        }
        delay(10);
    }
}
Back to top