leave FullScreen with Alt-Tab is not functional?

Advanced game related topics
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kaeru Gaman »

I'm often in a good mood.
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: leave FullScreen with Alt-Tab is not functional?

Post by blueznl »

You could have fooled me.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kaeru Gaman »

so you really think it's a friendly idea to pick on me when I already said I'm not in a good mood?
oh... and have a nice day.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kuron »

Kaeru Gaman: Just put him on ignore :wink:
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

Fast working example, only working with debugger disabled.

Code: Select all

;please disable debugger!
InitSprite()
InitMouse()
InitKeyboard()

OpenScreen(1024, 768, 32, "fllscrn")

CreateSprite(0, 64, 64)
StartDrawing(SpriteOutput(0))
  Line( 0, 0, 48, 32,$0FF0FF)
  Line( 0, 0, 64, 64,$0FF0FF)
  Line( 0, 0, 32, 48,$0FF0FF)
StopDrawing()

Repeat

  ExamineMouse()
  ExamineKeyboard()

  While WindowEvent()
  Wend

  ClearScreen(0)
  DisplayTransparentSprite(0, MouseX(), MouseY())
  FlipBuffers()

  If IsScreenActive() = 0

    ReleaseMouse(1)

    Repeat

      While WindowEvent()
      Wend
      Delay(100)

    Until IsScreenActive() <> 0

    Delay(2000)
    CloseScreen()
    OpenScreen(1024, 768, 32, "fllscrn")
    ReleaseMouse(0)

    CreateSprite(0, 64,64)
    StartDrawing(SpriteOutput(0))
      Line( 0, 0, 48, 32, $0FF0FF)
      Line( 0, 0, 64, 64, $0FF0FF)
      Line( 0, 0, 32, 48, $0FF0FF)
    StopDrawing()

  EndIf

Until KeyboardPushed(#PB_Key_Escape)
edit: to say to disable the debugger
Last edited by djes on Mon Mar 15, 2010 11:51 am, edited 1 time in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kaeru Gaman »

Fast working example
[ERROR] At least one window should be opened to use this command.
yep, fast ended... but not working. ;)

I get the idea... closing and re-opening the screen to avoid losing the context, resp. leaving the old context and creating a new one.
a thought I already played with*, especially for changing the resolution while running.
(* I already played with that thought)

to use this, it would be necessary to keep the amount of recently loaded content as low as possible,
and handle the re-loading from within memory, not from disk.
the reloading of the content must not take longer than the changing of the resolution, what takes two seconds or so.
should be solvable via Ressources scripts.


thanks for the idea, I will keep it in mind.
oh... and have a nice day.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

I forgot to say to disable the debugger... There's always a window on Windows :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kaeru Gaman »

ah.. I see.
well, I don't see why flushing the events helps anything, and why I don't do it normally.

the very solution in this code seems to be the re-opening of the screen.
in the end, something I wanted to avoid.
I wouldn't have taken any of the efforts about this*, if I accepted re-opening from the beginning on.

*
screen in a container http://www.purebasic.fr/english/viewtop ... 43#p273743
eliminate border of a window http://www.purebasic.fr/english/viewtop ... 12&t=41174
problem changing resolution API-wise http://www.purebasic.fr/english/viewtop ... 16&t=41179
oh... and have a nice day.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

No, the very solution is not *only* the re-opening of the screen. There's a fault on "flipbuffers" that should handle the events correctly (when alt-tabbed ;)), and give to the IsScreenActive() function the good signal to restore the screen. It doesn't work, and it's why the windowevent() is necessary (not to flush but to capture!).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: leave FullScreen with Alt-Tab is not functional?

Post by Kaeru Gaman »

hm... so this should work without the re-opening? o.O
oh... and have a nice day.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

I think so. I've already signaled this in the bugs section.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: leave FullScreen with Alt-Tab is not functional?

Post by #NULL »

without debugger it crashes here. so i opened an invisible window before opening the screen to legalize the WindowEvent(), and then it works better but sometimes the debugger says 'invalid memory access' at DisplayTransparentSprite(), and without debugger it crashes. sometimes it works flawlessly though.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

It's more a 'proof of concept' code. Try to add move the delay between the closescreen() and the openscreen().
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: leave FullScreen with Alt-Tab is not functional?

Post by djes »

Debugger activated code

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()

OpenScreen(1024, 768, 32, "fllscrn")

CreateSprite(0, 64, 64)
StartDrawing(SpriteOutput(0))
  Line( 0, 0, 48, 32,$0FF0FF)
  Line( 0, 0, 64, 64,$0FF0FF)
  Line( 0, 0, 32, 48,$0FF0FF)
StopDrawing()

