Example #1
0
        private Rectangle worldToScreen(WorldRectangle rectangle)
        {
            int x1 = worldToScreenX(rectangle.Left);
            int y1 = worldToScreenY(rectangle.Top);
            int x2 = worldToScreenX(rectangle.Right);
            int y2 = worldToScreenY(rectangle.Bottom);

            return(new Rectangle(x1, y1, x2 - x1, y2 - y1));
        }
Example #2
0
 public override void Draw(MooseGame mooseGame, GameTime gameTime, SpriteBatch spriteBatch)
 {
     base.Draw(mooseGame, gameTime, spriteBatch);
     if (NextMove != "" && !CurrentlyBlockingInput)
     {
         spriteBatch.Draw(game.ArrowTexture, WorldRectangle.Move(AnimationPosition.X + 8, AnimationPosition.Y + 8).ToRectangle(), null, Color.White,
                          CalculateRotation(NextMove), new(8, 8), SpriteEffects.None, 1f);
     }
 }
Example #3
0
        private void DrawLine(Graphics g, Pen pen, WorldPoint p1, WorldPoint p2)
        {
            double dx = p2.X - p1.X;
            double dy = p2.Y - p1.Y;

            WorldRectangle.TrimLineSegment(p1, p2, viewBounds);
            int screenX1 = worldToScreenX(p1.X);
            int screenY1 = worldToScreenY(p1.Y);
            int screenX2 = worldToScreenX(p2.X);
            int screenY2 = worldToScreenY(p2.Y);

            g.DrawLine(pen, screenX1, screenY1, screenX2, screenY2);
        }
Example #4
0
        //Returns the index of the closest point or line segment along with the distance
        public int Grab(double x, double y, double range, out double distance, out bool fromLine)
        {
            if (minX - range <= x && maxX + range >= x &&
                minY - range <= y && maxY + range >= y)
            {
                double closestPointDistance = range;

                int closestPointIndex = -1;

                WorldRectangle rect = new WorldRectangle(x - range, y - range, range * 2, range * 2);
                for (int i = 0; i < points.Count; i++)
                {
                    WorldPoint point = points[i];

                    if (rect.Contains(point))
                    {
                        double dx            = x - point.X;
                        double dy            = y - point.Y;
                        double pointDistance = Math.Sqrt(dx * dx + dy * dy);
                        if (pointDistance < closestPointDistance)
                        {
                            closestPointDistance = pointDistance;
                            closestPointIndex    = i;
                        }
                    }
                }
                if (closestPointIndex != -1)
                {
                    distance = closestPointDistance;
                    fromLine = false;
                    return(closestPointIndex);
                }
                else
                {
                    double closestLineDistance = range;
                    int    closestLineIndex    = -1;
                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        WorldPoint point1 = points[i];
                        WorldPoint point2 = points[i + 1];

                        WorldPoint closest;
                        double     lineDistance = FindDistanceToSegment(new WorldPoint(x, y), point1, point2, out closest);

                        if (lineDistance < closestLineDistance)
                        {
                            closestLineDistance = lineDistance;
                            closestLineIndex    = i;
                        }
                    }
                    if (IsConnected && Count >= 3)
                    {
                        WorldPoint point1 = points[0];
                        WorldPoint point2 = points[Count - 1];

                        WorldPoint closest;
                        double     lineDistance = FindDistanceToSegment(new WorldPoint(x, y), point1, point2, out closest);

                        if (lineDistance < closestLineDistance)
                        {
                            closestLineDistance = lineDistance;
                            closestLineIndex    = Count - 1;
                        }
                    }

                    if (closestLineIndex != -1)
                    {
                        distance = closestLineDistance;
                        fromLine = true;
                        return(closestLineIndex);
                    }
                }
            }
            distance = 0;
            fromLine = false;
            return(-1);
        }
Example #5
0
 public override void Draw(MooseGame game, GameTime gameTime, SpriteBatch spriteBatch)
 => spriteBatch.Draw(TextureGameObjectDef.Texture,
                     WorldRectangle.Move(Origin).ToRectangle(),
                     TextureGameObjectDef.SourceRectangle,
                     Color, Rotation, Origin, SpriteEffects, LayerDepth);
Example #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (World != null)
            {
                viewBounds = new WorldRectangle(viewX - 1, viewY - 1, mouseToWorldX(Width) - viewX + 2, mouseToWorldY(Height) - viewY + 2);

                //Draw Background
                double worldWest  = -viewX * zoomPercent / 100;
                double worldEast  = (World.Width - viewX) * zoomPercent / 100;
                double worldNorth = -viewY * zoomPercent / 100;
                double worldSouth = (World.Height - viewY) * zoomPercent / 100;
                if (worldWest > 0)
                {
                    e.Graphics.FillRectangle(Brushes.LightGray, 0, 0, (int)worldWest, Height);
                }
                if (worldEast < Width)
                {
                    e.Graphics.FillRectangle(Brushes.LightGray, (int)worldEast, 0, (int)(Width - worldEast), Height);
                }
                if (worldNorth > 0)
                {
                    e.Graphics.FillRectangle(Brushes.LightGray, 0, 0, Width, (int)worldNorth);
                }
                if (worldSouth < Height)
                {
                    e.Graphics.FillRectangle(Brushes.LightGray, 0, (int)worldSouth, Width, (int)(Height - worldSouth));
                }

                foreach (LineGraph line in World.Lines)
                {
                    drawLineGraph(e.Graphics, line, false, Pens.Black);
                }

                if (currentAction == ActionType.FreeDraw || currentAction == ActionType.PointDraw)
                {
                    drawLineGraph(e.Graphics, currentLineGraph, true, Pens.Gray);
                    if (currentLineGraph != null && currentLineGraph.Count >= 1)
                    {
                        WorldPoint lastPoint = currentLineGraph[currentLineGraph.Count - 1];
                        int        x         = worldToScreenX(lastPoint.X);
                        int        y         = worldToScreenY(lastPoint.Y);
                        Pen        pen       = new Pen(Color.Gray);
                        pen.DashPattern = new float[] { 2, 2 };
                        e.Graphics.DrawLine(pen, x, y, mouseX, mouseY);
                    }
                }
                else if (currentAction == ActionType.Select)
                {
                    Pen pen = new Pen(Color.Gray);
                    pen.DashPattern = new float[] { 5, 2 };
                    int x1 = worldToScreenX(mouseDownWorldX);
                    int y1 = worldToScreenY(mouseDownWorldY);
                    int x2 = worldToScreenX(mouseWorldX);
                    int y2 = worldToScreenY(mouseWorldY);
                    e.Graphics.DrawRectangle(pen, Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                }
                else if (currentAction == ActionType.Zoom)
                {
                    Pen pen = new Pen(Color.Gray);
                    pen.DashPattern = new float[] { 2, 8 };
                    int x1 = worldToScreenX(mouseDownWorldX);
                    int y1 = worldToScreenY(mouseDownWorldY);
                    int x2 = worldToScreenX(mouseWorldX);
                    int y2 = worldToScreenY(mouseWorldY);
                    e.Graphics.DrawRectangle(pen, Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                }
            }
        }
Example #7
0
        private void drawLineGraph(Graphics g, LineGraph lineGraph, bool highlightDots, Pen pen)
        {
            SolidBrush brush = new SolidBrush(pen.Color);

            //Draw Rectangle around object
            WorldRectangle bounds = lineGraph.Bounds;

            if (bounds.Left < viewBounds.Left)
            {
                bounds.Left = viewBounds.Left;
            }
            if (bounds.Right > viewBounds.Right)
            {
                bounds.Right = viewBounds.Right;
            }
            if (bounds.Top < viewBounds.Top)
            {
                bounds.Top = viewBounds.Top;
            }
            if (bounds.Bottom > viewBounds.Bottom)
            {
                bounds.Bottom = viewBounds.Bottom;
            }
            Rectangle screenRect = worldToScreen(bounds);
            //g.DrawRectangle(Pens.LightPink, screenRect);


            WorldPoint previous = null;

            foreach (WorldPoint point in lineGraph)
            {
                double x = point.X;
                double y = point.Y;
                if (currentAction == ActionType.MoveSelection && selection.Contains(point))
                {
                    x += mouseWorldX - mouseDownWorldX;
                    y += mouseWorldY - mouseDownWorldY;
                }

                bool selected = selection.Contains(point);


                //Trim off the ends!
                if (viewBounds.Contains(x, y))
                {
                }


                if (previous != null)
                {
                    WorldPoint p1 = new WorldPoint(previous.X, previous.Y);
                    WorldPoint p2 = new WorldPoint(x, y);
                    DrawLine(g, pen, p1, p2);
                }

                //DrawPoint
                if (viewBounds.Contains(x, y))
                {
                    int screenX = worldToScreenX(x);
                    int screenY = worldToScreenY(y);
                    if (selected)
                    {
                        g.FillRectangle(selectedBrush, screenX - 1, screenY - 1, 3, 3);
                    }
                    else if (highlightDots)
                    {
                        g.FillRectangle(brush, screenX - 1, screenY - 1, 3, 3);
                    }
                }



                previous = new WorldPoint(x, y);
            }
            if (lineGraph.IsConnected && lineGraph.Count > 2)
            {
                double x = lineGraph[0].X;
                double y = lineGraph[0].Y;
                if (currentAction == ActionType.MoveSelection && selection.Contains(lineGraph[0]))
                {
                    x += mouseWorldX - mouseDownWorldX;
                    y += mouseWorldY - mouseDownWorldY;
                }
                //int screenX = worldToScreenX(x);
                //int screenY = worldToScreenY(y);
                DrawLine(g, pen, new WorldPoint(x, y), previous);
                //g.DrawLine(pen, previous.X, previous.Y, screenX, screenY);
            }
        }