A few screen gadgets bugs (my screen menu fail)
Posted: Sun Mar 01, 2026 1:55 am
I failed at making a simple "menu", the reasons are multiple. Maybe there are some that are unknown?
I'm not sure but I wonder why there's not an event queue like it's usually the case for such kind of libraries, it doesn't prevent "loops"; why is the last event gadgets sometimes repeatedly clicked. Disabling hidden windows (and sometimes closed) doesn't prevent the invisible gadgets to receive events and display "hover" textures. Closing a window will also cause IMA the next time it is opened with the same ID.
Edit: you have to click on the "round" mini buttons to open the "menu"
I'm not sure but I wonder why there's not an event queue like it's usually the case for such kind of libraries, it doesn't prevent "loops"; why is the last event gadgets sometimes repeatedly clicked. Disabling hidden windows (and sometimes closed) doesn't prevent the invisible gadgets to receive events and display "hover" textures. Closing a window will also cause IMA the next time it is opened with the same ID.
Edit: you have to click on the "round" mini buttons to open the "menu"
Code: Select all
Procedure CloseMenu()
If IsScreenGadget(5)
DisableScreenWindow(3,1)
HideScreenWindow(3,1)
If IsScreenGadget(5)
ClearGadgetItems(5)
EndIf
EndIf
EndProcedure
Procedure DisplayScreenMenu(Menu,x,y,ItemList$) ; separated by chr(10) (LF)
Protected count = CountString(ItemList$,Chr(10))+1
Protected height = 18 * count
Protected item$
Protected size ,i=1,menulist
OpenScreenWindow(3,x,y,100,height,"",#PB_Window_BorderLess)
menulist=ListViewScreenGadget(Menu,0,0,200,height)
While i<=count
item$ = StringField(ItemList$,i,Chr(10))
If Left(item$,3)="---"
item$=LSet("",20,"-")
EndIf
AddScreenGadgetItem(menulist,-1,item$)
If size<Len(item$) And Left(item$,3)<>"---"
size=Len(item$)
EndIf
i+1
Wend
If size*12 > 100
ResizeScreenWindow(Menu,x,y,(size*12),height)
ResizeScreenGadget(menulist,0,0,size*12,height)
EndIf
CloseScreenGadgetList()
ProcedureReturn #True
EndProcedure
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "Line3D example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0,#PB_Screen_NoSynchronization)
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Point)
; Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 2, 1, 3, #PB_Absolute | #PB_Local)
CameraLookAt(0, 0, 0, 0)
; Create the line and attach it to the scene
CreateLine3D(0, 0, 0, 0, RGB(255, 0, 0), 1, 1, 1, RGB(0, 0, 255))
CreateEntity(0, MeshID(0), #PB_Material_None)
InitKeyboard() : InitMouse() : InitScreenGadgets()
ButtonScreenGadget(1,CameraProjectionX(0,0,0,0)-4,CameraProjectionY(0,0,0,0)-4,9,9,"")
ScreenGadgetToolTip(1,"Line3D start")
ButtonScreenGadget(2,CameraProjectionX(0,1,1,1)-4,CameraProjectionY(0,1,1,1)-4,9,9,"")
ScreenGadgetToolTip(2,"Line3D finish")
Repeat
If IsScreenActive()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
ExamineMouse()
; InputEvent(MouseX(),MouseY(),MouseButton(1),KeyboardInkey(),0)
If ScreenWindowEvent()=#PB_Event_Gadget
Select EventScreenGadget()
Case 1,2
DisplayScreenMenu(5,MouseX(),MouseY(),~"Move\nRotate\n------\nCopy\nCut\nDelete")
Case 5
Debug "Menu! "
Debug "state="+GetScreenGadgetState(5)
Debug "text="+GetScreenGadgetText(5) ; <---- frees the gadget?
;ClearGadgetItems(5) ; <----- uncomment for after gettext crash
DisableScreenWindow(3,1)
; CloseScreenWindow(3) ; ; closescreenwindow causes crash on next openscreenwindow
HideScreenWindow(3,1) ; make ghost window
Default
If IsScreenGadget(5)
DisableScreenWindow(3,1)
HideScreenWindow(3,1)
EndIf
EndSelect
ElseIf MouseButton(1) = 0 And lastmb=1
If IsScreenGadget(5)
DisableScreenWindow(3,1)
HideScreenWindow(3,1)
EndIf
EndIf
lastmb = MouseButton(1)
RenderWorld()
RenderScreenGadgets()
FlipBuffers()
EndIf
Until WaitWindowEvent(1) = #PB_Event_CloseWindow