Switch between Window and Screen

Just starting out? Need help? Post your questions and find answers here.
PHP
User
User
Posts: 79
Joined: Sat Sep 10, 2005 5:38 pm

Switch between Window and Screen

Post by PHP »

Hello,

This code snippet is from the PB help.

Is there a way to initially display only the gray interface with buttons, gadgets, and settings options, and then open the OpenWindowedScreen only when a specific button is clicked? Similarly, is there a way to close the screen using KeyboardPushed() and return to the gray interface?

Can OpenWindowedScreen() also be placed above gadgets? Or would you have to hide them first?

Thanks! :)


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, 340, 285, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "Grab input")
  TextGadget  (4, 10, 40, 300, 30, "Mouse and keyboard released")

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

    MouseX = (ScreenWidth() - SpriteWidth(0)) / 2
    MouseY = (ScreenHeight() - SpriteHeight(0)) / 2
    MouseLocate(MouseX, MouseY)
    
    ; 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")
    
            EndSelect
        
        EndSelect
        
      Until Event = 0 ; Quit the event loop only when no more events are available
      
      ExamineKeyboard()
      
      If InputReleased = 0
    
        If ExamineMouse()
          MouseX = MouseX()
          MouseY = MouseY()
        EndIf
    
        
        If KeyboardPushed(#PB_Key_F1)
          ReleaseMouse(#True)
          InputReleased = 1
          SetGadgetText(4, "Mouse and keyboard released");
        EndIf
      EndIf
      
  
      ClearScreen(RGB(0,0,0))
  
      
      ClipSprite(0, #PB_Default , #PB_Default , #PB_Default , #PB_Default)
      DisplaySprite(0, MouseX, MouseY)
    
      FlipBuffers() 
    
    Until  Quit Or KeyboardPushed(#PB_Key_Escape)
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf

User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Switch between Window and Screen

Post by mk-soft »

You can use the ScreenGadget Library there v6.30. This is still missing in the index of the PB help.

Search the PB Help for ScreenGadget
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
Post Reply