-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiwidgetsliderhorizontal.monkey
76 lines (63 loc) · 2.05 KB
/
guiwidgetsliderhorizontal.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Import horizon.guiwidget
Import horizon.blitzmaxfunctions
Class GuiWidgetSliderHorizontal Extends GuiWidget
Field sliderPosX:Float
Field startSlide:Bool
Field barImage:Image
Field sliderImage:Image
Method New()
SetBarImage(LoadImage(GuiSystem.SKIN_PATH + "slider/slider.png"))
SetSliderImage(LoadImage(GuiSystem.SKIN_PATH + "slider/knob.png"))
End Method
Method SetBarImage(img:Image)
barImage = img
rect.w = ImageWidth(barImage)
rect.h = ImageHeight(barImage)
End Method
Method SetSliderImage(img:Image)
sliderImage = img
MidHandleImage(sliderImage)
End Method
Method Update()
If Not MouseDown(0) Then startSlide = False
If (startSlide)
sliderPosX -= InputControllerMouse.GetInstance().GetDX()
If (sliderPosX < 0) Then sliderPosX = 0
If (sliderPosX > rect.w) Then sliderPosX = rect.w
End If
End Method
Method Render()
If (barImage And sliderImage)
DrawImage (barImage, rect.x, rect.y)
DrawImage (sliderImage, rect.x + sliderPosX, rect.y + rect.h / 2)
Else
SetColor(255,0,0)
DrawRect(rect.x, rect.y, rect.w, rect.h)
SetColor(0,255,0)
DrawRect(rect.x + sliderPosX - 2, rect.y - 2, 4, rect.h + 4)
SetColor(255,255,255)
End If
End Method
Method OnMouseDown()
Super.OnMouseDown()
End Method
Method OnMouseHit()
startSlide = True
sliderPosX = InputControllerMouse.GetInstance().GetX() - rect.x
If (sliderPosX < 0) Then sliderPosX = 0
If (sliderPosX > rect.w) Then sliderPosX = rect.w
End
Method OnMouseUp()
Super.OnMouseUp()
startSlide = False
End Method
Method GetPositionInPercent:Float()
Return sliderPosX / rect.w * 100.0
End Method
Method GetPositionInPixel:Int()
Return sliderPosX
End Method
Method SetPositionInPercent(p:Float)
sliderPosX = rect.w * p / 100.0
End Method
End