08-08-2023, 06:53 AM
(08-07-2023, 07:25 AM)SMcNeill Wrote:(08-07-2023, 01:52 AM)PhilOfPerth Wrote: How can I map several sections of the screen so that a (left) mouse click selects the one it's in, and allows actions based on this?
Easiest way is just to make an array to store your segment coordinates for the mouse.
Code: (Select All)TYPE Box 'a type to hold the mouse section information
x AS INTEGER
y AS INTEGER
x2 AS INTEGER
y2 AS INTEGER
END TYPE
DIM MouseSection(9) AS Box 'our mouse sections
SCREEN _NEWIMAGE(640, 480, 32)
FOR x = 0 TO 2
FOR y = 0 TO 2
i = i + 1
MouseSection(i).x = x * 213
MouseSection(i).x2 = x * 213 + 213
MouseSection(i).y = y * 160
MouseSection(i).y2 = y * 160 + 160
NEXT
NEXT
'color the segments just to be pretty
FOR i = 1 TO 9
LINE (MouseSection(i).x, MouseSection(i).y)-(MouseSection(i).x2, MouseSection(i).y2), _RGB32(RND * 255, RND * 255, RND * 255), BF
NEXT
PCOPY 0, 1
DO
PCOPY 1, 0
WHILE _MOUSEINPUT: WEND
mx = _MOUSEX: my = _MOUSEY
IF _MOUSEBUTTON(1) THEN
FOR i = 0 TO 9 'check the 9 segments
IF mx >= MouseSection(i).x AND mx <= MouseSection(i).x2 THEN
IF my >= MouseSection(i).y AND my <= MouseSection(i).y2 THEN
LOCATE 1, 1: PRINT "Mouse last down in segment #"; i
EXIT FOR
END IF
END IF
NEXT
END IF
IF _MOUSEBUTTON(2) THEN SYSTEM
_LIMIT 30
_DISPLAY
LOOP
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/