no CreateMenu with ExamineKeyboard

Linux specific forum
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

no CreateMenu with ExamineKeyboard

Post by Vera »

Hello,
while trying to keep kernadec's Mandalas3D working smart on Linux too, I came across the problem that the menu or popupmenu is unavailable.

I could get to the bottom of the issue and found it is due to using ExamineKeyboard().

The following example shows the menu, popupmenu and an added keyboardshortcut working fine until ExamineKeyboard is enabled. Even creating that popupmenu within its own thread won't build it up.

Code: Select all

Enumeration
  #Window0
  #ListView
  #PopMenu
  #Button0
  #Menu0
  #Menu1
  #Menu2
  #popM
EndEnumeration

Procedure popme(pm)
  If  CreatePopupMenu(#PopMenu)
    MenuItem(#Menu2, "List_____") : Debug "CreatePopup"
  EndIf

  DisplayPopupMenu(#PopMenu, WindowID(#Window0)) : Debug "DisplayPopup"
EndProcedure

InitSprite()
InitKeyboard()

Xs = 400 : Ys = 200
OpenWindow(#Window0, 0, 0, Xs, Ys, "CreateMenu + ExamineKeyboard", #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_ScreenCentered )
If CreateMenu(#Menu0, WindowID(#Window0))
  MenuTitle("&Listview")
  MenuItem(#Menu1, "Open&List"   + Chr(9) + "Ctrl+O")
EndIf

;  If CreateToolBar(#Menu0, WindowID(0))         ; the image will vanish, but the button stays valid
;    ToolBarStandardButton(#Menu1, #PB_ToolBarIcon_Open)
;  EndIf
    
  AddKeyboardShortcut(#Window0,#PB_Shortcut_F2,#popM)

ButtonGadget(#Button0, 80, 0, 130, 25, "click me ... or F2")
OpenWindowedScreen(WindowID(#Window0), 0, 30, Xs, Ys, 0, 0, 0, #PB_Screen_SmartSynchronization)


Repeat

  ClearScreen(0) : StartDrawing(ScreenOutput()) : DrawingMode(#PB_2DDrawing_Transparent)
  For i = 1 To 13
    DrawText(Random(300), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
  Next i
  StopDrawing() : Delay(100) : FlipBuffers()

;;                       uncomment and the menu becomes unavailable:
;   ExamineKeyboard()
;   If KeyboardPushed(#PB_Key_P) :Debug "Key_P": popy = CreateThread(@popme(), 1) : WaitThread(popy): EndIf ;DisplayPopupMenu(#PopMenu, WindowID(#Window0),100,100) : EndIf

  
  Repeat
   Event = WindowEvent()

    Select Event
      Case #PB_Event_Menu : Debug "case menu"
        Select EventMenu()
          Case #Menu1
            Debug "#Menu1"
          Case #popM    
            Debug "#popM" : popme(1)
        EndSelect

      Case #PB_Event_Gadget
        Select EventGadget()
          Case #Button0 : Debug "#Button0": popy = CreateThread(@popme(), 1) : WaitThread(popy)
        EndSelect
        
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0

 Until Event = #PB_Event_CloseWindow
;Until KeyboardPushed(#PB_Key_Escape)
End
Does anybody know what might be wrong or could be changed or worked around to keep the menu available?

Greets ~ Vera
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: no CreateMenu with ExamineKeyboard

Post by Vera »

Hi again,
until now I haven't found a solution for the primary menu-issue posted above.

BUT I found that a ToolBar could be used if it is visible.
The problem that the icon-display isn't repainted after hovering/re-toggling... the button/bar still remains atm.

Here's my according example (incl. Key_Space to toggle the bar)

Code: Select all

Enumeration
  #Window0
  #Menu0
  #Menu1
EndEnumeration

Procedure doStuff()
  Debug "doStuff successfully"
EndProcedure

Procedure toolBar()
 If CreateToolBar(#Menu0, WindowID(0)) 
   ToolBarStandardButton(#Menu1, #PB_ToolBarIcon_Open)    ; image-display will still vanish
   AddKeyboardShortcut(#Window0,#PB_Shortcut_F2,#Menu1)   ; won't work with ExamineKeyboard
 EndIf
EndProcedure

InitSprite()
InitKeyboard()

Xs = 400 : Ys = 200
OpenWindow(#Window0, 0, 0, Xs, Ys, "ToolBarMenu + ExamineKeyboard", #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_ScreenCentered )

toolBar()            ; moved into procedure to allow toggling on/off

OpenWindowedScreen(WindowID(#Window0), 0, 0, Xs, Ys, 0, 0, 0, #PB_Screen_SmartSynchronization)


Repeat

  ClearScreen(0) : StartDrawing(ScreenOutput()) : DrawingMode(#PB_2DDrawing_Transparent)
  For i = 1 To 13
    DrawText(Random(300), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
  Next i
  StopDrawing() : Delay(100) : FlipBuffers()

;;               comment out and the menu-shortcut (F2) becomes unavailable:
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_P) : doStuff() : EndIf
  If KeyboardReleased(#PB_Key_Space)  
    If Lt   = 0 : Lt   =  1  : FreeToolBar(#Menu0)
    Else :: Lt   = 0  : toolBar()
    EndIf 
  EndIf

 
  Repeat
   Event = WindowEvent()

    Select Event
      Case #PB_Event_Menu : Debug "case menu"
        Select EventMenu()
          Case #Menu1  : Debug "#Menu1"
            doStuff()
        EndSelect
       
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0

; Until Event = #PB_Event_CloseWindow      ; to be used without ExamineKeyboard
Until KeyboardPushed(#PB_Key_Escape)
End 
Post Reply