FreeBASIC binding of Irrlicht 3D engine 1.8.6

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by D.J.Peters »

VANYA wrote:It's okay now. The examples provided work correctly. Tested on Linux x86-64.
@VANYA thank you for the feedback !

@jepalza looks like I see the problem you got with MD3 stuff in the past with other language bindings !

I wrote "IAnimatedMeshMD2.bi" and "IAnimatedMeshMD3.bi" today
and the problem are the memory alignment BASIC/C VS. C++

I wrote it before, we will get it working with FreeBASIC (trust me :lol:)

Joshy
jepalza
Posts: 149
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by jepalza »

Full GUI example:

Code: Select all

/'* Example 005 User Interface

This tutorial shows how to use the built in User Interface of
the Irrlicht Engine. It will give a brief overview and show
how to create and use windows, buttons, scroll bars, static
texts, and list boxes.

As always, we include the header files, and use the irrlicht
namespaces. We also store a pointer to the Irrlicht device,
a counter variable for changing the creation position of a window,
and a pointer to a listbox.
'/
#include "Irrlicht-c.bi"

'Using irr
'
'using core
'using scene
'using video
'using io
'using gui 


'' Declare a structure to hold some context for the event receiver so that it
'' has it available inside its OnEvent() method.
Type SAppContext
	As IrrlichtDevice ptr	device
	As s32				ptr	counter
	As IGUIListBox		ptr	listbox
End Type
Dim shared As SAppContext context_ 


' SUBroutine to EVENT managed
Declare Function MyEventReceiver Cdecl (byref event as const SEvent) as BOOLEAN


' Define some values that we´ll use to identify individual GUI controls.
enum 
	USER_GUI_ID_QUIT_BUTTON= 101,
	USER_GUI_ID_NEW_WINDOW_BUTTON,
	USER_GUI_ID_FILE_OPEN_BUTTON,
	USER_GUI_ID_TRANSPARENCY_SCROLL_BAR
End Enum


' create the render device (window or fullscreen)
Dim Shared As IrrlichtDevice ptr dev 


' -------------------------------------------
' for getting EVENTS are two methods

' first, we create Device with Events
'dev = CreateDevice(,,,,,,@MyEventReceiver) ' includes EVENT receiver for GUI

' or maybe, creating empty Device, then refering Events with "GUIEnvironmentSetUserEventReceiver" (see it below code)
dev = CreateDevice() ' creating WITHOUT events
' -------------------------------------------

devicesetWindowCaption(dev,"Irrlicht Engine - User Interface Demo") 
'devicesetResizable(dev,TRUE) 

' get the driver (renderer)
var drv = DeviceGetVideoDriver(dev)

' GUI interface
Dim Shared As IGUIEnvironment Ptr env
env = devicegetGUIEnvironment(dev) 


' scroll bar creation
Dim Shared As IGUIScrollBar ptr scrollbar





' Set the skin transparency by changing the alpha values of all skin-colors
Sub user_setSkinTransparency(alpha_ As s32 , skin As IGUISkin Ptr)

	Dim As SColor col
	Print "Alpha Color for SKIN:";alpha_
	Dim As s32 Ptr ptrcol

	for i As s32=0 To EGDC_COUNT -1      ' Number of GUI elements

		col = GUISkinGetColor(skin,i) ' SKIN color by GUI Element
		ptrcol=@col ' Pointer to "Scolor" Skin
		*ptrcol =(*ptrcol And &h00ffffff) Or (alpha_ Shl 24) ' Setting Alpha Channel
		GUISkinSetColor(skin,i,col) ' Drop new color
	
   Next

End Sub




