LOCATE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 17: Line 17:
* In [[_NEWIMAGE]] graphic screen the number of text ''rows'' are calculated as [[_HEIGHT]] \ 16 except when a [[_FONT]] is used. Use [[_FONTHEIGHT]] to calculate font rows.
* In [[_NEWIMAGE]] graphic screen the number of text ''rows'' are calculated as [[_HEIGHT]] \ 16 except when a [[_FONT]] is used. Use [[_FONTHEIGHT]] to calculate font rows.
* [[_NEWIMAGE]] graphic screen text ''columns'' are calculated as [[_WIDTH (function)|_WIDTH]] \ 8 except when a [[_FONT]] is used. Use [[_PRINTWIDTH]] to measure a line of font text.
* [[_NEWIMAGE]] graphic screen text ''columns'' are calculated as [[_WIDTH (function)|_WIDTH]] \ 8 except when a [[_FONT]] is used. Use [[_PRINTWIDTH]] to measure a line of font text.
** Additionally, when a variable width [[_FONT]] is active, then the ''columns'' are not counted as char positions anymore but as pixel positions instead.
* The text ''row'' position is not required if the [[PRINT]] is going to be on the next row. The [[comma]] and a ''column'' value are required to set the column.
* The text ''row'' position is not required if the [[PRINT]] is going to be on the next row. The [[comma]] and a ''column'' value are required to set the column.
* If only the ''row'' parameter is given, then the column position remains the same. '''Neither ''row'' or ''column'' parameter can be 0.'''
* If only the ''row'' parameter is given, then the column position remains the same. '''Neither ''row'' or ''column'' parameter can be 0.'''
Line 22: Line 23:
* If the {{Parameter|cursorStart%}} line is given, the {{Parameter|cursorStop%}} line must also be given. A wider range between them produces a taller cursor.
* If the {{Parameter|cursorStart%}} line is given, the {{Parameter|cursorStop%}} line must also be given. A wider range between them produces a taller cursor.
* If you use LOCATE beyond the current number of rows in text mode, QB64 will try to adapt the screen instead of tossing an error.
* If you use LOCATE beyond the current number of rows in text mode, QB64 will try to adapt the screen instead of tossing an error.
* When writing to the console, only the ''row'' and ''column'' arguments are used, all others are ignored. Furthermore, on non-Windows systems LOCATE statements that do not give both a ''row'' and ''column'' will be ignored entirely.




