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


C# Shape.Contains方法代码示例

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


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

示例1: CreateTexture

        private Texture2D CreateTexture(Shape shape, Color fromColor, Color toColor, bool vertical)
        {
            var bounds = shape.Bounds;
            Color[] colorArr = new Color[bounds.Width * bounds.Height];
            int index = 0;
            float step = 0f;

            int diffR = toColor.R - fromColor.R;
            int diffG = toColor.G - fromColor.G;
            int diffB = toColor.B - fromColor.B;
            int diffA = toColor.A - fromColor.A;

            if (vertical)
            {
                for (int x = 0; x < bounds.Width; x++)
                {
                    step = x / (float)bounds.Width;
                    Color stepColor = new Color((int)(fromColor.R + diffR * step), (int)(fromColor.G + diffG * step), (int)(fromColor.B + diffB * step));

                    for (int y = 0; y < bounds.Height; y++)
                    {
                        index = y * bounds.Width + x;
                        if (shape.Contains(x + bounds.X, y + bounds.Y))
                        {
                            colorArr[index] = stepColor;
                        }
                        else
                            colorArr[index] = Color.Transparent;
                    }
                }
            }
            else // horizontal
            {
                for (int y = 0; y < bounds.Height; y++)
                {
                    step = y / (float)bounds.Height;
                    Color stepColor = new Color((int)(fromColor.R + diffR * step), (int)(fromColor.G + diffG * step), (int)(fromColor.B + diffB * step));

                    for (int x = 0; x < bounds.Width; x++)
                    {
                        index = y * bounds.Width + x;
                        if (shape.Contains(x + bounds.X, y + bounds.Y))
                        {
                            colorArr[index] = stepColor;
                        }
                        else
                            colorArr[index] = Color.Transparent;
                    }
                }
            }
            
            Texture2D texture = new Texture2D(_renderer.GraphicsDevice, bounds.Width, bounds.Height);
            texture.SetData(colorArr);
            return texture;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:55,代码来源:GradientShapeTextureProvider.cs

示例2: CreateTexture

        private Texture2D CreateTexture(Shape shape, object[] textureData)
        {
            // ignore any texture data.

            var bounds = shape.Bounds;
            Color[] colorArr = new Color[bounds.Width * bounds.Height];
            int index = 0;

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

                    if (shape.Contains(x + bounds.X, y + bounds.Y))
                        colorArr[index] = Color.White;
                    else
                        colorArr[index] = Color.Transparent;
                }
            }

            Texture2D texture = new Texture2D(_renderer.GraphicsDevice, bounds.Width, bounds.Height);
            texture.SetData(colorArr);
            return texture;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:25,代码来源:SingleColorShapeTextureProvider.cs


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