Răsfoiți Sursa

Added support for SColor8.

woollybah 5 ani în urmă
părinte
comite
338ec96749

+ 8 - 1
color.mod/color.bmx

@@ -36,7 +36,7 @@ Struct SColor8
 	Field ReadOnly a:Byte
 	
 	Rem
-	bbdoc: Craetes an #SColor8 instance using the specified @r, @g, @b and @a components.
+	bbdoc: Creates an #SColor8 instance using the specified @r, @g, @b and @a components.
 	End Rem
 	Method New(r:Byte, g:Byte, b:Byte, a:Byte = 255)
 		Self.r = r
@@ -44,6 +44,13 @@ Struct SColor8
 		Self.b = b
 		Self.a = a
 	End Method
+
+	Method New(r:Int, g:Int, b:Int, a:Int = 255)
+		Self.r = r
+		Self.g = g
+		Self.b = b
+		Self.a = a
+	End Method
 	
 	Rem
 	bbdoc: Creates an #SColor8 instance using the specified 32-bit RGBA value.

+ 12 - 0
d3d9max2d.mod/d3d9max2d.bmx

@@ -417,6 +417,14 @@ Type TD3D9Max2DDriver Extends TMax2dDriver
 		_iverts[15]=_color
 		_iverts[21]=_color
 	End Method
+
+	Method SetColor( color:SColor8 ) Override
+		_color=(_color&$ff000000)|color.ToARGB()	
+		_iverts[3]=_color
+		_iverts[9]=_color
+		_iverts[15]=_color
+		_iverts[21]=_color
+	End Method
 	
 	Method SetClsColor( red,green,blue ) Override
 		red=Max(Min(red,255),0)
@@ -425,6 +433,10 @@ Type TD3D9Max2DDriver Extends TMax2dDriver
 		_clscolor=$ff000000|(red Shl 16)|(green Shl 8)|blue
 	End Method
 	
+	Method SetClsColor( color:SColor8 ) Override
+		_clscolor=$ff000000|color.ToARGB()
+	End Method
+	
 	Method SetViewport( x,y,width,height ) Override
 		If x=0 And y=0 And width=_gw And height=_gh 'GraphicsWidth() And height=GraphicsHeight()
 			_d3dDev.SetRenderState D3DRS_SCISSORTESTENABLE,False

+ 11 - 0
glmax2d.mod/glmax2d.bmx

@@ -452,12 +452,23 @@ Type TGLMax2DDriver Extends TMax2DDriver
 		glColor4ubv color4ub
 	End Method
 
+	Method SetColor( color:SColor8 ) Override
+		color4ub[0]=color.r
+		color4ub[1]=color.g
+		color4ub[2]=color.b
+		glColor4ubv color4ub
+	End Method
+
 	Method SetClsColor( red,green,blue ) Override
 		red=Min(Max(red,0),255)
 		green=Min(Max(green,0),255)
 		blue=Min(Max(blue,0),255)
 		glClearColor red/255.0,green/255.0,blue/255.0,1.0
 	End Method
+
+	Method SetClsColor( color:SColor8 ) Override
+		glClearColor color.r/255.0,color.g/255.0,color.b/255.0,1.0
+	End Method
 	
 	Method SetViewport( x,y,w,h ) Override
 		If x=0 And y=0 And w=GraphicsWidth() And h=GraphicsHeight()

+ 7 - 0
max2d.mod/driver.bmx

