Browse Source

Fixes for BeginFullscreen() in ctor.

Mark Sibly 8 years ago
parent
commit
ddc9d756e2
2 changed files with 74 additions and 39 deletions
  1. 48 37
      modules/mojo/app/app.monkey2
  2. 26 2
      modules/mojo/app/window.monkey2

+ 48 - 37
modules/mojo/app/app.monkey2

@@ -181,6 +181,12 @@ Class AppInstance
 			
 			UpdateWindows()
 		End
+
+#if __DESKTOP_TARGET__ 
+		SDL_AddEventWatch( _EventFilter,Null )
+#Endif
+		RequestRender()
+	
 	End
 	
 	#rem monkeydoc Fallback font.
@@ -450,10 +456,10 @@ Class AppInstance
 	#end
 	Method MainLoop()
 		
-		If Not _requestRender Or Not Renderable
+		If (Not _requestRender Or Not Renderable) And Idle=Null
 
 			SDL_WaitEvent( Null )
-			
+
 		Endif
 		
 		UpdateEvents()
@@ -489,7 +495,7 @@ Class AppInstance
 		
 		Local render:=_requestRender
 		_requestRender=False
-		
+
 		If render UpdateFPS()
 		
 		For Local window:=Eachin Window.VisibleWindows()
@@ -520,7 +526,9 @@ Class AppInstance
 	
 	#end
 	Method ResetPolledInput()
+		
 		Keyboard.Reset()
+		
 		Mouse.Reset()
 	End
 	
@@ -528,7 +536,7 @@ Class AppInstance
 	#end
 	Function EmscriptenMainLoop()
 
-		App._requestRender=True
+		App.RequestRender()
 		
 		App.MainLoop()
 	End
@@ -536,14 +544,7 @@ Class AppInstance
 	#rem monkeydoc Run the app.
 	#end
 	Method Run()
-	
-#if __DESKTOP_TARGET__ 
-	
-		SDL_AddEventWatch( _EventFilter,Null )
 
-#endif
-		RequestRender()
-		
 #If __TARGET__="emscripten"
 
 		emscripten_set_main_loop( EmscriptenMainLoop,0,1 )
@@ -571,7 +572,36 @@ Class AppInstance
 		
 		_renderingSuspended=Max( _renderingSuspended-1,0 )
 	End
+
+	Internal
 	
+	Method DispatchEvents()
+		
+		Local event:SDL_Event
+
+		While SDL_PollEvent( Varptr event )
+		
+			DispatchEvent( Varptr event )
+			
+		Wend
+		
+	End
+	
+	Method UpdateEvents()
+	
+		Keyboard.Update()
+		
+		Mouse.Update()
+		
+		Touch.Update()
+		
+		DispatchEvents()
+		
+		Local idle:=Idle
+		Idle=Null
+		idle()
+		
+	End
 
 	Private
 	
@@ -629,28 +659,6 @@ Class AppInstance
 
 	End
 	
-	Method UpdateEvents()
-	
-		Keyboard.Update()
-		
-		Mouse.Update()
-		
-		Touch.Update()
-		
-		Local event:SDL_Event
-
-		While SDL_PollEvent( Varptr event )
-		
-			DispatchEvent( Varptr event )
-			
-		Wend
-		
-		Local idle:=Idle
-		Idle=Null
-		idle()
-		
-	End
-	
 	Method SendKeyEvent( type:EventType )
 	
 		Local view:=KeyView
@@ -968,7 +976,7 @@ Class AppInstance
 				
 			Case SDL_WINDOWEVENT_FOCUS_GAINED
 			
-				'Print "SDL_WINDOWEVENT_FOCUS_GAINED"
+				Print "SDL_WINDOWEVENT_FOCUS_GAINED"
 			
 				Local active:=_active
 				_activeWindow=_window
@@ -980,7 +988,7 @@ Class AppInstance
 				
 			Case SDL_WINDOWEVENT_FOCUS_LOST
 			
-				'Print "SDL_WINDOWEVENT_FOCUS_LOST"
+				Print "SDL_WINDOWEVENT_FOCUS_LOST"
 			
 				Local active:=_active
 				_active=False
@@ -1010,7 +1018,7 @@ Class AppInstance
 					SendMouseEvent( EventType.MouseLeave,_hoverView )
 					_hoverView=Null
 				Endif
-				
+
 			End
 			
 		Case SDL_USEREVENT
