MaxGUI help. (i'm clueless)

BlitzMax Forums/MaxGUI Module/MaxGUI help. (i'm clueless)

Captain Wicker (crazy hillbilly)(Posted 2012) [#1]
Im stuck on the MaxGUI module and do not know how to get something to happen after a button is clicked on. I understand this much:
Import maxgui.drivers

Graphics 800,600

Global mywindow:TGadget=CreateWindow("My New Window",0,0,400,300,Null,WINDOW_DEFAULT)
Global mybutton:TGadget=CreateButton("Click Me",0,0,100,25,mywindow,BUTTON_PUSH)
Global myradio:TGadget=CreateButton("Radio",200,0,100,25,mywindow,BUTTON_RADIO)
Global myok:TGadget=CreateButton("OK",0,30,100,25,mywindow,BUTTON_OK)

Repeat

Flip
Until AppTerminate()

Where is a good resource for learning about the MaxGUI?


Enyaw(Posted 2012) [#2]
There some good MaxGUI tutorials here - http://www.blitzbasic.com/Community/posts.php?topic=54579


Midimaster(Posted 2012) [#3]
You need a complete "Event-Handler" which manage the Events the GUI is reporting. Here is a (non working) example of the basic elements you will need:

Import MaxGUI.Drivers 
Global Window:TGadget , Canvas:TGadget, text:Tgadget



CreateMyWindow()


CreateTimer 60
While WaitEvent()
	Local tmpGadget:TGadget
	Global MausX%, MausY%
	Select EventID()
		Case EVENT_TIMERTICK
				MyMainLoop
	  			RedrawGadget canvas	
			
	  	Case EVENT_GADGETPAINT
		   		Local Fenster:TGraphics=CanvasGraphics(canvas)
		   		SetGraphics Fenster
				SetClsColor 255,255,255
				SetColor 255,0,0
				'Cls
				DrawOval MausX,MausY,5,5
				Flip
	   	Case EVENT_WINDOWCLOSE
			ProgrammEnde 
			
	  	Case EVENT_APPTERMINATE
			ProgrammEnde 
			
		Case EVENT_MENUACTION
		
	 	Case	EVENT_MOUSEDOWN 
				tmpGadget = TGadget(EventSource())			
				If tmpGadget=Canvas
					Print "maus " + mausx + " " + mausy
				EndIf
	 	Case	EVENT_MOUSEMOVE 
				tmpGadget= TGadget(EventSource())
				If tmpGadget=Canvas
					MausX=EventX()
					MausY=EventY()
				EndIf
		Case EVENT_GADGETACTION
			If AktivesFenster()=Window Then
				Event EventSource()					
		    Else
		
			EndIf
 		Case EVENT_KEYDOWN
			ScanTasten EventData(),1
			PrintOut "KKeydown" + EventData()
		Case EVENT_KEYUP
			ScanTasten EventID(),0	
	End Select
Wend
ProgrammEnde 


Function ProgrammEnde()
	End
End Function




Function MyMainLoop()

End Function




Function CreateMyWindow()
		Local flags%=WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS|WINDOW_CENTER
		Window= CreateWindow("Window with Canvas" , 0 , 0 , 600 , 400 , Null , Flags%)
		Canvas=CreateCanvas(5 , 95 , 400, 300 , Window)
		Text=CreateTextField(40,40,200,40,window)
		'ExitButton=CreateButtton(...)
		SetGadgetText text,"123456789!"
		Select text,1
End Function



Function Event (EventQuelle:Object)
		Local i%
		Local tmpGadget:TGadget = TGadget(EventQuelle)
		If tmpGadget 
			If (GadgetClass(tmpGadget) =GADGET_TOOLBAR)
						PrintOut "switch toolbar " + EventData()
						Select EventData()
							'Case TOOL_EXIT
							
							'Case ....
							
						End Select
			ElseIf (GadgetClass(tmpGadget) =GADGET_BUTTON)
					PrintOut "Event Button-Click " + GadgetText(tmpGadget)
					Select tmpGadget
						' Case ExitButton

						' Case .....

					End Select
			EndIf
	Endif
End Function


Function AktivesFenster:TGadget()
	Local tmpGadget:TGadget = ActiveGadget()
	While tmpGadget And GadgetClass(tmpGadget) <> GADGET_WINDOW
		tmpGadget = GadgetGroup(tmpGadget)
	Wend
	Return tmpGadget
End Function



I wrote it on the fly without testing it, but it shows the way....


Captain Wicker (crazy hillbilly)(Posted 2012) [#4]
Thanks to the both of you! :)
Midimaster, very nice code structure there. :)


Captain Wicker (crazy hillbilly)(Posted 2012) [#5]
Why doesn't the sphere show up in this?
I DO NOT CLAIM THIS CODE AS MY OWN AND AM USING IT ONLY FOR PRACTICE


Last edited 2012


jsp(Posted 2012) [#6]
I don't have minib3d installed so can't test this, but:
remove UpdateWorld, RenderWorld and Flip from the Repeat Forever loop, it does not belong there.
Try to have only one Flip, which is already correct in the UpdateCanvas. Put your UpdateWorld and Renderworld in a separate function.
Then add a timer like in the example Midimaster posted above and call the UpdateCanvas to display whatever you need.


Midimaster(Posted 2012) [#7]
You have to prepare some things before combining MaxGui and MiniB3D. There is a sample coming with the MiniB3D source. Here is a reduced minimum of this code:

' Based on code by Birdie and Peter Scheutz

Import sidesign.minib3d
Import maxgui.drivers
Strict

SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER

Local win:TGadget=CreateWindow("MiniB3D in a GUI window", 10, 10, 512, 512 )

Local can:TGadget=CreateCanvas(0,0,ClientWidth(win),ClientHeight(win),win,0)
SetGadgetLayout can,1,1,1,1

TGlobal.width=ClientWidth(win)
TGlobal.height=ClientHeight(win)

TGlobal.depth=16
TGlobal.mode=0
TGlobal.rate=60

SetGraphics CanvasGraphics(can)

TGlobal.GraphicsInit()

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-10
Local light:TLight=CreateLight(1)
Local cube:TMesh=CreateCube()
'PositionEntity cube,-6,0,0



CreateTimer( 60 )

While True
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
            End

		Case EVENT_WINDOWSIZE	
			TGlobal.width=ClientWidth(win)
			TGlobal.height=ClientHeight(win)
			cam.CameraViewport(0,0,ClientWidth(win),ClientHeight(win))
		Case EVENT_TIMERTICK
			RedrawGadget can
		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(can)
			TurnEntity cube,0,1,0
			RenderWorld
			Flip
	EndSelect
Wend




Captain Wicker (crazy hillbilly)(Posted 2012) [#8]
:D