public void Refresh(int width, int height, IEnumerable<Join> joins, IDictionary<string, ScreenDrawingSurface> surfaces)
{
if (image == null || image.Height != height || image.Width != width)
{
if (image != null) image.Dispose();
image = new Bitmap(width, height);
}
using (Graphics g = Graphics.FromImage(image))
{
g.Clear(Color.Transparent);
foreach (Join join in joins)
{
if (surfaces.ContainsKey(join.screenOne) && surfaces.ContainsKey(join.screenTwo))
{
int mid = join.Size * 8; // the 8 is from tilesize (16) / 2 for midpoint
int midOffsetOne = join.offsetOne * 16 + mid;
int midOffsetTwo = join.offsetTwo * 16 + mid;
if (join.type == JoinType.Horizontal)
{
if (surfaces[join.screenOne].Bottom != surfaces[join.screenTwo].Top)
{
int y1 = surfaces[join.screenOne].Left + midOffsetOne;
int y2 = surfaces[join.screenTwo].Left + midOffsetTwo;
int x1 = surfaces[join.screenOne].Bottom;
int x2 = surfaces[join.screenTwo].Top;
DrawJoinPath(g, x1, x2, y1, y2, true);
}
}
else
{
if (surfaces[join.screenOne].Right != surfaces[join.screenTwo].Left)
{
int x1 = surfaces[join.screenOne].Right;
int x2 = surfaces[join.screenTwo].Left;
int y1 = surfaces[join.screenOne].Top + midOffsetOne;
int y2 = surfaces[join.screenTwo].Top + midOffsetTwo;
DrawJoinPath(g, x1, x2, y1, y2, false);
}
}
}
}
}
Invalidate();
}