Isscreenactive() shouldn't be bound to Flipbuffers()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
rudd68
User
User
Posts: 29
Joined: Wed Jun 09, 2010 2:55 pm

Isscreenactive() shouldn't be bound to Flipbuffers()

Post by rudd68 »

Hello,

not every fullscreen application is a game and use Flipbuffers() many times per second. My (unfinished) fullscreen application use Flipbuffers() only seldom.

Here is my reduced code:

Code: Select all

; do not run this code
; this code is reduced to show the essential structure

; the main program open the main window, mouse click on a button call the
; procedure "Display_data()" as fullscreen application,
; the procedure "Screen_Handling()" should manage the Alt+Tab switching, but doesn't
; work correctly, because I use FlipBuffers() only seldom

Procedure Screen_Handling() ; check focus and redraw screen
  
  ; FlipBuffers()  ; this would give a strongly flickering, but without this 
                   ; the reaction is after many seconds (after FlipBuffers())
  
  If Not IsScreenActive() ; focus lost?
  
    CloseScreen()
    Window_State = GetWindowState(#Mainwindow)
    SetWindowState(#Mainwindow, #PB_Window_Minimize) ;minimize main window
  
    Repeat
    Until WaitWindowEvent() = 0 ; without this loop the screen is immediately opened again
    Repeat
    Until WaitWindowEvent() = #PB_Event_ActivateWindow ; getting focus again ? Doesn't work.
  
    SetWindowState(#Mainwindow, Window_State) ; resize main window
    OpenScreen(Desktop_W, Desktop_H, Desktop_D, Title$)
  
    ClearScreen(RGB(0,0,0)) 
    If StartDrawing(ScreenOutput())
      ; ... here I redraw data on the fullscreen
      StopDrawing()
      FlipBuffers()                 
    EndIf
  
  EndIf
  
EndProcedure

Procedure Display_data()
  
  If InitSprite_Result ; Direct X initialized?
    If OpenScreen(Desktop_W, Desktop_H, Desktop_D, Title$) ; Fullscreen initialized ?
      If InitKeyboard_Result ; Keyboard initialized ?
      
      ; ... here I prepare some variables
            
      End_Flag = #False
      Repeat
        
        ; Screen_Handling() ; this would doesn't work, but without this it works only
                            ; after some seconds and it works only once
        
        ClearScreen(RGB(0,0,0))
              
        ; ... here I modify variables for displaying data if no key pressed
        
        ; ... here I prepare data for displaying        
        
        If StartDrawing(ScreenOutput())
          ; ... here I draw data on the fullscreen
          StopDrawing()
          FlipBuffers()                 
        EndIf
        
        For i = 1 To max_time ; time and keyboard loop, max_time = seconds * 20
          Screen_Handling() ; check focus and redraw screen
          
          If Not Time_Mode 
            i = i - 1 ; endless time loop up to pressed key
          EndIf
          
          Delay(50) ; each second are 20 loopings
          ExamineKeyboard()
                    
          ; now many keys checked
          If KeyboardReleased(...)
            ; modify variables for displaying data
            Break
          EndIf
          
          If KeyboardPushed(...)
            ;modify variables for displaying data
            Break
          EndIf
          
          If KeyboardPushed(#PB_Key_Escape)
            End_Flag = #True
            Break
          EndIf
          
        Next ; end of time and keyboard loop
         
      Until End_Flag ; loops back for drawing new data on the fullscreen
      CloseScreen()
      
EndProcedure ; ends fullscreen application and goes back to the main window
I draw the data on the fullscreen and then the program goes into the time_and_key_loop. The program runs the time_and_key_loop for many seconds or many minutes or longer. Only after this loop the program loops back and draw new data on the fullscreen. This is wanted and correct so and works well.

But from this results that Flipbuffers() is only seldom called. And Alt+Tab reacts only if the time_and_key_loop ends, after many seconds or minutes. PureBasic 4.41 blocks the Alt+Tab keys within the time_and_key_loop. Why? The system becomes processing time with Delay(50).

Sometimes Alt+Tab (for tabbing out) works only at the second time.

I have many many hours tested with Flipbuffers(), Isscreenactive(), ReleaseMouse(), waiting for focus comes back (doesn't work) or close screen and minimize main window or open a new minimized window to the task bar and if the window becomes activating then close the new window or resize the main window and open a new screen. All this doesn't work or works only once. I have found Djes solution and I will test it in the next days.

But the main problem remains: Isscreenactive() must be called after Flipbuffers(). And Flipbuffers() is called seldom. Therefore Isscreenactive() should not be bound to Flipbuffers(). If I write Flipbuffers() in the procedure "Screen_Handling()" then the Alt+Tab reaction time is very short but I have a strongly flickering on the fullscreen.

PureBasic is very difficult for beginners. Why PureBasic doesn't handle the Alt+Tab switching?

Greetings.

I use PB 4.41 with Windows XP SP 3.
rudd68
User
User
Posts: 29
Joined: Wed Jun 09, 2010 2:55 pm

Re: Isscreenactive() shouldn't be bound to Flipbuffers()

Post by rudd68 »

I have found a solution which works well but which I don't like.

How I wrote the Flipbuffers() provides a short reaction time for Alt+Tab if it written in the procedure "Screen_Handling()". But Flipbuffers() alone gives a strongly flickering. Therefore I draw the data on the fullscreen also in the procedure "Screen-Handling()" before Flipbuffers() is called. So I have no flickering.

But - and this is the salient point - the data are drawn many times per second although it wouldn't be necessary actually at all. Therefore I don't like this solution and therefore Isscreenactive() should be in the position to be used independently to Flipbuffers().

And here is the complete solution:

If the main_window is moved, resized or restored and has the window_state "Normal" (not maximized) then save the position and size of it into variables.

If the button clicked for the fullscreen application then save the window_state of the main_window into a variable, close the main_window, save the state of the screensaver into a variable and switch it off (if necessary), check the desktop size and open the fullscreen.

Draw the data and go into the time_and_keyboard_loop. In each looping draw the data (to avoid flickering), use Flipbuffers() and check Isscreenactive().

If the screen is not active, release the mouse, close the fullscreen, set the screensaver to the saved state and open a new minimized window in the task bar. Wait for reactivation of it with "Repeat: Event=waitwindowevent(2): Until Event=#PB_Event_ActivateWindow".

If the minimized window gets the activation then close this window, save the state of the screensaver into a variable and switch it off (if necessary), check the desktop size, open the fullscreen, lock the mouse and return to the time_and_keyboard_loop.

If the fullscreen application has to be exited then close the fullscreen, set the screensaver to the saved state, open the main_window and create its gadgets, move and resize the main_window with the saved values, set the main_window state to the saved state and resize the gadgets (if you have gadget flexibility programmed). The program still goes on in the event loop of the old main_window.

This works well. (PB 4.41 on Windows XP SP 3).
Post Reply