Selaa lähdekoodia

Replaced Image.X0,S0 etc with Image.Vertices and Image.TexCoords.

Mark Sibly 9 vuotta sitten
vanhempi
commit
8c531a15cd
2 muutettua tiedostoa jossa 32 lisäystä ja 83 poistoa
  1. 13 18
      modules/mojo/graphics/canvas.monkey2
  2. 19 65
      modules/mojo/graphics/image.monkey2

+ 13 - 18
modules/mojo/graphics/canvas.monkey2

@@ -393,11 +393,12 @@ Class Canvas
 	End
 	
 	Method DrawRect( rect:Rectf,srcImage:Image )
+		Local tc:=srcImage.TexCoords
 		AddDrawOp( srcImage.Material,4,1 )
-		AddVertex( rect.min.x,rect.min.y,srcImage.S0,srcImage.T0 )
-		AddVertex( rect.max.x,rect.min.y,srcImage.S1,srcImage.T0 )
-		AddVertex( rect.max.x,rect.max.y,srcImage.S1,srcImage.T1 )
-		AddVertex( rect.min.x,rect.max.y,srcImage.S0,srcImage.T1 )
+		AddVertex( rect.min.x,rect.min.y,tc.min.x,tc.min.y )
+		AddVertex( rect.max.x,rect.min.y,tc.max.x,tc.min.y )
+		AddVertex( rect.max.x,rect.max.y,tc.max.x,tc.max.y )
+		AddVertex( rect.min.x,rect.max.y,tc.min.x,tc.max.y )
 	End
 	
 	Method DrawRect( x:Float,y:Float,width:Float,height:Float,srcImage:Image )
@@ -421,11 +422,13 @@ Class Canvas
 	End
 	
 	Method DrawImage( image:Image,tx:Float,ty:Float )
+		Local vs:=image.Vertices
+		Local tc:=image.TexCoords
 		AddDrawOp( image.Material,4,1 )
-		AddVertex( image.X0+tx,image.Y0+ty,image.S0,image.T0 )
-		AddVertex( image.X1+tx,image.Y0+ty,image.S1,image.T0 )
-		AddVertex( image.X1+tx,image.Y1+ty,image.S1,image.T1 )
-		AddVertex( image.X0+tx,image.Y1+ty,image.S0,image.T1 )
+		AddVertex( vs.min.x+tx,vs.min.y+ty,tc.min.x,tc.min.y )
+		AddVertex( vs.max.x+tx,vs.min.y+ty,tc.max.x,tc.min.y )
+		AddVertex( vs.max.x+tx,vs.max.y+ty,tc.max.x,tc.max.y )
+		AddVertex( vs.min.x+tx,vs.max.y+ty,tc.min.x,tc.max.y )
 	End
 	
 	Method DrawImage( image:Image,trans:Vec2f )
@@ -436,11 +439,7 @@ Class Canvas
 		Local matrix:=_matrix
 		Translate( tx,ty )
 		Rotate( rz )
-		AddDrawOp( image.Material,4,1 )
-		AddVertex( image.X0,image.Y0,image.S0,image.T0 )
-		AddVertex( image.X1,image.Y0,image.S1,image.T0 )
-		AddVertex( image.X1,image.Y1,image.S1,image.T1 )
-		AddVertex( image.X0,image.Y1,image.S0,image.T1 )
+		DrawImage( image,0,0 )
 		_matrix=matrix
 	End
 
@@ -454,11 +453,7 @@ Class Canvas
 		Translate( tx,ty )
 		Rotate( rz )
 		Scale( sx,sy )
-		AddDrawOp( image.Material,4,1 )
-		AddVertex( image.X0,image.Y0,image.S0,image.T0 )
-		AddVertex( image.X1,image.Y0,image.S1,image.T0 )
-		AddVertex( image.X1,image.Y1,image.S1,image.T1 )
-		AddVertex( image.X0,image.Y1,image.S0,image.T1 )
+		DrawImage( image,0,0 )
 		_matrix=matrix
 	End
 

+ 19 - 65
modules/mojo/graphics/image.monkey2

