Beispiel #1
0
        void SetCanvasOrigin(Point clientPosition)
        {
            if (Canvas == null)
            {
                return;
            }

            // get the minimap client area, in pixels, without borders and padding
            var clientArea = new Rect(0, 0, Width, Height);

            clientArea.Inflate(-TotalPadding, -TotalPadding);

            // clamp the mouse within the client area
            clientPosition = clientArea.Clamp(new Vector(clientPosition)).ToPoint();

            // get the mouse position as a percentage of the client area size
            var x = (clientPosition.X - TotalPadding) / clientArea.Width;
            var y = (clientPosition.Y - TotalPadding) / clientArea.Height;

            // get the visible area on the canvas, in canvas coordinates
            var viewport     = Canvas.Viewport;
            var canvasBounds = Canvas.ComputeCanvasBounds(false);

            // limit it to the rectangle in which the center of the viewport may be placed whilst rendering only the occupied portions of the canvas visible
            var restrictedBounds = canvasBounds;

            if (restrictedBounds.Width > viewport.Width)
            {
                restrictedBounds.Inflate(-viewport.Width / 2, 0);
            }
            else
            {
                restrictedBounds.X    += restrictedBounds.Width / 2;
                restrictedBounds.Width = 0;
            }
            if (restrictedBounds.Height > viewport.Height)
            {
                restrictedBounds.Inflate(0, -viewport.Height / 2);
            }
            else
            {
                restrictedBounds.Y     += restrictedBounds.Height / 2;
                restrictedBounds.Height = 0;
            }

            // center the canvas on the mouse position in canvas coordinates, limited to the above rectangle
            Canvas.Origin = restrictedBounds.Clamp(new Vector(canvasBounds.Left + canvasBounds.Width * x, canvasBounds.Top + canvasBounds.Height * y));
        }
Beispiel #2
0
        void SetCanvasOrigin(Point clientPosition)
        {
            if (Canvas == null)
            {
                return;
            }

            // get the minimap client area, in pixels, without borders and padding
            var clientArea = new Rect(0, 0, Width, Height);
            clientArea.Inflate(-TotalPadding, -TotalPadding);

            // clamp the mouse within the client area
            clientPosition = clientArea.Clamp(new Vector(clientPosition)).ToPoint();

            // get the mouse position as a percentage of the client area size
            var x = (clientPosition.X - TotalPadding) / clientArea.Width;
            var y = (clientPosition.Y - TotalPadding) / clientArea.Height;

            // get the visible area on the canvas, in canvas coordinates
            var viewport = Canvas.Viewport;
            var canvasBounds = Canvas.ComputeCanvasBounds(false);

            // limit it to the rectangle in which the center of the viewport may be placed whilst rendering only the occupied portions of the canvas visible
            var restrictedBounds = canvasBounds;
            if (restrictedBounds.Width > viewport.Width)
            {
                restrictedBounds.Inflate(-viewport.Width / 2, 0);
            }
            else
            {
                restrictedBounds.X += restrictedBounds.Width / 2;
                restrictedBounds.Width = 0;
            }
            if (restrictedBounds.Height > viewport.Height)
            {
                restrictedBounds.Inflate(0, -viewport.Height / 2);
            }
            else
            {
                restrictedBounds.Y += restrictedBounds.Height / 2;
                restrictedBounds.Height = 0;
            }

            // center the canvas on the mouse position in canvas coordinates, limited to the above rectangle
            Canvas.Origin = restrictedBounds.Clamp(new Vector(canvasBounds.Left + canvasBounds.Width * x, canvasBounds.Top + canvasBounds.Height * y));
        }
