summaryrefslogtreecommitdiff
path: root/simplegui/test.bmx
blob: 7f3c085f8338bca10702b8f9e08368fbdededf51 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
' $Id$

Import noddybox.simplegui
Import noddybox.bitmapfont

Incbin "font.bmf"

Const SCRW=800
Const SCRH=600

SetGraphicsDriver GLMax2DDriver()
Graphics SCRW,SCRH,32,60' Or HARDSYNC

Global font:TBitmapFont=TBitmapFont.Load("incbin::font.bmf",0)

TGUIFont.font=font

Global gui:TGUIHandler=TGUIHandler.Create()

Global label1:TLabel=TLabel.Create(gui,0,0,"Text 1:")
Global label2:TLabel=TLabel.Create(gui,0,20,"Text 2:")
Global text1:TText=TText.Create(gui,label1.w,0,"Text entry 1",20,False,TextCallback)
Global text2:TText=TText.Create(gui,label2.w,20,"Text entry 2",30,False)
Global check1:TCheckbox=TCheckbox.Create(gui,400,0,"Check 1",CheckCallback)
Global check2:TCheckbox=TCheckbox.Create(gui,400,20,"Check 2")
Global button1:TButton=TButton.Create(gui,0,360,100,30,"Test Alerts",ButtonCallback)
Global button2:TButton=TButton.Create(gui,110,360,100,30,"Quit",ButtonCallback)
Global buttonlist:TButtonList=TButtonList.Create(gui,500,0,["Hidden","Globally","Widgets"],0,Null)
Global vscroll:TScrollbar=TScrollbar.Create(gui,780,20,20,200,ScrollCallback)
Global hscroll:TScrollbar=TScrollbar.Create(gui,600,220,200,20,ScrollCallback)
Global hscroll2:TScrollbar=TScrollbar.Create(gui,600,250,200,20,ScrollCallback)

TLabel.Create(gui,0,60,"Float:")
Global numberf:TNumberDouble=TNumberDouble.Create(gui,80,60)

TLabel.Create(gui,0,80,"Int:")
Global numberi:TNumberInt=TNumberInt.Create(gui,80,80)

vscroll.SetBar(0,20,1)
hscroll.SetBar(0,10,1)
hscroll2.SetBar(0,1,1)
numberf.minval=0
numberf.maxval=100
numberf.change=1


TLabel.Create(gui,0,100,"Float")
TText.Create(gui,100,100,"",20,TText.NUMERIC)
TLabel.Create(gui,0,110,"Float pos")
TText.Create(gui,100,110,"",20,TText.NUMERIC|TText.POSITIVE)
TLabel.Create(gui,0,120,"Int")
TText.Create(gui,100,120,"",20,TText.NUMERIC|TText.INTEGER)
TLabel.Create(gui,0,130,"Int pos")
TText.Create(gui,100,130,"",20,TText.NUMERIC|TText.INTEGER|TText.POSITIVE)

Global textlist:TTextList=TTextList.Create(gui,0,400,100,5,TextListCallback)
Global tlscroll:TScrollbar=TScrollbar.Create(gui,101,400,10,textlist.h,TextListScrollCallback)
TButton.Create(gui,0,501,100,30,"Top Row to 3",TextTopCallback)
TButton.Create(gui,110,501,100,30,"Ens. Vis. to 6",TextEnsureCallback)

textlist.SetOptions(["A long, long long index 0","1","2","3","4","5","6","7","8","9","10","11","12"])
tlscroll.Setbar(0,13-5+1,1)		' Test of count-rows+1

