Slider (Dragline)

Monkey Archive Forums/Monkey Tutorials/Slider (Dragline)

StoneFaceEXE(Posted 2012) [#1]
This is a simple Slider function.

SYNTAX:
Variable01 = Slider(X,Y,L,W,V,I,T)
Variable01 - Tracked variable (the one that you want to change with slider)
X - X coordinate of Slider
Y - Y coordinate
L - Lenght of the slider
W - Width of the slider
V - Tracked variable (needed here too)
I - Image of the slider button. Not necessary to specify
T - Type of slider. 0 - straight line, 1 - filling bar

Returns from 0 to 100, depending on where the slider button is on the slider itself. It automaticaly calculates the value corresponding to the lenght of the slider.

http://carvertemphub.nm.ru/dls/Slider/

Here is non diddy function:

Function Slider:Int(xl:int = DeviceWidth() / 2, yl:int = DeviceHeight() / 2, Lenght:Int = 100, Width:Int = 20, TrackedValue:int, SliderImage:Image = Null, Type:Int = 0)
Local Percent:Int = Lenght * TrackedValue / 100
Select Type
	Case 0
		SetColor 255, 255, 255
		DrawRect(xl - 2, yl + Width / 2 - 2, Lenght + 4, 6)
		SetColor 000, 000, 000
		DrawRect(xl, yl + Width / 2, Lenght, 2)
	Case 1
		SetColor 128, 16, 16
		DrawRect(xl - 5, yl - 5, Lenght + 10, Width + 10)
		SetColor 128, 64, 64
		DrawRect(xl, yl, Lenght, Width)
		SetColor 64, 128, 64
		For Local YW:Int = 1 To Width
			DrawLine(xl, yl + YW, xl + Percent, yl + YW)
		Next
	End Select
SetColor 64, 162, 64
DrawRect(xl - 3 + Percent, yl, 6, Width)
If SliderImage <> Null Then DrawImage SliderImage, xl + Percent, yl + Width / 2
If TouchX() > xl and TouchX() < xl + Lenght
If TouchY() > yl and TouchY() < yl + Width
If TouchDown()
TrackedValue = (TouchX() -xl) / Lenght * 100
EndIf
EndIf
EndIf
If TrackedValue > 101 Then TrackedValue = 100
If TrackedValue = 99 Then TrackedValue = 100
If TrackedValue < 0 Then TrackedValue = 0
Return TrackedValue
End Function


PS: Sorry, I fixed now everything. Now you'll have to also assign this function to the variable you want it to change and to assign it in the function itself.