Browse Source

Experimental display mode support.

Mark Sibly 9 years ago
parent
commit
fdf628240f
2 changed files with 53 additions and 3 deletions
  1. 26 2
      modules/mojo/app/app.monkey2
  2. 27 1
      modules/mojo/app/window.monkey2

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

@@ -8,6 +8,14 @@ Namespace mojo.app
 #end
 #end
 Global App:AppInstance
 Global App:AppInstance
 
 
+#rem monkeydoc @hidden
+#end
+Struct DisplayMode
+	Field width:Int
+	Field height:Int
+	Field hertz:Int
+End
+
 #rem monkeydoc The AppInstance class.
 #rem monkeydoc The AppInstance class.
 
 
 The AppInstance class is mainly reponsible for running the app 'event loop', but also provides several utility functions for managing
 The AppInstance class is mainly reponsible for running the app 'event loop', but also provides several utility functions for managing
@@ -177,7 +185,7 @@ Class AppInstance
 	
 	
 		Return _hoverView
 		Return _hoverView
 	End
 	End
-
+	
 	#rem monkeydoc The desktop size
 	#rem monkeydoc The desktop size
 	#end	
 	#end	
 	Property DesktopSize:Vec2i()
 	Property DesktopSize:Vec2i()
@@ -233,6 +241,23 @@ Class AppInstance
 		Return _mouseLocation
 		Return _mouseLocation
 	End
 	End
 	
 	
+	#rem monkeydoc @hidden
+	#end
+	Method GetDisplayModes:DisplayMode[]()
+	
+		Local n:=SDL_GetNumDisplayModes( 0 )
+		Local modes:=New DisplayMode[n]
+		For Local i:=0 Until n
+			Local mode:SDL_DisplayMode
+			SDL_GetDisplayMode( 0,i,Varptr mode )
+			modes[i].width=mode.w
+			modes[i].height=mode.h
+			modes[i].hertz=mode.refresh_rate
+		Next
+
+		Return modes
+	End
+	
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end
 	Method BeginModal( view:View )
 	Method BeginModal( view:View )
@@ -296,7 +321,6 @@ Class AppInstance
 	Method Run()
 	Method Run()
 	
 	
 		SDL_AddEventWatch( _EventFilter,Null )
 		SDL_AddEventWatch( _EventFilter,Null )
-'		SDL_SetEventFilter( _EventFilter,Null )
 		
 		
 		RequestRender()
 		RequestRender()
 		
 		

+ 27 - 1
modules/mojo/app/window.monkey2

@@ -70,6 +70,28 @@ Class Window Extends View
 		_swapInterval=swapInterval
 		_swapInterval=swapInterval
 	End
 	End
 	
 	
+	Property Fullscreen:Bool()
+	
+		Return _fullscreen
+	
+	Setter( fullscreen:Bool )
+	
+		If fullscreen=_fullscreen Return
+	
+		_fullscreen=fullscreen
+
+		If _fullscreen
+			Local mode:SDL_DisplayMode
+			mode.w=Width
+			mode.h=Height
+			SDL_SetWindowDisplayMode( _sdlWindow,Varptr mode )
+			SDL_SetWindowFullscreen( _sdlWindow,SDL_WINDOW_FULLSCREEN )
+		Else
+			SDL_SetWindowFullscreen( _sdlWindow,0 )
+		Endif
+	
+	End
+	
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end
 	Method Update()
 	Method Update()
@@ -225,6 +247,8 @@ Class Window Extends View
 	
 	
 	Private
 	Private
 	
 	
+	Field _flags:WindowFlags
+	Field _fullscreen:Bool
 	Field _sdlWindow:SDL_Window Ptr
 	Field _sdlWindow:SDL_Window Ptr
 	Field _sdlGLContext:SDL_GLContext
 	Field _sdlGLContext:SDL_GLContext
 	Field _swapInterval:Int=1
 	Field _swapInterval:Int=1
@@ -273,7 +297,9 @@ Class Window Extends View
 		If flags & WindowFlags.Hidden sdlFlags|=SDL_WINDOW_HIDDEN
 		If flags & WindowFlags.Hidden sdlFlags|=SDL_WINDOW_HIDDEN
 		If flags & WindowFlags.Resizable sdlFlags|=SDL_WINDOW_RESIZABLE
 		If flags & WindowFlags.Resizable sdlFlags|=SDL_WINDOW_RESIZABLE
 		If flags & WindowFlags.Borderless sdlFlags|=SDL_WINDOW_BORDERLESS
 		If flags & WindowFlags.Borderless sdlFlags|=SDL_WINDOW_BORDERLESS
-		If flags & WindowFlags.Fullscreen sdlFlags|=SDL_WINDOW_FULLSCREEN
+		If flags & WindowFlags.Fullscreen _fullscreen=True ; sdlFlags|=SDL_WINDOW_FULLSCREEN
+		
+		_flags=flags
 	
 	
 		_sdlWindow=SDL_CreateWindow( title,x,y,rect.Width,rect.Height,sdlFlags )
 		_sdlWindow=SDL_CreateWindow( title,x,y,rect.Width,rect.Height,sdlFlags )
 		Assert( _sdlWindow,"Failed to create SDL_Window" )
 		Assert( _sdlWindow,"Failed to create SDL_Window" )