public static Point GetLocationOf(this Size size, KnownPoint ofPoint = KnownPoint.TopLeft) { switch (ofPoint) { case KnownPoint.TopLeft: return(Point.Empty); case KnownPoint.TopMiddle: return(new Point(size.Width / 2, 0)); case KnownPoint.TopRight: return(new Point(size.Width, 0)); case KnownPoint.MiddleRight: return(new Point(size.Width, size.Height / 2)); case KnownPoint.BottomRight: return(new Point(size.Width, size.Height)); case KnownPoint.BottomMiddle: return(new Point(size.Width / 2, size.Height)); case KnownPoint.BottomLeft: return(new Point(0, size.Height)); case KnownPoint.MiddleLeft: return(new Point(0, size.Height / 2)); case KnownPoint.Center: return(new Point(size.Width / 2, size.Height / 2)); default: throw new NotImplementedException(); } }
protected override void OnMouseMove(MouseEventArgs e) { if (!isResizing) { currentlyHoveredGrip = handles.FirstOrDefault(x => x.Value.Contains(e.Location)).Key; switch (currentlyHoveredGrip) { case KnownPoint.BottomRight: Cursor = Cursors.SizeNWSE; break; case KnownPoint.MiddleRight: Cursor = Cursors.SizeWE; break; case KnownPoint.TopRight: Cursor = Cursors.SizeNESW; break; case KnownPoint.BottomLeft: Cursor = Cursors.SizeNESW; break; case KnownPoint.MiddleLeft: Cursor = Cursors.SizeWE; break; case KnownPoint.TopLeft: Cursor = Cursors.SizeNWSE; break; case KnownPoint.BottomMiddle: Cursor = Cursors.SizeNS; break; case KnownPoint.TopMiddle: Cursor = Cursors.SizeNS; break; case KnownPoint.Center: Cursor = Cursors.Cross; break; default: Cursor = Cursors.Default; break; } } else { var currentMouseLocation = this.PointToScreen(e.Location); var deltaX = currentMouseLocation.X - mouseMoveStartLocation.X; var deltaY = currentMouseLocation.Y - mouseMoveStartLocation.Y; Rectangle newBoundaries = Target.Bounds.Grow(currentlyHoveredGrip, deltaX, deltaY); mouseMoveStartLocation = currentMouseLocation; Target.SetBounds(newBoundaries.X, newBoundaries.Y, newBoundaries.Width, newBoundaries.Height, BoundsSpecified.All); } }
private void NewKnownpoint_Click(object sender, RoutedEventArgs e) { if (SelectedBattery != null) { KnownPoint k = new KnownPoint(new Coordinate("00", 0), "New Known Point"); SelectedBattery.Knownpoints.Add(k); EKPSelect.SelectedItem = k; } }
private void NewObserver_Click(object sender, RoutedEventArgs e) { if (SelectedBattery != null) { KnownPoint o = new KnownPoint(new Coordinate("00", 0), "New Observer"); SelectedBattery.Observers.Add(o); EObsSelect.SelectedItem = o; } }
public static Rectangle Grow(this Rectangle source, KnownPoint draggedPoint, int dw, int dh) { Size size = source.Size; Point loc = source.Location; switch (draggedPoint) { case KnownPoint.TopLeft: loc = loc.Translate(dw, dh); size = size.Grow(-dw, -dh); break; case KnownPoint.TopMiddle: loc = loc.Translate(0, dh); size = size.Grow(0, -dh); break; case KnownPoint.TopRight: loc = loc.Translate(0, dh); size = size.Grow(dw, -dh); break; case KnownPoint.MiddleRight: // no need to change location => loc = loc.Translate(0, 0); size = size.Grow(dw, 0); break; case KnownPoint.BottomRight: // no need to change location => loc = loc.Translate(0, 0); size = size.Grow(dw, dh); break; case KnownPoint.BottomMiddle: // no need to change location => loc = loc.Translate(0, 0); size = size.Grow(0, dh); break; case KnownPoint.BottomLeft: loc = loc.Translate(dw, 0); size = size.Grow(-dw, dh); break; case KnownPoint.MiddleLeft: loc = loc.Translate(dw, 0); size = size.Grow(-dw, 0); break; case KnownPoint.Center: loc = loc.Translate(dw / 2, dh / 2); size = size.Grow(dw, dh); break; } return(new Rectangle(loc, size)); }
private void AdjustRecord_Click(object sender, RoutedEventArgs e) { MissionGridSpec mission = new MissionGridSpec(SelectedBattery); SelectedBattery.CurrentMission.CopyTo(mission); mission.TargetNumber = mission.TargetNumber + " Recorded"; mission.Grid = SelectedBattery.CurrentMission.AdjustedCoords; mission.Adjustment = Coordinate.Zero; SelectedBattery.Missions.Add(mission); KnownPoint p = new KnownPoint(mission.Grid, mission.TargetNumber); SelectedBattery.Knownpoints.Add(p); }
public static void MakeLocationRelativeTo(this Control ctrl, Control target, int dx, int dy, KnownPoint fromPoint = KnownPoint.TopLeft) { ctrl.Location = target.Bounds.GetLocationOf(fromPoint).Translate(dx, dy); target.LocationChanged += (s, a) => { ctrl.Location = target.Bounds.GetLocationOf(fromPoint).Translate(dx, dy); }; target.SizeChanged += (s, a) => { ctrl.Location = target.Bounds.GetLocationOf(fromPoint).Translate(dx, dy); }; }
public static Point GetLocationOf(this Rectangle rectangle, KnownPoint ofPoint = KnownPoint.TopLeft) { return(rectangle.Size.GetLocationOf(ofPoint).Translate(rectangle.X, rectangle.Y)); }
public static Rectangle Grow(this Rectangle source, KnownPoint draggedPoint, Point deltaSize) { return(Grow(source, draggedPoint, deltaSize.X, deltaSize.Y)); }