Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignMode)
            {
                e.Graphics.Clear(Settings.Color[Colors.Canvas]);
                return;
            }

            foreach (var element in Project.Current.Elements)
            {
                element.Flagged = false;
            }
            foreach (var element in Canvas.SelectedElements)
            {
                element.Flagged = true;
            }

            using (var nativeGraphics = Graphics.FromHdc(e.Graphics.GetHdc()))
            {
                using (var graphics = XGraphics.FromGraphics(nativeGraphics, new XSize(Width, Height)))
                {
                    using (var palette = new Palette())
                    {
                        var clientArea = new Rectangle(0, 0, Width, Height);

                        ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.Raised);
                        clientArea.Inflate(-OuterBorderSize, -OuterBorderSize);
                        nativeGraphics.FillRectangle(SystemBrushes.Control, clientArea);
                        clientArea.Inflate(-OuterPadding, -OuterPadding);
                        ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.SunkenOuter);
                        clientArea.Inflate(-InnerBorderSize, -InnerBorderSize);

                        nativeGraphics.FillRectangle(palette.CanvasBrush, clientArea);
                        clientArea.Inflate(-InnerPadding, -InnerPadding);

                        //nativeGraphics.FillRectangle(Brushes.Cyan, clientArea);

                        var canvasBounds = Canvas != null ? Canvas.ComputeCanvasBounds(false) : Rect.Empty;

                        var borderPen = palette.Pen(Settings.Color[Colors.Border], 0);
                        foreach (var element in Project.Current.Elements)
                        {
                            if (element is Room)
                            {
                                var room = (Room)element;
                                var roomBounds = CanvasToClient(room.InnerBounds.ToRectangleF(), canvasBounds, clientArea);
                                graphics.DrawRectangle(borderPen, room.Flagged ? palette.BorderBrush : palette.FillBrush, roomBounds);
                            }
                        }

                        if (Canvas != null)
                        {
                            // draw the viewport area as a selectable "handle"
                            var viewportBounds = CanvasToClient(Canvas.Viewport.ToRectangleF(), canvasBounds, clientArea);
                            viewportBounds.Intersect(clientArea);
                            if (Project.Current.Elements.Count > 0)
                            {
                                var context = new DrawingContext(1f);
                                context.Selected = m_draggingViewport;
                                Drawing.DrawHandle(Canvas, graphics, palette, new Rect(viewportBounds), context, true, false);
                            }
                        }
                    }
                }
            }
            e.Graphics.ReleaseHdc();

            base.OnPaint(e);
        }
Example #2
0
 public void Draw(Canvas canvas, XGraphics graphics, Palette palette, DrawingContext context)
 {
     Drawing.DrawHandle(canvas, graphics, palette, bounds, context, false, false);
 }
Example #3
0
 public virtual void Draw(Canvas canvas, XGraphics graphics, Palette palette, DrawingContext context)
 {
     Drawing.DrawHandle(canvas, graphics, palette, visualBounds, context, false, true);
 }
Example #4
0
        public override void RecomputeSmartLineSegments(DrawingContext context)
        {
            m_smartSegments.Clear();
              foreach (var lineSegment in GetSegments())
              {
            List<LineSegment> newSegments = null;
            if (Split(lineSegment, context, ref newSegments))
            {
              foreach (var newSegment in newSegments)
              {
            m_smartSegments.Add(newSegment);
              }
            }
            else
            {
              m_smartSegments.Add(lineSegment);
            }
              }

              foreach (var segment in m_smartSegments)
              {
            context.LinesDrawn.Add(segment);
              }
        }
