Author Topic: _PRINTSTRING For INPUT  (Read 4026 times)

0 Members and 1 Guest are viewing this topic.

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
_PRINTSTRING For INPUT
« on: November 01, 2019, 04:11:23 am »
Hey,
Is there a command like _PRINTSTRING that allows coordinate placement of text but for INPUT?
I am aware of LOCATE, but it doesnt use screen coordinates. If there isnt a way to do this, is there a way to convert LOCATE coords to _PRINTSCREEN coords?

Thanks,
Zep
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

FellippeHeitor

  • Guest
Re: _PRINTSTRING For INPUT
« Reply #1 on: November 01, 2019, 04:22:25 am »
LOCATE row, col: PRINT text$ 'is the same as
_PRINTSTRING (col * _FONTWIDTH - _FONTWIDTH, row * _FONTHEIGHT - _FONTHEIGHT), text$ 'provided you’re using a fixed-width font

I just don’t know if INPUT will continue from the last _PRINTSTRING coordinates. You’ll have to try it out. (I have a hunch it won’t).
« Last Edit: November 01, 2019, 04:33:22 am by FellippeHeitor »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: _PRINTSTRING For INPUT
« Reply #2 on: November 01, 2019, 07:56:33 am »
Hi Zeppelin
...about use of INPUT
I find INPUT treacherouse!

Why? Because
1. when you use INPUT your control of flow of program is suspended
2. if you press RETURN key the output text is a new line... so how do you have control of the output in your program interface?
3. if you, user of the program, give the erroneous input type , INPUT goes ahead asking again input from user... also this is out of control and creates problems with your interface of program
IMHO
so  INPUT is good only for programs with text line of output i.e. the command line of old OSes
It seems that you have to use INPUT in a graphic interface... evaluate your conditions
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _PRINTSTRING For INPUT
« Reply #3 on: November 01, 2019, 10:18:15 am »
You might want to check out Terry Ritchie’s Input library.  It has graphic coordinate input in it,
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: _PRINTSTRING For INPUT
« Reply #4 on: November 01, 2019, 11:31:26 am »
Hi again
here an example of a new INPUT function in graphic mode 32 bit

Code: QB64: [Select]
  1. REM a function alternative to old INPUT of QBasic
  2. REM              must return the type of data of request   -->not yet implemented
  3. REM          for now user gets back a string to be converted to desidered data type
  4. REM          for now programmer can define desidered input with Krange string
  5. REM              must accept the  range of key interesting for input
  6. REM              must permit to correct the input of user before to press Return
  7. REM              must control the max input keys
  8. REM              ends to input after return key is pressed
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. _PRINTSTRING (100, 100), "What is your age?"
  12. result$ = __NewInput$("I", "0123456789", 4, 100, 200, _RGBA32(200, 200, 10, 255), _RGBA(0, 10, 100, 255))
  13. _PRINTSTRING (100, 300), "Your age is " + result$
  14.  
  15.  
  16. FUNCTION __NewInput$ (Dtype AS STRING, Krange AS STRING, Kmax AS INTEGER, Xinp AS INTEGER, Yinp AS INTEGER, Forecol AS _UNSIGNED LONG, Backcol AS _UNSIGNED LONG)
  17.     CONST Back = 8, Enter = 13, Del = 21248, Right = 19712, Left = 19200
  18.     DIM temp$, InK AS SINGLE, Xpos AS SINGLE, Mcol AS _UNSIGNED LONG
  19.     temp$ = "": InK = 0: Xpos = 0: Mcol = INT(Forecol + Backcol / 2)
  20.     COLOR Forecol, Backcol
  21.     DO
  22.         _LIMIT 30
  23.         InK = _KEYHIT
  24.         IF InK < 256 AND InK > 13 THEN
  25.             ' is a character to get?
  26.             IF INSTR(Krange, CHR$(InK)) AND LEN(temp$) < Kmax THEN
  27.                 ' is a charachter of interest to get?
  28.                 temp$ = temp$ + CHR$(InK)
  29.                 Xpos = LEN(temp$)
  30.             END IF
  31.         ELSE
  32.             ' backspace
  33.             IF InK = 8 THEN temp$ = LEFT$(temp$, Xpos - 2) + RIGHT$(temp$, LEN(temp$) - Xpos + 1): Xpos = Xpos - 1: IF Xpos < 0 THEN Xpos = 1
  34.             ' right arrow
  35.             IF InK = Right THEN IF Xpos < LEN(temp$) THEN Xpos = Xpos + 1
  36.             ' left arrow
  37.             IF InK = Left THEN IF Xpos > 1 THEN Xpos = Xpos - 1
  38.             'Delete
  39.             IF InK = Del THEN
  40.                 IF Xpos <= LEN(temp$) THEN temp$ = LEFT$(temp$, Xpos - 1) + RIGHT$(temp$, LEN(temp$) - Xpos)
  41.             END IF
  42.         END IF
  43.         ' output for feedback to user
  44.         _PRINTSTRING (Xinp, Yinp), SPACE$(LEN(temp$) + 1)
  45.         _PRINTSTRING (Xinp, Yinp), temp$
  46.         ' output of cursor's position
  47.         COLOR Mcol
  48.         _PRINTSTRING (Xinp + (Xpos * _FONTWIDTH - _FONTWIDTH), Yinp), MID$(temp$, Xpos, 1)
  49.         COLOR Forecol
  50.     LOOP UNTIL InK = Enter AND LEN(temp$) <= Kmax
  51.     __NewInput$ = temp$

