08-07-2023, 02:32 AM
(This post was last modified: 08-07-2023, 02:34 AM by commandvom.)
hello Phil, using the example of _MOUSEX in qb64 wiki, a few modifications, detect if mouse down on left side of screen (1) or right side of screen (2)
is the beginning, you add more sectors to detect:
is the beginning, you add more sectors to detect:
Code: (Select All)
DIM mousesector(10, 5) AS INTEGER
mousesector(1, 1) = 1 'xi
mousesector(1, 2) = 1 'yi
mousesector(1, 3) = 320 'xf
mousesector(1, 4) = 480 'yf
mousesector(1, 5) = 1 'option selected
mousesector(2, 1) = 321 'xi
mousesector(2, 2) = 1 'yi
mousesector(2, 3) = 639 'xf
mousesector(2, 4) = 480 'yf
mousesector(2, 5) = 2 'option selected
SCREEN 12
LINE (99, 9)-(601, 401), 7, BF
LINE (101, 11)-(599, 399), 8, BF
tm$ = " Column = ### Row = ### Button1 = ## Button2 = ## Button3 = ##"
LOCATE 29, 20: PRINT "LeftButton = draw - RightButton = Erase";
DO: K$ = INKEY$
DO WHILE _MOUSEINPUT
X = _MOUSEX: Y = _MOUSEY
IF X > 100 AND X < 600 AND PX > 100 AND PX < 600 THEN
IF Y > 10 AND Y < 400 AND PY > 10 AND PY < 400 THEN
IF _MOUSEBUTTON(1) THEN LINE (PX, PY)-(X, Y), 15
IF _MOUSEBUTTON(2) THEN LINE (101, 11)-(599, 399), 8, BF
END IF
END IF
PX = X: PY = Y
LOCATE 27, 10: PRINT USING tm$; X; Y; _MOUSEBUTTON(1); _MOUSEBUTTON(2); _MOUSEBUTTON(3)
LOOP
'---------------------- code detecting sector --------------
IF _MOUSEBUTTON(1) THEN
FOR i = 1 TO 2
IF X > mousesector(i, 1) AND Y > mousesector(i, 2) AND X < mousesector(i, 3) AND Y < mousesector(i, 4) THEN
OptionSelected = mousesector(i, 5)
END IF
NEXT
END IF
LOCATE 28, 19: PRINT "OPTION SELECTED: "; OptionSelected
'----------------- end code -------------
LOOP UNTIL K$ = CHR$(27)
SYSTEM