MaxGUI: EVENT_MOUSEDOWN

BlitzMax Forums/BlitzMax Beginners Area/MaxGUI: EVENT_MOUSEDOWN

po(Posted 2006) [#1]
How would I use EVENT_MOUSEDOWN in my program so that the mouse is actually held down, rather than used just as a click? It seems whenever I use this it always acts as a MouseHit rather than a MouseDown.


CS_TBL(Posted 2006) [#2]

Field lmd:int

If event.id=EVENT_MOUSEDOWN
  lmd=1
Endif

If event.id=EVENT_MOUSEUP
  lmd=0
Endif

If lmd ' mousedown
' your stuff here
Endif



SebHoll(Posted 2006) [#3]
Exactly what I was about to say. Basically, use a variable to keep track of whether or not the mouse button is down. Below, the variable varMouseDown is 1 when the mouse button is down, and 0 when it isn't.

SuperStrict

Global wndMain:TGadget = CreateWindow("Test Window", 100, 100, 400, 300, Null, 11)
Global gadPanel:TGadget = CreatePanel(0,0,ClientWidth(wndMain),ClientHeight(wndMain),wndMain,PANEL_ACTIVE)

SetPanelColor(gadPanel,255,0,0)			'So that you can see the panel and know it is there
SetGadgetLayout(gadPanel,1,1,1,1)			'Make sure the panel stretches when panel is resized

Local varCount:Int = 0
Local varMouseDown:Int = 0


Repeat


	Select PollEvent()
	
		Case EVENT_MOUSEDOWN ; If EventSource() = gadPanel Then varMouseDown = 1
		Case EVENT_MOUSEUP ; If EventSource() = gadPanel Then varMouseDown = 0
		
		Case EVENT_WINDOWCLOSE ; End
		
	EndSelect

	If varMouseDown Then			'If mouse is currently held down then do something
	
		varCount:+1
		SetStatusText(wndMain,"Count: " + varCount)

	EndIf	


Forever



CS_TBL(Posted 2006) [#4]
..except that it's better to have a dedicated var for each mousebutton :P

hence: lmd, rmd ..

Note that this lmd or rmd doesn't create an event, if you want to draw lines or pixels at a constant rate (like drawing dark pixels that become lighter on the same place) then you want this 'If lmd (..) EndIf'-construction inside a timer event ..


po(Posted 2006) [#5]
That works, thanks.