Page 2 of 3

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

Posted: Sun Mar 14, 2010 8:59 pm
by Kaeru Gaman
I'm often in a good mood.

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

Posted: Sun Mar 14, 2010 9:28 pm
by blueznl
You could have fooled me.

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

Posted: Sun Mar 14, 2010 9:43 pm
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?

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

Posted: Sun Mar 14, 2010 9:49 pm
by Kuron
Kaeru Gaman: Just put him on ignore :wink:

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

Posted: Sun Mar 14, 2010 10:42 pm
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

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

Posted: Mon Mar 15, 2010 10:00 am
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.

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

Posted: Mon Mar 15, 2010 11:45 am
by djes
I forgot to say to disable the debugger... There's always a window on Windows :)

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

Posted: Mon Mar 15, 2010 12:03 pm
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

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

Posted: Mon Mar 15, 2010 12:09 pm
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!).

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

Posted: Mon Mar 15, 2010 12:12 pm
by Kaeru Gaman
hm... so this should work without the re-opening? o.O

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

Posted: Mon Mar 15, 2010 12:21 pm
by djes
I think so. I've already signaled this in the bugs section.

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

Posted: Mon Mar 15, 2010 12:58 pm
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.

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

Posted: Mon Mar 15, 2010 2:17 pm
by djes
It's more a 'proof of concept' code. Try to add move the delay between the closescreen() and the openscreen().

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

Posted: Mon Mar 15, 2010 2:56 pm
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)

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

Posted: Sun May 02, 2010 9:38 pm
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