Beispiel #3
0
        private static void Annotate(XGraphics graphics, Palette palette, LineSegment lineSegment, TextBlock text, StringAlignment alignment)
        {
            Vector point;
            var    delta = lineSegment.Delta;

            switch (alignment)
            {
            case StringAlignment.Near:
            default:
                point = lineSegment.Start;
                delta.Negate();
                break;

            case StringAlignment.Center:
                point = lineSegment.Mid;
                break;

            case StringAlignment.Far:
                point = lineSegment.End;
                break;
            }

            var bounds = new Rect(point, Vector.Zero);

            bounds.Inflate(Settings.TextOffsetFromConnection);

            var angle        = (float)-(Math.Atan2(delta.Y, delta.X) / Math.PI * 180.0);
            var compassPoint = CompassPoint.East;

            if (Numeric.InRange(angle, 0, 45))
            {
                compassPoint = CompassPoint.NorthWest;
            }
            else if (Numeric.InRange(angle, 45, 90))
            {
                compassPoint = CompassPoint.SouthEast;
            }
            else if (Numeric.InRange(angle, 90, 135))
            {
                compassPoint = CompassPoint.SouthWest;
            }
            else if (Numeric.InRange(angle, 135, 180))
            {
                compassPoint = CompassPoint.NorthEast;
            }
            else if (Numeric.InRange(angle, 0, -45))
            {
                compassPoint = CompassPoint.NorthEast;
            }
            else if (Numeric.InRange(angle, -45, -90))
            {
                compassPoint = CompassPoint.NorthEast;
            }
            else if (Numeric.InRange(angle, -90, -135))
            {
                compassPoint = CompassPoint.NorthWest;
            }
            else if (Numeric.InRange(angle, -135, -180))
            {
                compassPoint = CompassPoint.SouthEast;
            }

            var pos    = bounds.GetCorner(compassPoint);
            var format = new XStringFormat();

            Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, compassPoint);
            if (alignment == StringAlignment.Center && Numeric.InRange(angle, -10, 10))
            {
                // HACK: if the line segment is pretty horizontal and we're drawing mid-line text,
                // move text below the line to get it out of the way of any labels at the ends,
                // and center the text so it fits onto a line between two proximal rooms.
                pos = bounds.GetCorner(CompassPoint.South);
                format.Alignment     = XStringAlignment.Center;
                format.LineAlignment = XLineAlignment.Near;
            }
            if (!Settings.DebugDisableTextRendering)
            {
                text.Draw(graphics, Settings.LineFont, palette.LineTextBrush, pos, Vector.Zero, format);
            }
        }
Beispiel #4
0
        public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
        {
            Random random = new Random(Name.GetHashCode());

            var topLeft     = InnerBounds.GetCorner(CompassPoint.NorthWest);
            var topRight    = InnerBounds.GetCorner(CompassPoint.NorthEast);
            var bottomLeft  = InnerBounds.GetCorner(CompassPoint.SouthWest);
            var bottomRight = InnerBounds.GetCorner(CompassPoint.SouthEast);

            var top    = new LineSegment(topLeft, topRight);
            var right  = new LineSegment(topRight, bottomRight);
            var bottom = new LineSegment(bottomRight, bottomLeft);
            var left   = new LineSegment(bottomLeft, topLeft);

            context.LinesDrawn.Add(top);
            context.LinesDrawn.Add(right);
            context.LinesDrawn.Add(bottom);
            context.LinesDrawn.Add(left);

            var brush = context.Selected ? palette.BorderBrush : palette.FillBrush;

            if (!Settings.DebugDisableLineRendering)
            {
                var path = palette.Path();
                Drawing.AddLine(path, top, random);
                Drawing.AddLine(path, right, random);
                Drawing.AddLine(path, bottom, random);
                Drawing.AddLine(path, left, random);
                graphics.DrawPath(brush, path);

                if (IsDark)
                {
                    var state = graphics.Save();
                    graphics.IntersectClip(path);
                    brush = context.Selected ? palette.FillBrush : palette.BorderBrush;
                    graphics.DrawPolygon(brush, new PointF[] { topRight.ToPointF(), new PointF(topRight.X - Settings.DarknessStripeSize, topRight.Y), new PointF(topRight.X, topRight.Y + Settings.DarknessStripeSize) }, XFillMode.Alternate);
                    graphics.Restore(state);
                }

                graphics.DrawPath(palette.BorderPen, path);
            }

            var font = Settings.LargeFont;

            brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush;
            Rect textBounds = InnerBounds;

            textBounds.Inflate(-5, -5);

            if (textBounds.Width > 0 && textBounds.Height > 0)
            {
                m_name.Draw(graphics, font, brush, textBounds.Position, textBounds.Size, XStringFormats.Center);
            }

            var expandedBounds = InnerBounds;

            expandedBounds.Inflate(Settings.ObjectListOffsetFromRoom, Settings.ObjectListOffsetFromRoom);
            var drawnObjectList = false;

            font  = Settings.SmallFont;
            brush = palette.SmallTextBrush;

            if (!string.IsNullOrEmpty(Objects))
            {
                XStringFormat format = new XStringFormat();
                Vector        pos    = expandedBounds.GetCorner(m_objectsPosition);
                if (!Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, m_objectsPosition))
                {
                    // object list appears inside the room below its name
                    format.LineAlignment = XLineAlignment.Far;
                    format.Alignment     = XStringAlignment.Near;
                    //format.Trimming = StringTrimming.EllipsisCharacter;
                    //format.FormatFlags = StringFormatFlags.LineLimit;
                    var height = InnerBounds.Height / 2 - font.Height / 2;
                    var bounds = new Rect(InnerBounds.Left + Settings.ObjectListOffsetFromRoom, InnerBounds.Bottom - height, InnerBounds.Width - Settings.ObjectListOffsetFromRoom, height - Settings.ObjectListOffsetFromRoom);
                    brush = context.Selected ? palette.FillBrush : brush;
                    if (bounds.Width > 0 && bounds.Height > 0)
                    {
                        m_objects.Draw(graphics, font, brush, bounds.Position, bounds.Size, format);
                    }
                    drawnObjectList = true;
                }
                else if (m_objectsPosition == CompassPoint.North || m_objectsPosition == CompassPoint.South)
                {
                    pos.X += Settings.ObjectListOffsetFromRoom;
                }

                if (!drawnObjectList)
                {
                    m_objects.Draw(graphics, font, brush, pos, Vector.Zero, format);
                }
            }
        }
