Topic: Using GUI and User Input With Event Reciever.
I'm trying to use the Event Reciever with GUI and User Input.
I tried pasting the both tutorials into my Event Reciever and get some errors.
Here's my code. Thanks.
'===============================================
'----------------- User Input ------------------
'===============================================
' 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)
'---------------- Input Events -----------------
If (event.getEventType()=EET_KEY_INPUT_EVENT And event.getKeyPressedDown()=True)
Local Key:Int=event.getKeyInputKey()
Select Key
'Thrust
' Case EKEY_KEY_UP
' thrust:Int = 1
' Return True
'Retro
' Case EKEY_KEY_DOWN
' retro:Int = 1
' Return True
'Yaw
'Right
Case EKEY_KEY_D
Return True
'Left
Case EKEY_KEY_A
Return True
'Pitch
'Up
Case EKEY_KEY_W
Return True
'Down
Case EKEY_KEY_S
Return True
'Roll
'Right
Case EKEY_KEY_E
Return True
'Left
Case EKEY_KEY_Q
Return True
'Action Primary
' Case EKEY_KEY_SPACE
' Return True
'Action Secondary
' Case EKEY_KEY_CONTROL
' Return True
'Weapon Select
'Next
' Case EKEY_KEY_PERIOD
' Return True
'Previous
' Case EKEY_KEY_COMMA
' Return True
'Item Select
'Next
' Case EKEY_KEY_
' Return True
'Previous
' Case EKEY_KEY_
' Return True
Default
Return False
EndSelect
EndIf
Return False
'----------------- GUI Events ------------------
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