Detect Touch in TEXT Mode

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Detect Touch in TEXT Mode

Post by rbytes »

I posted a similar comment in Libraries, but wanted to be sure Mr. K and Dutchman were aware of it. The documentation for TOUCH commands says that they don't work in text mode. But they do under special conditions, opening up new possibilities for user control on a TEXT screen.

The trick is to create a field on the TEXT screen. It can be as tiny as 1 x 1 points and located at a screen corner. That activates the whole screen for detecting touches! In fact I just tested again with the field entirely outside the visible screen area (ie. made the field x coordinate a negative number.) The TOUCH commands still work.

Here is some code to demonstrate:

Code: Select all

/*
Touch in Text Mode
rbytes, February 2019
*/
FIELD "activate" TEXT "" AT 0,0 SIZE 1,1
PRINT "Touch with one finger to get screen coordinates in TEXT mode."
PRINT "Touch with two fingers to quit."
PRINT
DO SLOWDOWN
GET TOUCH 0 as x,y
GET TOUCH 1 as ox,oy
if x>-1 or y>-1 then print x,y
if ox>-1 then end
UNTIL 0
Attachments
272FBAEF-0791-43E9-A001-DDC4ACC15D76.png
272FBAEF-0791-43E9-A001-DDC4ACC15D76.png (153.38 KiB) Viewed 2451 times
The only thing that gets me down is gravity...

matt7
Posts: 115
Joined: Sun Jul 12, 2015 5:00 pm
My devices: iPhone
Location: USA

Re: Detect Touch in TEXT Mode

Post by matt7 »

Interesting. I think this is happening because when you create the field (this would probably work for any interface object), SB creates a page to put it on. That page by default is fullscreen and transparent, allowing the TEXT screen below to still be visible, but touches now hit the invisible page before they hit the TEXT screen. The trade off here is that the normal behavior of touching the TEXT screen is lost (highlighting/selecting text, moving a selection handle, scrolling, etc.).
Every created interface object belongs to currently active page. Pages can be created and manipulated by PAGE commands. If interface object, for example button, is created, but there are no any pages yet, then default page is created with empty name "", transparent background and fullscreen size. Active page covers other pages which are located below even if it has transparent background.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Detect Touch in TEXT Mode

Post by rbytes »

Those aren't usually reasons why I choose text mode, but they are still achievable if instead of accepting the default page generated by an interface object, you create a page yourself at a location other than 0,0.

Run this code and you will see that you can touch the new page (colored pink) to get screen coordinates or use 2 fingers to quit.

A very cool feature. Start a 1 finger touch on the pink page then drag your finger anywhere on screen. You will still see the correct screen coordinates print!

But as soon as you release your touch the text page behaves like a text page, and you can interact with the text (eg. scroll, select, copy or paste).

There is one limitation on the new page that you define. It cannot be adjusted in size with the FRAME command. It is always screen-sized. But it can be relocated to either side, placed at top or bottom or moved to any corner to serve as a control area.

Code: Select all

/*
Touch in Text Mode 2
rbytes, February 2019
*/
get screen size sw,sh
Page "new" SET ! PAGE "new" show
page "new" color 1,.8,.8,1
page "new" at sw/2,sh/2

PRINT "  The white area is a text page."
PRINT "  The pink page is a control page."
PRINT
PRINT "1. Touch the control page and then drag anywhere with one finger."
PRINT "   You will see the screen coordinates print on the text screen."
PRINT "2. Double tap any text on the text page."
PRINT "   You can select, copy and paste the text."
PRINT "3. Print screen coordinates to overfill the screen."
PRINT "   Then scroll the text page up and down."
PRINT "4. Touch the control page with two fingers to quit."
PRINT
DO SLOWDOWN
GET TOUCH 0 as x,y
GET TOUCH 1 as ox,oy
if x>-1 or y>-1 then
print x, y
endif
if ox>-1 then ! text clear ! end ! endif
UNTIL 0
Attachments
93B4094A-C671-4AE9-8C9F-3F5CB84E9E6B.png
93B4094A-C671-4AE9-8C9F-3F5CB84E9E6B.png (133.98 KiB) Viewed 2411 times
Last edited by rbytes on Tue Feb 05, 2019 5:24 am, edited 3 times in total.
The only thing that gets me down is gravity...

matt7
Posts: 115
Joined: Sun Jul 12, 2015 5:00 pm
My devices: iPhone
Location: USA

Re: Detect Touch in TEXT Mode

Post by matt7 »

Good observation. The key is where the touch starts. If it starts on a page, then you can get the touch coordinates for that touch no matter where the touch moves on the screen (including off the page). But if the touch starts in an editable field (user-created interface object) or in the TEXT mode "field" due to no pages being at the touch location, then the touch will interact with the field and its text and not produce coordinates.

I can think of situations where you might want one or the other. Sometimes I build a quick script that spits out code or DATA, which I then copy out of the TEXT screen and paste into another program. Other times I have a test program that prints output to the screen (and I only need to be able to read it), but I want to control when the next iteration occurs. Using this method, it looks like it is simple to just create a transparent page and have the code wait for a touch to proceed.

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Detect Touch in TEXT Mode

Post by Dutchman »

I have added a note on page 18 in the updated manual.
See viewtopic.php?f=79&p=13920#p13920
Last edited by Dutchman on Thu Jan 19, 2023 3:51 pm, edited 1 time in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Detect Touch in TEXT Mode

Post by rbytes »

One further improvement to my code in this topic. I was mistaken that the first page created on a text screen had to be the full size of the screen. It was just a misunderstanding about where and how the command PAGE N$ FRAME X,Y, W,H can be used. It can't create a page of a certain shape. But if that page is already created with the PAGE N$ SET command, the FRAME command can resize it. So now the control page only needs to be a small square. Dutchman, the information about the FRAME command limitation should be added to the PDF manual.

Code: Select all

/*
Touch in Text Mode 3
rbytes, February 2019
*/
get screen size sw,sh
Page "new" SET ! PAGE "new" show
page "new" color 1,.8,.8,1
page "new" frame sw/2-sw/8,sh/2-sh/8,sw/4,sh/4
'page "new" at sw/2,sh/2


PRINT "  The white area is a text page."
PRINT "  The pink page is a control page."
PRINT
PRINT "1. Touch the control page and then drag anywhere with one finger."
PRINT "   You will see the screen coordinates print on the text screen."
PRINT "2. Double tap any text on the text page."
PRINT "   You can select, copy and paste the text."
PRINT "3. Print screen coordinates to overfill the screen."
PRINT "   Then scroll the text page up and down."
PRINT "4. Touch the control page with two fingers to quit."
PRINT
DO SLOWDOWN
GET TOUCH 0 as x,y
GET TOUCH 1 as ox,oy
if x>-1 or y>-1 then
print x, y
endif
if ox>-1 then ! text clear ! end ! endif
UNTIL 0
Attachments
5B2A1CB9-F3A2-42D3-8800-8DDC12B32567.png
5B2A1CB9-F3A2-42D3-8800-8DDC12B32567.png (134.49 KiB) Viewed 2404 times
The only thing that gets me down is gravity...

Post Reply