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 :-)
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)