Example #5
0
        /// <summary>
        ///   Split the given line segment if it crosses line segments we've already drawn.
        /// </summary>
        /// <param name="lineSegment">The line segment to consider.</param>
        /// <param name="context">The context in which we've been drawing line segments.</param>
        /// <param name="newSegments">
        ///   The results of splitting the given line segment, if any. Call with a reference to a null
        ///   list.
        /// </param>
        /// <returns>True if the line segment was split and newSegments now exists and contains line segments; false otherwise.</returns>
        private bool Split(LineSegment lineSegment, DrawingContext context, ref List<LineSegment> newSegments)
        {
            foreach (var previousSegment in context.LinesDrawn)
              {
            var amount = Math.Max(1, Settings.LineWidth)*3;
            List<LineSegmentIntersect> intersects;
            if (lineSegment.Intersect(previousSegment, true, out intersects))
            {
              foreach (var intersect in intersects)
              {
            switch (intersect.Type)
            {
              case LineSegmentIntersectType.MidPointA:
                var one = new LineSegment(lineSegment.Start, intersect.Position);
                if (one.Shorten(amount))
                {
                  if (!Split(one, context, ref newSegments))
                  {
                    if (newSegments == null)
                    {
                      newSegments = new List<LineSegment>();
                    }
                    newSegments.Add(one);
                  }
                }
                var two = new LineSegment(intersect.Position, lineSegment.End);
                if (two.Forshorten(amount))
                {
                  if (!Split(two, context, ref newSegments))
                  {
                    if (newSegments == null)
                    {
                      newSegments = new List<LineSegment>();
                    }
                    newSegments.Add(two);
                  }
                }
                break;

              case LineSegmentIntersectType.StartA:
                if (lineSegment.Forshorten(amount))
                {
                  if (!Split(lineSegment, context, ref newSegments))
                  {
                    if (newSegments == null)
                    {
                      newSegments = new List<LineSegment>();
                    }
                    newSegments.Add(lineSegment);
                  }
                }
                break;

              case LineSegmentIntersectType.EndA:
                if (lineSegment.Shorten(amount))
                {
                  if (!Split(lineSegment, context, ref newSegments))
                  {
                    if (newSegments == null)
                    {
                      newSegments = new List<LineSegment>();
                    }
                    newSegments.Add(lineSegment);
                  }
                }
                break;
            }

            // don't check other intersects;
            // we've already split this line, and tested the parts for further intersects.
            return newSegments != null;
              }
            }
              }
              return false;
        }
Example #6
0
        public static void DrawHandle(Canvas canvas, XGraphics graphics, Palette palette, Rect bounds, DrawingContext context, bool alwaysAlpha, bool round)
        {
            if (bounds.Width <= 0 || bounds.Height <= 0)
              {
            return;
              }

              using (var quality = new Smoothing(graphics, XSmoothingMode.Default))
              {
            XBrush brush;
            Pen pen;
            var alpha = 180;

            if (context.Selected)
            {
              if (!alwaysAlpha)
              {
            alpha = 255;
              }
              brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LemonChiffon), Color.FromArgb(alpha, Color.DarkOrange));
              pen = palette.Pen(Color.FromArgb(alpha, Color.Chocolate), 0);
            }
            else
            {
              brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LightCyan), Color.FromArgb(alpha, Color.SteelBlue));
              pen = palette.Pen(Color.FromArgb(alpha, Color.Navy), 0);
            }

            if (round)
            {
              graphics.DrawEllipse(brush, bounds.ToRectangleF());
              graphics.DrawEllipse(pen, bounds.ToRectangleF());
            }
            else
            {
              graphics.DrawRectangle(brush, bounds.ToRectangleF());
              graphics.DrawRectangle(pen, bounds.ToRectangleF());
            }
              }
        }
Example #7
0
        public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
        {
            var lineSegments = context.UseSmartLineSegments ? m_smartSegments : GetSegments();

              foreach (var lineSegment in lineSegments)
              {
            var pen = palette.GetLinePen(context.Selected, context.Hover, Style == ConnectionStyle.Dashed);
            Pen specialPen = null;

            if (!context.Hover)
              if ((ConnectionColor != Color.Transparent) && !context.Selected)
              {
            specialPen = (Pen) pen.Clone();
            specialPen.Color = ConnectionColor;
              }

            if (!Settings.DebugDisableLineRendering)
            {
              graphics.DrawLine(specialPen ?? pen, lineSegment.Start.ToPointF(), lineSegment.End.ToPointF());
            }
            var delta = lineSegment.Delta;
            if (Flow == ConnectionFlow.OneWay && delta.Length > Settings.ConnectionArrowSize)
            {
              SolidBrush brush = (SolidBrush) palette.GetLineBrush(context.Selected, context.Hover);
              SolidBrush specialBrush = null;

              if (!context.Hover)
            if ((ConnectionColor != Color.Transparent) && !context.Selected)
            {
              specialBrush = (SolidBrush) brush.Clone();
              specialBrush.Color = ConnectionColor;
            }

              Drawing.DrawChevron(graphics, lineSegment.Mid.ToPointF(), (float) (Math.Atan2(delta.Y, delta.X)/Math.PI*180), Settings.ConnectionArrowSize, specialBrush ?? brush);
            }
            context.LinesDrawn.Add(lineSegment);
              }

              Annotate(graphics, palette, lineSegments);
        }
Example #8
0
        public override void PreDraw(DrawingContext context)
        {
            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);
        }
Example #9
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);
                }
            }
        }
Example #10
0
        public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
        {
            List<LineSegment> lineSegments;
            if (context.UseSmartLineSegments)
            {
                lineSegments = m_smartSegments;
            }
            else
            {
                lineSegments = GetSegments();
            }

            var path = palette.Path();
            var random = new Random(GetHashCode());
            foreach (var lineSegment in lineSegments)
            {
                var pen = palette.GetLinePen(context.Selected, context.Hover, Style == ConnectionStyle.Dashed);
                if (!Settings.DebugDisableLineRendering)
                {
                    graphics.DrawLine(pen, lineSegment.Start.ToPointF(), lineSegment.End.ToPointF());
                }
                var delta = lineSegment.Delta;
                if (Flow == ConnectionFlow.OneWay && delta.Length > Settings.ConnectionArrowSize)
                {
                    var brush = palette.GetLineBrush(context.Selected, context.Hover);
                    Drawing.DrawChevron(graphics, lineSegment.Mid.ToPointF(), (float)(Math.Atan2(delta.Y, delta.X) / Math.PI * 180), Settings.ConnectionArrowSize, brush);
                }
                context.LinesDrawn.Add(lineSegment);
            }

            Annotate(graphics, palette, lineSegments);
        }
Example #11
0
        public override void PreDraw(DrawingContext context)
        {
            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 topCenter = InnerBounds.GetCorner(CompassPoint.North);
            var rightCenter = InnerBounds.GetCorner(CompassPoint.East);
            var bottomCenter = InnerBounds.GetCorner(CompassPoint.South);
            var leftCenter = InnerBounds.GetCorner(CompassPoint.West);

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

            var halfTopRight = new LineSegment(topCenter, topRight);
            var halfBottomRight = new LineSegment(bottomRight, bottomCenter);
            var centerVertical = new LineSegment(bottomCenter, topCenter);

            var centerHorizontal = new LineSegment(leftCenter, rightCenter);
            var halfRightBottom = new LineSegment(rightCenter, bottomRight);
            var halfLeftBottom = new LineSegment(bottomLeft, leftCenter);

            var slantUp = new LineSegment(bottomLeft, topRight);
            var slantDown = new LineSegment(bottomRight, topLeft);

            context.LinesDrawn.Add(top);
            context.LinesDrawn.Add(right);
            context.LinesDrawn.Add(bottom);
            context.LinesDrawn.Add(left);
        }
Example #12
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 topCenter = InnerBounds.GetCorner(CompassPoint.North);
            var rightCenter = InnerBounds.GetCorner(CompassPoint.East);
            var bottomCenter = InnerBounds.GetCorner(CompassPoint.South);
            var leftCenter = InnerBounds.GetCorner(CompassPoint.West);

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

            var halfTopRight = new LineSegment(topCenter, topRight);
            var halfBottomRight = new LineSegment(bottomRight, bottomCenter);
            var centerVertical = new LineSegment(bottomCenter, topCenter);

            var centerHorizontal = new LineSegment(leftCenter, rightCenter);
            var halfRightBottom = new LineSegment(rightCenter, bottomRight);
            var halfLeftBottom = new LineSegment(bottomLeft, leftCenter);

            var slantUp = new LineSegment(bottomLeft, topRight);
            var slantDown = new LineSegment(bottomRight, 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;
            // Room specific fill brush (White shows global color)
            if (RoomFill != ColorTranslator.FromHtml("White") && RoomFill != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomFill); }

            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);

                // Second fill for room specific colors with a split option
                if (SecondFill != ColorTranslator.FromHtml("White") && SecondFill != ColorTranslator.FromHtml("#FFFFFF"))
                {
                    // Set the second fill color
                    brush = new SolidBrush(SecondFill);

                    // Define the second path based on the second fill location
                    var secondPath = palette.Path();
                    switch (SecondFillLocation)
                    {
                        case "Bottom":
                            Drawing.AddLine(secondPath, centerHorizontal, random);
                            Drawing.AddLine(secondPath, halfRightBottom, random);
                            Drawing.AddLine(secondPath, bottom, random);
                            Drawing.AddLine(secondPath, halfLeftBottom, random);
                            break;
                        case "BottomRight":
                            Drawing.AddLine(secondPath, slantUp, random);
                            Drawing.AddLine(secondPath, right, random);
                            Drawing.AddLine(secondPath, bottom, random);
                            break;
                        case "Right":
                            Drawing.AddLine(secondPath, halfTopRight, random);
                            Drawing.AddLine(secondPath, right, random);
                            Drawing.AddLine(secondPath, halfBottomRight, random);
                            Drawing.AddLine(secondPath, centerVertical, random);
                            break;
                        case "TopRight":
                            Drawing.AddLine(secondPath, top, random);
                            Drawing.AddLine(secondPath, right, random);
                            Drawing.AddLine(secondPath, slantDown, random);
                            break;
                        default:
                            break;
                    }
                    // Draw the second fill over the first
                    graphics.DrawPath(brush, secondPath);
                }

                if (IsDark)
                {
                    var state = graphics.Save();
                    graphics.IntersectClip(path);
                    brush = context.Selected ? palette.FillBrush : palette.BorderBrush;
                    // Room specific fill brush (White shows global color)
                    if (RoomBorder != ColorTranslator.FromHtml("White") && RoomBorder != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomBorder); }
                    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);
                }

                if (RoomBorder == ColorTranslator.FromHtml("White") || RoomBorder == ColorTranslator.FromHtml("#FFFFFF"))
                {
                    graphics.DrawPath(palette.BorderPen, path);
                }
                else
                {
                    var RoomBorderPen = new Pen(RoomBorder, Settings.LineWidth);
                    RoomBorderPen.StartCap = LineCap.Round;
                    RoomBorderPen.EndCap = LineCap.Round;
                    graphics.DrawPath(RoomBorderPen, path);
                }
            }

            var font = Settings.LargeFont;
            brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush;
            // Room specific fill brush (White shows global color)
            if (RoomLargeText != ColorTranslator.FromHtml("White") && RoomLargeText != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomLargeText); }

            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;
            // Room specific fill brush (White shows global color)
            if (RoomSmallText != ColorTranslator.FromHtml("White") && RoomSmallText != ColorTranslator.FromHtml("#FFFFFF")) { brush = new SolidBrush(RoomSmallText); }

            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);
                }
            }
        }