Beispiel #1
0
        /// <summary>
        /// Draw all the available labels onto the screen (drawArea).
        /// </summary>
        /// <param name="drawArea">The area we are drawing on</param>
        public void Draw(DrawArea drawArea)
        {
            this.drawArea = drawArea;
            if (!Properties.Settings.Default.showLabels)
            {
                return;
            }
            float closestDistanceSquared = float.MaxValue;

            foreach (StorableLabel label in labels.Labels)
            {
                if (!dragging || !label.Equals(draggingLabelToReplace))
                {
                    DrawLabel(label);
                }
                float distanceSquared = CloseToMouse.GetGroundDistanceSquared(label.WorldLocation, drawArea.MouseLocation);
                if (distanceSquared < closestDistanceSquared)
                {
                    closestDistanceSquared = distanceSquared;
                    closestToMouseLabel    = label;
                }
            }

            if (dragging)
            {
                DrawLabel(draggingLabel);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Find the node in the path that is closest to the mouse,
        /// </summary>
        /// <param name="drawArea">Area that is being drawn upon and where we have a mouse location</param>
        /// <param name="drawnPathData">The data structure with the information on the drawn path</param>
        void FindActiveNode(DrawArea drawArea, DrawnPathData drawnPathData)
        {
            // Initial simplest implementation: find simply the closest and first.
            float         closestMouseDistanceSquared = float.MaxValue;
            TrainpathNode closestNode = null;

            foreach (TrainpathNode node in drawnPathData.DrawnNodes)
            {
                float distanceSquared = CloseToMouse.GetGroundDistanceSquared(node.Location, drawArea.MouseLocation);
                // by using '<=' instead of '<' we should get the latest one, which overrides earlier ones
                if (distanceSquared <= closestMouseDistanceSquared)
                {
                    closestMouseDistanceSquared = distanceSquared;
                    closestNode = node;
                }
            }

            activeNode = closestNode;
        }
Beispiel #3
0
        /// <summary>
        /// Find the node in the path that is closest to the mouse,
        /// </summary>
        /// <param name="drawArea">Area that is being drawn upon and where we have a mouse location</param>
        /// <param name="drawnPathData">The data structure with the information on the drawn path</param>
        void FindActiveNode(DrawArea drawArea, DrawnPathData drawnPathData)
        {
            // Initial simplest implementation: find simply the closest and first.
            float         closestMouseDistanceSquared = float.MaxValue;
            TrainpathNode closestNode = null;

            foreach (TrainpathNode node in drawnPathData.DrawnNodes)
            {
                float distanceSquared = CloseToMouse.GetGroundDistanceSquared(node.Location, drawArea.MouseLocation);
                // by using '<=' instead of '<' we should get the latest one, which overrides earlier ones
                // To prevent numerical issues, we add a small number (smaller than two junctions would normally be together
                if (distanceSquared <= closestMouseDistanceSquared + 0.1f)
                {
                    closestMouseDistanceSquared = distanceSquared;
                    closestNode = node;
                }
            }

            activeNode = closestNode;
        }