/// <summary> /// When the mouse is hovering over the box, do collision tests against the handles and change the cursor if needed. /// </summary> /// <param name="viewport">The viewport</param> /// <param name="e">The mouse event</param> protected override void MouseHoverWhenDrawn(Viewport2D viewport, ViewportEvent e) { if (_currentTool == null) { base.MouseHoverWhenDrawn(viewport, e); return; } var padding = 7 / viewport.Zoom; viewport.Cursor = Cursors.Default; State.Action = BoxAction.Drawn; State.ActiveViewport = null; var now = viewport.ScreenToWorld(e.X, viewport.Height - e.Y); var start = viewport.Flatten(State.BoxStart); var end = viewport.Flatten(State.BoxEnd); var ccs = new Coordinate(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), 0); var cce = new Coordinate(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), 0); // Check center handle if (now.X > ccs.X && now.X < cce.X && now.Y > ccs.Y && now.Y < cce.Y) { State.Handle = ResizeHandle.Center; State.ActiveViewport = viewport; State.Action = BoxAction.ReadyToResize; viewport.Cursor = CursorForHandle(State.Handle); return; } // Check other handles foreach (var handle in _currentTool.GetHandles(start, end, viewport.Zoom).Where(x => _currentTool.FilterHandle(x.Item1))) { var x = handle.Item2; var y = handle.Item3; if (now.X < x - padding || now.X > x + padding || now.Y < y - padding || now.Y > y + padding) { continue; } State.Handle = handle.Item1; State.ActiveViewport = viewport; State.Action = BoxAction.ReadyToResize; viewport.Cursor = CursorForHandle(State.Handle); return; } }
private void RenderHandles(Viewport2D viewport, Coordinate start, Coordinate end) { if (_currentTool == null) { return; } var circles = _currentTool.RenderCircleHandles; // Get the filtered list of handles, and convert them to vector locations var z = (double)viewport.Zoom; var handles = _currentTool.GetHandles(start, end, viewport.Zoom) .Where(x => _currentTool.FilterHandle(x.Item1)) .Select(x => new Vector2d((double)x.Item2, (double)x.Item3)) .ToList(); // Draw the insides of the handles in white GL.Color3(Color.White); foreach (var handle in handles) { GL.Begin(BeginMode.Polygon); if (circles) { GLX.Circle(handle, 4, z, loop: true); } else { GLX.Square(handle, 4, z, true); } GL.End(); } // Draw the borders of the handles in black GL.Color3(Color.Black); GL.Begin(BeginMode.Lines); foreach (var handle in handles) { if (circles) { GLX.Circle(handle, 4, z); } else { GLX.Square(handle, 4, z); } } GL.End(); }