Sprite Candy GUI problems

Blitz3D Forums/Blitz3D Userlibs/Sprite Candy GUI problems

Aussie(Posted 2013) [#1]
G'day all.
Been a while, but i have recently been able to get back into working on my world editor again & am trying to work in some GUI.
Having problems with mouse clicks over buttons & draggable windows. When over a button or draggable window it doesn't always register when the mouse is being used. I have found if i remove the LimitFramRate function it improves but i used the same function while doing tests with Sprite Candy & it works fine in the tests. I can't figure out whats causing the problem.
Here is the code,
Any help would be greatly appreciated.




Aussie(Posted 2013) [#2]
Ok, so i have found it is something to do with my Control_Camera Function i will have a look through the function & see if i can find whats causing the problem, if anyone else can help out it would be awesome. :)
Function control_camera()

	Local msx# = MouseXSpeed()
	Local msy# = MouseYSpeed()
	Local msz# = MouseZSpeed()
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Rotate camera;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	If MouseDown(3)
		If mouse_down_3 = 0
			mouse_down_3 = 1
			mouse_X = MouseX()
			mouse_Y = MouseY()
			MoveMouse mouse_X,mouse_Y
		EndIf
		RotateEntity camera,EntityPitch(camera,True)+(msy*0.2),EntityYaw(camera,True)+(msx*-0.2),0
		MoveMouse mouse_X, mouse_Y
	Else
		mouse_down_3 = 0
	End If
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Move camera left, right, up & Down;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	If KeyDown(42)
		If shift_down = 0
			shift_down = 1
			mouse_X = MouseX()
			mouse_Y = MouseY()
			MoveMouse mouse_X,mouse_Y
		EndIf
		MoveEntity camera,msx*.025,msy*-.025,0
		MoveMouse mouse_X, mouse_Y
	Else
		shift_down = 0
	End If
	
	MoveEntity camera,0,0,msz*.2
	
	If KeyDown(200) MoveEntity camera,0,0,2
	If KeyDown(208) MoveEntity camera,0,0,-2
	
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Pick & mouse_state;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
	Select mouse_state
		
		Case 0
			
			HideEntity widget
			
			If MouseHit(1)
				entity = CameraPick(camera,MouseX(),MouseY())
				mouse_state = (entity<>0)
			End If
			
			
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;position & scale widget;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			Case 1
			
			ShowEntity widget
			PositionEntity widget, EntityX(entity), EntityY(entity), EntityZ(entity)
						;;;;;;;;;;;;;;;;;move entity X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			If KeyDown(45)
				If X_down = 0 Then
					X_down = 1
					mouse_X = MouseX()
					mouse_Y = MouseY()
				End If
				MoveEntity widget, msx*.02,0,0
				MoveMouse mouse_X,mouse_Y
			Else
				X_down = 0
			End If
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Move entity Y;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			If KeyDown(21) 
				If Y_down = 0 Then
					Y_down = 1
					mouse_X = MouseX()
					mouse_Y = MouseY()
				End If
				MoveEntity widget,0,-msy*.02,0
				MoveMouse mouse_X,mouse_Y
			Else 
				Y_down = 0
			End If
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Move entity Z;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
			If KeyDown(44)
				If Z_down = 0 Then
					Z_down = 1
					mouse_X = MouseX()
					mouse_Y = MouseY()
				End If
				MoveEntity widget,0,0,msy*.02
				MoveMouse mouse_X,mouse_Y
			Else
				Z_down = 0
			End If
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Deselect Entity;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			If MouseHit(2) Then 
				mouse_state = 0
				entity = 0
			End If
	End Select
	FlushMouse
End Function




Omnicode(Posted 2013) [#3]
Hi, your Case-Select loop seems to only have ways to exit, rather than enter. Either that or i'm terribly unfamiliar with the usage of "(entity<>0)" as to assign a variable, you may need to revise that. Something about that just seems off.

Also, I don't believe you ever assigned "widget" a pickmode that isn't 0. So that it's pickable by your camera.

When using "CameraPick", the returned object has to have a pickmode that isn't 0. Something you should always remember, i've done this a couple of times myself.

Hope that helps.


Omnicode(Posted 2013) [#4]
Wait, upon a second glance I realize I was addressing the wrong issue.

If you're having trouble with mouse click detection try running an entire pass that isn't localized to a specific function. Have a global assigned to a function that returns the type of mouse button clicked.

Blitz seems to have an issue que'ing a lot of objects or types of objects when associating them with mouse clicks, specifically mousehits. Mousedown performs a more constant flow of detection and how i got around this was using this:

;Main Program.
Global MouseCheck=0

;Before All GUI updates.
MouseCheck=Check_Mouse()

;After All GUI updates. -Not really needed, but it's just a visual to know.
MouseCheck=0

;Removing all mousechecks from anywhere else and replacing it with MouseCheck=0;1;2
Function Check_Mouse()
        Local Mouse_Timer=0
	If MouseDown(1)=True
		Mouse_Timer=1
	ElseIf MouseDown(2)=True
		Mouse_Timer=2
	Else
		Mouse_Timer=0
	EndIf
	Return Mouse_Timer
End Function



It works with MouseHits as well. Just replace the mousedowns with mousehits.


Aussie(Posted 2013) [#5]
Thanks for the help Omnicode but it still does the same thing.
Not to sure what it is but i will probably re work the Control_Camera function over the weekend & see what i can do. I know it defiantly has something to do with the function, if i take the function out of the main loop the GUI works perfectly.
Still if anyone can figure out whats going on that would be great.
Thanks again. :)


MCP(Posted 2013) [#6]
It's been awhile since I've coded in Blitz3D but here are some possible issues...

1) You're reading mouse states multiple times MouseX,MouseY etc when they should only be read once per game loop. Try storing mouse states in global variables at the start of your game loop.

2) MouseFlush clears all pending mouse events??? This may affect MouseXSpeed/MouseHit results etc. try removing it.


Kryzon(Posted 2013) [#7]
I agree with MCP's second observation.
Inside Control_Camera, the last thing you do is call FlushMouse() without the necessity for it, and subsequently in your program you're calling the HUD's and GUI's update code - they're going to meet a blank event list from the previous flushing.


Aussie(Posted 2013) [#8]
Thanks MCP & Kryzon.
I have tried removing the FlushMouse() cause i thought it could be interfering with the GUI but that seems to make no difference. I had to use FlushMouse() because if i right click then select an object with a left click it deselects the object straight away. Might hve to try something else to avoid that problem.
Just tried setting globals for MouseX & MouseY doesn't seem to work either.
Thanks for the help. :)


Kryzon(Posted 2013) [#9]
Another possibility is that the Mouse[n]Speed commands reset the speed of the mouse.
If the Sprite Candy GUI uses the mouse's speed to drag the windows, when it calls these functions again they will return zero (the mouse didn't move since the last call).

You'd need to change the Sprite Candy GUI code to store the mouse speeds in Globals that you can access in your program as well - so you leave it to SC GUI to call the mouse speed commands, and you only read from the globals.


Aussie(Posted 2013) [#10]
Found the problem.
Part of it was the FlushMouse()
The other part of the problem was this.
Select mouse_state
		
		Case 0
			
			HideEntity widget
			
			If MouseHit(1)
				entity = CameraPick(camera,MouseX(),MouseY())
				mouse_state = (entity<>0)
			End If
			If entity <> 0 Then
				mouse_state = 1
			End If


The CameraPick seems to clash with the GUI, if i change MouseHit(1) to MouseHit(3) it works no worries. Will have to come up with a workaround because i want to use MouseHit(1) for selecting objects.


Aussie(Posted 2013) [#11]
New problem.
Sprite Candy Gui seems to be missing a function. GUI_MouseOverWindow from the include file. Wandering if anyone here who has Sprite Candy has this function or did you not get it with the include file as well? If someone dose have it could you please post the code. Cheers :)