1 (edited by HondaDirtBiker 2006-05-29 14:52:25)

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

Re: Using GUI and User Input With Event Reciever.

greetings smile  what are the errors your getting?

3 (edited by HondaDirtBiker 2006-05-29 22:25:13)

Re: Using GUI and User Input With Event Reciever.

Ok. Actually I don't get errors but the GUI does not respond to the the events and probably the User Input aswell.
I am using the include function of BlitzMax for organization. The event reciver is in one file and the GUI templates are in another.

Here is the other file.

'===============================================
'----------- Graphic User Interface ------------
'===============================================

'------------------ GUI Skins ------------------

'Global Fonts and Skins
Global skin:T_irrIGUISkin = gui.getSkin()

Global guifont:T_irrIGUIFont = gui.getFont("media/fonthaettenschweiler.bmp")
Global hudfont:T_irrIGUIFont = gui.getFont("media/hudfont.bmp")
If (guifont.isValid())
    skin.setFont(guifont)
EndIf

'---------------- GUI Templates ----------------

'Temporary
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))

'Main Menu

'Player Menu

'Station Menu

'Station Creation

Re: Using GUI and User Input With Event Reciever.

sorry for the delay.  the first thing i see is that you have:

        Return False

'----------------- GUI Events ------------------
        If (event.getEventType()=EET_GUI_EVENT)

if im reading that correctly, it will always return before you make it to the GUI If statement so this is probably the cause of your woes.  more than likely its there due to copy/paste.  try removing that and see if your GUI events start firing.  also, you are remembering to create an instance of the T_irrIEventReceiver and setting it on the device correct?