Skip to content

Cursor

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

Configure

Warning

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

Cursor myCursor(&myGUI);

The constructor Cursor() creates a cursor and sets the link to the GUI myGUI.

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.

Note

Use literals instead of values for upward compatibility.

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.

Note

Use literals instead of values for upward compatibility.

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 of how the element is checked:

  • checkNormal for normal check mode;

  • checkInstant for instant check mode.

Default mode is normal check mode.

In normal check 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 check mode, the element raises the event when the finger touches the element. No cinematic sequence is performed.

Start, press

The technical note Optimise GUI speed provides more details on the cinematic sequences of each check mode.

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.delegate(false);

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

    Text myText(&myGUI);
    myText.dDefine(0, dy, x, dy, 0, 0, fontMedium);

    Cursor myCursor(&myGUI);
    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.delegate(true);

    while (!checkNext())
    {
        if (myCursor.check())
        {
            value = myCursor.getValue();
            myText.draw(formatString("%i", value));
        }
        hV_HAL_delayMilliseconds(10);
    }
}