public override MapViewer.DragAction LeftButtonDown(Pane pane, PointF location, float pixelSize, ref bool displayUpdateNeeded)
        {
            if (pane != Pane.Map)
            {
                return(MapViewer.DragAction.None);
            }

            // Begin dragging out the description block; start at 1 column
            startLocation  = location;
            startingObj    = new DescriptionCourseObj(Id <Special> .None, startLocation, 1F, symbolDB, description, kind, false, 1);
            handleDragging = new PointF(startingObj.rect.Right, startingObj.rect.Top);
            DragTo(location);
            displayUpdateNeeded = true;
            return(MapViewer.DragAction.ImmediateDrag);
        }
Exemple #2
0
        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 = (DescriptionCourseObj)startingObj.Clone();
     currentObj.MoveHandle(handleDragging, location);
 }
        public void DescriptionEquals()
        {
            SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml"));
            UndoMgr undomgr = new UndoMgr(5);
            EventDB eventDB = new EventDB(undomgr);
            eventDB.Load(TestUtil.GetTestFile("coursesymbols\\sampleevent1.coursescribe"));
            eventDB.Validate();
            CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3)));
            DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB);
            DescriptionLine[] description = descFormatter.CreateDescription(false);

            CourseObj courseobj1 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);
            description = descFormatter.CreateDescription(false);
            CourseObj courseobj2 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);
            CourseObj courseobj3 = (CourseObj) courseobj1.Clone();
            CourseObj courseobj4 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 3), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);
            CourseObj courseobj5 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 1.0F, symbolDB, description, DescriptionKind.Symbols, 1);
            CourseObj courseobj6 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Text, 1);

            undomgr.BeginCommand(12, "move control");
            ChangeEvent.ChangeControlLocation(eventDB, ControlId(11), new PointF(4, 8));
            undomgr.EndCommand(12);
            description = descFormatter.CreateDescription(false);
            CourseObj courseobj7 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);

            undomgr.BeginCommand(13, "change description");
            ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.4");
            undomgr.EndCommand(13);

            description = descFormatter.CreateDescription(false);
            CourseObj courseobj8 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);

            undomgr.BeginCommand(13, "change description");  // change description back
            ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.2");
            undomgr.EndCommand(13);

            description = descFormatter.CreateDescription(false);
            CourseObj courseobj9 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1);
            CourseObj courseobj10 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 2);

            Assert.AreEqual(courseobj1, courseobj2);
            Assert.AreEqual(courseobj1, courseobj3);
            Assert.AreNotEqual(courseobj1, courseobj4);
            Assert.AreNotEqual(courseobj1, courseobj5);
            Assert.AreNotEqual(courseobj1, courseobj6);
            Assert.AreEqual(courseobj1, courseobj7);
            Assert.AreNotEqual(courseobj1, courseobj8);
            Assert.AreEqual(courseobj1, courseobj9);
            Assert.AreNotEqual(courseobj9, courseobj10);
        }