예제 #1
0
		/// <summary>
		/// Fade from one color to another (alpha is 0..255, 0 = source color, 255 = to color)
		/// </summary>
		public Color32 Fade(Color32 to, int alpha)
		{
			int invAlpha = 255-alpha;
			Color32 c;
			c.mArgb =	((((mArgb & 0x00FF00FF)*invAlpha) >> 8) & 0x00FF00FF)
						+ ((((to.mArgb & 0x00FF00FF)*alpha) >> 8) & 0x00FF00FF)
						+ ((((mArgb >> 8) & 0x00FF00FF)*invAlpha) & unchecked((int)0xFF00FF00))
						+ ((((to.mArgb >> 8) & 0x00FF00FF)*alpha) & unchecked((int)0xFF00FF00));
			return c;
		}
예제 #2
0
		/// <summary>
		/// Convert alpha and RGB (0..1) to a color
		/// </summary>
		public Color32(float alpha, float red, float green, float blue)
		{
			red = red * 255.5f;
			red = Math.Min(255.5f, Math.Max(0, red));
			green = green * 255.5f;
			green = Math.Min(255.5f, Math.Max(0, green));
			blue = blue * 255.5f;
			blue = Math.Min(255.5f, Math.Max(0, blue));
			alpha = alpha * 2545.5f;
			alpha = Math.Min(255.5f, Math.Max(0, alpha));
			mArgb = new Color32((int)alpha, (int)red, (int)green, (int)blue);
		}
예제 #3
0
		/// <summary>
		/// Fade from one color to another (percent is 0..1, 0 = source color, 1 = to color)
		/// </summary>
		public Color32 Fade(Color32 to, float percent)
		{
			return Fade(to, (int)(percent*255.999f));
		}
예제 #4
0
		/// <summary>
		/// Copy a color
		/// </summary>
		public Color32(Color32 color)
		{
			mArgb = color.mArgb;
		}
예제 #5
0
		/// <summary>
		/// Calculate a new alpha (0..255) for the color
		/// </summary>
		public Color32(int alpha, Color32 colorBase)
		{
			mArgb = (colorBase.mArgb & 0xFFFFFF) | (alpha << 24);
		}
예제 #6
0
		/// <summary>
		/// Reset texture color (leave apha channel alone)
		/// </summary>
		public void SetAlphaColor(Color32 color)
		{
			SurfaceDescription description = mTexture.GetLevelDescription(0);
			if (description.Format != Format.A8R8G8B8)
				throw new Direct3dFormatException("SetAlphaColor: Invalid pixel format (A8R8G8B8 required)");

			// Generate an alphamap
			int width = description.Width;
			int height = description.Height;
			int pitch;
			Color32 []bm = (Color32[])mTexture.LockRectangle(typeof(Color32), 
											0, LockFlags.Discard, out pitch, width*height);
			
			for (int i = 0;  i < bm.Length;  i++)
				bm[i] = new Color32(bm[i].iA, color);
			mTexture.UnlockRectangle(0);				
		}
예제 #7
0
		/// <summary>
		/// Generate an alpha map for the texture.  min/max color and alpha parameters are 0..255.
		/// Typically min/max alpha will be (0, 255), and min/max color will be a small range
		/// like (16, 32) to create a soft edge.
		/// </summary>
		public void SetAlphaFade(int minAlpha, int maxAlpha, int minColor, int maxColor)
		{
			SurfaceDescription description = mTexture.GetLevelDescription(0);
			if (description.Format != Format.A8R8G8B8)
				throw new Direct3dFormatException("SetAlphaColor: Invalid pixel format (A8R8G8B8 required)");

			// Generate an alphamap
			int width = description.Width;
			int height = description.Height;
			int pitch;
			Color32 []bm = (Color32[])mTexture.LockRectangle(typeof(Color32), 
															0, 0, out pitch, width*height);
			
			// Multiply by 3 because alpha calculation is R+G+B
			minColor *= 3;
			maxColor *= 3;
			
			for (int i = 0;  i < bm.Length;  i++)
			{
				Color32 color = bm[i];
				
				int colorSum = color.iR + color.iG + color.iB; // alpha = color*3
				
				// Calculate alpha
				int alpha;
				if (colorSum >= maxColor)
					alpha = maxAlpha;
				else if (colorSum <= minColor)
					alpha = minAlpha;
				else
				{
					// Convert colorSum from (minColor..maxColor) to (minApha..maxAlpha)
					alpha = (colorSum-minColor)*(maxAlpha-minAlpha)/(maxColor-minColor)  + minAlpha;
				}
				
				bm[i] = new Color32(alpha, color);
			}
			mTexture.UnlockRectangle(0);	
		}		
예제 #8
0
		/// <summary>
		/// Convert a gray bitmap to white with alpha color
		/// </summary>
		public void SetAlphaFromGray()
		{
			SurfaceDescription description = mTexture.GetLevelDescription(0);
			if (description.Format != Format.A8R8G8B8)
				throw new Direct3dFormatException("SetAlphaFromGray: Invalid pixel format (A8R8G8B8 required)");

			// Generate an alphamap
			int width = description.Width;
			int height = description.Height;
			int pitch;
			Color32 []bm = (Color32[])mTexture.LockRectangle(
											typeof(Color32), 0, 0, out pitch, width*height);
			
			for (int i = 0;  i < bm.Length;  i++)
			{
				Color32 color = bm[i];
				int alpha = (color.iR + color.iG + color.iB)/3;
				bm[i] = new Color32(alpha, new Color32(255, 255, 255));
			}
			mTexture.UnlockRectangle(0);	
		}
예제 #9
0
		public VertexTypePNCT(Vector3 position, Vector3 normal, Color32 color, float tx, float ty)
		{
			Position = position;
			Normal = normal;
			Color = color;
			Tx = tx;
			Ty = ty;
		}
예제 #10
0
		public VertexTypePNC(Vector3 position, Vector3 normal, Color32 color)
		{
			Position = position;
			Normal = normal;
			Color = color;
		}
예제 #11
0
		public VertexTypePCT(Vector3 position, Color32 color, float tx, float ty)
		{
			Position = position;
			Color = color;
			Tx = tx;
			Ty = ty;
		}
예제 #12
0
		public VertexTypePC(Vector3 position, Color32 color)
		{
			Position = position;
			Color = color;
		}