gui abuse!

BlitzMax Forums/BlitzMax Programming/gui abuse!

was seeing what you could and couldnt do with maxgui
thought someone might find the code useful...



SuperStrict 	' yippie!

SetGraphicsDriver GLGraphicsDriver()

Local w:TGadget,e:Int,x:Float,y:Float,z:Float
Local mx:Float,my:Float,lmx:Float,lmy:Float
Local m_down:Int

w=CreateWindow("Gui Test",40,40,800,600)
Local c:TGadget = CreateCanvas(200,16,w.clientwidth()-200,w.clientheight()-16,w,0,GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER)
c.setlayout 1,EDGE_ALIGNED,1,EDGE_ALIGNED

Local l:tgadget=CreateLabel("Click & drag to rotate main view",200,0,100,15,w)
l.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0

Global textfield_r1:tgadget=CreateTextArea(74,4,120,22,w)
l:tgadget=CreateLabel("X radius",4,8,60,15,w,LABEL_RIGHT)
l.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0

Global textfield_r2:tgadget=CreateTextArea(74,28,120,22,w)
l:tgadget=CreateLabel("Y radius",4,32,60,15,w,LABEL_RIGHT)
l.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0



SetGadgetFilter textfield_r1,filter_r1
SetGadgetFilter textfield_r2,filter_r2
SetTextAreaText textfield_r1,"10"
SetTextAreaText textfield_r2,"5"
textfield_r1.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0
textfield_r2.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0


Global sect_cols:Int[20]

Global combobox1:tgadget=CreateComboBox(74,52,120,22,w)
For Local l:Int=0 To 19
	AddGadgetItem combobox1,"sector "+l
Next
SelectGadgetItem combobox1,0


Local combobox2:tgadget=CreateComboBox(74,76,120,22,w)
AddGadgetItem combobox2,"White"
AddGadgetItem combobox2,"Red"
AddGadgetItem combobox2,"Green"
AddGadgetItem combobox2,"Blue"
SelectGadgetItem combobox2,0

combobox1.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0
combobox2.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0

l:tgadget=CreateLabel("Sector colour",4,80,65,15,w,LABEL_RIGHT)
l.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0

Global fpsl:tgadget=CreateLabel("Frames per second : ",4,104,190,15,w)
fpsl.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0

Global rr:Int,rg:Int,rb:Int
Global cp:tgadget=CreatePanel(100,126,32,22,w,PANEL_ACTIVE|PANEL_BORDER)
cp.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0
SetPanelColor cp,rr,rg,rb

l:tgadget=CreateLabel("Background colour",4,128,94,15,w)
l.setlayout EDGE_ALIGNED,0,EDGE_ALIGNED,0


ActivateGadget c	' very important for key events

Local msg:String="                  its a maxgui demo !!!!                   "

Local tick:Int,lms:Int,frames:Int

