Bläddra i källkod

Added Image.Rect, Image.Width, Image.Height - these are *untransformed* by Handle/Scale.

Mark Sibly 9 år sedan
förälder
incheckning
6960896470
2 ändrade filer med 28 tillägg och 20 borttagningar
  1. 6 6
      modules/mojo/graphics/canvas.monkey2
  2. 22 14
      modules/mojo/graphics/image.monkey2

+ 6 - 6
modules/mojo/graphics/canvas.monkey2

@@ -19,7 +19,7 @@ Class Canvas
 
 	Method New( image:Image )
 	
-		Init( image.Texture,image.Texture.Rect.Size,image.RenderRect )
+		Init( image.Texture,image.Texture.Rect.Size,image.Rect )
 	End
 	
 	#rem monkeydoc @hidden
@@ -406,10 +406,10 @@ Class Canvas
 	End
 	
 	Method DrawRect( rect:Rectf,srcImage:Image,srcRect:Recti )
-		Local s0:=Float(srcImage.RenderRect.min.x+srcRect.min.x)/srcImage.Texture.Width
-		Local t0:=Float(srcImage.RenderRect.min.y+srcRect.min.y)/srcImage.Texture.Height
-		Local s1:=Float(srcImage.RenderRect.min.x+srcRect.max.x)/srcImage.Texture.Width
-		Local t1:=Float(srcImage.RenderRect.min.y+srcRect.max.y)/srcImage.Texture.Height
+		Local s0:=Float(srcImage.Rect.min.x+srcRect.min.x)/srcImage.Texture.Width
+		Local t0:=Float(srcImage.Rect.min.y+srcRect.min.y)/srcImage.Texture.Height
+		Local s1:=Float(srcImage.Rect.min.x+srcRect.max.x)/srcImage.Texture.Width
+		Local t1:=Float(srcImage.Rect.min.y+srcRect.max.y)/srcImage.Texture.Height
 		AddDrawOp( srcImage.Material,4,1 )
 		AddVertex( rect.min.x,rect.min.y,s0,t0 )
 		AddVertex( rect.max.x,rect.min.y,s1,t0 )
@@ -467,7 +467,7 @@ Class Canvas
 		ty-=_font.Height * handleY
 	
 		Local image:=_font.Image
-		Local sx:=image.RenderRect.min.x,sy:=image.RenderRect.min.y
+		Local sx:=image.Rect.min.x,sy:=image.Rect.min.y
 		Local tw:=image.Texture.Width,th:=image.Texture.Height
 		
 		AddDrawOp( image.Material,4,text.Length )

+ 22 - 14
modules/mojo/graphics/image.monkey2

@@ -52,13 +52,21 @@ Class Image
 		Return _texture
 	End
 	
-	#rem monkeydoc @hidden
-	#end
-	Property RenderRect:Recti()
+	Property Rect:Recti()
+	
+		Return _rect
+	End
 	
-		Return _renderRect
+	Property Width:Int()
+	
+		Return _rect.Width
 	End
 	
+	Property Height:Int()
+	
+		Return _rect.Height
+	End
+
 	Property Handle:Vec2f()
 	
 		Return _handle
@@ -122,7 +130,7 @@ Class Image
 	
 	Field _material:Material
 	Field _texture:Texture
-	Field _renderRect:Recti
+	Field _rect:Recti
 	
 	Field _handle:=New Vec2f( 0,0 )
 	Field _scale:=New Vec2f( 1,1 )
@@ -140,17 +148,17 @@ Class Image
 		
 		_material=material
 		_texture=texture
-		_renderRect=rect
+		_rect=rect
 		
 		UpdateVertices()
 		UpdateTexCoords()
 	End
 	
 	Method UpdateVertices()
-		_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
+		_vertices.min.x=Float(_rect.Width)*(0-_handle.x)*_scale.x
+		_vertices.min.y=Float(_rect.Height)*(0-_handle.y)*_scale.y
+		_vertices.max.x=Float(_rect.Width)*(1-_handle.x)*_scale.x
+		_vertices.max.y=Float(_rect.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 )
@@ -159,10 +167,10 @@ Class Image
 	End
 	
 	Method UpdateTexCoords()
-		_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
+		_texCoords.min.x=Float(_rect.min.x)/_texture.Width
+		_texCoords.min.y=Float(_rect.min.y)/_texture.Height
+		_texCoords.max.x=Float(_rect.max.x)/_texture.Width
+		_texCoords.max.y=Float(_rect.max.y)/_texture.Height
 	End
 	
 End