Mouse Clicking in areas

Blitz3D Forums/Blitz3D Beginners Area/Mouse Clicking in areas

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Use my ZoneLib.
; ZoneLib by Dave Kirk, 30th March 2001
; This is a set of functions for creating ScreenZones, like in AMOS.

; ZLReserveZone		- Set the maximum number of zones to use (reserves some memory).
; ZLSetZone			- Define a zone.  Must be between 1 and the number specified in ZLReserveZone
; ZLKillZone		- Delete a zone.
; ZLFreeZones		- Delete all zones and free up reserved memory.
; MouseZone()		- Returns the number of the zone the mouse pointer is in.

AppTitle "ZoneLib"

;Globals for ZoneLib - PUT THESE IN YOUR PROGRAM TOO!
Global ZoneLib%,NumZones

;Demo code
Graphics 800,600

ZLReserveZone(5)

SetBuffer BackBuffer()

ZLSetZone 1,50,50,150,70
ZLSetZone 2,200,300,240,380
While KeyDown(1)=0
	If MouseDown(2) Then ZLKillZone 2
	Cls
	Color 255,255,0
	Rect 50,50,100,20,True
	Rect 200,300,40,80,True
	Z = MouseZone()
	Locate 0,0 : Print "Zone:" + Z
	Oval MouseX()-2,MouseY()-2,4,4,True
	Flip
Wend
EndGraphics
End
;End of demo code




;ZONELIB FUNCTIONS
Function ZLReserveZone(Num%)
	ZoneLib = CreateBank(Num*8)
	NumZones = Num
End Function

Function ZLSetZone(Zone,X1,Y1,X2,Y2)
	M = (Zone-1)*8
	PokeShort ZoneLib,M,X1
	PokeShort ZoneLib,M+2,Y1
	PokeShort ZoneLib,M+4,X2
	PokeShort ZoneLib,M+6,Y2	
End Function

Function ZLKillZone(Zone)
	M = (Zone-1)*8
	PokeShort ZoneLib,M,0
	PokeShort ZoneLib,M+2,0
	PokeShort ZoneLib,M+4,0
	PokeShort ZoneLib,M+6,0	
End Function

Function ZLFreeZones()
	FreeBank ZoneLib
End Function

Function MouseZone()
	ZoneNum = 0
	For N = 1 To NumZones
		M = (N-1)*8
		X1 = PeekShort(ZoneLib,M)
		Y1 = PeekShort(ZoneLib,M+2)
		X2 = PeekShort(ZoneLib,M+4)
		Y2 = PeekShort(ZoneLib,M+6)
		If MouseX()>X1
			If MouseX()<X2
				If MouseY()>Y1
					If MouseY()<Y2
						ZoneNum = N
					EndIf
				EndIf
			EndIf
		EndIf
	Next
	Return ZoneNum
End Function
I think someone made an enhanced version based on this code. I can't remember who it was now though...