/'
The Event Receiver is not only capable of getting keyboard and
mouse input events, but also events of the graphical user interface
(gui). There are events for almost everything: Button click,
Listbox selection change, events that say that a element was hovered
and so on. To be able to react to some of these events, we create
an event receiver.
We only react to gui events, and if it´s such an event, we get the
id of the caller (the gui element which caused the event) and get
the pointer to the gui environment.
'/
function MyEventReceiver Cdecl (byref event_ as const SEvent) as BOOLEAN

		If event_.EventType<>4 Then 
			Locate 20,1
			'Print "EventType: ";event_.EventType ',event_.GUIEvent.Caller
		EndIf

		select case as const event_.EventType 

			Case EET_GUI_EVENT ' 0
			    print "EventType: 0 GUI_EVENT INTERFACE: " & event_.GUIEvent.EventType
			    ' Get ID USER Event
			    Dim As s32 id = GUIElementGetID(event_.GUIEvent.Caller)
			    select case as const event_.GUIEvent.EventType
			    	Case EGET_SCROLL_BAR_CHANGED 
						if (id = USER_GUI_ID_TRANSPARENCY_SCROLL_BAR) Then 
							Dim As s32 scrollbarpos = GUIScrollBarGetPos(scrollbar)
							Print "Scroll Bar Position:";scrollbarpos;"  "
							user_setSkinTransparency(scrollbarpos, GUIEnvironmentgetSkin(env)) 
						EndIf
	
			    	Case EGET_BUTTON_CLICKED 
						Select Case (id)
						 
							Case USER_GUI_ID_QUIT_BUTTON 
								DeviceClose(dev)  ' C++ equivalent -> Context.device->closeDevice(); ???
								return TRUE 
		
							case USER_GUI_ID_NEW_WINDOW_BUTTON 
								GUIlistBoxAddItem(context_.listbox,"Window created") 
								context_.counter += 30 
								if (context_.counter > 200) Then  context_.counter = 0
								
								Dim As IGUIWindow ptr window_ = GUIEnvironmentAddWindow( env , _
									Type( CLng( 50 + context_.counter), _
											CLng( 50 + context_.counter), _
											CLng(200 + context_.counter), _
											CLng(200 + context_.counter) ), _
									FALSE, _
									"Test window") 
		
								GUIEnvironmentAddStaticText(env ,"Please close me", _
									type(35,35,140,50), _
									TRUE, _
									FALSE, _
									window_) 
								return TRUE 
		
							Case USER_GUI_ID_FILE_OPEN_BUTTON 
								GUIlistBoxAddItem(context_.listbox,"File open") 
								'' There are some options for the file open dialog
								'' We set the title, make it a modal window, and make sure
								'' that the working directory is restored after the dialog
								'' is finished.
								GUIEnvironmentaddFileOpenDialog(env,"Please choose a file.", TRUE , 0, -1, TRUE ) 
								return TRUE 
		
							Case else 
								Return FALSE 
						
		           	End Select
	
	
					case EGET_FILE_SELECTED 
						' show the model filename, selected in the file dialog
						Dim As IGUIFileOpenDialog ptr dialog = Cast(IGUIFileOpenDialog Ptr, event_.GUIEvent.Caller)
						GUIlistBoxAddItem(context_.listbox,GUIFileOpenDialogGetFileName(dialog)) 
	
	
			    	case EGET_ELEMENT_FOCUS_LOST 
			    	case EGET_ELEMENT_FOCUSED
			    	case EGET_ELEMENT_HOVERED
			    	case EGET_ELEMENT_LEFT
			    	case EGET_ELEMENT_CLOSED
			    	case EGET_CHECKBOX_CHANGED
			    	case EGET_LISTBOX_CHANGED
			    	case EGET_LISTBOX_SELECTED_AGAIN
			    	case EGET_DIRECTORY_SELECTED
			    	case EGET_FILE_CHOOSE_DIALOG_CANCELLED
			    	case EGET_MESSAGEBOX_YES
			    	case EGET_MESSAGEBOX_NO
			    	case EGET_MESSAGEBOX_OK
			    	case EGET_MESSAGEBOX_CANCEL
			    	case EGET_EDITBOX_ENTER
			    	case EGET_EDITBOX_CHANGED
			    	case EGET_EDITBOX_MARKING_CHANGED
			    	case EGET_TAB_CHANGED
			    	case EGET_MENU_ITEM_SELECTED
			    	case EGET_COMBO_BOX_CHANGED
			    	case EGET_SPINBOX_CHANGED
			    	case EGET_TABLE_CHANGED
			    	case EGET_TABLE_HEADER_CHANGED
			    	case EGET_TABLE_SELECTED_AGAIN
			    	case EGET_TREEVIEW_NODE_DESELECT
			    	case EGETT_TREEVIEW_NODE_SELECT
			    	case EGET_TREEVIEW_NODE_EXPAND
			    	case EGET_TREEVIEW_NODE_COLLAPSE
			    end select
		    
		    
		    
		    
		   ' ------------------------------------  MOUSE ------------------------------- 
			Case EET_MOUSE_INPUT_EVENT ' 1
			   Dim as string k = "EventType: 1 MOUSE_INPUT_EVENT "
		   	Select case as const event_.MouseInput.Event    
		   		Case EMIE_LMOUSE_PRESSED_DOWN : k &= "L Down"
		   		case EMIE_RMOUSE_PRESSED_DOWN : k &= "R Down"
		   		case EMIE_MMOUSE_PRESSED_DOWN : k &= "M Down"
		   		case EMIE_LMOUSE_LEFT_UP      : k &= "L UP"
		   		case EMIE_RMOUSE_LEFT_UP      : k &= "R UP"
		   		case EMIE_MMOUSE_LEFT_UP      : k &= "M UP"
		   		case EMIE_MOUSE_MOVED         : k &= "MOVE : " & event_.MouseInput.X & ", " & event_.MouseInput.Y
		   		case EMIE_MOUSE_WHEEL         : k &= "WHEEL: " & event_.MouseInput.wheel
		   		case EMIE_LMOUSE_DOUBLE_CLICK : k &= "L DBL"
		   		case EMIE_RMOUSE_DOUBLE_CLICK : k &= "R DBL"
		   		case EMIE_MMOUSE_DOUBLE_CLICK : k &= "M DBL"
		   		case EMIE_LMOUSE_TRIPLE_CLICK : k &= "L TRI"
		   		case EMIE_RMOUSE_TRIPLE_CLICK : k &= "R TRI"
		   		case EMIE_MMOUSE_TRIPLE_CLICK : k &= "M TRI"
		   	end select
		    	If event_.MouseInput.Shift   then k &= " [shift]"
		    	If event_.MouseInput.Control then k &= " [ctrl]"
		    	Print k


		   ' ------------------------------------  KEYBOARD  ------------------------------- 		    
			Case EET_KEY_INPUT_EVENT '2
		   	Print "EventType: 2 KEY_INPUT_EVENT ";
		   	Dim as string k
		   	If event_.KeyInput.char    then k  = "char code: " & event_.KeyInput.char & " " 
		   	If event_.KeyInput.key     then k &= "key code : " & event_.KeyInput.key
		   	If event_.KeyInput.shift   then k &= " & [shift]" 
		   	If event_.KeyInput.Control then k &= " & [ctrl]" 
		   	Print k


		   ' ------------------------------------ JOYSTICK ------------------------------- 		    
			Case EET_JOYSTICK_INPUT_EVENT ' 3
		   	Print "EventType: 3 JOYSTICK_INPUT_EVENT "


		   ' ------------------------------------ LOG EVENT ------------------------------- 		    
			Case EET_LOG_TEXT_EVENT ' 4
		   	Print "EventType: 4 LOG_TEXT_EVENT -> " & *event_.LogEvent.text
		   	Return TRUE

		   ' ------------------------------------ USER ------------------------------- 		    
			Case EET_USER_EVENT ' 5
		   	Print "EventType: 5 USER_EVENT "

		End Select ' end EVENTYPE
  
		return FALSE 