I'ld see the function of Terry's Input library.. I'll search it.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: _PRINTSTRING For INPUT
« Reply #5 on: November 01, 2019, 12:22:02 pm »
Yeah, I've done this for different Basic's, here is a quicky I wrote up this morning for QB64, I see TempodiBasic has already posted one ;-)

Code: QB64: [Select]
  1. _TITLE "Graphics Input, inputG test" 'b+ 2019-11-01
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 20
  4. y = 200: x = 100
  5.     P$ = "Enter something like *testing 1, 2, 3... * about 20 chars max > "
  6.     expectedEnterLen% = 20
  7.     inputG x, y, P$, inpt$, expectedEnterLen%
  8.     IF inpt$ = "" THEN EXIT DO
  9.     PRINT "You entered: "; inpt$
  10.     y = y + 25
  11.     x = x + 30
  12.     IF x + (LEN(P$) + expectedEnterLen% + 5) * 8 > _WIDTH THEN x = 1
  13. PRINT "Test is done when empty string returned by inputG."
  14.  
  15. 'INPUT for Graphics screen
  16. SUB inputG (x, y, prmpt$, var$, expectedLenVar%) 'input for a graphics screen x, y is where the prompt will start , returns through var$
  17.     DIM tmp$, k$
  18.     saveAD = _AUTODISPLAY
  19.     _KEYCLEAR
  20.     _PRINTSTRING (x, y), prmpt$ + " {}"
  21.     DO
  22.         k$ = INKEY$
  23.         IF LEN(k$) THEN
  24.             SELECT CASE ASC(k$)
  25.                 CASE 13: var$ = tmp$: EXIT SUB
  26.                 CASE 27: var$ = "": EXIT SUB
  27.                 CASE 8 'backspace
  28.                     IF LEN(tmp$) THEN
  29.                         IF LEN(tmp$) = 1 THEN tmp$ = "" ELSE tmp$ = LEFT$(tmp$, LEN(tmp$) - 1)
  30.                     END IF
  31.                 CASE ELSE: tmp$ = tmp$ + k$
  32.             END SELECT
  33.             _PRINTSTRING (x, y), prmpt$ + " {" + tmp$ + "}" + SPACE$(expectedLenVar% - LEN(tmp$)) 'spaces needed at end to clear backspace chars
  34.             IF saveAD <> -1 THEN _DISPLAY
  35.         END IF
  36.     LOOP
  37.  
  38.  

You can modify for your needs eg adding colors and anticolors in user input section,
but this demos the general idea of doing this and should serve basic needs.