@@ -1105,6 +1113,8 @@ Class AppInstance
 			
 			Case SDL_WINDOWEVENT_MOVED
 			
+				Print "SDL_WINDOWEVENT_MOVED"
+			
 				SdlEventFilter( event )
 	
 				SendWindowEvent( EventType.WindowMoved )
@@ -1112,6 +1122,8 @@ Class AppInstance
 				Return 0
 					
 			Case SDL_WINDOWEVENT_RESIZED
+				
+				Print "SDL_WINDOWEVENT_RESIZED"
 			
 				SdlEventFilter( event )
 	
@@ -1120,7 +1132,6 @@ Class AppInstance
 				UpdateWindows()
 			
 				Return 0
-
 			End
 
 		End

+ 26 - 2
modules/mojo/app/window.monkey2

@@ -146,6 +146,7 @@ Class Window Extends View
 	
 	#end	
 	Method BeginFullscreen()
+		
 		SDL_SetWindowFullscreen( _sdlWindow,SDL_WINDOW_FULLSCREEN_DESKTOP )
 	End
 	
@@ -155,6 +156,7 @@ Class Window Extends View
 	
 	#end
 	Method BeginFullscreen( width:Int,height:Int,hertz:Int )
+		
 		Local mode:SDL_DisplayMode
 		mode.w=width
 		mode.h=height
@@ -168,24 +170,28 @@ Class Window Extends View
 	#rem monkeydoc Ends fullscreen mode.
 	#end
 	Method EndFullscreen()
+		
 		SDL_SetWindowFullscreen( _sdlWindow,0 )
 	End
 
 	#rem monkeydoc Maximizes the window.
 	#end	
 	Method Maximize()
+		
 		SDL_MaximizeWindow( _sdlWindow )
 	End
 	
 	#rem monkeydoc Minimizes the window.
 	#end	
 	Method Minimize()
+		
 		SDL_MinimizeWindow( _sdlWindow )
 	End
 	
 	#rem monkeydoc Restores the window.
 	#end	
 	Method Restore()
+		
 		SDL_RestoreWindow( _sdlWindow )
 	End
 	
@@ -217,6 +223,7 @@ Class Window Extends View
 	#rem monkeydoc @hidden The internal SDL_GLContext used by this window.
 	#end	
 	Property SDLGLContext:SDL_GLContext()
+		
 		Return _sdlGLContext
 	End
 
@@ -433,7 +440,7 @@ Class Window Extends View
 	#rem monkeydoc @hidden
 	#end
 	Method RenderWindow()
-	
+		
 		If _maxfudge
 			_maxfudge-=1
 			App.RequestRender()
@@ -463,10 +470,13 @@ Class Window Extends View
 		_canvas.EndRender()
 		
 		SDL_GL_SwapWindow( _sdlWindow )
+		
 	End
 	
 	Method Init( title:String,rect:Recti,flags:WindowFlags )
 		Style=GetStyle( "Window" )
+		
+		If flags & WindowFlags.Hidden Visible=False
 	
 		Local x:=(flags & WindowFlags.CenterX) ? SDL_WINDOWPOS_CENTERED Else rect.X
 		Local y:=(flags & WindowFlags.CenterY) ? SDL_WINDOWPOS_CENTERED Else rect.Y
@@ -490,7 +500,7 @@ Class Window Extends View
 		Endif
 		
 		If flags & WindowFlags.Hidden sdlFlags|=SDL_WINDOW_HIDDEN
-		
+			
 		If flags & WindowFlags.Resizable sdlFlags|=SDL_WINDOW_RESIZABLE
 		
 		If flags & WindowFlags.Borderless sdlFlags|=SDL_WINDOW_BORDERLESS
@@ -551,5 +561,19 @@ Class Window Extends View
 		UpdateActive()
 
 		LayoutWindow()
+
+		Activated+=Lambda()
+			Local flags:=Cast<SDL_WindowFlags>( SDL_GetWindowFlags( _sdlWindow ) )
+			If (flags & SDL_WINDOW_HIDDEN)
+				SDL_ShowWindow( _sdlWindow )
+				SDL_RaiseWindow( _sdlWindow )
+				_visibleWindows.Push( Self )
+			Endif
+		End
+		
+		Deactivated+=Lambda()
+			RuntimeError( "Windows cannot be deactivated" )
+		End
+
 	End
 End