End Function 


/'
Ok, now for the more interesting part. First, create the Irrlicht device. As in
some examples before, we ask the user which driver he wants to use for this
example:
'/





	/'
	To make the font a little bit nicer, we load an external font
	and set it as the new default font in the skin.
	To keep the standard font for tool tip text, we set it to
	the built-in font.
	'/
	Dim As IGUISkin Ptr skin = GUIEnvironmentGetSkin(env) 
	Dim As IGUIFont Ptr font = GUIEnvironmentGetFontByPath(env,GetPath("./media/fonthaettenschweiler.bmp")) 
	if (font) Then  GUISkinSetFont(skin,font)
  

	GuiSkinSetFont(skin,GUIEnvironmentgetBuiltInFont(env), EGDF_TOOLTIP) 

	/'
	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.
	'/	
	GUIEnvironmentAddButton(env,Type(10,240,110,240 + 32), 0, USER_GUI_ID_QUIT_BUTTON, "Quit", "Exits Program") 
	GUIEnvironmentAddButton(env,Type(10,280,110,280 + 32), 0, USER_GUI_ID_NEW_WINDOW_BUTTON, "New Window", "Launches a new Window") 
	GUIEnvironmentAddButton(env,Type(10,320,110,320 + 32), 0, USER_GUI_ID_FILE_OPEN_BUTTON, "File Open", "Opens a file") 

	/'
	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.
	'/
	GUIEnvironmentaddStaticText(env,"Transparent Control:",type(150,20,350,40), TRUE) 
	scrollbar = GUIEnvironmentaddScrollBar(env,TRUE, type(150, 45, 350, 60), 0, USER_GUI_ID_TRANSPARENCY_SCROLL_BAR) 
	GUIScrollBarSetMax( scrollbar,255)
	GUIScrollBarSetPos( scrollbar,255)
	
	' custom Set Skin Transparency SUB
	user_setSkinTransparency( GUIScrollBarGetPos(scrollbar), GUIEnvironmentGetSkin(env) )


	' set scrollbar position to alpha value of an arbitrary element
	'GUIScrollBarSetPos( env, scrollbar, GUIEnvironmentgetSkin()->getColor(EGDC_WINDOW).getAlpha() ) 


	GUIEnvironmentaddStaticText(env,"Logging ListBox:", type(50,110,250,130), TRUE ) 
	Dim As IGUIListBox ptr listbox = GUIEnvironmentaddListBox(env, Type(50, 140, 250, 210)) 
	GUIEnvironmentaddEditBox(env, "Editable Text", type(350, 80, 550, 100)) 


	'' Store the appropriate data in a context structure.
	context_.device  = dev 
	context_.counter = 0 
	context_.listbox = listbox 

	' another method of get events (see "CreateDevice()" above code)
	GUIEnvironmentSetUserEventReceiver(env,@MyEventReceiver)


	' And at last, we create a nice Irrlicht Engine logo in the top left corner.
	Var logo= DriverGetTextureFromPath(drv,getpath("./media/irrlichtlogo2.png"))
	Var img = GUIEnvironmentAddImage(env, recti(10,10,160, 120))
	GUIImageSetImage(img,logo)