lms=MilliSecs()
While True

	tick:+1
	If tick>9 Then
		msg=Right(msg,1)+Left(msg,Len(msg)-1)
		SetStatusText(w,msg)
		tick=0
	EndIf

	frames:+1
	If lms+1000<MilliSecs() Then
		lms:+1000
		SetGadgetText fpsl,"Frames per second : "+frames
		RedrawGadget fpsl
		frames=0
	EndIf

	Local wid:Int = c.clientwidth()
	Local hgt:Int = c.clientheight()
	Local asp# = Float(wid)/Float(hgt)	

	SetGraphics CanvasGraphics( c )	
	glViewport 0,0,wid,hgt
	glMatrixMode GL_PROJECTION
	glLoadIdentity
	gluPerspective 45, asp, 1, 1000

	
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
 	gltranslatef 0,0,-30
	glrotatef x,1,0,0
	glrotatef z,0,0,1

	glClearColor rr/255.0,rg/255.0,rb/255.0,1
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
	

	orbit(Float(TextAreaText(textfield_r1)),Float(TextAreaText(textfield_r2)))
	
	
	e=PollEvent()

	If e Then
	
		'Print "source="+EventSourceHandle()

		Select e
			Case EVENT_WINDOWCLOSE
				End

			Case EVENT_GADGETACTION
			'	Print "eventdata="+EventData()

				If EventSource()=combobox1 Then 
					SelectGadgetItem(combobox2,sect_cols[SelectedGadgetItem(combobox1)])
				EndIf
				
				If EventSource()=combobox2 Then
					sect_cols[SelectedGadgetItem(combobox1)]=SelectedGadgetItem(combobox2)
					ActivateGadget combobox2
				EndIf
		
			Case EVENT_KEYDOWN
			'	Print "eventdata kd="+EventData()
				Select EventData() 
					Case KEY_SPACE
						GLDrawText("spc",0,20)
					Case KEY_ESCAPE
						GLDrawText("esc",0,0)
						End
				End Select
				
				
			Case EVENT_MOUSEMOVE
				
				'ActivateGadget c
				mx=EventX()
				my=EventY()

			Case EVENT_MOUSEDOWN
				If EventSource()=c Then m_down=True
				
				If EventSource()=cp Then 
					If RequestColor(rr,rg,rb)
						rr=RequestedRed()
						rg=RequestedGreen()
						rb=RequestedBlue()
						SetPanelColor cp,rr,rg,rb
					EndIf
				EndIf	
								

			Case EVENT_MOUSEUP
				m_down=False
				
		EndSelect
	EndIf
	
	If m_down Then
		If Abs(lmx-mx)>50 Then lmx=mx
		If Abs(lmy-my)>50 Then lmy=my
		z:+(lmx-mx)
		x:+(lmy-my)
		lmx=mx
		lmy=my
	EndIf

	Flip 1

Wend

' I was trying to make the escape key always exit and experimenting with
' validation but you cant filter combobox's etc :((

Function filter_r1:Int(event:TEvent,context:Object)

	If event.id=EVENT_KEYDOWN Then
		If event.data=27 Then End
		If event.data=13 Then Return 0
		If event.data=9 Then
			ActivateGadget textfield_r2
			Return 0
		EndIf
	EndIf
	
	If event.id=EVENT_KEYCHAR And event.data=9 Then Return 0
	
	If Len(TextAreaText(textfield_r1))>8 And event.data<>8 Then Return 0
				
	Return 1

End Function


Function filter_r2:Int(event:TEvent,context:Object)

	If event.id=EVENT_KEYDOWN Then
		If event.data=27 Then End
		If event.data=13 Then Return 0
		If event.data=9 Then
			ActivateGadget combobox1
			Return 0
		EndIf
	EndIf

	If event.id=EVENT_KEYCHAR And event.data=9 Then Return 0

	If Len(TextAreaText(textfield_r2))>8 And event.data<>8 Then Return 0

	Return 1

End Function


Function orbit(r1:Float,r2:Float)
	glcolor3f 1,1,1
	glbegin GL_Line_Loop
	For Local x:Int=0 To 359 Step 18

		Select sect_cols[x/18]
			Case 0	glcolor3f 1,1,1
			Case 1	glcolor3f 1,0,0
			Case 2	glcolor3f 0,1,0
			Case 3	glcolor3f 0,0,1
		EndSelect
		glvertex3f Sin(x)*r1,Cos(x)*r2,0
	Next                               
	glend
	glbegin GL_Lines
		glcolor3f 1,1,1
		glvertex3f Sin(90)*r1,Cos(90)*r2,0
		glvertex3f Sin(270)*r1,Cos(270)*r2,0
		glvertex3f 0,0,0
		glvertex3f Sin(180)*r1,Cos(180)*r2,0
		glcolor3f 1,0,0
		glvertex3f 0,0,0
		glvertex3f Sin(0)*r1,Cos(0)*r2,0
		
	glend
End Function



Cool now if only we could have some pritty buttons and sliders like Mac ones for Win BmxGui

Very nice 1500 fps full screen window :) 1280,1024,32

Cool now if only we could have some pritty buttons and sliders like Mac one


That's easy, buy a mac ;)