protected void HatchPercentage(CGContext context)
{
var hatchWidth = getHatchWidth (hatchStyle);
var hatchHeight = getHatchHeight (hatchStyle);
var lineWidth = getLineWidth (hatchStyle);
initializeContext(context, hatchHeight, false);
/* some patterns require us to reverse the colors */
switch (hatchStyle) {
case HatchStyle.Percent05:
case HatchStyle.Percent10:
case HatchStyle.Percent20:
case HatchStyle.Percent25:
case HatchStyle.Percent30:
drawBackground (context, backColor, hatchWidth, hatchWidth);
context.SetFillColor(foreColor.ToCGColor());
break;
default:
drawBackground (context, foreColor, hatchWidth, hatchWidth);
context.SetFillColor(backColor.ToCGColor());
break;
}
// create a work rectangle for setting pixels
CGRect rect = new CGRect (0,0,1,1);
// Only set the pixels for some
if (hatchStyle != HatchStyle.Percent50 &&
hatchStyle != HatchStyle.Percent40 &&
hatchStyle != HatchStyle.Percent30 &&
hatchStyle != HatchStyle.Percent60)
{
rect.X = 0;
rect.Y = (int)(hatchHeight / 2.0f);
setPixels(context, rect);
rect.X = (int)(hatchWidth / 2.0f);
rect.Y = 0;
setPixels(context, rect);
}
// 50 and 40 start out the same with a 50 percent
if (hatchStyle == HatchStyle.Percent50 ||
hatchStyle == HatchStyle.Percent40 )
{
int x = 0;
int y = 0;
for (y = 0; y<hatchHeight; y+=2)
{
for (x = 1; x < hatchWidth; x+=2)
{
rect.X = x;
rect.Y = y;
setPixels(context, rect);
}
}
for (y = 1; y<hatchHeight; y+=2)
{
for (x = 0; x < hatchWidth; x+=2)
{
rect.X = x;
rect.Y = y;
setPixels(context, rect);
}
}
// Percent40 is a 50 with two more dots set of back color
// within a set area. This creates an interesting effect
// of a double plus sign in opposite corners.
if (hatchStyle == HatchStyle.Percent40)
{
rect.X = 1;
rect.Y = 1;
setPixels(context, rect);
rect.X = 5;
rect.Y = 5;
setPixels(context, rect);
}
}
// Percent30 and Percent60 are really messed up so we will just set some dots
// to present the pattern. Percent60 is a 30 with colors reversed, go figure.
if (hatchStyle == HatchStyle.Percent30 ||
hatchStyle == HatchStyle.Percent60)
{
rect.X = 0;
rect.Y = 0;
setPixels(context, rect);
rect.X = 2;
rect.Y = 0;
setPixels(context, rect);
rect.X = 0;
rect.Y = 2;
setPixels(context, rect);
rect.X = 2;
rect.Y = 2;
setPixels(context, rect);
rect.X = 1;
rect.Y = 3;
setPixels(context, rect);
rect.X = 3;
rect.Y = 1;
setPixels(context, rect);
}
}