;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; IrrlichtWrapper and FreeBasic-Example by Frank Dodd (2006)
;; Improved IrrlichtWrapper - Michael Taupitz (2007)
;; PureBasic-Examples by Michael Taupitz (neotoma) & Marius Eckardt (Thalius) 
;; ----------------------------------------------------------------------------
;; Example 26: Use the IrrlichtGui
;; This simple example builds some Gui-Controls in the IrrlichtGui. This
;; is an important Feature. You can have this GUI also in Fullscreen-Mode.
;; ----------------------------------------------------------------------------

;; ////////////////////////////////////////////////////////////////////////////
;; Include the Irr3D-Requester
XIncludeFile "Irr3DRequester.pb"


;; ////////////////////////////////////////////////////////////////////////////
;; Global variables
ScreenWidth.l = irr3DRequesterSetting\videomode\dimension\width
ScreenHeight.l = irr3DRequesterSetting\videomode\dimension\Height

; -----------------------------------------------------------------------------
; To Start the Irrlicht-Device we use the Irr3DRequester, to make it more comfortable
; for the Users, and also easier to test different resolutions and devices.
If Irr3DRequester()
  ; Set the title of the display
  IrrSetWindowCaption( "Example 26: Using the Irrlicht-GUI" )
  
  ; add a static text object to the graphical user interface, at the moment
  ; this is the only interface object we support. The text will be drawn inside
  ; the defined rectangle, the box will not have a border and the text will not
  ; be wrapped around if it runs off the end
  *caption.l = IrrGuiAddStaticText( "Hello World", 4,0,200,16, #IRR_GUI_NO_BORDER, #IRR_GUI_NO_WRAP )
  
  
  ; change the default text color of the gui object
  IrrGuiStaticSetOverrideColor(*caption,255,255,255)
  
  
  ; 
  *button.l = IrrGuiAddButton( "Hello World", 4,100,200,116, 0,10 )
  
  *scrollbar.l = IrrGuiAddScrollBar(#True, 4,120,200,136,0,11)
  IrrGuiScrollBarSetMax(*scrollbar,255)
  v.l = IrrGuiGetAlpha()
  IrrGuiScrollBarSetPos(*scrollbar,v)
  
  *PureLogo = IrrGetTexture( "media\PureBasicLogo2.jpg" )
  pw.l = 256
  ph.l = 64
  
  *Image = IrrGuiAddImage(ScreenWidth-pw,ScreenHeight-ph,(ScreenWidth-ph)+256,(ScreenHeight-ph)+64,0,12)
  
  IrrGuiImageSetImage(*Image,*PureLogo)
  IrrGuiImageSetUseAlphaChannel(*Image,#False)
  
  
  ; load the Scene, which was created with IrrEdit. So we have a complete Scene, with
  ; Objects, Animator and Lights. 
  IrrLoadScene("media\example.irr");
  
  ; add a first person perspective camera into the scene that is controlled with
  ; the mouse and the cursor keys. if however you capture events when starting
  ; irrlicht this will become a normal camera that can only be moved by code
  *OurCamera = IrrAddCamera( 50,0,0, 0,0,0 )
  
  ; while the scene is still running
  While IrrRunning()
  
      ; begin the scene, erasing the canvas to white before rendering
      IrrBeginScene( 255,255,255 )
  
      ; draw the scene
      
    While IrrGuiEventAvailable()
      *guievent.IRR_GUI_EVENT = IrrReadGuiEvent()
  ;;      Debug(Str(*guievent\eventtype))
      If *guievent\EventType > 0
      EndIf
      If *guievent\EventType > 0 
        If *guievent\Caller = *button And *guievent\EventType = #IRR_EGET_BUTTON_CLICKED
          Debug("Button !")
          IrrGuiSetText(*caption, "Button was pressed")
          mytext.s = IrrGuiGetText(*button)
          Debug(mytext)
        EndIf
        If *guievent\Caller = *scrollbar
          Debug("Scrollbar !")
          v.l = IrrGuiScrollBarGetPos(*scrollbar)
          IrrGuiSetAlpha(v )
         EndIf
      EndIf
    Wend
    
      ; while there are key events waiting to be processed
      While IrrKeyEventAvailable()
  
          ; read the key event out. the key event has three parameters the key
          ; scan code, the direction of the key and flags that indicate whether
          ; the control key or the shift keys were also pressed
          *KeyEvent.IRR_KEY_EVENT = IrrReadKeyEvent()
          Debug( "Key="+ Str(*KeyEvent\key))
       Wend
  
      IrrDrawScene()      
  
      ; draw the Graphical User Interface
      IrrDrawGUI()
  
      ; end drawing the scene and render it
      IrrEndScene()
      
  Wend
  
  ; -----------------------------------------------------------------------------
  ; Stop the irrlicht engine and release resources
  IrrStop()
EndIf

End

; jaPBe Version=3.7.2.629
; Build=0
; Language=0x0000 Language Neutral
; FirstLine=13
; CursorPosition=26
; ExecutableFormat=Console
; DontSaveDeclare
; IDE Options = PureBasic 4.10 Beta 2 (Windows - x86)
; CursorPosition = 83
; FirstLine = 74
; jaPBe Version=3.7.10.668
; Build=0
; FirstLine=0
; CursorPosition=0
; ExecutableFormat=Windows
; DontSaveDeclare
; EOF