.Pressed()

back to Icon

Description

This function is used to check to see if an icon is being touched. It takes inputs for the current x and y positions of the touch and determines if those positions are within the area of the icon. The mode input is used to determine if the icon should alternate between selecting and deselecting with each press (mode = 0) or if the icon should stay in whatever select or deselect state it is in (mode = 1).

Note that the LCD.Touch() function must be called to get touch values for x and y to send into the .Pressed() function. This .Pressed() function does not itself check to see where the LCD is being touched. So, every time the icon should be checked to see if it was pressed, the LCD.Touch() function must be called before the .Pressed() function.

Syntax

.Pressed(float x, float y, int mode);

Parameters

x: float pixel position in x direction of current touch
y: float pixel position in y direction of current touch
mode: integer representing state of pressing where 0 means the icon alternates selecting and deselecting and 1 means it stays the same

Returns

This function returns an integer 1 if the icon is currently being touched and an integer 0 if the icon is not currently being touched.

Examples

#include <FEHLCD.h>

int main(void)
{
    // declare a single icon called software_button
    FEHIcon::Icon software_button;

    // set its parameters with "BUTTON" as the label,
    // top left corner at 120,80 and size 80 by 80,
    // and make the border scarlet and the text gray
    software_button.SetProperties("BUTTON", 120, 80, 80, 80, SCARLET, GRAY);

    // draw the icon
    software_button.Draw();

    // declare int n to keep track of number of presses and
    // floats x and y for touch positions
    int n=0;
    float x, y;

    // continuously check to see if the icon is pressed and
    // increment the number of presses label if so
    while (true)
    {
        LCD.Touch(&x,&y);
        if (software_button.Pressed(x,y,0))
        {
            n++;
            LCD.Clear(BLACK);
            software_button.ChangeLabelInt(n);
        }
    }
}