No announcement yet.


  • Filter
  • Time
  • Show
Clear All
new posts

  • img_Touched

    I populate the screen with several images, and using img_Touched want to retrieve the index number of any one of the images touched.This function works as expected when the index for a specific image is passed to the function, as in the following code snippet.

    state := touch_Get(TOUCH_STATUS); // we'll look for any touch activity
    if (state == TOUCH_PRESS)
    index := img_Touched(j, 5
    ); // pass image index "5"
    print (index,"\n"); // will print "5" if the image was touched, "-1" if not

    However in the 4DGL manual it states that passing an index value of "-1", will return the index for any displayed image.

    The following code does not function as expected, since any press, anywhere on the screen, including an image returns and prints "0".

    state := touch_Get(TOUCH_STATUS); // we'll look for any touch activity
    if (state == TOUCH_PRESS)
    index := img_Touched(j, -1
    ); // pass image index "-1" to watch for all images
    print (index,"\n"); // should return "x" = index of any image pressed,
    // or "-1" if no image pressed

    Did I incorrectly interpret the manual, make code mistake, or is this a bug with this function?


  • #2


    In a previous thread, you said that you had been able to run the sample program: "TestImageControl.4dg". That program uses the ing_Touched command to determine which image is touched. The sample program uses the defined constant "ALL", but I've tested the code using -1 also and it works as advertised.

    Can you try TestImageControl.4dg again and see if it runs OK? If it does, that would indicate that the problem is in the code that you posted parts of here.

    Hint (and this bites me all the time The 4DGL compiler still does not always pick up all syntax errors in the code. It will sometimes miss a missing ";" somewhere in your code. This can cause problems that are very hard to diagnose.

    Any technology, sufficiently developed, is indistinguishable from magic. A.C. Clark(RIP)

    NEW! Lower prices on all 4D Systems products for 2009 and continuing into 2010!


    • #3

      This is another 4DGL learning the hopes that this will expedite others learning I am posting this.

      A  fullscreen image and some smaller button images are loaded on the card .
      The fullscreen image may or may not be displayed as a backdrop depending on user navigation thru the different page views.

      In my case the fullscreen image was index "0", with button images indexed from 1....

      imgCtrl := file_ImageControl;
      img_SetPosition( imgCtrl, 1,x,y);

      index := (n,-1)

      function will return index "0" when the screen is pressed anywhere.
      In otherwords, even if the fullscreen image is never displayed using img_Show, but a button image, or blank screen area is pressed, the fullscreen image index is returned.

      img_Disable(imgCtrl, 0);
      index := (n,-1)

      You must disable all other images that you do not want to return an index if touched, whether they are displayed or not, if you wish to make use of the function.
      If you want a backdrop, display the backdrop, then disable it, then display and monitor your other touch active images.