All pastes #1345725 Raw Edit

Jemand

public text v1 · immutable
#1345725 ·published 2009-02-24 10:46 UTC
rendered paste body
Import maxgui.win32maxguiex

Global TestWindow:TGadget = createWindow("TestWindow", 0, 0, 230, 170, Null, WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_MENU)
Global Canvas:TGadget = CreateCanvas(10, 10, 200, 100, TestWindow)

Global CanvasX:Int, CanvasY:Int, CanvasOver:Int
Global mDown:Int, lastVal:Int

SetGraphics CanvasGraphics(Canvas)

Function MouseX:Int()
	Return CanvasX
End Function

Function MouseY:Int()
	Return CanvasY
End Function

Function MouseDown:Int()
	Return mDown
End Function

Function MouseHit:Int() ' Quick and dirty. There is probably another Event to handle this
	If lastVal = 0 And mDown = 1 Then
		lastVal = 1
		Return 1
	ElseIf mDown = 0 Then
		lastVal = 0
	End If
	Return 0
End Function

Repeat
	PollEvent()
	Select CurrentEvent.id
		Case EVENT_WINDOWCLOSE
			End
			
		Case EVENT_MOUSEMOVE
			Select CurrentEvent.source
				Case Canvas
					CanvasX = CurrentEvent.X
					CanvasY = CurrentEvent.Y
			End Select
		Case EVENT_MOUSEENTER
			Select CurrentEvent.source
				Case Canvas
					CanvasOver = 1
			End Select
		Case EVENT_MOUSELEAVE
			Select CurrentEvent.source
				Case Canvas
					CanvasOver = 0
			End Select
		Case EVENT_MOUSEDOWN
			mDown = 1
		Case EVENT_MOUSEUP
			mDown = 0
	End Select
	
	DrawText "X: " + MouseX() + " Y: " + MouseY(), 0, 0
	DrawText "MouseOver: " + CanvasOver, 0, 20
	DrawText "MouseDown: " + MouseDown(), 0, 40
	DrawText "MouseHit: " + MouseHit(), 0, 60
	
	Flip
	Cls
	
Forever