@@ -81,61 +81,21 @@ Class Image
 		UpdateVertices()
 	End
 	
-	Property Width:Float()
+	Property Vertices:Rectf()
 	
-		Return _x1-_x0
+		Return _vertices
 	End
 	
-	Property Height:Float()
+	Property TexCoords:Rectf()
 	
-		Return _y1-_y0
+		Return _texCoords
 	End
-	
+
 	Property Radius:Float()
 	
 		Return _radius
 	End
 	
-	Property X0:Float()
-	
-		Return _x0
-	End
-	
-	Property Y0:Float()
-	
-		Return _y0
-	End
-	
-	Property X1:Float()
-	
-		Return _x1
-	End
-	
-	Property Y1:Float()
-	
-		Return _y1
-	End
-	
-	Property S0:Float()
-	
-		Return _s0
-	End
-	
-	Property T0:Float()
-	
-		Return _t0
-	End
-	
-	Property S1:Float()
-	
-		Return _s1
-	End
-	
-	Property T1:Float()
-	
-		Return _t1
-	End
-	
 	Function Load:Image( path:String,shader:Shader=Null )
 	
 		Local texture:=mojo.graphics.Texture.Load( path )
@@ -166,15 +126,9 @@ Class Image
 	
 	Field _handle:=New Vec2f( 0,0 )
 	Field _scale:=New Vec2f( 1,1 )
+	Field _vertices:Rectf
+	Field _texCoords:Rectf
 	Field _radius:Float
-	Field _x0:Float
-	Field _y0:Float
-	Field _x1:Float
-	Field _y1:Float
-	Field _s0:Float
-	Field _t0:Float
-	Field _s1:Float
-	Field _t1:Float
 	
 	Method Init( material:Material,texture:Texture,rect:Recti,shader:Shader )
 		
@@ -193,22 +147,22 @@ Class Image
 	End
 	
 	Method UpdateVertices()
-		_x0=Float(_renderRect.Width)*(0-_handle.x)*_scale.x
-		_y0=Float(_renderRect.Height)*(0-_handle.y)*_scale.y
-		_x1=Float(_renderRect.Width)*(1-_handle.x)*_scale.x
-		_y1=Float(_renderRect.Height)*(1-_handle.y)*_scale.y
-		_radius=_x0*_x0+_y0*_y0
-		_radius=Max( _radius,_x1*_x1+_y0*_y0 )
-		_radius=Max( _radius,_x1*_x1+_y1*_y1 )
-		_radius=Max( _radius,_x0*_x0+_y1*_y1 )
+		_vertices.min.x=Float(_renderRect.Width)*(0-_handle.x)*_scale.x
+		_vertices.min.y=Float(_renderRect.Height)*(0-_handle.y)*_scale.y
+		_vertices.max.x=Float(_renderRect.Width)*(1-_handle.x)*_scale.x
+		_vertices.max.y=Float(_renderRect.Height)*(1-_handle.y)*_scale.y
+		_radius=_vertices.min.x*_vertices.min.x+_vertices.min.y*_vertices.min.y
+		_radius=Max( _radius,_vertices.max.x*_vertices.max.x+_vertices.min.y*_vertices.min.y )
+		_radius=Max( _radius,_vertices.max.x*_vertices.max.x+_vertices.max.y*_vertices.max.y )
+		_radius=Max( _radius,_vertices.min.x*_vertices.min.x+_vertices.max.y*_vertices.max.y )
 		_radius=Sqrt( _radius )
 	End
 	
 	Method UpdateTexCoords()
-		_s0=Float(_renderRect.min.x)/_texture.Width
-		_t0=Float(_renderRect.min.y)/_texture.Height
-		_s1=Float(_renderRect.max.x)/_texture.Width
-		_t1=Float(_renderRect.max.y)/_texture.Height
+		_texCoords.min.x=Float(_renderRect.min.x)/_texture.Width
+		_texCoords.min.y=Float(_renderRect.min.y)/_texture.Height
+		_texCoords.max.x=Float(_renderRect.max.x)/_texture.Width
+		_texCoords.max.y=Float(_renderRect.max.y)/_texture.Height
 	End
 	
 End