Explorar o código

Added "letterbox-int"

Mark Sibly %!s(int64=9) %!d(string=hai) anos
pai
achega
3e0cacd9ce
Modificáronse 2 ficheiros con 57 adicións e 46 borrados
  1. 34 18
      modules/mojo/app/view.monkey2
  2. 23 28
      modules/mojo/app/window.monkey2

+ 34 - 18
modules/mojo/app/view.monkey2

@@ -562,16 +562,30 @@ Class View
 		
 		
 			_matrix=_matrix.Translate( (_frame.Width-_bounds.Width)*_gravity.x,(_frame.Height-_bounds.Height)*_gravity.y )
 			_matrix=_matrix.Translate( (_frame.Width-_bounds.Width)*_gravity.x,(_frame.Height-_bounds.Height)*_gravity.y )
 			
 			
+			_matrix.t.x=Round( _matrix.t.x )
+			_matrix.t.y=Round( _matrix.t.y )
+			
 		Case "stretch"
 		Case "stretch"
 		
 		
 			Local sx:=Float(_frame.Width)/_bounds.Width
 			Local sx:=Float(_frame.Width)/_bounds.Width
 			Local sy:=Float(_frame.Height)/_bounds.Height
 			Local sy:=Float(_frame.Height)/_bounds.Height
 			_matrix=_matrix.Scale( sx,sy )
 			_matrix=_matrix.Scale( sx,sy )
+
+		Case "stretch-int"
+		
+			Local sx:=Float(_frame.Width)/_bounds.Width
+			Local sy:=Float(_frame.Height)/_bounds.Height
+
+			If sx>1 sx=Floor( sx )
+			If sy>1 sy=Floor( sy )
+			
+			_matrix=_matrix.Scale( sx,sy )
 			
 			
 		Case "scale","letterbox"
 		Case "scale","letterbox"
 		
 		
 			Local sx:=Float(_frame.Width)/_bounds.Width
 			Local sx:=Float(_frame.Width)/_bounds.Width
 			Local sy:=Float(_frame.Height)/_bounds.Height
 			Local sy:=Float(_frame.Height)/_bounds.Height
+			
 			If sx<sy
 			If sx<sy
 				_matrix=_matrix.Translate( 0,(_frame.Height-_bounds.Height*sx)*_gravity.y )
 				_matrix=_matrix.Translate( 0,(_frame.Height-_bounds.Height*sx)*_gravity.y )
 				_matrix=_matrix.Scale( sx,sx )
 				_matrix=_matrix.Scale( sx,sx )
@@ -580,14 +594,26 @@ Class View
 				_matrix=_matrix.Scale( sy,sy )
 				_matrix=_matrix.Scale( sy,sy )
 			Endif
 			Endif
 			
 			
+		Case "scale-int","letterbox-int"
+		
+			Local sx:=Float(_frame.Width)/_bounds.Width
+			Local sy:=Float(_frame.Height)/_bounds.Height
+			
+			If sx>1 sx=Floor( sx )
+			If sy>1 sy=Floor( sy )
+			
+			Local sc:=Min( sx,sy )
+			_matrix=_matrix.Translate( (_frame.Width-_bounds.Width*sc)*_gravity.x,(_frame.Height-_bounds.Height*sc)*_gravity.y )
+			_matrix=_matrix.Scale( sc,sc )
+			
 		End
 		End
 
 
 		_matrix=_matrix.Translate( -_bounds.min.x,-_bounds.min.y )
 		_matrix=_matrix.Translate( -_bounds.min.x,-_bounds.min.y )
 		
 		
 		If _parent _rmatrix=_parent._rmatrix * _matrix Else _rmatrix=_matrix
 		If _parent _rmatrix=_parent._rmatrix * _matrix Else _rmatrix=_matrix
 		
 		
-		_rmatrix.t.x=Round( _rmatrix.t.x )
-		_rmatrix.t.y=Round( _rmatrix.t.y )
+'		_rmatrix.t.x=Round( _rmatrix.t.x )
+'		_rmatrix.t.y=Round( _rmatrix.t.y )
 		
 		
 		_rclip=TransformRecti( _rect,_rmatrix )
 		_rclip=TransformRecti( _rect,_rmatrix )
 		_rbounds=TransformRecti( _bounds,_rmatrix )
 		_rbounds=TransformRecti( _bounds,_rmatrix )
@@ -610,33 +636,23 @@ Class View
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end
 	Method Render( canvas:Canvas )
 	Method Render( canvas:Canvas )
-		
+
 		If Not _visible Return
 		If Not _visible Return
 		
 		
-		Local rmatrix:=canvas.RenderMatrix
-		Local rbounds:=canvas.RenderBounds
-		Local viewport:=canvas.Viewport
-
-		canvas.RenderMatrix=_rmatrix
-		canvas.RenderBounds=_rbounds
-		canvas.Viewport=_bounds
+		canvas.BeginRender( _bounds,_matrix )
 		
 		
 		_rstyle.Render( canvas,New Recti( 0,0,_bounds.Size ) )
 		_rstyle.Render( canvas,New Recti( 0,0,_bounds.Size ) )
 		
 		
-		canvas.RenderMatrix=_rmatrix
-		canvas.RenderBounds=_rclip
 		canvas.Viewport=_rect
 		canvas.Viewport=_rect
 		
 		
 		OnRender( canvas )
 		OnRender( canvas )
-		canvas.ClearMatrix()
-		
+
 		For Local view:=Eachin _children
 		For Local view:=Eachin _children
 			view.Render( canvas )
 			view.Render( canvas )
 		Next
 		Next
-
-		canvas.RenderMatrix=rmatrix
-		canvas.RenderBounds=rbounds
-		canvas.Viewport=viewport
+		
+		canvas.EndRender()
+		
 	End
 	End
 	
 	
 	Protected
 	Protected

+ 23 - 28
modules/mojo/app/window.monkey2

@@ -37,8 +37,18 @@ Class Window Extends View
 		Init( title,rect,flags )
 		Init( title,rect,flags )
 	End
 	End
 	
 	
-	#rem monkeydoc Window clear color
+	#rem monkeydoc Window title.
+	#end
+	Property Title:String()
+	
+		Return String.FromUtf8String( SDL_GetWindowTitle( _sdlWindow ) )
+	
+	Setter( title:String )
 	
 	
+		SDL_SetWindowTitle( _sdlWindow,title )
+	End
+	
+	#rem monkeydoc Window clear color.
 	#end
 	#end
 	Property ClearColor:Color()
 	Property ClearColor:Color()
 
 
@@ -49,7 +59,7 @@ Class Window Extends View
 		_clearColor=clearColor
 		_clearColor=clearColor
 	End
 	End
 	
 	
-	#rem monkeydoc @hidden
+	#rem monkeydoc Window swap interval
 	#end
 	#end
 	Property SwapInterval:Int()
 	Property SwapInterval:Int()
 	
 	
@@ -63,7 +73,6 @@ Class Window Extends View
 	#rem monkeydoc @hidden
 	#rem monkeydoc @hidden
 	#end
 	#end
 	Method Update()
 	Method Update()
-	
 
 
 #If __TARGET__="emscripten"
 #If __TARGET__="emscripten"
 
 
@@ -108,33 +117,19 @@ Class Window Extends View
 	
 	
 		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )
 		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )
 
 
-'		Causes a warning in SDL2 on windows...
-'		
 		SDL_GL_SetSwapInterval( _swapInterval )
 		SDL_GL_SetSwapInterval( _swapInterval )
 		
 		
-		Local viewport:=New Recti( 0,0,Frame.Size )
-		
-		_canvas.Resize( viewport.Size )
+		Local bounds:=New Recti( 0,0,Frame.Size )
 		
 		
-		_canvas.RenderColor=Color.White
-		_canvas.RenderMatrix=New AffineMat3f
-		_canvas.RenderBounds=viewport
+		_canvas.Resize( bounds.Size )
 		
 		
-		_canvas.Viewport=viewport
-		_canvas.Scissor=New Recti( 0,0,1000000,1000000 )'16384,16384 )
-		_canvas.ViewMatrix=New Mat4f
-		_canvas.ModelMatrix=New Mat4f
-
-		_canvas.BlendMode=BlendMode.Alpha
-		_canvas.Color=Color.White
-		_canvas.Font=Null
-		_canvas.Matrix=New AffineMat3f
+		_canvas.BeginRender( bounds,New AffineMat3f )
 		
 		
 		_canvas.Clear( _clearColor )
 		_canvas.Clear( _clearColor )
 		
 		
 		Render( _canvas )
 		Render( _canvas )
-
-		_canvas.Flush()
+		
+		_canvas.EndRender()
 		
 		
 		SDL_GL_SwapWindow( _sdlWindow )
 		SDL_GL_SwapWindow( _sdlWindow )
 	End
 	End
@@ -287,11 +282,6 @@ Class Window Extends View
 		_windowsByID[SDL_GetWindowID( _sdlWindow )]=Self
 		_windowsByID[SDL_GetWindowID( _sdlWindow )]=Self
 		If Not (flags & WindowFlags.Hidden) _visibleWindows.Push( Self )
 		If Not (flags & WindowFlags.Hidden) _visibleWindows.Push( Self )
 		
 		
-		'Create GLContext and canvas
-		
-		_sdlGLContext=SDL_GL_CreateContext( _sdlWindow )
-		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )
-		
 		_minSize=GetMinSize()
 		_minSize=GetMinSize()
 		MinSize=_minSize
 		MinSize=_minSize
 		
 		
@@ -301,7 +291,12 @@ Class Window Extends View
 		_frame=GetFrame()
 		_frame=GetFrame()
 		Frame=_frame
 		Frame=_frame
 		
 		
-		_canvas=New Canvas( Frame.Width,Frame.Height )
+		'Create GLContext and canvas
+		
+		_sdlGLContext=SDL_GL_CreateContext( _sdlWindow )
+		SDL_GL_MakeCurrent( _sdlWindow,_sdlGLContext )
+		
+		_canvas=New Canvas( _frame.Width,_frame.Height )
 		
 		
 		Update()
 		Update()
 	End
 	End