' while window is open
while DeviceRun(dev) andalso drv<>NULL
  ' and is active
  if DeviceIsWindowActive(dev) then
    ' draw a frame 
    DriverBeginScene(drv,TRUE,TRUE,SColor(200,200,200)) ' begin a render frame
    
    GUIEnvironmentDrawAll(env)
    
    DriverEndScene(drv) ' show the result on screen
    DeviceSleep(dev,1000\60) ' down't eat all CPU cycles :-)
  else
    ' handle only window events 
    DeviceYield(dev)
  endif

wend
' delete the device
DeviceDrop(dev)

Last edited by jepalza on Jan 13, 2022 4:35, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by D.J.Peters »

jepalza wrote:Skin Transparency with ScrollBar and Logo Image on GUI don't work by the moment
Be sure you used allways the same or latest version I use here from: Sun Jan 09, 2022 9:57 see first post.

You made an mistake in the context structure the member "counter" is a signed number (s32) not a pointer !
Transparency works so far but I must do and deeper look at the texture to GUI image function.

Again thank you for reporting problems.
Writing all the C++ and FreeBASIC stuff is a big thing but testing all this 1230 method's are a nother big thing :-)

Joshy

here are how I change the alpha value of ALL kinds of GUI colors

Code: Select all

' Set the skin transparency by changing the alpha values of all skin-colors
Sub setSkinTransparency(alpha_ As s32)
   for i as u32 = 0 to EGDC_COUNT-1
     var col = GUISkinGetColor(skin,i)
     col.color and = &H00FFFFFF ' ignore current alpha value
     col.color or  = (alpha_ and &HFF) shl 24 ' set new alpha value
     GUISkinSetColor(skin,i,col)
   next  
End Sub
Here are your posted example:

Code: Select all

/'* Example 005 User Interface

This tutorial shows how to use the built in User Interface of
the Irrlicht Engine. It will give a brief overview and show
how to create and use windows, buttons, scroll bars, static
texts, and list boxes.

As always, we include the header files, and use the irrlicht
namespaces. We also store a pointer to the Irrlicht device,
a counter variable for changing the creation position of a window,
and a pointer to a listbox.
'/
#include "Irrlicht-c.bi"

'' Declare a structure to hold some context for the event receiver so that it
'' has it available inside its OnEvent() method.
Type SAppContext
   As IrrlichtDevice ptr   device
   As s32               counter
   As IGUIListBox    ptr   listbox
End Type
Dim shared As SAppContext context_


