Author Topic: Locate:  (Read 5672 times)

0 Members and 1 Guest are viewing this topic.

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Locate:
« on: December 27, 2021, 08:21:29 pm »
Does qb64 have a option similar to _Printstring (x-pixel,y-pixel) for Locate.
I often need to use something like "Input N$" but need to place it at a [x y]
position.  If not, maybe it could be added to the next release.

R1

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Locate:
« Reply #1 on: December 27, 2021, 09:11:37 pm »
I made my own graphics input that can do fonts:
Code: QB64: [Select]
  1. _Title "fINPUT testing brief" 'B+ started 2020-06-29 cut stuff 2021-12-27
  2.  
  3. Const xmax = 1000, ymax = 500
  4. Screen _NewImage(xmax, ymax, 32)
  5. _Delay .25
  6.  
  7. Dim f36 As Long, myStr$
  8. f36 = _LoadFont("Arial.ttf", 36) ' everyone has this right?
  9. Color &HFFFFFF00, &HFF880000
  10. While _KeyDown(27) = 0
  11.     Cls
  12.     myStr$ = fINPUT$(f36, &HFF9999FF, 200, 250, "Enter name: ")
  13.     Print "fInput returned: "; myStr$
  14.     Print "screen will clear in 3 secs..."
  15.     _Delay 3
  16.  
  17. Function fINPUT$ (fh&, foreColor~&, x, y, prompt$)
  18.     Dim oldFont&, oldBC~&, oldFC~&, olddisplay, screenshot&
  19.     Dim done As _Byte, OK$, k$, t$
  20.     oldFont& = _Font '_printwidth(s$, desth&)
  21.     oldBC~& = _BackgroundColor
  22.     oldFC~& = _DefaultColor
  23.     olddisplay = _AutoDisplay
  24.     screenshot& = _NewImage(_Width, _Height, 32)
  25.     _PutImage , 0, screenshot&
  26.     _Font fh& 'get measures
  27.     Color foreColor~&, 0
  28.  
  29.     _PrintString (x, y), prompt$ + " {} "
  30.     OK$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"
  31.     OK$ = OK$ + Chr$(8) + Chr$(27) + Chr$(13) + "1234567890!@#$%^&*()_-+={}[]|\:;'<,>.?/"
  32.     Do
  33.         _PutImage , screenshot&, 0
  34.         k$ = InKey$
  35.         If InStr(OK$, k$) Then
  36.             If k$ = Chr$(8) Then
  37.                 If t$ <> "" Then
  38.                     If Len(t$) = 1 Then t$ = "" Else t$ = Left$(t$, Len(t$) - 1)
  39.                 End If
  40.             Else
  41.                 If k$ = Chr$(13) Or k$ = Chr$(27) Then
  42.                     If k$ = Chr$(27) Then t$ = ""
  43.                     Exit Do
  44.                 Else
  45.                     t$ = t$ + k$
  46.                 End If
  47.             End If
  48.             _PrintString (x, y), prompt$ + " {" + t$ + "}"
  49.             k$ = ""
  50.         End If
  51.         _Limit 60
  52.         _Display
  53.     Loop Until done
  54.     fINPUT$ = t$ 'return the sub's var$ with desired entered or escape string.
  55.  
  56.     'restore
  57.     If olddisplay Then _AutoDisplay
  58.     _FreeImage screenshot&
  59.     Color oldFC~&, oldBC~&
  60.     _Font oldFont&
  61.  
  62.  

Also have an Input box that doesn't mess up your screen and that you can drag around the screen.

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Re: Locate:
« Reply #2 on: December 27, 2021, 11:13:26 pm »
bplus

This is what I am using now.  I thought there might be a keyword i was missing.
Hitting the return key exits the loop so it works much like line input.  I would
like to see a keyword option like _Locatexy which would work like the code
below.

R1

syntax would look something like -> locatexy(10,10), input n$

Code: QB64: [Select]
  1. KEYLIST$=".+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  2. KEY1$=""
  3. IF INSTR(KEYLIST$,K$) < 1 THEN EXIT DO
  4. KEY1$=KEY1$+K$
  5. _PRINTSTRING (10,10), KEY1$
  6.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Locate:
« Reply #3 on: December 28, 2021, 03:14:55 am »
Quote
K$=RIGHT$(INKEY$,1)
IF INSTR(KEYLIST$,K$) < 1 THEN EXIT DO
WOW
that is the first time that I see a code that shows why  returning TRUE (-1) from INSTR is useful when the searched string is void ("").

Thanks random1

PostScriptum 1: is it less complicated than the use of IMP?  Maybe it is.

PostScriptum 2: surely here you write
Quote
locatexy(10,10), input n$
  but you would type
Code: QB64: [Select]
  1. locatexy(10,10): input n$
  2.  
because locatexy moves the position of cursor, and it is for input and output.
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: Locate:
« Reply #4 on: December 28, 2021, 04:31:31 am »
Am I missing something, or is this as simple as:


InputString 10, 10, "What is your name", user$
Print "Your name is "; user$

SUB InputString (x, y, prompt$, return$)
   LOCATE x, y
   INPUT prompt$, return$
END SUB
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Re: Locate:
« Reply #5 on: December 28, 2021, 07:17:07 am »
SMcNeill

Locate y,x gives you row and column not the x,y pixel position.

R1


Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Re: Locate:
« Reply #6 on: December 28, 2021, 07:22:17 am »
TempodiBasic

It took me forever to get use to _printstring (x,y) as locate always used Locate y,x, LOL
Yes, I should have used Locatexy (10,10):


R1
« Last Edit: December 28, 2021, 07:27:18 am by random1 »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Locate:
« Reply #7 on: December 28, 2021, 09:05:50 am »
SMcNeill

Locate y,x gives you row and column not the x,y pixel position.

R1

Then just reverse them in your SUB:

InputString 10, 10, "What is your name", user$
Print "Your name is "; user$

SUB InputString (x, y, prompt$, return$)
   LOCATE y, x
   INPUT prompt$, return$
END SUB
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Re: Locate:
« Reply #8 on: December 29, 2021, 02:22:05 am »

Locate y, x gives us the row and column of a fixed grid so to say. Lets say that I have
a input cell box that is not aligned with the grid.   In the old days we used locate and
print which was also tied to a grid, _printstring removed that limitation and we can
now print to any location.  All I am saying is that Locate could be updated to select
the x and y pixel location instead of the y,x grid. 

R1
     

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Locate:
« Reply #9 on: December 29, 2021, 02:51:21 am »
Locate y, x gives us the row and column of a fixed grid so to say. Lets say that I have
a input cell box that is not aligned with the grid.   In the old days we used locate and
print which was also tied to a grid, _printstring removed that limitation and we can
now print to any location.  All I am saying is that Locate could be updated to select
the x and y pixel location instead of the y,x grid. 

R1
   

That won't happen without breaking legacy code.  QB45 has locate work by character position; not pixel position.  If you absolutely must have an input that's pixel-precise, you'll want to write your own routine for that.  I've got a few on here for that purpose.  Terry Ritchie has a GLINPUT library (Graphic Line Input).  Several options already exist out there, if you don't want to roll your own.

Side note:  If you use non-monospaced fonts, LOCATE drops legacy support and offers pixel precision placement on the x-axis.  Y-axis is still by row, however.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Locate:
« Reply #10 on: December 29, 2021, 08:00:13 am »
I've occasionally thought that an "_INPUTSTRING(x,y), in$,etc." would be kinda nice, but after all is said and done, I really don't like INPUT to begin with. I use it for quickies and unsophisticated stuff, but I prefer properly constrained and conditioned input for important UI. I'm sure it's nice for freeing up clock cycles to the system and all, when it's waiting on us molasses slow humans, but we have _LIMIT for that.

