It is currently Thu Jun 04, 2020 6:31 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: On click on the border of the window, the screen is paused
PostPosted: Sun Jan 19, 2020 6:15 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Dec 04, 2015 9:26 pm
Posts: 287
Hello guys, how do I make sure that when I click on the edge of the window, the windowed screen is not 'paused'?

example code >

Code:
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_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 OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
    LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
    StickyWindow(0,1)
    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
                SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
            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


Top
 Profile  
Reply with quote  
 Post subject: Re: On click on the border of the window, the screen is paus
PostPosted: Sun Jan 19, 2020 2:02 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2487
Location: Germany
I think is work with threads, but only with windows

With macOS and Linux is only work inside main scope
Code:
CompilerIf Not #PB_Compiler_OS = #PB_OS_Windows
  CompilerError "Only for Windows"
CompilerEndIf

CompilerIf Not #PB_Compiler_Thread
  CompilerError "Use Compiler Option Threadsafe"
CompilerEndIf

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

Global InputReleased = 1
Global Quit

Procedure thScreen(ID)
 
  Protected direction = 1
  Protected playerX = 1
  Protected playerY = 1
 
   
  Repeat
   
    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)
 
  Quit = 1
 
EndProcedure

If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #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 OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
    LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
    StickyWindow(0,1)
   
    ; Start with released input
    ReleaseMouse(#True)
    InputReleased = 1
   
    CreateThread(@thScreen(), 0)
   
    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
              SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
          EndSelect
         
      EndSelect
     
    Until Quit ; Quit the event loop only when no more events are available
   
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye