c. Defining & Using Tags

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 13 - Touch Primitives >

c. Defining & Using Tags

This section shows how to define and use tags.

 

 

Code

 

 

void setup()

{

/* Initialize CleO */

 CleO.begin();

}

 

void display()

{

 /* Start drawing the screen shot */

 CleO.Start();

 CleO.StringExt(FONT_MEDIUM, 160, 50, LIGHT_GREEN, MM, 0, 0, "TOUCH OBJECTS");

 CleO.Tag(1);

 CleO.LineWidth(10);

 CleO.LineColor(DARK_ORANGE);

 CleO.Line(105, 125, 225, 125);

 CleO.Tag(2);

 CleO.PointRadius(20);

 CleO.LineColor(DARK_ORANGE);

 CleO.Point(160, 300);

 CleO.Tag(255);

 

 if (lineTouched)

   CleO.StringExt(FONT_MEDIUM, 160, 200, LIGHT_GREEN, MM, 0, 0,

   "Touching Line");

 

 if (pointTouched)

   CleO.StringExt(FONT_MEDIUM, 160, 400, LIGHT_GREEN, MM, 0, 0,

   "Touching Point");

 

/* Show the screenshot */

 CleO.Show();

}

 

void control()

{

 int16_t x, y, dur, tag, newval;

 CleO.TouchCoordinates(x, y, dur, tag);

 if (tag == 1)

   lineTouched = true;

 else if (tag == 2)

   pointTouched = true;

 else

   pointTouched = lineTouched = false;

}

 

void loop()

{

 display();

 control();

}

 

 

Description

 

Using the Tag(int tag_no) routine, you can draw the CleO primitives which get assigned a tag.

This tag is used to identify touch on drawing.

The display() function draws a line with tag 1 and point with tag 2.

It checks whether these drawings are touched and if so, it creates an effect of a button press.

The control() routine checks for touch using the TouchCoordinates() command and fills up the tag value based on which drawing was touched.

It checks the tag value and updates the boolean to notify which drawing was affected.

 

Note: A tag is applicable on all the objects after which it is used. In this case, the object point (160,300) starts with tag 2 and ends with END tag 255.

 

 

Output

 

Here is the output displayed upon executing the code snippet -

 

3 -DefiningAndUsingTags