Page 1 of 1

Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 2:04 am
by Mythros
Hi all! Is it possible to use `StatusBar` with `OpenWindowedScreen ( )` ?

I tried & it won't show up until having removed the `OpenWindowedScreen ( )`

Only problem is : I need `OpenWindowedScreen ( )` so the user can push the Escape key to exit the program.

Any help is GREATLY appreciated!

Thank You! <3

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 2:37 am
by RASHAD
Hi
No problem here
Check the height of the WindowedScreen it may cover the area of statusbar
PB 5.72 x86 - Windows 10 x64

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 600, 400, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "Grab input")
  ButtonGadget(2, 120,  10, 100, 25, "Button 2")
  ButtonGadget(3, 230,  10, 100, 25, "Button 3")
  TextGadget  (4, 10, 40, 300, 30, "Mouse and keyboard released")
 
  If CreateStatusBar(0, WindowID(0))
    AddStatusBarField(200)
    AddStatusBarField(150)
    AddStatusBarField(100)
  EndIf

  StatusBarText(0, 0, "Area 1")
  StatusBarText(0, 1, "Area 2", #PB_StatusBar_BorderLess)
  StatusBarText(0, 2, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised)
  
  wwheight = WindowHeight(0)-GadgetY(4)-GadgetHeight(4)- 10 - StatusBarHeight(0)

  If OpenWindowedScreen(WindowID(0), 10, 70, 580, wwheight, 0, 0, 0)
    LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")

    direction = 1
    playerX = 1
    playerY = 1
   
    ; Start with released input
    ReleaseMouse(#True)
    InputReleased = 1
   
    Repeat
      Repeat
        ; Always process all the events to flush the queue at every frame
        Event = WindowEvent()
       
        Select Event
          Case #PB_Event_CloseWindow
            Quit = 1
       
          Case #PB_Event_Gadget
           
            ; Do the normal application management here
            Gadget = EventGadget()
       
            Select Gadget
              Case 1
                InputReleased = 0
                ReleaseMouse(#False)
                SetGadgetText(4, "Press 'F1' to ungrab keyboard and mouse")
   
              Case 2 , 3
                StatusBarText(0, 0, "Button "+Str(Gadget)+" pressed.",#PB_StatusBar_Raised)             

            EndSelect
       
        EndSelect
       
      Until Event = 0 ; Quit the event loop only when no more events are available
     
      ExamineKeyboard()
     
      If InputReleased = 0
   
        ExamineMouse()
   
        ; do the sprite & screen management at every frame
        If KeyboardPushed(#PB_Key_Up)    And playerY > 0   : playerY -3 : EndIf 
        If KeyboardPushed(#PB_Key_Down)  And playerY < 280 : playerY +3 : EndIf 
        If KeyboardPushed(#PB_Key_Left)  And playerX > 0   : playerX -3 : EndIf 
        If KeyboardPushed(#PB_Key_Right) And playerX < 300 : playerX +3 : EndIf 
   
        If KeyboardPushed(#PB_Key_F1)
          ReleaseMouse(#True)
          InputReleased = 1
          SetGadgetText(4, "Mouse and keyboard released");
        EndIf
      EndIf
     
      ; Clear the screen and draw our sprites
      ClearScreen(RGB(0,0,0))
      ClipSprite(0, 0, 0, x, x/8)
      DisplaySprite(0, x, 100)
      DisplaySprite(0, x, x)
      DisplaySprite(0, 300-x, x)
      DisplaySprite(0, playerX, playerY)
   
      x + direction
      If x > 300 : direction = -1 : EndIf   ; moving back to the left with negative value
      If x < 0   : direction =  1 : EndIf   ; moving to the right with positive value
       
      FlipBuffers()       ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
   
    Until  Quit Or KeyboardPushed(#PB_Key_Escape)
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf

Edit : Updated

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 2:47 am
by mk-soft
You don't need OpenScreenWindow ...

Code: Select all

;-TOP

Enumeration Windows
  #Main
EndEnumeration

Enumeration Menu
  #MenuBar
EndEnumeration

Enumeration MenuItems
  #MenuExit
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    CreateMenu(#MenuBar, WindowID(#Main))
    
    AddKeyboardShortcut(#Main, #PB_Shortcut_Escape, #MenuExit)
    
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    StatusBarText(#MainStatusBar, 0, "Press Escape to exit program")
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_Menu
          Select EventMenu()
            Case #MenuExit
              Break
          EndSelect
      
      EndSelect
      
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 2:49 am
by Mythros
Thanks! That worked! How can I get the height of the windowed screen to take up the whole window between the file menu & the statusbar menu? I don't want to use a hard-coded height.

Thank You! <3

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 3:03 am
by RASHAD
First post updated
It depends on your GUI design
You have all needed functions to calculate it including StatusBarHeight(?)

But if you need WindowedScreen only to use Esc key it is better to use mk-soft snippet

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 6:37 am
by Mythros
Which code snippet?

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 6:54 am
by Kuron
Mythros wrote:Which code snippet?
This one.

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 9:58 am
by mrv2k
If you just have a statusbar and a menu use...

Code: Select all

WindowHeight(#WINDOW) - StatusBarHeight(#STATUSBAR) - MenuHeight()

Re: Use Statusbar with `OpenWindowedScreen ( )`?

Posted: Sat May 23, 2020 6:20 pm
by Mythros
Thanks for all of your help, guys! <3