@@ -37,6 +37,13 @@ Type TMax2DDriver Extends TGraphicsDriver
 	Method SetViewport( x,y,width,height ) Abstract
 	Method SetTransform( xx#,xy#,yx#,yy# ) Abstract
 	Method SetLineWidth( width# ) Abstract
+
+	Method SetColor( color:SColor8 )
+		SetColor(color.r, color.g, color.b)
+	End Method
+	Method SetClsColor( color:SColor8)
+		SetClsColor(color.r, color.g, color.b)
+	End Method
 	
 	Method Cls() Abstract
 	Method Plot( x#,y# ) Abstract

+ 30 - 22
max2d.mod/max2d.bmx

@@ -83,9 +83,11 @@ Public
 
 Type TMax2DGraphics Extends TGraphics
 
-	Field color_red,color_green,color_blue
+	'Field color_red,color_green,color_blue
+	Field color:SColor8
 	Field color_alpha#
-	Field clscolor_red,clscolor_green,clscolor_blue
+	'Field clscolor_red,clscolor_green,clscolor_blue
+	Field clscolor:SColor8
 	Field line_width#
 	Field tform_rot#,tform_scale_x#,tform_scale_y#
 	Field tform_ix#,tform_iy#,tform_jx#,tform_jy#
@@ -142,9 +144,9 @@ Type TMax2DGraphics Extends TGraphics
 		EndIf
 		SetVirtualResolution vres_width,vres_height
 		SetBlend blend_mode
-		SetColor color_red,color_green,color_blue
+		SetColor color
 		SetAlpha color_alpha
-		SetClsColor clscolor_red,clscolor_green,clscolor_blue
+		SetClsColor clscolor
 		SetLineWidth line_width
 		SetRotation tform_rot
 		SetScale tform_scale_x,tform_scale_y
@@ -187,13 +189,9 @@ Type TMax2DGraphics Extends TGraphics
 		t.g_width=gw
 		t.g_height=gh
 		t.blend_mode=MASKBLEND
-		t.color_red=255
-		t.color_green=255
-		t.color_blue=255
+		t.color = New SColor8(255, 255, 255)
 		t.color_alpha=1
-		t.clscolor_red=0
-		t.clscolor_green=0
-		t.clscolor_blue=0
+		t.clscolor = New SColor8(0, 0, 0)
 		t.line_width=1
 		t.tform_rot=0
 		t.tform_scale_x=1
@@ -249,20 +247,23 @@ The @red, @green and @blue parameters should be in the range of 0 to 255.
 The default cls color is black.
 End Rem
 Function SetClsColor( red,green,blue )
-	gc.clscolor_red=red
-	gc.clscolor_green=green
-	gc.clscolor_blue=blue
+	gc.clscolor = New SColor8(red, green, blue)
 	_max2dDriver.SetClsColor red,green,blue
 End Function
 
+Function SetClsColor( color:SColor8 )
+	gc.clscolor = color
+	_max2dDriver.SetClsColor color
+End Function
+
 Rem
 bbdoc: Get red, green and blue component of current cls color.
 returns: Red, green and blue values in the range 0..255 in the variables supplied.
 End Rem
 Function GetClsColor( red Var,green Var,blue Var )
-	red=gc.clscolor_red
-	green=gc.clscolor_green
-	blue=gc.clscolor_blue
+	red=gc.clscolor.r
+	green=gc.clscolor.g
+	blue=gc.clscolor.b
 End Function
 
 Rem
@@ -469,20 +470,27 @@ The #SetColor command affects the color of #Plot, #DrawRect, #DrawLine, #DrawTex
 The @red, @green and @blue parameters should be in the range of 0 to 255.
 End Rem
 Function SetColor( red,green,blue )
-	gc.color_red=red
-	gc.color_green=green
-	gc.color_blue=blue
+	gc.color = New SColor8(red, green, blue)
 	_max2dDriver.SetColor red,green,blue
 End Function
 
+Function SetColor( color:SColor8 )
+	gc.color = color
+	_max2dDriver.SetColor color
+End Function
+
 Rem
 bbdoc: Get red, green and blue component of current color.
 returns: Red, green and blue values in the range 0..255 in the variables supplied.
 End Rem
 Function GetColor( red Var,green Var,blue Var )
-	red=gc.color_red
-	green=gc.color_green
-	blue=gc.color_blue
+	red=gc.color.r
+	green=gc.color.g
+	blue=gc.color.b
+End Function
+
+Function GetColor( color:SColor8 Var )
+	color = gc.color
 End Function
 
 Rem

+ 45 - 1
pixmap.mod/pixmap.bmx

@@ -22,6 +22,7 @@ ModuleInfo "History: Removed AddPixmapLoader function"
 
 Import BRL.Math
 Import BRL.Stream
+Import BRL.Color
 
 Import "pixel.bmx"
 
@@ -133,7 +134,7 @@ Type TPixmap
 	Rem
 	bbdoc: Read a pixel from a pixmap
 	returns: The pixel at the specified coordinates packed into an integer
-	end rem
+	End Rem
 	Method ReadPixel( x,y )
 		Assert x>=0 And x<width And y>=0 And y<height Else "Pixmap coordinates out of bounds"
 		Local p:Byte Ptr=PixelPtr(x,y)
@@ -153,6 +154,10 @@ Type TPixmap
 		End Select
 	End Method
 
+	Method ReadPixelColor:SColor8( x,y )
+		Return New SColor8(ReadPixel(x, y))
+	End Method
+
 	Rem
 	bbdoc: Write a pixel to a pixmap
 	end rem
@@ -175,6 +180,28 @@ Type TPixmap
 		End Select
 	End Method
 	
+	Rem
+	bbdoc: Writes a pixel to a pixmap of the specified #SColor8
+	End Rem
+	Method WritePixel(x:Int, y:Int, col:SColor8)
+		Assert x>=0 And x<width And y>=0 And y<height Else "Pixmap coordinates out of bounds"
+		Local p:Byte Ptr=PixelPtr(x,y)
+		Select format
+		Case PF_A8
+			p[0]=col.a
+		Case PF_I8
+			p[0]=(col.r + col.g + col.b)/3
+		Case PF_RGB888
+			p[0]=col.r ; p[1]=col.g ; p[2]=col.b
+		Case PF_BGR888
+			p[0]=col.b ; p[1]=col.g ; p[2]=col.r
+		Case PF_RGBA8888
+			p[0]=col.r ; p[1]=col.g ; p[2]=col.b; p[3]=col.a
+		Case PF_BGRA8888
+			p[0]=col.b ; p[1]=col.g ; p[2]=col.r ; p[3]=col.a
+		End Select	
+	End Method
+	
 	Rem
 	bbdoc: Create a pixmap
 	returns: A new TPixmap object
@@ -251,6 +278,11 @@ Type TPixmap
 		Next
 	End Method
 	
+	Method ClearPixels( color:SColor8 )
+		ClearPixels(color.ToARGB())
+	End Method
+
+	
 End Type
 
 Private
@@ -558,6 +590,10 @@ Function ReadPixel( pixmap:TPixmap,x,y )
 	Return pixmap.ReadPixel( x,y )
 End Function
 
+Function ReadPixelColor:SColor8( pixmap:TPixmap,x,y )
+	Return pixmap.ReadPixelColor( x,y )
+End Function
+
 Rem
 bbdoc: Write a pixel to a pixmap
 about:
@@ -573,6 +609,10 @@ Function WritePixel( pixmap:TPixmap,x,y,argb )
 	pixmap.WritePixel x,y,argb
 End Function
 
+Function WritePixel( pixmap:TPixmap,x,y,color:SColor8 )
+	pixmap.WritePixel x,y,color
+End Function
+
 Rem
 bbdoc: Clear a pixmap
 about:
@@ -589,3 +629,7 @@ End Rem
 Function ClearPixels( pixmap:TPixmap,argb=0 )
 	pixmap.ClearPixels argb
 End Function
+
+Function ClearPixels( pixmap:TPixmap,color:SColor8 )
+	pixmap.ClearPixels color
+End Function