Repeat

  ExamineMouse()
  ExamineKeyboard()

  ClearScreen(0)
  DisplayTransparentSprite(0, MouseX(), MouseY())
  FlipBuffers()

  If IsScreenActive() = 0

    ReleaseMouse(1)

    Repeat

      While PeekMessage_(msg.MSG, 0, 0, 0, #PM_REMOVE) 
        TranslateMessage_(msg) 
        DispatchMessage_(msg) 
      Wend 
      Delay(100)

    Until IsScreenActive() <> 0

    CloseScreen()
    Delay(1000)
    OpenScreen(1024, 768, 32, "fllscrn")
    ReleaseMouse(0)

    CreateSprite(0, 64,64)
    StartDrawing(SpriteOutput(0))
      Line( 0, 0, 48, 32, $0FF0FF)
      Line( 0, 0, 64, 64, $0FF0FF)
      Line( 0, 0, 32, 48, $0FF0FF)
    StopDrawing()

  EndIf

Until KeyboardPushed(#PB_Key_Escape)
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: leave FullScreen with Alt-Tab is not functional?

Post by dobro »

this code work fine : (No API)


; Purebasic 4.41
;By Dobro
; exemple de l'utilisation de IsScreenActive()

; quittez le pseudo jeux avec Alt+TAB
; on retourne dans le jeux d'un clique sur la fenetre en barre des taches

initsprite ()
initmouse ()
initkeyboard ()
Enumeration
         #sprite
EndEnumeration
Structure sprite
        x.i
        y.i
        pas_x.i
        pas_y.i
EndStructure
Dim sprite.sprite(1)
examinedesktops ()
x_screen= desktopwidth (0) ; je recup la rez de l'ecran
y_screen= desktopheight (0)
flag=0
debut: ; le label qui permet le retour dans le jeux !!
openscreen (x_screen, y_screen, 32, "Fullscreen + ALT-TAB démo" )
releasemouse (0)
createsprite ( #sprite , 64, 64)
startdrawing ( spriteoutput ( #sprite ))
         box (0,0,64,64, rgb (255,13,40))
stopdrawing ()


;********* initialisation du sprite **********
If flag=0 ; le joueur n'est jamais sorti du jeu , s'il est sorti on ne fais pas ce bloc de code !!
sprite(1)\x=x_screen/2 ; on place le sprite au centre
sprite(1)\y=y_screen/2 ; on place le sprite au centre
sprite(1)\pas_x=2 ; on donne une vitesse de deplacement a notre sprite
sprite(1)\pas_y=2 ; on donne une vitesse de deplacement a notre sprite
EndIf

Repeat
         examinekeyboard () ; ne sert que pour quitter le prg avec la touche esc
    
         ; ************* gere le deplacement du sprite ***************
        sprite(1)\x=sprite(1)\x+sprite(1)\pas_x
        sprite(1)\y=sprite(1)\y+sprite(1)\pas_y
                 ; ----------------------------------------------------------------------------
         If sprite(1)\x+64>=x_screen:sprite(1)\pas_x=-sprite(1)\pas_x: EndIf
         If sprite(1)\y+64>=y_screen:sprite(1)\pas_y=-sprite(1)\pas_y: EndIf
         ; ----------------------------------------------------------------------------
         If sprite(1)\x<=0:sprite(1)\pas_x=-sprite(1)\pas_x: EndIf
         If sprite(1)\y<=0:sprite(1)\pas_y=-sprite(1)\pas_y: EndIf
         ; *******************************************************
        
        
         ; ********** affichage du sprite *********************
         displaytransparentsprite ( #sprite , sprite(1)\x, sprite(1)\y)
        
         flipbuffers ()
         clearscreen (0)
        
         ; *************** attention toute l'astuce est la !! *******************
         If isscreenactive () = 0 ; le joueur a quitter le jeu (Alt-tab)
                 releasemouse (1) ; je libere la souris ... inutile ici mais bon
                flag=1 ; on note que l'utilisateur est sorti du jeux
                 closescreen () ; on ferme l'ecran
                
                 ; ******* la ruse de guerre !! ****************************
                 openwindow (1,1,1,1,1, "toto le jeu " , #PB_Window_Minimize ) ; j'ouvre une fenetre que je minimise en bar des taches
                 Repeat :Event= waitwindowevent (2): Until Event= #PB_Event_ActivateWindow ; j'attend qu'on clique sur la fenetre
                 closewindow (1) ; je ferme la fenetre
                 Goto debut ; je retourne dans le jeux sans réinitialiser les variables de déplacement (on reprends ou on en etait! !!! )
     EndIf
Until keyboardpushed ( #PB_Key_Escape ) ; là , on veux vraiment quitter le jeux LOL
End

Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply