private void MoveOverlapped(IEditor editor, List <IEditor> moved) { moved.Add(editor); var bounds = editor.Figure.Bounds; foreach (var edi in Host.Root.Content.GetChildrenByPosition()) { if (moved.Contains(edi)) { continue; } if (!(edi.Model is MemoText || edi.Model is MemoImage || edi.Model is MemoTable || edi.Model is MemoFile)) { continue; } var ediBounds = edi.Figure.Bounds; if ( (ediBounds.Left > bounds.Left || ediBounds.Top > bounds.Top) && ediBounds.IntersectsWith(bounds) ) { var needMoveLower = false; var needMoveRight = false; if (bounds.Contains(ediBounds)) { var center = RectUtil.GetCenter(bounds); var ediCenter = RectUtil.GetCenter(ediBounds); var dir = PointUtil.GetDirectionStraightly(center, ediCenter); if (EnumUtil.HasAnyFlags((int)dir, (int)(Directions.Left | Directions.Down))) { needMoveLower = true; } else { needMoveRight = true; } } else if (ediBounds.Left <= bounds.Left) { needMoveLower = true; } else if (ediBounds.Top <= bounds.Top) { needMoveRight = true; } else { var intersect = Rectangle.Intersect(bounds, ediBounds); if (intersect.Width == ediBounds.Width) { /// LeftもRightもbounds内 needMoveLower = true; } else if (intersect.Height == ediBounds.Height) { /// TopもBottomもbounds内 needMoveRight = true; } else if (intersect.Width >= intersect.Height) { needMoveLower = true; } else { needMoveRight = true; } } if (needMoveLower) { var newTop = bounds.Bottom + MemopadConsts.DefaultElementSpace; edi.RequestMove(new Size(0, newTop - ediBounds.Top)); MoveOverlapped(edi, moved); } else if (needMoveRight) { var newLeft = bounds.Right + MemopadConsts.DefaultElementSpace; edi.RequestMove(new Size(newLeft - ediBounds.Left, 0)); MoveOverlapped(edi, moved); } } } }