Global dialog:TGUIHandler=TGUIHandler.Create()
Global dpanel:TPanel=TPanel.Create(dialog,-1,-1,400,300)
Global dlab:TLabel=TLabel.Create(dialog,dpanel.x+5,dpanel.y+5,"Enter a number:")
Global dnum:TNumberInt=TNumberInt.Create(dialog,dpanel.x+25,dpanel.y+25)
Global dok:TButton=TButton.Create(dialog,dpanel.x+5,dpanel.y+dpanel.h-25,dpanel.w/2-10,20,"OK",Null)
Global dcan:TButton=TButton.Create(dialog,dpanel.x+dpanel.w/2+5,dpanel.y+dpanel.h-25,dpanel.w/2-10,20,"Cancel",Null)

Global fname:String=Null
TButton.Create(gui,300,501,100,30,"Load",LoadCallback)
TButton.Create(gui,410,501,100,30,"Save",SaveCallback)


SetBlend(ALPHABLEND)

Global quit=False

While Not KeyHit(KEY_ESCAPE) And Not quit
	Cls
	
	gui.EventLoop()
	
	If KeyHit(KEY_MOUSERIGHT)
		Menu()
	EndIf
	
	SetColor(255,0,0)
	DrawRect(390,300,10,numberf.value)
	SetColor(0,255,0)
	DrawRect(400,300,10,numberi.value)
	
	Flip
	FlushMem
Wend

EndGraphics
End

Function TextCallback(w:TWidget)
	GUINotify(w.Text)
End Function

Function CheckCallback(w:TWidget)
	Local c:TCheckbox=TCheckbox(w)
	
	check2.enabled=c.checked
	text2.enabled=c.checked
	button2.enabled=c.checked
End Function

Function ButtonCallback(w:TWidget)
	If w.text="Quit"
		quit=GUIYesNo("Really quit this really rather impressive (cough) demo?")
	Else
		
		GUINotify(w.text + " pressed")
		GUINotify("Hello|World")
		If GUIYesNo("Test yes/no?")
			GUINotify("yes")
		Else
			GUINotify("no")
		EndIf
		If GUIYesNo("Test yes/no|with some very very very long|multiple lines?")
			GUINotify("yes")
		Else
			GUINotify("no")
		EndIf
	EndIf
End Function


Function Menu()
	Local opt:Int=GUIMenu("A long long Menu",["Test Dialog","Option 1","Option 2","Option 3"],MouseX(),MouseY())
	
	If opt>-1
		If opt=0
			dnum.value=numberi.value
			
			If GUIDialog(dialog,dok,dcan)
				numberi.value=dnum.value
			EndIf
		Else
			GUINotify("Selected " + opt)
		EndIf
	EndIf
End Function

Function ScrollCallback(w:TWidget)
	Local s:TScrollbar=TScrollbar(w)
	numberf.value=s.GetValue()
End Function

TButton.Create(gui,0,501,100,30,"Top Row to 3",TextTopCallback)
TButton.Create(gui,110,501,100,30,"Ens. Vis. to 6",TextEnsureCallback)


Function TextListCallback(w:TWidget)
	Local t:TTextList=TTextList(w)
	Local o:Object=t.GetSelectedItem()
	Local i:Int=t.GetSelectedIndex()
	GUINotify("Item=" + o.ToString() + "|index=" + i)
End Function

Function TextListScrollCallback(w:TWidget)
	Local s:TScrollbar=TScrollbar(w)
	textlist.SetTopRow(s.GetValue())
End Function

Function TextTopCallback(w:TWidget)
	textlist.SetTopRow(3)
	tlscroll.SetValue(3)
End Function

Function TextEnsureCallback(w:TWidget)
	textlist.EnsureVisible(6)
	tlscroll.SetValue(textlist.GetTopRow())
End Function

Function LoadCallback(w:TWidget)
	Local f:String=GUIFileSelect("Load a file",fname,False)
	
	If f<>Null
		GUINotify("path="+f)
		fname=f
	EndIf
End Function

Function SaveCallback(w:TWidget)
	Local f:String=GUIFileSelect("Save a file",fname,True)
	
	If f<>Null
		GUINotify("path="+f)
		fname=f
	EndIf
End Function