Beispiel #5
0
        private static void Annotate(XGraphics graphics, Palette palette, LineSegment lineSegment, TextBlock text, StringAlignment alignment, RoomShape? shape = RoomShape.SquareCorners)
        {
            Vector point;
              var delta = lineSegment.Delta;
              switch (alignment)
              {
            case StringAlignment.Near:
            default:
              point = lineSegment.Start;
              delta.Negate();
              break;
            case StringAlignment.Center:
              point = lineSegment.Mid;
              break;
            case StringAlignment.Far:
              point = lineSegment.End;
              break;
              }

              var bounds = new Rect(point, Vector.Zero);
              bounds.Inflate(Settings.TextOffsetFromConnection);

              var angle = (float) -(Math.Atan2(delta.Y, delta.X)/Math.PI*180.0);
              var compassPoint = CompassPoint.East;
              if (Numeric.InRange(angle, 0, 45))
              {
            compassPoint = CompassPoint.NorthWest;
              }
              else if (Numeric.InRange(angle, 45, 90))
              {
            compassPoint = CompassPoint.SouthEast;
              }
              else if (Numeric.InRange(angle, 90, 135))
              {
            compassPoint = CompassPoint.SouthWest;
              }
              else if (Numeric.InRange(angle, 135, 180))
              {
            compassPoint = CompassPoint.NorthEast;
              }
              else if (Numeric.InRange(angle, 0, -45))
              {
            compassPoint = CompassPoint.NorthEast;
              }
              else if (Numeric.InRange(angle, -45, -90))
              {
            compassPoint = CompassPoint.NorthEast;
              }
              else if (Numeric.InRange(angle, -90, -135))
              {
            compassPoint = CompassPoint.NorthWest;
              }
              else if (Numeric.InRange(angle, -135, -180))
              {
            compassPoint = CompassPoint.SouthEast;
              }

              var pos = bounds.GetCorner(compassPoint);
              var format = new XStringFormat();
              Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, compassPoint);
              if (alignment == StringAlignment.Center && Numeric.InRange(angle, -10, 10))
              {
            // HACK: if the line segment is pretty horizontal and we're drawing mid-line text,
            // move text below the line to get it out of the way of any labels at the ends,
            // and center the text so it fits onto a line between two proximal rooms.
            pos = bounds.GetCorner(CompassPoint.South);
            format.Alignment = XStringAlignment.Center;
            format.LineAlignment = XLineAlignment.Near;
              }

              if (!Settings.DebugDisableTextRendering)
            text.Draw(graphics, Settings.LineFont, palette.LineTextBrush, pos, Vector.Zero, format);
        }