private void LayoutFromScreen(ScreenDrawingSurface surface, Point location)
{
surface.Location = location;
surface.Placed = true;
var myJoins = stage.Joins.Where(j => j.screenOne == surface.Screen.Name || j.screenTwo == surface.Screen.Name);
var joinedScreens = surfaces.Values.Where(s => myJoins.Any(j => j.screenOne == s.Screen.Name || j.screenTwo == s.Screen.Name));
var placed = surfaces.Values.Where(s => s.Placed && s != surface && !joinedScreens.Contains(s));
var collision = SurfaceCollides(placed, surface);
while (collision != Rectangle.Empty)
{
TryToFixCollision(surface, collision);
collision = SurfaceCollides(placed, surface);
}
foreach (var join in stage.Joins.Where(j => j.screenOne == surface.Screen.Name))
{
var nextScreen = surfaces[join.screenTwo];
if (nextScreen.Placed) continue;
LayoutNextScreen(nextScreen, surface.Location, join, true);
}
foreach (var join in stage.Joins.Where(j => j.screenTwo == surface.Screen.Name))
{
var nextScreen = surfaces[join.screenOne];
if (nextScreen.Placed) continue;
LayoutNextScreen(nextScreen, surface.Location, join, false);
}
}