' Define some values that we´ll use to identify individual GUI controls.
enum
   USER_GUI_ID_QUIT_BUTTON= 101
   USER_GUI_ID_NEW_WINDOW_BUTTON
   USER_GUI_ID_FILE_OPEN_BUTTON
   USER_GUI_ID_TRANSPARENCY_SCROLL_BAR
End Enum


' create the render device (window or fullscreen)
Dim Shared As IrrlichtDevice ptr dev
' GUI interface
Dim Shared As IGUIEnvironment Ptr env
' scroll bar creation
Dim Shared As IGUIScrollBar ptr scrollbar

Dim Shared As IGUISkin ptr skin

' Set the skin transparency by changing the alpha values of all skin-colors
Sub setSkinTransparency(alpha_ As s32)
   Dim As SColor col
   Print "SKIN:";alpha_
   for i as u32 = 0 to EGDC_COUNT-1
     col = GUISkinGetColor(skin,i)
     col.color and = &H00FFFFFF
     col.color or  = (alpha_ and &HFF) shl 24
     GUISkinSetColor(skin,i,col)
   next  
End Sub

' The Event Receiver is not only capable of getting keyboard and mouse input events,
' but also events of the graphical user interface (gui).
' There are events for almost everything: Button click, Listbox selection change,
' events that say that a element was hovered and so on.
' To be able to react to some of these events, we create an event receiver.
' We only react to gui events, and if it´s such an event,
' we get the id of the caller (the gui element which caused the event) and get the pointer to the gui environment.
function MyEventReceiver Cdecl (byref event_ as const SEvent) as BOOLEAN
  If event_.EventType<>4 Then Locate 20,1
  select case as const event_.EventType
  Case EET_GUI_EVENT ' 0
    print "EventType: 0 GUI_EVENT INTERFACE: " & event_.GUIEvent.EventType
    ' Get ID USER Event
    Dim As s32 id = GUIElementGetID(event_.GUIEvent.Caller)
    select case as const event_.GUIEvent.EventType
    Case EGET_SCROLL_BAR_CHANGED
      if (id = USER_GUI_ID_TRANSPARENCY_SCROLL_BAR) Then
        Dim As s32 scrollbarpos = GUIScrollBarGetPos(scrollbar)
        Print "Scroll Bar Position:";scrollbarpos;"  "
        SetSkinTransparency(scrollbarpos)
      EndIf
    Case EGET_BUTTON_CLICKED
      Select Case (id)
      Case USER_GUI_ID_QUIT_BUTTON
        DeviceClose(dev)  ' C++ equivalent -> Context.device->closeDevice(); ???
        return TRUE
      case USER_GUI_ID_NEW_WINDOW_BUTTON
        GUIlistBoxAddItem(context_.listbox,"Window created")
        context_.counter += 30
        if (context_.counter > 200) Then  context_.counter = 0
        dim as recti size = type<recti>( 50 + context_.counter,50 + context_.counter, 200 + context_.counter, 200 + context_.counter)
        Dim As IGUIWindow ptr window_ = GUIEnvironmentAddWindow(env,size,,"Test window")
        GUIEnvironmentAddStaticText(env ,"Please close me",type(35,35,140,50),TRUE,FALSE,window_)
        return TRUE
      Case USER_GUI_ID_FILE_OPEN_BUTTON
        GUIlistBoxAddItem(context_.listbox,"File open")
        ' There are some options for the file open dialog
        ' We set the title, make it a modal window, and make sure
        ' that the working directory is restored after the dialog is finished.
        GUIEnvironmentaddFileOpenDialog(env,"Please choose a file.", TRUE , 0, -1, TRUE )
        return TRUE
      Case else
        Return FALSE
      End Select
    case EGET_FILE_SELECTED
      ' show the model filename, selected in the file dialog
      Dim As IGUIFileOpenDialog ptr dialog = Cast(IGUIFileOpenDialog Ptr, event_.GUIEvent.Caller)
      GUIlistBoxAddItem(context_.listbox,GUIFileOpenDialogGetFileName(dialog))
    case EGET_ELEMENT_FOCUS_LOST
    case EGET_ELEMENT_FOCUSED
    case EGET_ELEMENT_HOVERED
    case EGET_ELEMENT_LEFT
    case EGET_ELEMENT_CLOSED
    case EGET_CHECKBOX_CHANGED
    case EGET_LISTBOX_CHANGED
    case EGET_LISTBOX_SELECTED_AGAIN
    case EGET_DIRECTORY_SELECTED
    case EGET_FILE_CHOOSE_DIALOG_CANCELLED
    case EGET_MESSAGEBOX_YES
    case EGET_MESSAGEBOX_NO
    case EGET_MESSAGEBOX_OK
    case EGET_MESSAGEBOX_CANCEL
    case EGET_EDITBOX_ENTER
    case EGET_EDITBOX_CHANGED
    case EGET_EDITBOX_MARKING_CHANGED
    case EGET_TAB_CHANGED
    case EGET_MENU_ITEM_SELECTED
    case EGET_COMBO_BOX_CHANGED
    case EGET_SPINBOX_CHANGED
    case EGET_TABLE_CHANGED
    case EGET_TABLE_HEADER_CHANGED
    case EGET_TABLE_SELECTED_AGAIN
    case EGET_TREEVIEW_NODE_DESELECT
    case EGETT_TREEVIEW_NODE_SELECT
    case EGET_TREEVIEW_NODE_EXPAND
    case EGET_TREEVIEW_NODE_COLLAPSE
    end select
         
  ' ------------------------------------  MOUSE -------------------------------
  Case EET_MOUSE_INPUT_EVENT ' 1
    Dim as string k = "EventType: 1 MOUSE_INPUT_EVENT "
    Select case as const event_.MouseInput.Event   
    Case EMIE_LMOUSE_PRESSED_DOWN : k &= "L Down"
    case EMIE_RMOUSE_PRESSED_DOWN : k &= "R Down"
    case EMIE_MMOUSE_PRESSED_DOWN : k &= "M Down"
    case EMIE_LMOUSE_LEFT_UP      : k &= "L UP"
    case EMIE_RMOUSE_LEFT_UP      : k &= "R UP"
    case EMIE_MMOUSE_LEFT_UP      : k &= "M UP"
    case EMIE_MOUSE_MOVED         : k &= "MOVE : " & event_.MouseInput.X & ", " & event_.MouseInput.Y
    case EMIE_MOUSE_WHEEL         : k &= "WHEEL: " & event_.MouseInput.wheel
    case EMIE_LMOUSE_DOUBLE_CLICK : k &= "L DBL"
    case EMIE_RMOUSE_DOUBLE_CLICK : k &= "R DBL"
    case EMIE_MMOUSE_DOUBLE_CLICK : k &= "M DBL"
    case EMIE_LMOUSE_TRIPLE_CLICK : k &= "L TRI"
    case EMIE_RMOUSE_TRIPLE_CLICK : k &= "R TRI"
    case EMIE_MMOUSE_TRIPLE_CLICK : k &= "M TRI"
    end select
    if event_.MouseInput.Shift   then k &= " [shift]"
    If event_.MouseInput.Control then k &= " [ctrl]"
    Print k
    
  ' ------------------------------------  KEYBOARD  -------------------------------          
  Case EET_KEY_INPUT_EVENT '2
    Print "EventType: 2 KEY_INPUT_EVENT ";
    Dim as string k
    If event_.KeyInput.char    then k  = "char code: " & event_.KeyInput.char & " "
    If event_.KeyInput.key     then k &= "key code : " & event_.KeyInput.key
    If event_.KeyInput.shift   then k &= " & [shift]"
    If event_.KeyInput.Control then k &= " & [ctrl]"
    Print k

  ' ------------------------------------ JOYSTICK -------------------------------          
  Case EET_JOYSTICK_INPUT_EVENT ' 3
    Print "EventType: 3 JOYSTICK_INPUT_EVENT "
  ' ------------------------------------ LOG EVENT -------------------------------          
  Case EET_LOG_TEXT_EVENT ' 4
    Print "EventType: 4 LOG_TEXT_EVENT -> " & *event_.LogEvent.text
    Return TRUE

  ' ------------------------------------ USER -------------------------------          
  Case EET_USER_EVENT ' 5
    Print "EventType: 5 USER_EVENT "
  End Select ' end EVENTYPE
  return FALSE
