Ver código fonte

Experimental display mode support.

Mark Sibly 9 anos atrás
pai
commit
fdf628240f
2 arquivos alterados com 53 adições e 3 exclusões
  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
 Global App:AppInstance
 
+#rem monkeydoc @hidden
+#end
+Struct DisplayMode
+	Field width:Int
+	Field height:Int
+	Field hertz:Int
+End
+
 #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
@@ -177,7 +185,7 @@ Class AppInstance
 	
 		Return _hoverView
 	End
-
+	
 	#rem monkeydoc The desktop size
 	#end	
 	Property DesktopSize:Vec2i()
@@ -233,6 +241,23 @@ Class AppInstance
 		Return _mouseLocation
 	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
 	#end
 	Method BeginModal( view:View )
@@ -296,7 +321,6 @@ Class AppInstance
 	Method Run()
 	
 		SDL_AddEventWatch( _EventFilter,Null )
-'		SDL_SetEventFilter( _EventFilter,Null )
 		
 		RequestRender()
 		

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

@@ -70,6 +70,28 @@ Class Window Extends View
 		_swapInterval=swapInterval
 	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
 	#end
 	Method Update()
@@ -225,6 +247,8 @@ Class Window Extends View
 	
 	Private
 	
+	Field _flags:WindowFlags
+	Field _fullscreen:Bool
 	Field _sdlWindow:SDL_Window Ptr
 	Field _sdlGLContext:SDL_GLContext
 	Field _swapInterval:Int=1
@@ -273,7 +297,9 @@ Class Window Extends View
 		If flags & WindowFlags.Hidden sdlFlags|=SDL_WINDOW_HIDDEN
 		If flags & WindowFlags.Resizable sdlFlags|=SDL_WINDOW_RESIZABLE
 		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 )
 		Assert( _sdlWindow,"Failed to create SDL_Window" )