当前位置: 首页>>代码示例>>C#>>正文


C# IShape.Contains方法代码示例

本文整理汇总了C#中IShape.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# IShape.Contains方法的具体用法?C# IShape.Contains怎么用?C# IShape.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShape的用法示例。


在下文中一共展示了IShape.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: createTexture

        private static Texture2D createTexture(GraphicsDevice device, IShape shape)
        {
            //Create color array that contains the texture data:
            Color[] colorArr = new Color[shape.Bounds.Width * shape.Bounds.Height];

            for (int x = 0; x < shape.Bounds.Width; x++)
            {
                for (int y = 0; y < shape.Bounds.Height; y++)
                {
                    int index = y * shape.Bounds.Width + x;

                    //If the point is on the shape, set the color to white.
                    if (shape.Contains(x + shape.Bounds.X, y + shape.Bounds.Y))
                        colorArr[index] = Color.White;
                    else
                        colorArr[index] = Color.Transparent;
                }
            }

            //Create and fill the texture:
            Texture2D texture = new Texture2D(device, shape.Bounds.Width, shape.Bounds.Height);
            texture.SetData(colorArr);
            return texture;
        }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:24,代码来源:ShapeTextureProvider.cs

示例2: createTexture

        private static Texture2D createTexture(GraphicsDevice device, Gradient gradient, IShape shape)
        {
            //Set the size along which the gradient gets drawn:
            int uSize = shape.Bounds.Height;
            if (gradient.Horizontal)
                uSize = shape.Bounds.Width;

            double diffR, diffG, diffB, diffA;

            var fromColor = gradient.FromColor;
            var toColor = gradient.ToColor;

            //Calculate from and to color differences:
            diffR = (int)toColor.R - (int)fromColor.R;
            diffG = (int)toColor.G - (int)fromColor.G;
            diffB = (int)toColor.B - (int)fromColor.B;
            diffA = (int)toColor.A - (int)fromColor.A;

            //Set the steps of colors used. If the steps in the gradient config is smaller than 0, as many steps as possible are used.
            double stepCount = gradient.Steps;
            if (stepCount < 0)
                stepCount = uSize;

            float stepSize = (float)Math.Ceiling((float)(uSize / stepCount));

            Color[] colorArr = new Color[shape.Bounds.Width * shape.Bounds.Height];

            int cR, cG, cB, cA;

            int length = (int)Math.Ceiling(stepSize);
            for (int cStep = 1; cStep <= stepCount; cStep++)
            {
                //Get the color for the current frame.
                cR = (int)(((diffR / stepCount) * cStep) + (int)fromColor.R);
                cG = (int)(((diffG / stepCount) * cStep) + (int)fromColor.G);
                cB = (int)(((diffB / stepCount) * cStep) + (int)fromColor.B);
                cA = (int)(((diffA / stepCount) * cStep) + (int)fromColor.A);

                //If the color overflows, it was calculated from the wrong side, ie black to white instead of white to black.
                if (cR < 0)
                    cR += 255;
                if (cG < 0)
                    cG += 255;
                if (cB < 0)
                    cB += 255;
                if (cA < 0)
                    cA += 255;

                Color c = new Color(cR, cG, cB, cA);
                int start = (int)((cStep - 1) * stepSize);

                if (gradient.Horizontal)
                {

                    for (int x = start; x < start + length; x++)
                    {
                        for (int y = 0; y < shape.Bounds.Height; y++)
                        {
                            int i = x + y * shape.Bounds.Width;
                            if (shape.Contains(x + shape.Location.X, y + shape.Location.Y))
                            {
                                colorArr[i] = c;
                            }
                            else
                            {
                                colorArr[i] = Color.Transparent;
                            }
                        }
                    }
                }
                else
                {
                    for (int y = start; y < start + length; y++)
                    {
                        for (int x = 0; x < shape.Bounds.Width; x++)
                        {
                            int i = x + y * shape.Bounds.Width;
                            if (shape.Contains(x + shape.Location.X, y + shape.Location.Y))
                            {
                                colorArr[i] = c;
                            }
                            else
                            {
                                colorArr[i] = Color.Transparent;
                            }
                        }
                    }
                }
            }

            //Create and fill texture:
            Texture2D texture = new Texture2D(device, shape.Bounds.Width, shape.Bounds.Height);
            texture.SetData(colorArr);
            return texture;
        }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:95,代码来源:GradientTextureProvider.cs


注:本文中的IShape.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。