End Function




' -------------------------------------------
' for getting EVENTS are two methods

' first, creatin Device with Events
'dev = CreateDevice(,,,,,,@MyEventReceiver) ' includes EVENT receiver for GUI

' or second, creating empty Device, then refering Events with "GUIEnvironmentSetUserEventReceiver" (see it below code)
dev = CreateDevice() ' creating WITHOUT events
' -------------------------------------------

devicesetWindowCaption(dev,"Irrlicht Engine - User Interface Demo")
'devicesetResizable(dev,TRUE)

' get the driver (renderer)
var drv = DeviceGetVideoDriver(dev)


env = devicegetGUIEnvironment(dev)

' To make the font a little bit nicer, we load an external font and set it as the new default font in the skin.
' To keep the standard font for tool tip text, we set it to the built-in font.
skin = GUIEnvironmentGetSkin(env)
Dim As IGUIFont Ptr font = GUIEnvironmentGetFontByPath(env,GetPath("./media/fonthaettenschweiler.bmp"))
if (font) Then  GUISkinSetFont(skin,font)
GuiSkinSetFont(skin,GUIEnvironmentgetBuiltInFont(env), EGDF_TOOLTIP)

' 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.
GUIEnvironmentAddButton(env,recti(10,240,110,240 + 32), 0, USER_GUI_ID_QUIT_BUTTON      , "Quit"      , "Exits Program")
GUIEnvironmentAddButton(env,recti(10,280,110,280 + 32), 0, USER_GUI_ID_NEW_WINDOW_BUTTON, "New Window", "Launches a new Window")
GUIEnvironmentAddButton(env,recti(10,320,110,320 + 32), 0, USER_GUI_ID_FILE_OPEN_BUTTON , "File Open" , "Opens a file")

' 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.
GUIEnvironmentaddStaticText(env,"Transparent Control:",recti(150,20,350,40), TRUE)
scrollbar = GUIEnvironmentaddScrollBar(env,TRUE, recti(150, 45, 350, 60), 0, USER_GUI_ID_TRANSPARENCY_SCROLL_BAR)
GUIScrollBarSetMax(scrollbar,255)
GUIScrollBarSetPos(scrollbar,255)
   
' custom Set Skin Transparency SUB
SetSkinTransparency(GUIScrollBarGetPos(scrollbar))

' set scrollbar position to alpha value of an arbitrary element
'GUIScrollBarSetPos( env, scrollbar, GUIEnvironmentgetSkin()->getColor(EGDC_WINDOW).getAlpha() )
GUIEnvironmentAddStaticText(env,"Logging ListBox:", recti(50,110,250,130), TRUE )
dim As IGUIListBox ptr listbox = GUIEnvironmentaddListBox(env, recti(50, 140, 250, 210))
GUIEnvironmentaddEditBox(env, "Editable Text", recti(350, 80, 550, 100))

' Store the appropriate data in a context structure.
context_.device  = dev
context_.counter = 0
context_.listbox = listbox

' another method of get events (see "CreateDevice()" above code)
GUIEnvironmentSetUserEventReceiver(env,@MyEventReceiver)


' And at last, we create a nice Irrlicht Engine logo in the top left corner.
Var logo = DriverGetTextureFromPath(drv,getpath("./media/irrlichtlogo2.png"))

/'
  irr::gui::IGUIImage* CAPI GUIEnvironmentAddImageByTexture(
  irr::gui::IGUIEnvironment* env,
  irr::video::ITexture* image,
  irr::core::position2di pos,
  bool useAlphaChannel,
  irr::gui::IGUIElement* parent,
  irr::s32 id,
  const wchar_t* text){
  return env->addImage(image,pos,useAlphaChannel,parent,id,text);
'/   
'var img = GUIEnvironmentAddImageByTexture(env, logo, type(10,10)) ' Don't works by now!!!

/'
irr::gui::IGUIImage* CAPI GUIEnvironmentAddImage(
  irr::gui::IGUIEnvironment* env,
  const irr::core::recti& rectangle,
  irr::gui::IGUIElement* parent = 0,
  irr::s32 id = -1,
  const wchar_t* text = 0,
  bool useAlphaChannel = true);
'/   
var img = GUIEnvironmentAddImage(env, type(10,10,120,70))

' while window is open
while DeviceRun(dev) andalso drv<>NULL
  ' and is active
  if DeviceIsWindowActive(dev) then
    ' draw a frame
    DriverBeginScene(drv,,,SColor(200,200,200)) ' begin a render frame
   
    GUIEnvironmentDrawAll(env)
   
    DriverEndScene(drv) ' show the result on screen
    DeviceSleep(dev,1000\60) ' down't eat all CPU cycles :-)
  else
    ' handle only window events
    DeviceYield(dev)
  endif

