Announcement

Collapse
No announcement yet.

Strings object touchable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strings object touchable?

    Are Strings objects touchable?

    Here's what I'm trying to achieve:
    I have a screen with a lot of user-settable values displayed in Strings. A keyboard form will open when a String value is touched, allowing the user to input a new value.

    Can't get this to work:


    in magic preactivate form:

    Code:
    img_ClearAttributes(hndl, iStrings92, I_TOUCH_DISABLE); //enable object

    in magic touch:

    Code:
    if (ImageTouched == iStrings92)
            ActivateForm(9);
            SendReport(REPORT_EVENT,tForm,9,0);
            ImageTouched:=-1;
    endif
    Last edited by jeremywilson; 28 June 2019, 08:19 AM.

  • #2
    Hi Jeremy,

    If you want to raise an event by touching a String, you could try to detect the x + y coordinates of the touch then evaluate if it's within the area of the string.

    You could check the attached sample program for further details.

    I hope this helps.

    Best regards,
    Attached Files
    Last edited by michael_4D; 28 June 2019, 06:28 PM.
    Michael

    Comment


    • #3
      Thanks, Michael.

      x,y coordinates works, but it's not as clean as if touch could be enabled for strings.


      Code:
          // Alarms page 1 (Form 3)
          if (CurrentForm==3)
              temp_var:=0;
              if ((TouchYpos > 95) && (TouchYpos < 150))  // row 1
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=1;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=2;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=3;
                  endif
              else if ((TouchYpos > 150) && (TouchYpos < 205))  // row 2
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=4;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=5;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=6;
                  endif
              else if ((TouchYpos > 205) && (TouchYpos < 260))  // row 3
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=7;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=8;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=9;
                  endif
              else if ((TouchYpos > 260) && (TouchYpos < 315))  // row 4
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=10;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=11;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=12;
                  endif
              else if ((TouchYpos > 315) && (TouchYpos < 370))  // row 5
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=13;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=14;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=15;
                  endif
              else if ((TouchYpos > 370) && (TouchYpos < 420))  // row 6
                  if ((TouchXpos > 136) && (TouchXpos < 281))  // col 1
                      temp_var:=16;
                  else if ((TouchXpos > 281) && (TouchXpos < 431))  // col 2
                      temp_var:=17;
                  else if ((TouchXpos > 431) && (TouchXpos < 511))  // col 3
                      temp_var:=18;
                  endif
              endif
      
              if (temp_var!=0)
                  SendReport(REPORT_EVENT,tForm,3,temp_var);    // report string touched
              endif
          endif

      Click image for larger version

Name:	Capture .JPG
Views:	127
Size:	73.6 KB
ID:	68802
      Attached Files

      Comment


      • #4
        Hi,

        I actually bought 4D Workshop PRO just to be able to make strings touchable, which is widely used on any touch OS I am aware of.
        Now I find out that this does not work with strings for an unknown reason and I have to check the coordinates myself which is annoying, especially when changing display size.
        So why is

        img_ClearAttributes(hndl, iStrings0, I_TOUCH_DISABLE);

        not possible for strings?

        Thanks,

        Anguel

        Comment


        • #5
          Hi Anguel,

          The strings object is an ouptut object and as such has no touch capability

          I have attached an example of an easy way to detect touch on a string where the co-ordinates of the string object is retrieved so there is no issue with display size etc.

          You may be interested in this video of one of our Diablo displays connecting to a wifi access point with an android OS look and feel

          https://www.dropbox.com/s/bs2p4c6nez...ideo1.mp4?dl=0

          I hope this helps

          Best regards

          Paul
          Attached Files

          Comment


          • #6
            Hi Paul,

            Many thanks for the code, this works great now! Is this using some undocumented functions?

            BTW: In the meantime I tried to detect touches from Strings objects by using coordinates and touch_Get() methods inserted in MainLoop, similar to the example above and 4D-AN-00054, but this seems to interfere somehow with the normal touch events and leaded to "missed" touches.

            Regarding the Android access point emulation video: This is really amazing, do you have this application example somewhere to download?

            Many thanks,

            Anguel

            Comment


            • #7
              Hi Anguel,

              The function in MagicCode0 is using the generated code from genie in particular the data created for the Strings object.

              It is always better to use the Magic Touch, Magic Move, Magic Release for adding your own touch code. If you use a touch_Get() in the mainloop it will interfere with the Genie touch routines. There are 3 variables available to use

              ImageTouched
              TouchXpos
              TouchYpos

              Thanks for your comments on the Access Point video. The access point code is a work in progress and I will surely send you the application example when complete.

              Best regards

              Paul

              Comment


              • #8
                Hi Paul,

                Thank you for the information, I did not read about this approach in the forum so far.
                So you seem to be accessing the following data to read the coordinates of the object (if I understand):
                x1 := strNum[6];
                y1 := strNum[8];
                x2 := strNum[10];
                y2 := strNum[12];

                Is it documented somewhere where I can find more info about this? I am a little confused where you get these values from.
                For example, I would also like to do the same touch detection for static text and images if possible in magic code.

                Thanks in advance,

                Anguel

                Comment


                • #9
                  Hi Anguel,

                  It isn't documented but I will look into it and see if we can create an appnote etc. The question has been asked before so the function would be useful to others.

                  Static text is rendered into an image so the co-ordinates are a little different. I added a function to the example for this. You could use this function for images also.

                  Best regards

                  Paul
                  Attached Files

                  Comment


                  • #10
                    Many thanks, Paul!
                    This is great. These are nice touchscreens, so yes, users expect everything to be touchable ;-)
                    Now the only wish I have is being able to use alias names instead of the cryptic iStringsX or iStatictextX, etc.
                    Maybe you have an idea? I have already posted my question here:
                    https://forum.4dsystems.com.au/node/72563
                    But the answer does not seem to cover the iStringX aliases, I see similar iObjectX aliases being generated in GCIConst.inc but not iStringX.
                    Maybe you have an idea?

                    Thanks,
                    Anguel

                    Comment


                    • #11
                      Hi Anguel,

                      The Strings object is handled differently as it isn't a GCI object but I will certainly have a look into it.

                      Best regards

                      Paul

                      Comment


                      • #12
                        Hi Paul,

                        Thanks, I think it would be a great idea to be able to somehow access the alias names for strings from code. Working with and maintaining the internal string names on multiple forms is much additional work and often leads to confusion.

                        Thanks,
                        Anguel

                        Comment


                        • #13
                          I see, that magic object aliases are also not output to the constants files. Why don't you just output all indices for all object types listed under
                          6.3. Genie Magic Useful Constants
                          This way the user can make use of all alias names he has defined in Workshop and does not have to rely on numeric indices that may change from project to project or even inside a project.

                          Comment


                          • #14
                            Thanks for reporting this, we will ensure it is fixed for the next Workshop release.
                            Mark

                            Comment


                            • Anguel
                              Anguel commented
                              Editing a comment
                              Great! Thanks!

                          • #15
                            Exactly where are the wrong constants generated?

                            It all seems to work as far as I can see
                            Mark

                            Comment

                            Working...
                            X