private Box GetRectangle(ICamera camera) { var start = camera.Flatten(BoxState.Start); var end = camera.Flatten(BoxState.End); var box = new Box(start, end); var wid = Math.Min(box.Width / 10, camera.PixelsToUnits(20)); var len = Math.Min(box.Length / 10, camera.PixelsToUnits(20)); switch (Handle) { case ResizeHandle.TopLeft: return(new Box(new Vector3(start.X, end.Y - len, 0), new Vector3(start.X + wid, end.Y, 0))); case ResizeHandle.Top: return(new Box(new Vector3(start.X, end.Y - len, 0), end)); case ResizeHandle.TopRight: return(new Box(new Vector3(end.X - wid, end.Y - len, 0), new Vector3(end.X, end.Y, 0))); case ResizeHandle.Left: return(new Box(start, new Vector3(start.X + wid, end.Y, 0))); case ResizeHandle.Center: return(box); case ResizeHandle.Right: return(new Box(new Vector3(end.X - wid, start.Y, 0), end)); case ResizeHandle.BottomLeft: return(new Box(new Vector3(start.X, start.Y, 0), new Vector3(start.X + wid, start.Y + len, 0))); case ResizeHandle.Bottom: return(new Box(start, new Vector3(end.X, start.Y + len, 0))); case ResizeHandle.BottomRight: return(new Box(new Vector3(end.X - wid, start.Y, 0), new Vector3(end.X, start.Y + len, 0))); default: throw new ArgumentOutOfRangeException(); } }
private Vector3 GetOriginForTransform(ICamera camera, BoxState state) { float x = 0; float y = 0; var cstart = camera.Flatten(state.OrigStart); var cend = camera.Flatten(state.OrigEnd); switch (Handle) { case ResizeHandle.TopLeft: case ResizeHandle.Top: case ResizeHandle.TopRight: case ResizeHandle.Left: case ResizeHandle.Right: y = cstart.Y; break; case ResizeHandle.BottomLeft: case ResizeHandle.Bottom: case ResizeHandle.BottomRight: y = cend.Y; break; } switch (Handle) { case ResizeHandle.Top: case ResizeHandle.TopRight: case ResizeHandle.Right: case ResizeHandle.BottomRight: case ResizeHandle.Bottom: x = cstart.X; break; case ResizeHandle.TopLeft: case ResizeHandle.Left: case ResizeHandle.BottomLeft: x = cend.X; break; } return(camera.Expand(new Vector3(x, y, 0))); }
protected (Vector3, Vector3) GetWorldPositionAndScreenOffset(ICamera camera) { const int distance = 6; var start = camera.Flatten(BoxState.Start); var end = camera.Flatten(BoxState.End); var mid = (start + end) / 2; Vector3 center; Vector3 offset; switch (Handle) { case ResizeHandle.TopLeft: center = new Vector3(start.X, end.Y, 0); offset = new Vector3(-distance, -distance, 0); break; case ResizeHandle.Top: center = new Vector3(mid.X, end.Y, 0); offset = new Vector3(0, -distance, 0); break; case ResizeHandle.TopRight: center = new Vector3(end.X, end.Y, 0); offset = new Vector3(distance, -distance, 0); break; case ResizeHandle.Left: center = new Vector3(start.X, mid.Y, 0); offset = new Vector3(-distance, 0, 0); break; case ResizeHandle.Center: center = mid; offset = Vector3.Zero; break; case ResizeHandle.Right: center = new Vector3(end.X, mid.Y, 0); offset = new Vector3(distance, 0, 0); break; case ResizeHandle.BottomLeft: center = new Vector3(start.X, start.Y, 0); offset = new Vector3(-distance, distance, 0); break; case ResizeHandle.Bottom: center = new Vector3(mid.X, start.Y, 0); offset = new Vector3(0, distance, 0); break; case ResizeHandle.BottomRight: center = new Vector3(end.X, start.Y, 0); offset = new Vector3(distance, distance, 0); break; default: throw new ArgumentOutOfRangeException(); } return(camera.Expand(center), offset); }