I recently used an approach somewhat similar to the fINPUT$ function that Bplus posted. His is much nicer and more complete. Mine built an input string a character at a time from allowable possibilities. fINPUT$ has a similar algo at its core. Used in a display loop, the string it creates can be placed anywhere via _PRINTSTRING and doesn't have to interfere with other loop inputs, like mouse ops. It won't accept characters improper to the input sought, and can be dealt with appropriately as a string or VAL'd for numerical input.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(400, 400, 32)
  2. xp% = 0: yp% = 0
  3.     CLS
  4.     x$ = INKEY$
  5.         xp% = _MOUSEX: yp% = _MOUSEY
  6.     END IF
  7.     IF x$ <> "" THEN
  8.         IF x$ = CHR$(13) THEN
  9.             EXIT DO
  10.         ELSE
  11.             Build_Str b$, "0123456789.", x$
  12.         END IF
  13.     END IF
  14.     _PRINTSTRING (xp%, yp%), b$
  15.     _LIMIT 30
  16.     _DISPLAY
  17. PRINT "You entered "; b$; " @ ("; xp%; ","; yp%; ")"
  18.  
  19. SUB Build_Str (main AS STRING, allow AS STRING, kp AS STRING)
  20.  
  21.     'Build a string out of allowable characters(allow) received via keypress(kp), return in 'main'
  22.     SELECT CASE kp '                                            keypress as case selection
  23.         CASE IS = CHR$(8) '                                     if backspace pressed
  24.             IF LEN(main) > 0 THEN '                             and main string exists
  25.                 main = LEFT$(main, LEN(main) - 1) '             remove rightmost character
  26.             END IF '
  27.         CASE ELSE '                                             if anything other than backspace
  28.             IF INSTR(allow, kp) <> 0 THEN '                     if an allowable character has been pressed
  29.                 main = main + _TRIM$(kp) '                      add it to main string
  30.             END IF '
  31.     END SELECT '
  32.     kp = "" '                                                   clear the input
  33.  
  34. END SUB 'Build_Str
  35.  

INPUT is just a loop awaiting a keypress to respond with an appended echo, so I just take those reins and do it myself. It's certainly more work, but it's just one of those things you develop to your taste and put in an $INCLUDE library or a cut and paste template.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Locate:
« Reply #11 on: December 29, 2021, 10:32:00 am »
Yeah, the beauty of DIY is you can modify it to the particular needs of the app.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Locate:
« Reply #12 on: December 29, 2021, 01:09:14 pm »
Just thinking out loud, but...

Since there seems to be a precedent set with WIDTH & _WIDTH

Would having a LOCATE & _LOCATE create too many development challenges and/or confusion?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Locate:
« Reply #13 on: December 29, 2021, 01:38:20 pm »
How does that work when people choose the option not to use the _underlines?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Locate:
« Reply #14 on: December 29, 2021, 04:30:28 pm »
How does that work when people choose the option not to use the _underlines?

In this case, Width is a SUB and _WIDTH is a function.  The parser differentiates the two by usage.

LOCATE and _LOCATE, however, would both be Subs and wouldn't work.  Even bigger problem would be that the internals would need a complete overhaul...

For example, let's LOCATE 3 pixels right, 3 pixels down and PRINT "foo".

The way things are now, we increase ROW by one, so we can print in the proper spot below it on the next line.  Only problem here is we've offset 3 pixels below a normal row...

What should CSRLIN and POS print for us?  How do we track that 3 pixel offset?  With _FONT 8, width and height of a font is 8 pixels...   Normally we print at ROW 1, COLUMN 1 (0, 0 pixels), hit ENTER, and move down to ROW 2...

But here, we located to 3,3 before printing.

Does the next row start at 8 pixels like usual?  Do we go in and make CSRLIN and POS report SINGLE values?  We're at row 1.4, column 1.4? 

All these commands are interconnected and work off the premise of ROW and COLUMN coordinates.   Once LOCATE changes, all of their underlying structures change as well.

Now, somebody will ask, "WHY DO WE HAVE A _PRINTSTRING COMMAND THEN?"

The answer to that is, "It exists outside LOCATE, CSRLIN, POS, POINT, SCREEN, and all those other interconnected commands."

Try this:

LOCATE 10, 10
_PRINTSTRING (1, 1), "Test"
PRINT "Foo"

Where does that Foo print?  Down on line 2, below the Test from _PRINTSTRING?  Or is it in relationto that last LOCATE at 10, 10, and completely unaffected by that Test??

Our LOCATE coordinate system is integer-based, and dependent on _FONTHEIGHT and _FONTWIDTH.  To change it to pixel-based, you'd need to alter all the existing code to swap from grid-coordinates over to pixel-coordinates...

Anyone want to volunteer to do that?  All I can say is it won't be me.  I don't have the time to undertake such a massive alteration for something which I doubt I'd ever use at all.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!