MOUSEY: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_MOUSEY}} The _MOUSEY function returns the current vertical (row) mouse cursor position when read after _MOUSEINPUT. {{PageSyntax}} : {{Parameter|pixelRow%}} = _MOUSEY {{PageDescription}} * SCREEN 0 returns the INTEGER vertical text row position (from build 20170817/62 onward); older versions return a SINGLE vertical text row position. Use INTEGER variables to avoid floating decimal returns. * Graphic screen modes 1, 2 and 7...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 13: Line 13:
* [[_MOUSEINPUT]] must be used to detect any changes in the mouse position and is '''required''' for any coordinate returns.
* [[_MOUSEINPUT]] must be used to detect any changes in the mouse position and is '''required''' for any coordinate returns.


 
=== QBasic/QuickBASIC ===
==QBasic/QuickBASIC==
* In [[SCREEN]] 0, QBasic's [[CALL ABSOLUTE|ABSOLUTE]] returned graphic coordinates. QB64 mouse functions return the text coordinates.
* In [[SCREEN]] 0, QBasic's [[ABSOLUTE]] returned graphic coordinates. QB64 mouse functions return the text coordinates.  




{{PageExamples}}
{{PageExamples}}
''Example:'' Highlighting a row of text in Screen 0.
''Example:'' Highlighting a row of text in Screen 0.
{{CodeStart}} '' ''
{{CodeStart}}
minX = 20: maxX = 60: minY = 10: maxY = 24
minX = 20: maxX = 60: minY = 10: maxY = 24
selection = 0 'the screen Y coordinate of the previously highlighted item
selection = 0 'the screen Y coordinate of the previously highlighted item
Line 36: Line 35:
     {{Cl|END IF}}
     {{Cl|END IF}}
     'Highlight any selected row
     'Highlight any selected row
     {{Cl|IF}} selection {{Cl|THEN}} SelectRow selection, minX, maxX, 2  
     {{Cl|IF}} selection {{Cl|THEN}} SelectRow selection, minX, maxX, 2
     {{Cl|IF}} {{Cl|_MOUSEBUTTON}}(1) {{Cl|THEN}} {{Cl|LOCATE}} 1, 2: {{Cl|PRINT}} x, y, selection  
     {{Cl|IF}} {{Cl|_MOUSEBUTTON}}(1) {{Cl|THEN}} {{Cl|LOCATE}} 1, 2: {{Cl|PRINT}} x, y, selection
   {{Cl|END IF}}
   {{Cl|END IF}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
Line 49: Line 48:
   addr& = addr& + 2
   addr& = addr& + 2
{{Cl|NEXT}}
{{Cl|NEXT}}
{{Cl|END SUB}} '' ''
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}


Line 57: Line 56:
* [[_MOUSEINPUT]], [[_MOUSEMOVE]]
* [[_MOUSEINPUT]], [[_MOUSEMOVE]]
* [[_MOUSESHOW]], [[_MOUSEHIDE]]
* [[_MOUSESHOW]], [[_MOUSEHIDE]]
* [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]] {{text|(relative pointer moves)}}
* [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]]
* [[Controller Devices]]
* [[Controller Devices]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 21:19, 2 February 2023

The _MOUSEY function returns the current vertical (row) mouse cursor position when read after _MOUSEINPUT.


Syntax

pixelRow% = _MOUSEY


Description

  • SCREEN 0 returns the INTEGER vertical text row position (from build 20170817/62 onward); older versions return a SINGLE vertical text row position. Use INTEGER variables to avoid floating decimal returns.
  • Graphic screen modes 1, 2 and 7 to 13 and _NEWIMAGE 32 bit return the INTEGER pixel columns.
  • To calculate text rows in graphic modes divide the return by 16 or the _FONTHEIGHT of _FONT characters.
  • _MOUSEINPUT must be used to detect any changes in the mouse position and is required for any coordinate returns.

QBasic/QuickBASIC

  • In SCREEN 0, QBasic's ABSOLUTE returned graphic coordinates. QB64 mouse functions return the text coordinates.


Examples

Example: Highlighting a row of text in Screen 0.

minX = 20: maxX = 60: minY = 10: maxY = 24
selection = 0 'the screen Y coordinate of the previously highlighted item
FOR i% = 1 TO 25: LOCATE i%, 40: PRINT i%;: NEXT
DO: _LIMIT 100
  IF _MOUSEINPUT THEN
    'Un-highlight any selected row
    IF selection THEN selectRow selection, minX, maxX, 0
    x = _MOUSEX
    y = _MOUSEY
    IF x >= minX AND x <= maxX AND y >= minY AND y <= maxY THEN
      selection = y
    ELSE
      selection = 0
    END IF
    'Highlight any selected row
    IF selection THEN SelectRow selection, minX, maxX, 2
    IF _MOUSEBUTTON(1) THEN LOCATE 1, 2: PRINT x, y, selection
  END IF
LOOP UNTIL INKEY$ <> ""

SUB SelectRow (y, x1, x2, col)
DEF SEG = &HB800
addr& = (x1 - 1 + (y - 1) * _WIDTH) * 2 + 1
FOR x = x1 TO x2
  oldCol = PEEK(addr&) AND &B10001111   ' Mask foreground color and blink bit
  POKE addr&, oldCol OR ((col AND &B111) * &B10000) ' Apply background color
  addr& = addr& + 2
NEXT
END SUB


See also



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