• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ColorRgba类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ColorRgba的典型用法代码示例。如果您正苦于以下问题:C# ColorRgba类的具体用法?C# ColorRgba怎么用?C# ColorRgba使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ColorRgba类属于命名空间,在下文中一共展示了ColorRgba类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Create

		public static void Create(Vector3 pos, string text, ColorRgba color)
		{
			GameObject pe = new GameObject(GameRes.Data.Prefabs.PowerupEffect_Prefab);
			pe.GetComponent<PowerupEffect>().Text = text;
			pe.GetComponent<TextRenderer>().ColorTint = color;
			pe.Transform.Pos = pos;
			Scene.Current.RegisterObj(pe);
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:8,代码来源:PowerupEffect.cs


示例2: PixelData

        public PixelData(int width, int height, ColorRgba[] data)
        {
            if (data == null) throw new ArgumentNullException("data");
            if (width < 0) throw new ArgumentException("Width may not be negative.", "width");
            if (height < 0) throw new ArgumentException("Height may not be negative.", "height");

            this.SetPixelDataRgba(data, width, height);
        }
开发者ID:gitMaxim,项目名称:duality,代码行数:8,代码来源:PixelData.cs


示例3: PixelData

		public PixelData(int width, int height, ColorRgba backColor)
		{
			if (width < 0) throw new ArgumentException("Width may not be negative.", "width");
			if (height < 0) throw new ArgumentException("Height may not be negative.", "height");

			this.width = width;
			this.height = height;
			this.data = new ColorRgba[width * height];

			for (int i = 0; i < this.data.Length; i++)
				this.data[i] = backColor;
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:12,代码来源:PixelData.cs


示例4: GetPixelDataRgba

		/// <summary>
		/// Extracts a Bitmaps pixel data.
		/// </summary>
		/// <param name="bm"></param>
		/// <returns></returns>
		public static ColorRgba[] GetPixelDataRgba(this Bitmap bm)
		{
			int[] argbValues = GetPixelDataIntArgb(bm);

			// Convert to ColorRGBA
			ColorRgba[] result = new ColorRgba[argbValues.Length];
			unchecked
			{
				for (int i = 0; i < argbValues.Length; i++)
					result[i].SetIntArgb(argbValues[i]);
			}
			return result;
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:18,代码来源:ExtMethodsBitmap.cs


示例5: VisualizeAtlas

        public static void VisualizeAtlas(Bitmap bitmap, List<Rect> atlas)
        {
            ColorRgba atlasColor = new ColorRgba(255, 128, 128, 164);

            // Draw atlas rects
            if (atlas != null)
            {
                Pen atlasPen = new Pen(Color.FromArgb(atlasColor.A, atlasColor.R, atlasColor.G, atlasColor.B));
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    foreach (Rect r in atlas) g.DrawRectangle(atlasPen, r.X, r.Y, r.W, r.H);
                }
            }
        }
开发者ID:SirePi,项目名称:duality,代码行数:14,代码来源:PixmapAtlasVisualizer.cs


示例6: if

        void ICmpUpdatable.OnUpdate()
        {
            Trigger trig = this.GameObj.GetComponent<Trigger>();
            SpriteRenderer sprite = this.GameObj.GetComponent<SpriteRenderer>();

            if (trig.Triggered && !this.wasTriggered)
            {
                this.oldColorTint = sprite.ColorTint;
                sprite.ColorTint = ColorRgba.Mix(this.oldColorTint, ColorRgba.Red, 0.5f);
            }
            else if (!trig.Triggered && this.wasTriggered)
            {
                sprite.ColorTint = this.oldColorTint;
            }
            this.wasTriggered = trig.Triggered;
        }
开发者ID:Andrea,项目名称:dualityTechDemos,代码行数:16,代码来源:TriggerDebugRenderer.cs


示例7: SetPixelDataArgb

		public static void SetPixelDataArgb(this PixelData pixelData, int[] data, int width = -1, int height = -1)
		{
			if (width < 0) width = pixelData.Width;
			if (height < 0) height = pixelData.Height;
			if (data.Length != width * height) throw new ArgumentException("Data length doesn't match width * height", "pixelData");

			ColorRgba[] tempData = new ColorRgba[width * height];
			Parallel.ForEach(Partitioner.Create(0, tempData.Length), range =>
			{
				for (int i = range.Item1; i < range.Item2; i++)
				{
					tempData[i].A = (byte)((data[i] & 0xFF000000) >> 24);
					tempData[i].R = (byte)((data[i] & 0x00FF0000) >> 16);
					tempData[i].G = (byte)((data[i] & 0x0000FF00) >> 8);
					tempData[i].B = (byte)((data[i] & 0x000000FF) >> 0);
				}
			});

			pixelData.SetData(tempData, width, height);
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:20,代码来源:ExtMethodsPixelData.cs


示例8: Read

		public PixelData Read(Stream stream)
		{
			ColorRgba[] rawColorData;
			int width;
			int height;
			PixelData pixelData = new PixelData();

			using (Bitmap bitmap = Bitmap.FromStream(stream) as Bitmap)
			{
				// Retrieve data
				BitmapData bitmapData = bitmap.LockBits(
					new Rectangle(0, 0, bitmap.Width, bitmap.Height),
					ImageLockMode.ReadOnly,
					PixelFormat.Format32bppArgb);
			
				int pixelCount = bitmapData.Width * bitmapData.Height;
				int[] argbValues = new int[pixelCount];
				Marshal.Copy(bitmapData.Scan0, argbValues, 0, pixelCount);
				bitmap.UnlockBits(bitmapData);
				
				width = bitmapData.Width;
				height = bitmapData.Height;
				rawColorData = new ColorRgba[width * height];
				Parallel.ForEach(Partitioner.Create(0, rawColorData.Length), range =>
				{
					for (int i = range.Item1; i < range.Item2; i++)
					{
						rawColorData[i].A = (byte)((argbValues[i] & 0xFF000000) >> 24);
						rawColorData[i].R = (byte)((argbValues[i] & 0x00FF0000) >> 16);
						rawColorData[i].G = (byte)((argbValues[i] & 0x0000FF00) >> 8);
						rawColorData[i].B = (byte)((argbValues[i] & 0x000000FF) >> 0);
					}
				});
			}

			pixelData.SetData(rawColorData, width, height);
			pixelData.ColorTransparentPixels();

			return pixelData;
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:40,代码来源:BitmapImageCodec.cs


示例9: ColorChangeElement

 public ColorChangeElement(ColorRgba color)
 {
     this.color = color;
 }
开发者ID:ninja2003,项目名称:duality,代码行数:4,代码来源:FormattedText.cs


示例10: PrepareVertices

		protected void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
		{
			Vector3 posTemp = this.gameobj.Transform.Pos;
			float scaleTemp = 1.0f;
			device.PreprocessCoords(ref posTemp, ref scaleTemp);

			Vector2 xDot, yDot;
			MathF.GetTransformDotVec(this.GameObj.Transform.Angle, scaleTemp, out xDot, out yDot);

			Rect rectTemp = this.rect.Transformed(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);

			Vector2 edge1 = rectTemp.TopLeft;
			Vector2 edge2 = rectTemp.BottomLeft;
			Vector2 edge3 = rectTemp.BottomRight;
			Vector2 edge4 = rectTemp.TopRight;

			MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
            
			float left   = uvRect.X;
			float right  = uvRect.RightX;
			float top    = uvRect.Y;
			float bottom = uvRect.BottomY;

			if ((this.flipMode & FlipMode.Horizontal) != FlipMode.None)
				MathF.Swap(ref left, ref right);
			if ((this.flipMode & FlipMode.Vertical) != FlipMode.None)
				MathF.Swap(ref top, ref bottom);

			if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];

			vertices[0].Pos.X = posTemp.X + edge1.X;
			vertices[0].Pos.Y = posTemp.Y + edge1.Y;
			vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[0].TexCoord.X = left;
			vertices[0].TexCoord.Y = top;
			vertices[0].Color = mainClr;

			vertices[1].Pos.X = posTemp.X + edge2.X;
			vertices[1].Pos.Y = posTemp.Y + edge2.Y;
			vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[1].TexCoord.X = left;
			vertices[1].TexCoord.Y = bottom;
			vertices[1].Color = mainClr;

			vertices[2].Pos.X = posTemp.X + edge3.X;
			vertices[2].Pos.Y = posTemp.Y + edge3.Y;
			vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[2].TexCoord.X = right;
			vertices[2].TexCoord.Y = bottom;
			vertices[2].Color = mainClr;
				
			vertices[3].Pos.X = posTemp.X + edge4.X;
			vertices[3].Pos.Y = posTemp.Y + edge4.Y;
			vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[3].TexCoord.X = right;
			vertices[3].TexCoord.Y = top;
			vertices[3].Color = mainClr;

			if (this.pixelGrid)
			{
				vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
				vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
				vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
				vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);

				if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
				{
					vertices[0].Pos.X += 0.5f;
					vertices[1].Pos.X += 0.5f;
					vertices[2].Pos.X += 0.5f;
					vertices[3].Pos.X += 0.5f;
				}

				vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
				vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
				vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
				vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);

				if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
				{
					vertices[0].Pos.Y += 0.5f;
					vertices[1].Pos.Y += 0.5f;
					vertices[2].Pos.Y += 0.5f;
					vertices[3].Pos.Y += 0.5f;
				}
			}
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:90,代码来源:SpriteRenderer.cs


示例11: DrawOnto

            /// <summary>
            /// Performs a drawing operation from this Layer to a target layer.
            /// </summary>
            /// <param name="target"></param>
            /// <param name="blend"></param>
            /// <param name="destX"></param>
            /// <param name="destY"></param>
            /// <param name="width"></param>
            /// <param name="height"></param>
            /// <param name="srcX"></param>
            /// <param name="srcY"></param>
            /// <param name="colorTint"></param>
            public void DrawOnto(Layer target, BlendMode blend, int destX, int destY, int width, int height, int srcX, int srcY, ColorRgba colorTint)
            {
                if (colorTint == ColorRgba.White)
                {
                    this.DrawOnto(target, blend, destX, destY, width, height, srcX, srcY);
                    return;
                }
                if (width == -1) width = this.width;
                if (height == -1) height = this.height;

                int beginX = MathF.Max(0, -destX, -srcX);
                int beginY = MathF.Max(0, -destY, -srcY);
                int endX = MathF.Min(width, this.width, target.width - destX, this.width - srcX);
                int endY = MathF.Min(height, this.height, target.height - destY, this.height - srcY);
                if (endX - beginX < 1) return;
                if (endY - beginY < 1) return;

                ColorRgba clrSource;
                ColorRgba clrTarget;
                System.Threading.Tasks.Parallel.For(beginX, endX, i =>
                //for (int i = beginX; i < endX; i++)
                {
                    for (int j = beginY; j < endY; j++)
                    {
                        int sourceN = srcX + i + this.width * (srcY + j);
                        int targetN = destX + i + target.width * (destY + j);

                        clrSource = this.data[sourceN] * colorTint;

                        if (blend == BlendMode.Solid)
                        {
                            target.data[targetN] = clrSource;
                        }
                        else if (blend == BlendMode.Mask)
                        {
                            if (clrSource.A >= 0) target.data[targetN] = this.data[sourceN];
                        }
                        else if (blend == BlendMode.Add)
                        {
                            clrTarget	= target.data[targetN];
                            float alphaTemp = (float)clrSource.A / 255.0f;
                            target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.R + clrSource.R * alphaTemp)));
                            target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.G + clrSource.G * alphaTemp)));
                            target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.B + clrSource.B * alphaTemp)));
                            target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
                        }
                        else if (blend == BlendMode.Alpha)
                        {
                            clrTarget	= target.data[targetN];
                            float alphaTemp = (float)clrSource.A / 255.0f;
                            target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.R * (1.0f - alphaTemp) + clrSource.R * alphaTemp)));
                            target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.G * (1.0f - alphaTemp) + clrSource.G * alphaTemp)));
                            target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.B * (1.0f - alphaTemp) + clrSource.B * alphaTemp)));
                            target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.A * (1.0f - alphaTemp) + clrSource.A)));
                        }
                        else if (blend == BlendMode.Multiply)
                        {
                            clrTarget	= target.data[targetN];
                            float clrTempR = (float)clrTarget.R / 255.0f;
                            float clrTempG = (float)clrTarget.G / 255.0f;
                            float clrTempB = (float)clrTarget.B / 255.0f;
                            float clrTempA = (float)clrTarget.A / 255.0f;
                            target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.R * clrTempR)));
                            target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.G * clrTempG)));
                            target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.B * clrTempB)));
                            target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
                        }
                        else if (blend == BlendMode.Light)
                        {
                            clrTarget	= target.data[targetN];
                            float clrTempR = (float)clrTarget.R / 255.0f;
                            float clrTempG = (float)clrTarget.G / 255.0f;
                            float clrTempB = (float)clrTarget.B / 255.0f;
                            float clrTempA = (float)clrTarget.A / 255.0f;
                            target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.R * clrTempR + clrTarget.R)));
                            target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.G * clrTempG + clrTarget.G)));
                            target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.B * clrTempB + clrTarget.B)));
                            target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
                        }
                        else if (blend == BlendMode.Invert)
                        {
                            clrTarget	= target.data[targetN];
                            float clrTempR = (float)clrTarget.R / 255.0f;
                            float clrTempG = (float)clrTarget.G / 255.0f;
                            float clrTempB = (float)clrTarget.B / 255.0f;
                            float clrTempA = (float)clrTarget.A / 255.0f;
                            float clrTempR2 = (float)clrSource.R / 255.0f;
                            float clrTempG2 = (float)clrSource.G / 255.0f;
//.........这里部分代码省略.........
开发者ID:sorceron2000,项目名称:duality,代码行数:101,代码来源:Pixmap.cs


示例12: ColorTransparentPixels

 /// <summary>
 /// Sets the color of all transparent pixels to the specified color.
 /// </summary>
 /// <param name="transparentColor"></param>
 public void ColorTransparentPixels(ColorRgba transparentColor)
 {
     for (int i = 0; i < this.data.Length; i++)
     {
         if (this.data[i].A != 0) continue;
         this.data[i] = transparentColor;
     }
 }
开发者ID:sorceron2000,项目名称:duality,代码行数:12,代码来源:Pixmap.cs


示例13: CloneSubImage

 /// <summary>
 /// Extracts a rectangular region of this Layer. If the extracted region is bigger than the original Layer,
 /// all new space is filled with a background color.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="w"></param>
 /// <param name="h"></param>
 /// <param name="backColor"></param>
 public Layer CloneSubImage(int x, int y, int w, int h, ColorRgba backColor)
 {
     Layer tempLayer = new Layer(w, h, backColor);
     this.DrawOnto(tempLayer, BlendMode.Solid, -x, -y);
     return tempLayer;
 }
开发者ID:sorceron2000,项目名称:duality,代码行数:15,代码来源:Pixmap.cs


示例14: InternalRescale

            private ColorRgba[] InternalRescale(int w, int h, FilterMethod filter)
            {
                if (this.width == w && this.height == h) return null;

                ColorRgba[]	tempDestData	= new ColorRgba[w * h];
                if (filter == FilterMethod.Nearest)
                {
                    // Don't use Parallel.For here, the overhead is too big and the compiler
                    // does a great job optimizing this piece of code without, so don't get in the way.
                    for (int i = 0; i < tempDestData.Length; i++)
                    {
                        int y = i / w;
                        int x = i - (y * w);

                        int xTmp	= (x * this.width) / w;
                        int yTmp	= (y * this.height) / h;
                        int nTmp	= xTmp + (yTmp * this.width);
                        tempDestData[i] = this.data[nTmp];
                    }
                }
                else if (filter == FilterMethod.Linear)
                {
                    //for (int i = 0; i < tempDestData.Length; i++)
                    System.Threading.Tasks.Parallel.For(0, tempDestData.Length, i =>
                    {
                        int y = i / w;
                        int x = i - (y * w);

                        float	xRatio	= ((float)(x * this.width) / (float)w) + 0.5f;
                        float	yRatio	= ((float)(y * this.height) / (float)h) + 0.5f;
                        int		xTmp	= (int)xRatio;
                        int		yTmp	= (int)yRatio;
                        xRatio -= xTmp;
                        yRatio -= yTmp;

                        int		xTmp2	= xTmp + 1;
                        int		yTmp2	= yTmp + 1;
                        xTmp = xTmp < this.width ? xTmp : this.width - 1;
                        yTmp = (yTmp < this.height ? yTmp : this.height - 1) * this.width;
                        xTmp2 = xTmp2 < this.width ? xTmp2 : this.width - 1;
                        yTmp2 = (yTmp2 < this.height ? yTmp2 : this.height - 1) * this.width;

                        int		nTmp0	= xTmp + yTmp;
                        int		nTmp1	= xTmp2 + yTmp;
                        int		nTmp2	= xTmp + yTmp2;
                        int		nTmp3	= xTmp2 + yTmp2;

                        tempDestData[i].R =
                            (byte)
                            (
                                ((float)this.data[nTmp0].R * (1.0f - xRatio) * (1.0f - yRatio)) +
                                ((float)this.data[nTmp1].R * xRatio * (1.0f - yRatio)) +
                                ((float)this.data[nTmp2].R * yRatio * (1.0f - xRatio)) +
                                ((float)this.data[nTmp3].R * xRatio * yRatio)
                            );
                        tempDestData[i].G =
                            (byte)
                            (
                                ((float)this.data[nTmp0].G * (1.0f - xRatio) * (1.0f - yRatio)) +
                                ((float)this.data[nTmp1].G * xRatio * (1.0f - yRatio)) +
                                ((float)this.data[nTmp2].G * yRatio * (1.0f - xRatio)) +
                                ((float)this.data[nTmp3].G * xRatio * yRatio)
                            );
                        tempDestData[i].B =
                            (byte)
                            (
                                ((float)this.data[nTmp0].B * (1.0f - xRatio) * (1.0f - yRatio)) +
                                ((float)this.data[nTmp1].B * xRatio * (1.0f - yRatio)) +
                                ((float)this.data[nTmp2].B * yRatio * (1.0f - xRatio)) +
                                ((float)this.data[nTmp3].B * xRatio * yRatio)
                            );
                        tempDestData[i].A =
                            (byte)
                            (
                                ((float)this.data[nTmp0].A * (1.0f - xRatio) * (1.0f - yRatio)) +
                                ((float)this.data[nTmp1].A * xRatio * (1.0f - yRatio)) +
                                ((float)this.data[nTmp2].A * yRatio * (1.0f - xRatio)) +
                                ((float)this.data[nTmp3].A * xRatio * yRatio)
                            );
                    });
                }

                return tempDestData;
            }
开发者ID:sorceron2000,项目名称:duality,代码行数:84,代码来源:Pixmap.cs


示例15: EmitVertices

 /// <summary>
 /// Emits sets of vertices for glyphs and icons based on this formatted text. To render it, use each set of vertices combined with
 /// the corresponding Fonts <see cref="Material"/>.
 /// </summary>
 /// <param name="vertText">One set of vertices for each Font that is available to this ForattedText.</param>
 /// <param name="vertIcons">A set of icon vertices.</param>
 /// <param name="x">An X-Offset applied to the position of each emitted vertex.</param>
 /// <param name="y">An Y-Offset applied to the position of each emitted vertex.</param>
 /// <param name="z">An Z-Offset applied to the position of each emitted vertex.</param>
 /// <param name="clr">The color value that is applied to each emitted vertex.</param>
 /// <param name="angle">An angle by which the text is rotated (before applying the offset).</param>
 /// <param name="scale">A factor by which the text is scaled (before applying the offset).</param>
 /// <returns>
 /// Returns an array of vertex counts for each emitted vertex array. 
 /// Index 0 represents the number of emitted icon vertices, Index n represents the number of vertices emitted using Font n - 1.
 /// </returns>
 public int[] EmitVertices(ref VertexC1P3T2[][] vertText, ref VertexC1P3T2[] vertIcons, float x, float y, float z, ColorRgba clr, float angle = 0.0f, float scale = 1.0f)
 {
     Vector2 xDot, yDot;
     MathF.GetTransformDotVec(angle, scale, out xDot, out yDot);
     return this.EmitVertices(ref vertText, ref vertIcons, x, y, z, clr, xDot, yDot);
 }
开发者ID:ninja2003,项目名称:duality,代码行数:22,代码来源:FormattedText.cs


示例16: PrepareVerticesLightSmooth

		protected void PrepareVerticesLightSmooth(ref VertexC1P3T4A4A1[] vertices, IDrawDevice device, float curAnimFrameFade, ColorRgba mainClr, Rect uvRect, Rect uvRectNext, DrawTechnique tech)
		{
			bool perPixel = tech is LightingTechnique;

			Vector3 pos = this.GameObj.Transform.Pos;
			Vector3 posTemp = pos;
			float scaleTemp = 1.0f;
			device.PreprocessCoords(ref posTemp, ref scaleTemp);

			Vector2 xDot, yDot;
			float rotation = this.GameObj.Transform.Angle;
			MathF.GetTransformDotVec(rotation, out xDot, out yDot);

			Rect rectTemp = this.rect.Transformed(this.GameObj.Transform.Scale, this.GameObj.Transform.Scale);
			Vector2 edge1 = rectTemp.TopLeft;
			Vector2 edge2 = rectTemp.BottomLeft;
			Vector2 edge3 = rectTemp.BottomRight;
			Vector2 edge4 = rectTemp.TopRight;

			MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
			MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);

			// Using Per-Vertex Lighting? Calculate vertex light values
			Vector4[] vertexLight = null;
			if (!perPixel)
			{
				vertexLight = new Vector4[4];
				Light.GetLightAtWorldPos(pos + new Vector3(edge1), out vertexLight[0], this.vertexTranslucency);
				Light.GetLightAtWorldPos(pos + new Vector3(edge2), out vertexLight[1], this.vertexTranslucency);
				Light.GetLightAtWorldPos(pos + new Vector3(edge3), out vertexLight[2], this.vertexTranslucency);
				Light.GetLightAtWorldPos(pos + new Vector3(edge4), out vertexLight[3], this.vertexTranslucency);
			}

			Vector2.Multiply(ref edge1, scaleTemp, out edge1);
			Vector2.Multiply(ref edge2, scaleTemp, out edge2);
			Vector2.Multiply(ref edge3, scaleTemp, out edge3);
			Vector2.Multiply(ref edge4, scaleTemp, out edge4);

			// Using Per-Pixel Lighting? Pass objRotation Matrix via vertex attribute.
			Vector4 objRotMat = Vector4.Zero;
			if (perPixel)
				objRotMat = new Vector4((float)Math.Cos(-rotation), -(float)Math.Sin(-rotation), (float)Math.Sin(-rotation), (float)Math.Cos(-rotation));

			if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T4A4A1[4];
			
			// Calculate UV coordinates
			float left       = uvRect.X;
			float right      = uvRect.RightX;
			float top        = uvRect.Y;
			float bottom     = uvRect.BottomY;
			float nextLeft   = uvRectNext.X;
			float nextRight  = uvRectNext.RightX;
			float nextTop    = uvRectNext.Y;
			float nextBottom = uvRectNext.BottomY;

			if ((this.flipMode & FlipMode.Horizontal) != FlipMode.None)
			{
				MathF.Swap(ref left, ref right);
				MathF.Swap(ref nextLeft, ref nextRight);
			}
			if ((this.flipMode & FlipMode.Vertical) != FlipMode.None)
			{
				MathF.Swap(ref top, ref bottom);
				MathF.Swap(ref nextTop, ref nextBottom);
			}

			// Directly pass World Position with each vertex, see note in Light.cs
			vertices[0].Pos.X = posTemp.X + edge1.X;
			vertices[0].Pos.Y = posTemp.Y + edge1.Y;
			vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[0].TexCoord.X = left;
			vertices[0].TexCoord.Y = top;
			vertices[0].TexCoord.Z = nextLeft;
			vertices[0].TexCoord.W = nextTop;
			vertices[0].Color = mainClr;
			vertices[0].Attrib = perPixel ? objRotMat : vertexLight[0];
			vertices[0].Attrib2 = curAnimFrameFade;

			vertices[1].Pos.X = posTemp.X + edge2.X;
			vertices[1].Pos.Y = posTemp.Y + edge2.Y;
			vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[1].TexCoord.X = left;
			vertices[1].TexCoord.Y = bottom;
			vertices[1].TexCoord.Z = nextLeft;
			vertices[1].TexCoord.W = nextBottom;
			vertices[1].Color = mainClr;
			vertices[1].Attrib = perPixel ? objRotMat : vertexLight[1];
			vertices[1].Attrib2 = curAnimFrameFade;

			vertices[2].Pos.X = posTemp.X + edge3.X;
			vertices[2].Pos.Y = posTemp.Y + edge3.Y;
			vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
			vertices[2].TexCoord.X = right;
			vertices[2].TexCoord.Y = bottom;
			vertices[2].TexCoord.Z = nextRight;
			vertices[2].TexCoord.W = nextBottom;
			vertices[2].Color = mainClr;
			vertices[2].Attrib = perPixel ? objRotMat : vertexLight[2];
//.........这里部分代码省略.........
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:101,代码来源:LightingAnimSpriteRenderer.cs


示例17: RenderState

            public RenderState(FormattedText parent)
            {
                this.parent = parent;
                this.vertTextIndex = new int[this.parent.fonts != null ? this.parent.fonts.Length : 0];
                this.font = (this.parent.fonts != null && this.parent.fonts.Length > 0) ? this.parent.fonts[0].Res : null;
                this.color = ColorRgba.White;
                this.lineAlign = parent.lineAlign;

                this.PeekLineStats();
                this.offset.X = this.lineBeginX;
            }
开发者ID:ninja2003,项目名称:duality,代码行数:11,代码来源:FormattedText.cs


示例18: DrawTileHighlights

        private static void DrawTileHighlights(Canvas canvas, ICmpTilemapRenderer renderer, Point2 origin, IReadOnlyGrid<bool> highlight, ColorRgba fillTint, ColorRgba outlineTint, TileHighlightMode mode, List<Vector2[]> outlineCache = null)
        {
            if (highlight.Width == 0 || highlight.Height == 0) return;

            // Generate strippled line texture if not available yet
            if (strippledLineTex == null)
            {
                PixelData pixels = new PixelData(8, 1);
                for (int i = 0; i < pixels.Width / 2; i++)
                    pixels[i, 0] = ColorRgba.White;
                for (int i = pixels.Width / 2; i < pixels.Width; i++)
                    pixels[i, 0] = ColorRgba.TransparentWhite;

                using (Pixmap pixmap = new Pixmap(pixels))
                {
                    strippledLineTex = new Texture(pixmap,
                        TextureSizeMode.Default,
                        TextureMagFilter.Nearest,
                        TextureMinFilter.Nearest,
                        TextureWrapMode.Repeat,
                        TextureWrapMode.Repeat,
                        TexturePixelFormat.Rgba);
                }
            }

            BatchInfo defaultMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor);
            BatchInfo strippleMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor, strippledLineTex);
            bool uncertain = (mode & TileHighlightMode.Uncertain) != 0;
            bool selection = (mode & TileHighlightMode.Selection) != 0;

            Component component = renderer as Component;
            Transform transform = component.GameObj.Transform;
            Tilemap tilemap = renderer.ActiveTilemap;
            Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null;
            Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize;
            Rect localRect = renderer.LocalTilemapRect;

            // Determine the object's local coordinate system (rotated, scaled) in world space
            Vector2 worldAxisX = Vector2.UnitX;
            Vector2 worldAxisY = Vector2.UnitY;
            MathF.TransformCoord(ref worldAxisX.X, ref worldAxisX.Y, transform.Angle, transform.Scale);
            MathF.TransformCoord(ref worldAxisY.X, ref worldAxisY.Y, transform.Angle, transform.Scale);

            Vector2 localOriginPos = tileSize * origin;
            Vector2 worldOriginPos = localOriginPos.X * worldAxisX + localOriginPos.Y * worldAxisY;

            canvas.PushState();
            {
                // Configure the canvas so our shapes are properly rotated and scaled
                canvas.State.TransformHandle = -localRect.TopLeft;
                canvas.State.TransformAngle = transform.Angle;
                canvas.State.TransformScale = new Vector2(transform.Scale);

                // Fill all highlighted tiles that are currently visible
                {
                    canvas.State.SetMaterial(defaultMaterial);
                    canvas.State.ColorTint = fillTint * ColorRgba.White.WithAlpha(selection ? 0.2f : 0.375f);

                    // Determine tile visibility
                    Vector2 worldTilemapOriginPos = localRect.TopLeft;
                    MathF.TransformCoord(ref worldTilemapOriginPos.X, ref worldTilemapOriginPos.Y, transform.Angle, transform.Scale);
                    TilemapCulling.TileInput cullingIn = new TilemapCulling.TileInput
                    {
                        // Remember: All these transform values are in world space
                        TilemapPos = transform.Pos + new Vector3(worldTilemapOriginPos) + new Vector3(worldOriginPos),
                        TilemapScale = transform.Scale,
                        TilemapAngle = transform.Angle,
                        TileCount = new Point2(highlight.Width, highlight.Height),
                        TileSize = tileSize
                    };
                    TilemapCulling.TileOutput cullingOut = TilemapCulling.GetVisibleTileRect(canvas.DrawDevice, cullingIn);
                    int renderedTileCount = cullingOut.VisibleTileCount.X * cullingOut.VisibleTileCount.Y;

                    // Draw all visible highlighted tiles
                    {
                        Point2 tileGridPos = cullingOut.VisibleTileStart;
                        Vector2 renderStartPos = worldOriginPos + tileGridPos.X * tileSize.X * worldAxisX + tileGridPos.Y * tileSize.Y * worldAxisY;;
                        Vector2 renderPos = renderStartPos;
                        Vector2 tileXStep = worldAxisX * tileSize.X;
                        Vector2 tileYStep = worldAxisY * tileSize.Y;
                        int lineMergeCount = 0;
                        int totalRects = 0;
                        for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++)
                        {
                            bool current = highlight[tileGridPos.X, tileGridPos.Y];
                            if (current)
                            {
                                // Try to merge consecutive rects in the same line to reduce drawcalls / CPU load
                                bool hasNext = (tileGridPos.X + 1 < highlight.Width) && ((tileGridPos.X + 1 - cullingOut.VisibleTileStart.X) < cullingOut.VisibleTileCount.X);
                                bool next = hasNext ? highlight[tileGridPos.X + 1, tileGridPos.Y] : false;
                                if (next)
                                {
                                    lineMergeCount++;
                                }
                                else
                                {
                                    totalRects++;
                                    canvas.FillRect(
                                        transform.Pos.X + renderPos.X - lineMergeCount * tileXStep.X,
                                        transform.Pos.Y + renderPos.Y - lineMergeCount * tileXStep.Y,
//.........这里部分代码省略.........
开发者ID:SirePi,项目名称:duality,代码行数:101,代码来源:TilemapEditorCamViewState.cs


示例19: PrepareVertices

        protected void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
        {
            Vector3 posTemp = this.gameobj.Transform.Pos;
            float scaleTemp = 1.0f;
            device.PreprocessCoords(ref posTemp, ref scaleTemp);

            Vector2 xDot, yDot;
            MathF.GetTransformDotVec(this.GameObj.Transform.Angle, scaleTemp, out xDot, out yDot);

            Rect rectTemp = this.rect.Transform(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
            Vector2 edge1 = rectTemp.TopLeft;
            Vector2 edge2 = rectTemp.BottomLeft;
            Vector2 edge3 = rectTemp.BottomRight;
            Vector2 edge4 = rectTemp.TopRight;

            MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
            MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);

            if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];

            vertices[0].SetVertex(posTemp.X + edge1.X,
                                    posTemp.Y + edge1.Y,
                                    posTemp.Z + this.VertexZOffset,
                                    uvRect.X, uvRect.Y, mainClr);

            vertices[1].SetVertex(posTemp.X + edge2.X,
                                    posTemp.Y + edge2.Y,
                                    posTemp.Z + this.VertexZOffset,
                                    uvRect.X, uvRect.MaximumY, mainClr);

            vertices[2].SetVertex(posTemp.X + edge3.X,
                                    posTemp.Y + edge3.Y,
                                    posTemp.Z + this.VertexZOffset,
                                    uvRect.MaximumX, uvRect.MaximumY, mainClr);

            vertices[3].SetVertex(posTemp.X + edge4.X,
                                    posTemp.Y + edge4.Y,
                                    posTemp.Z + this.VertexZOffset,
                                    uvRect.MaximumX, uvRect.Y, mainClr);

            if (this.pixelGrid)
            {
                vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
                vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
                vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
                vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);

                if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
                {
                    vertices[0].Pos.X += 0.5f;
                    vertices[1].Pos.X += 0.5f;
                    vertices[2].Pos.X += 0.5f;
                    vertices[3].Pos.X += 0.5f;
                }

                vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
                vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
                vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
                vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);

                if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
                {
                    vertices[0].Pos.Y += 0.5f;
                    vertices[1].Pos.Y += 0.5f;
                    vertices[2].Pos.Y += 0.5f;
                    vertices[3].Pos.Y += 0.5f;
                }
            }
        }
开发者ID:nicstop,项目名称:duality,代码行数:71,代码来源:SpriteRenderer.cs


示例20: PrepareVerticesSmooth

        protected void PrepareVertices 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ColorSetWindow类代码示例发布时间:2022-05-24
下一篇:
C# ColorPicker类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap