public override void LeftButtonEndDrag(Pane pane, PointF location, PointF locationStart, float pixelSize, ref bool displayUpdateNeeded) { Debug.Assert(pane == Pane.Map); float deltaX = (location.X - startDrag.X); float deltaY = (location.Y - startDrag.Y); PointF newHandleLocation = new PointF(handleLocation.X + deltaX, handleLocation.Y + deltaY); if (courseObjectStart.specialId.IsNotNone) { // Moving a corner of a special Id <Special> specialId = courseObjectStart.specialId; if (courseObjectStart is DescriptionCourseObj) { // Moving a description. Descriptions are rather special in the way their locations are used. DescriptionCourseObj descObj = (DescriptionCourseObj)courseObjectStart.Clone(); descObj.MoveHandle(handleLocation, location); controller.MoveSpecial(specialId, new PointF[2] { new PointF(descObj.rect.Left, descObj.rect.Bottom), new PointF(descObj.rect.Left + descObj.CellSize, descObj.rect.Bottom) }, descObj.NumberOfColumns); } else if (courseObjectStart is RectCourseObj) { // Moving rectangle handles is sort of special too. RectCourseObj rectObj = (RectCourseObj)courseObjectStart.Clone(); rectObj.MoveHandle(handleLocation, location); RectangleF rect = rectObj.rect; controller.MoveSpecial(specialId, new PointF[2] { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top) }); } else if (courseObjectStart is BasicTextCourseObj) { // Moving text handles is sort of special too. BasicTextCourseObj textObj = (BasicTextCourseObj)courseObjectStart.Clone(); textObj.MoveHandle(handleLocation, location); RectangleF rect = textObj.GetHighlightBounds(); rect = textObj.AdjustBoundingRect(rect); controller.MoveSpecial(specialId, new PointF[2] { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top) }); } else { controller.MoveSpecialPoint(specialId, handleLocation, newHandleLocation); } } else if ((courseObjectStart is LegCourseObj) || (courseObjectStart is FlaggedLegCourseObj)) { // Moving a leg bend. LineCourseObj lineCourseObj = (LineCourseObj)courseObjectStart; controller.MoveLegBendOrGap(lineCourseObj.courseControlId, lineCourseObj.courseControlId2, handleLocation, newHandleLocation); } else if ((courseObjectStart is ControlCourseObj) || (courseObjectStart is FinishCourseObj)) { PointCourseObj pointObj = (PointCourseObj)courseObjectStart.Clone(); pointObj.MoveHandle(handleLocation, location); controller.MoveControlGap(courseObjectStart.controlId, pointObj.movableGaps); } else { Debug.Fail("unknown situation"); } controller.DefaultCommandMode(); }
// Update currentObj to reflect dragging to the given location. void DragTo(PointF location) { currentObj = (RectCourseObj)startingObj.Clone(); currentObj.MoveHandle(handleDragging, location); }
// Move a description handle and make sure the description ends up in the right place. void MoveRectangleHandle(RectCourseObj courseObj, PointF initialHandle, PointF finalHandle, RectangleF finalRect) { courseObj.MoveHandle(initialHandle, finalHandle); RectangleF result = courseObj.rect; Assert.AreEqual(finalRect.Left, result.Left, 0.001F); Assert.AreEqual(finalRect.Right, result.Right, 0.001F); Assert.AreEqual(finalRect.Top, result.Top, 0.001F); Assert.AreEqual(finalRect.Bottom, result.Bottom, 0.001F); }