Sure, Thanks.
'===============================================
'--------------- Player HUD Test ---------------
'===============================================
' *!* make sure you build this example with the "Build GUI App" option turned off
Strict
Framework BRL.Blitz
Import BRL.StandardIO
Import gg.IrrBMAX
'===============================================
'---------------- Player Input -----------------
'===============================================
'===============================================
'---------------- Irrlicht GUI -----------------
'===============================================
' due to OnEvent implementation, these must be global
Global cnt:Int = 0
Global listbox:T_irrIGUIListBox
Type MyEventReceiver Extends T_irrIEventReceiver
Method OnEvent:Int(event:T_irrSEvent)
If (event.getEventType()=EET_GUI_EVENT)
Local id:Int = event.getGUIEventCaller().getID()
Local gui:T_irrIGUIEnvironment = device.getGUIEnvironment()
Local evtype:Int=event.getGUIEventType()
Select evtype
Rem
If a scrollbar changed its scroll position, And it is 'our'
scrollbar (the one with id 104), Then we change the
transparency of all gui elements. This is a very easy task:
There is a skin Object, in which all color settings are stored.
We simply go through all colors stored in the skin And change
their alpha value.
EndRem
Case EGET_SCROLL_BAR_CHANGED
If (id = 104)
Local pos:Int = T_irrIGUIScrollBar.createFromHandle(event.getGUIEventCaller().handle,False).getPos()
Local i:Int
For i=0 To EGDC_COUNT-1
Local col:T_irrSColor = gui.getSkin().GetColor(i)
col.setAlpha(pos)
gui.getSkin().SetColor(i,col)
Next
EndIf
Rem
If a button was clicked, it could be one of 'our'
three buttons. If it is the first, we shut down the engine.
If it is the second, we create a little window with some
text on it. We also add a String To the list box To Log
what happened. And If it is the third button, we create
a file open dialog, And add also this as String To the list box.
That's all for the event receiver.
EndRem
Case EGET_BUTTON_CLICKED
If (id = 103)
device.closeDevice()
Return True
EndIf
If (id = 102)
listbox.addItem("Window created")
cnt :+ 30
If (cnt > 200)
cnt = 0
EndIf
Local window:T_irrIGUIWindow = gui.addWindow( ..
T_irrRect_s32.createFromVals(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt), ..
False, .. ' modal?
"Test window")
gui.addStaticText("Please close me", ..
T_irrRect_s32.createFromVals(35,35,140,50), ..
True, .. ' border?
False, .. ' wordwrap?
window)
Return True
EndIf
If (id = 101)
listbox.addItem("File open");
gui.addFileOpenDialog("Please choose a file.")
Return True
EndIf
EndSelect
EndIf
Return False
EndMethod
' we must override the generate function in order for instantiation to work properly
' must return T_irrIEventReceiver
Function generate:T_irrIEventReceiver()
Return T_irrIEventReceiver(New MyEventReceiver)
EndFunction
EndType
'===============================================
'---------------- Engine Set Up ----------------
'===============================================
Rem
The Next few lines start up the engine. Just like in most other tutorials
before. But in addition, we ask the user If he wants this example To use
high level shaders If he selected a driver which is capable of doing so.
EndRem
Rem
Select driver Type
EDT_SOFTWARE, EDT_SOFTWARE2, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, EDT_OPENGL.
EndRem
' create device
Global device:T_irrIrrlichtDevice=T_irrIrrlichtDevice.create(EDT_DIRECT3D8,T_irrDimension2d_s32.create(1024,768),16,True,False,True,Null)
If device.handle=0 Then Return ' could Not create selected driver.
Local video:T_irrIVideoDriver=device.getVideoDriver()
Local scene:T_irrISceneManager=device.getSceneManager()
Local gui:T_irrIGUIEnvironment=device.getGUIEnvironment()
'===============================================
'------------------ Main Menu ------------------
'===============================================
Rem
We add three buttons. The first one closes the engine. The second
creates a window And the third opens a file open dialog. The third
parameter is the id of the button, with which we can easily identify
the button in the event receiver.
EndRem
gui.addButton(T_irrRect_s32.createFromVals(10,210,100,240), Null, 101, "File Open")
gui.addButton(T_irrRect_s32.createFromVals(10,250,100,290), Null, 102, "New Window")
gui.addButton(T_irrRect_s32.createFromVals(10,300,100,340), Null, 103, "Quit")
Rem
Now, we add a static text And a scrollbar, which modifies the
transparency of all gui elements. We set the maximum value of
the scrollbar To 255, because that's the maximal value for
a color value.
Then we create an other static text And a list box.
EndRem
gui.addStaticText("Transparent Control:", T_irrRect_s32.createFromVals(150,20,350,40), True)
Local scrollbar:T_irrIGUIScrollBar = gui.addScrollBar(True, T_irrRect_s32.createFromVals(150, 45, 350, 60), Null, 104)
scrollbar.setMax(255)
gui.addStaticText("Console:", T_irrRect_s32.createFromVals(50,80,250,100), True)
listbox = gui.addListBox(T_irrRect_s32.createFromVals(50, 110, 250, 180))
Rem
To make the font a little bit nicer, we load an external font
And set it as New font in the skin. An at last, we create a
nice Irrlicht Engine logo in the top Left corner.
EndRem
Local skin:T_irrIGUISkin = gui.getSkin()
Local font:T_irrIGUIFont = gui.getFont("media/fonthaettenschweiler.bmp")
If (font.isValid())
skin.setFont(font)
EndIf
'===============================================
'------------------ Player HUD -----------------
'===============================================
Global weapon:T_IrrIVideoDriver = video.draw2DImage (video, weaponimage, T_irrPosition2d_s32.createFromVals(400, 64))
Local weaponimage = video.addTexture ("media/machine gun.bmp")
'===============================================
'----------------- Scene Props -----------------
'===============================================
'===============================================
'----------------- Scene Setup -----------------
'===============================================
Rem
And last, we add a skybox And a user controlled camera To the scene.
For the skybox textures, we disable mipmap generation, because we don't
need mipmaps on it.
EndRem
' add a nice skybox
scene.addSkyBoxSceneNode( ..
video.getTexture("media/Galaxy_UP.bmp"), ..
video.getTexture("media/Galaxy_DN.bmp"), ..
video.getTexture("media/Galaxy_LT.bmp"), ..
video.getTexture("media/Galaxy_RT.bmp"), ..
video.getTexture("media/Galaxy_FT.bmp"), ..
video.getTexture("media/Galaxy_BK.bmp"))
video.setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, False)
video.setTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED, True)
Rem
We create a Mesh Viewer style camera and make the
mouse cursor visible.
EndRem
Local cam:T_irrICameraSceneNode = scene.addCameraSceneNodeMaya(Null, 100.0, 100.0)
cam.setPosition(T_irrVector3df.createFromVals(-100,50,100))
cam.setTarget(T_irrVector3df.createFromVals(0,0,0))
device.getCursorControl().setVisible(True)
Local lastFPS:Int = -1
Local fps:Int = 0
Local str:String=""
'===============================================
'---------------- Render Scene -----------------
'===============================================
While(device.run())
If (device.isWindowActive())
device.setEventReceiver(T_irrIEventReceiver.create(MyEventReceiver.generate))
video.beginScene(True, True, T_irrSColor.createFromVals(255,0,0,0))
scene.drawAll()
gui.drawAll()
video.endScene()
fps = video.getFPS()
If (lastFPS <> fps) Then
str$ = "HUD Test - Irrlicht ["
str$ :+ video.getName()
str$ :+ "] FPS:"
str$ :+ fps
device.setWindowCaption(str$)
lastFPS = fps
EndIf
EndIf
'FlushMem
Wend