本文整理汇总了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;
}
示例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;
}