Why doesnt this work...right?

Blitz3D Forums/Blitz3D Beginners Area/Why doesnt this work...right?

darklordz(Posted 2004) [#1]
working on my lil game gui for the options menu, i need sliders (Blitz3D) and i came up with this.... I left out the mouuse state bit cuz thats another set of functions ....
Type SLIDER
	Field ID% ; ID
	Field XP% ; X Pos
	Field YP% ; Y Pos
	Field MX% ; Max Value
	Field MN% ; Min Value
	Field CV% ; Curr. Value
	Field ST% ; State (Mouse Up/Over/Dwn etc...)
	Field DR% ; Direction (Vertical / Horizontal)
	; Field EN% ; ImageEntity
End Type

Graphics3D 300,300,32,2
SetBuffer BackBuffer()

SliderCreate(0,52,80,0,100,50,0,0)
SliderCreate(0,80,150,0,100,50,0,1)

While Not KeyHit(1)
	Cls
	
	SliderUpdate%()
	
	RenderWorld
	UpdateWorld
	Flip
Wend

End


Function SliderCreate(ID%=-1,XP%=0,YP%=0,MN%=0,MX%=100,CV%=50,ST%=0,DR%=0)
	S.SLIDER = New SLIDER
	S\ID%    = ID%
	S\XP%    = XP%
	S\YP%    = YP%
	S\MN%    = MN%
	S\MX%    = MX%
	S\CV%    = CV%
	S\ST%    = ST%
	S\DR%    = DR%
	; S\EN%    = EN%
	SliderDraw(S\ID%)
	Return True
End Function

Function SliderUpdate%()
	For S.SLIDER = Each SLIDER
		If S\DR%=0
			If MouseX() > S\XP% And MouseX() < S\XP% + S\MX% And MouseY() > S\YP% And MouseY() < S\YP% + 22 And MouseDown(1)=1
				S\CV% = S\CV%+MouseXSpeed();(S\MX%/100*)
				If S\CV%>=S\MX% Then S\CV%=S\MX%
				If S\CV%<=S\MN% Then S\CV%=S\MN%
			EndIf
		ElseIf S\DR%=1
			If MouseX() > S\XP% And MouseX() < S\XP% + 22 And MouseY() > S\YP% And MouseY() < S\YP% + S\MX% And MouseDown(1)=1
				S\CV% = S\CV%+MouseYSpeed();(S\MX%/100*)
				If S\CV%>=S\MX% Then S\CV%=S\MX%
				If S\CV%<=S\MN% Then S\CV%=S\MN%
			EndIf
		EndIf
		Text 20,20,S\CV%
		SliderDraw(S\ID%)
	Next
	Return True
End Function

Function SliderDraw(ID%)
	For S.SLIDER = Each SLIDER 
		If S\ID% = ID% Then 
			If S\DR% = 0 Then 	
				Color 255,255,255
				Rect S\XP%-11,S\YP%,S\MX+22,21
				Color 122,122,122
				Rect S\XP%+(S\MX%/100*S\CV%)-11,S\YP%+1,22,19
			ElseIf S\DR% = 1 Then
				Color 255,255,255 
				Rect S\XP%-11,S\YP%-11,22,S\MX%+22
				Color 122,122,122
				Rect S\XP%-11+1,S\YP%+(S\MX%/100*S\CV%)-11,20,19
			EndIf
		EndIf
	Next
	Return True
End Function


now both horizontal and vertical work ... kina but they are still flawed.... can anyone help improve this? it would seem that when initialized the gadget auto jumps to 100 witch should not be, also when moving to fast with the mouse the slider looses focus.... :(


NOT BLITZ PLUS! BLITZ3D....


SoggyP(Posted 2004) [#2]
Hi folks,

Not really looked, but have you tried removing the multiple calls to Mousex() and mousey()?

Just a thought.

Later,

Jes


darklordz(Posted 2004) [#3]
@SoggyP > Thats not it.... And how hard can it be to copy paste and execute ? This code is a demo... Take a look man and tell me what could be the problem if you can cuz this is bugging me out....


EOF(Posted 2004) [#4]
Try this replacement function:
Function SliderUpdate%()
	Local mx=MouseX() , my=MouseY()
	Local mxs=MouseXSpeed() , mys=MouseYSpeed()
	For S.SLIDER = Each SLIDER
		If MouseDown(1)
			If S\DR%=0
				If (mx>S\XP% And mx<S\XP%+S\MX%) And (my>S\YP% And my<S\YP%+22)
					S\CV% = S\CV%+mxs;(S\MX%/100*)
					If S\CV%>=S\MX% Then S\CV%=S\MX%
					If S\CV%<=S\MN% Then S\CV%=S\MN%
				EndIf
			ElseIf S\DR%=1
				If mx>(S\XP% And mx<S\XP%+22) And (my>S\YP% And my<S\YP%+S\MX%)
					S\CV% = S\CV%+mys;(S\MX%/100*)
					If S\CV%>=S\MX% Then S\CV%=S\MX%
					If S\CV%<=S\MN% Then S\CV%=S\MN%
				EndIf
			EndIf
			DebugLog "slider DR="+Str$(S\DR%)+" Value="+Str$(S\CV%)
		EndIf
		SliderDraw(S\ID%)
	Next
	Return True
End Function

Looks like the mulitple calls to MouseXSpeed()/MouseYSpeed() were causing the erratic behaviour. These functions should only be called once per frame.


darklordz(Posted 2004) [#5]
wow thanks m8te anychance you could explain why this works better why i cant use mousex() etc instead?


EOF(Posted 2004) [#6]
See above. Edited post.


SoggyP(Posted 2004) [#7]
Hi Folks,

I was on a machine without Blitz.
I was in a hurry.
I was making a suggestion based on something I'd read in the forums previously.
I was trying to help.

Anyway, it works now, that's nice of Syntax Error. Oh, and to cut and paste
These functions should only be called once per frame.


Have a nice day.

Later,

Jes


darklordz(Posted 2004) [#8]
@SoggyP > man no offence intended....i was merely stating ur assumption was wrong.... it's fixed now thanks...


Hansie(Posted 2004) [#9]
The users in this forum are here to help each other :-D