wend
' delete the device
DeviceDrop(dev)
jepalza
Posts: 149
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by jepalza »

D.J.Peters wrote: Be sure you used allways the same or latest version I use here from: Sun Jan 09, 2022 9:57 see first post.
upsss!! sorry
D.J.Peters wrote: You made an mistake in the context structure the member "counter" is a signed number (s32) not a pointer !
sorry again
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by D.J.Peters »

New version uploaded with 1360 commands.

I added new feature to the C++ code
every interface like:
IrrlichtDevice
VideoDriver
GUIenvironment
OSOperator
...

and all classes like:
SceneNodes
Emitters
Affectors
Meshbuffers
GUIElements
...

Got a SetUserData() and GetUserData()
with this feature there are no need for shared vars any more.

Joshy

here are a simple example without any shared var.

fle: guitest01.bas

Code: Select all

#include "Irrlicht-c.bi"

enum 
  WindowID = 1
  ButtonID
end enum  

function EventReceiver cdecl (byref event as const SEvent) as boolean
  select case as const event.EventType
  case EET_GUI_EVENT
    var element = cptr(IGUIElement ptr,event.GUIEvent.Caller)
    var device = cptr(IrrlichtDevice ptr,GUIElementGetUserData(element))
    var ID = GUIElementGetID(element)
    print "GUI EventType: " & event.GUIEvent.EventType
    select case as const event.GUIEvent.EventType
    case EGET_BUTTON_CLICKED
      print "clicked: " & ID
      if ID=ButtonID then
        DeviceClose(device) 
        return true
      end if
    case EGET_ELEMENT_CLOSED
      if ID=WindowID then
        DeviceClose(device) 
        return true
      end if
    end select  
  end select
  return false
end function

var dev = CreateDevice()
var drv = DeviceGetVideoDriver    (dev)
var gui = DeviceGetGUIEnvironment (dev)
var win = GUIEnvironmentAddWindow (gui,recti( 0, 0,64+88,126),,"Hello World!")
var img = GUIEnvironmentAddImage  (gui,recti(32,32,32+88, 63),win)
var btn = GUIEnvironmentAddButton (gui,recti(32,63,32+88, 94),win,,"close","close the application")
var tex = DriverGetTextureFromPath(drv,getpath("./media/irrlichtlogo.jpg"))

DeviceSetEventReceiver(dev,@EventReceiver)

GUIImageSetUseAlphaChannel(img,true)
GUIImageSetImage(img,tex)

GUIElementSetID(win,WindowID)
GUIElementSetUserData(win,dev)

GUIElementSetID(btn,ButtonID)
GUIElementSetUserData(btn,dev)

while DeviceRun(dev)
  if DeviceIsWindowActive(dev) then
    DriverBeginScene(drv,,,SColor(0,128,128)) ' begin a frame
    
      ' ... draw everything here
      GUIEnvironmentDrawAll(gui)      
      
    DriverEndScene(drv)
    DeviceSleep(dev,1000/60)
  else
    ' handle only window events 
    DeviceYield(dev)
  endif

wend
DeviceDrop(dev)
jepalza
Posts: 149
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by jepalza »

D.J.Peters wrote:New version uploaded with 1360 commands.
File "irrlicht-1.8.6-c.zip" is missing
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by D.J.Peters »

jepalza wrote:File "irrlicht-1.8.6-c.zip" is missing
fixed :-)
jepalza
Posts: 149
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by jepalza »

Ok, now, GUI example is completed !!! Look it in post:
viewtopic.php?f=14&t=31076&p=288869#p288869

My solution for Alpha SKIN channel was:

Code: Select all

	Dim As SColor col
	Dim As s32 Ptr ptrcol
	for i As s32=0 To EGDC_COUNT -1      ' Number of GUI elements
		col = GUISkinGetColor(skin,i) ' SKIN color by GUI Element
		ptrcol=@col ' Pointer to "Scolor" Skin
		*ptrcol =(*ptrcol And &h00ffffff) Or (alpha_ Shl 24) ' Setting Alpha Channel
		GUISkinSetColor(skin,i,col) ' Drop new color
	Next
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FreeBASIC binding of Irrlicht 3D engine 1.8.6

Post by D.J.Peters »

fixed some byval vs byref typos.

Joshy
Post Reply