Line 27: Line 29:
''Example:'' Moving the cursor around (now you can finally create a Commodore 64 emulator!). '''Default SCREEN 0 only:'''
''Example:'' Moving the cursor around (now you can finally create a Commodore 64 emulator!). '''Default SCREEN 0 only:'''
{{CodeStart}}
{{CodeStart}}
crx = 10
crx = {{Text|10|#F580B1}}
cry = 10
cry = {{Text|10|#F580B1}}
DO
{{Cl|DO}}
  {{Cl|LOCATE}} cry, crx, 1, 0, 8
    {{Cl|LOCATE}} cry, crx, {{Text|1|#F580B1}}, {{Text|0|#F580B1}}, {{Text|8|#F580B1}}
  a$ = {{Cl|INKEY$}}
    a$ = {{Cl|INKEY$}}
  {{Cl|SELECT CASE}} a$
    {{Cl|SELECT CASE}} a$
    {{Cl|CASE}} {{Cl|CHR$}}(0) + "H": {{Cl|IF...THEN|IF}} cry > 1 {{Cl|THEN}} cry = cry - 1 'up
        {{Cl|CASE}} {{Cl|CHR$}}({{Text|0|#F580B1}}) + {{Text|<nowiki>"H"</nowiki>|#FFB100}}: {{Cl|IF}} cry > {{Text|1|#F580B1}} {{Cl|THEN}} cry = cry - {{Text|1|#F580B1}} {{Text|<nowiki>'up</nowiki>|#919191}}
    {{Cl|CASE}} {{Cl|CHR$}}(0) + "P": {{Cl|IF...THEN|IF}} cry < 25 {{Cl|THEN}} cry = cry + 1 'down
        {{Cl|CASE}} {{Cl|CHR$}}({{Text|0|#F580B1}}) + {{Text|<nowiki>"P"</nowiki>|#FFB100}}: {{Cl|IF}} cry < {{Text|25|#F580B1}} {{Cl|THEN}} cry = cry + {{Text|1|#F580B1}} {{Text|<nowiki>'down</nowiki>|#919191}}
    {{Cl|CASE}} {{Cl|CHR$}}(0) + "K": {{Cl|IF...THEN|IF}} crx > 1 {{Cl|THEN}} crx = crx - 1 'left
        {{Cl|CASE}} {{Cl|CHR$}}({{Text|0|#F580B1}}) + {{Text|<nowiki>"K"</nowiki>|#FFB100}}: {{Cl|IF}} crx > {{Text|1|#F580B1}} {{Cl|THEN}} crx = crx - {{Text|1|#F580B1}} {{Text|<nowiki>'left</nowiki>|#919191}}
    {{Cl|CASE}} {{Cl|CHR$}}(0) + "M": {{Cl|IF...THEN|IF}} crx < 80 {{Cl|THEN}} crx = crx + 1 'right
        {{Cl|CASE}} {{Cl|CHR$}}({{Text|0|#F580B1}}) + {{Text|<nowiki>"M"</nowiki>|#FFB100}}: {{Cl|IF}} crx < {{Text|80|#F580B1}} {{Cl|THEN}} crx = crx + {{Text|1|#F580B1}} {{Text|<nowiki>'right</nowiki>|#919191}}
    {{Cl|CASE}} {{Cl|CHR$}}(27): {{Cl|END}}
        {{Cl|CASE}} {{Cl|CHR$}}({{Text|27|#F580B1}}): {{Cl|END}}
  {{Cl|END SELECT}}
    {{Cl|END SELECT}}
LOOP
{{Cl|LOOP}}
{{CodeEnd}}
{{CodeEnd}}


Line 46: Line 48:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[CSRLIN]], [[POS]] {{text|(cursor position)}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1218 Featured in our "Keyword of the Day" series]
* [[CSRLIN]], [[POS]] {{Text|(cursor position)}}
* [[SCREEN]], [[PRINT]], [[COLOR]]
* [[SCREEN]], [[PRINT]], [[COLOR]]
* [[INPUT]], [[LINE INPUT]], [[INPUT$]] {{text|(keyboard input)}}
* [[INPUT]], [[LINE INPUT]], [[INPUT$]] {{Text|(keyboard input)}}
* [[WIDTH]], [[INPUT$]], [[INKEY$]]
* [[WIDTH]], [[INPUT$]], [[INKEY$]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 17:29, 25 May 2024

The LOCATE statement locates the screen text row and column positions for a PRINT or INPUT procedure.


Syntax

LOCATE [row%][, column%] [, cursor%][, cursorStart%, cursorStop%]


Parameters

  • optional text row% INTEGER values are from 1 to 25, 43 or 50 in SCREEN 0 and 25 in most other legacy graphic screen modes, except screens 11 and 12 which can have 30 or 60 rows.
  • optional column% INTEGER values are from 1 to 40 or 80 in SCREEN 0 and 80 in all other legacy screen modes.
  • optional cursor% value can be 0 to turn displaying the cursor off or 1 to turn it on.
  • optional cursorStart% and cursorStop% values define the shape of the cursor by setting the start and stop scanline (values range from 0 to 31) for the cursor character.


Description

  • WIDTH statement can be used to determine the text width and height in SCREEN 0 and height of 30 or 60 in SCREEN 11 or 12.
  • In _NEWIMAGE graphic screen the number of text rows are calculated as _HEIGHT \ 16 except when a _FONT is used. Use _FONTHEIGHT to calculate font rows.
  • _NEWIMAGE graphic screen text columns are calculated as _WIDTH \ 8 except when a _FONT is used. Use _PRINTWIDTH to measure a line of font text.
    • Additionally, when a variable width _FONT is active, then the columns are not counted as char positions anymore but as pixel positions instead.
  • The text row position is not required if the PRINT is going to be on the next row. The comma and a column value are required to set the column.
  • If only the row parameter is given, then the column position remains the same. Neither row or column parameter can be 0.
  • When PRINTing on the bottom 2 rows, use a semicolon after the PRINT expression to avoid a screen roll.
  • If the cursorStart% line is given, the cursorStop% line must also be given. A wider range between them produces a taller cursor.
  • If you use LOCATE beyond the current number of rows in text mode, QB64 will try to adapt the screen instead of tossing an error.
  • When writing to the console, only the row and column arguments are used, all others are ignored. Furthermore, on non-Windows systems LOCATE statements that do not give both a row and column will be ignored entirely.


Examples

Example: Moving the cursor around (now you can finally create a Commodore 64 emulator!). Default SCREEN 0 only:

crx = 10
cry = 10
DO
    LOCATE cry, crx, 1, 0, 8
    a$ = INKEY$
    SELECT CASE a$
        CASE CHR$(0) + "H": IF cry > 1 THEN cry = cry - 1 'up
        CASE CHR$(0) + "P": IF cry < 25 THEN cry = cry + 1 'down
        CASE CHR$(0) + "K": IF crx > 1 THEN crx = crx - 1 'left
        CASE CHR$(0) + "M": IF crx < 80 THEN crx = crx + 1 'right
        CASE CHR$(27): END
    END SELECT
LOOP
Explanation: The CHR$(0) + "H", "P", "K", "M" represents the cursor arrow keys. start = 0, stop = 8 is the tallest cursor, experiment with the start and stop values for different effects (start = 8, stop = 8 is the default producing a _ cursor).


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link