Exemplo n.º 1
0
        public bool HitTestStreamOut(Point p)
        {
            bool         hit  = false;
            Point        slot = this.GetStreamOutSlotPoint();
            GraphicsPath gp   = new GraphicsPath();

            gp.AddLine(this.Width, slot.Y - UI.SLOT_DELTA, this.Width, slot.Y + UI.SLOT_DELTA);
            //Pen pen = new Pen(Color.Black, 20);
            //Graphics g = this.CreateGraphics();
            hit = gp.IsOutlineVisible(p, penBlack20, g);
            gp.Dispose();

            return(hit);
        }
Exemplo n.º 2
0
 static public Line GetLineClick(int x, int y)
 {
     for (int i = line_drawn_list.Count - 1; i >= 0; --i)
     {
         Line item     = line_drawn_list[i];
         var  new_path = new GraphicsPath();
         new_path.AddLine(item.first_point, item.second_point);
         if (new_path.IsOutlineVisible(x, y, new Pen(Color.Black, 5)))
         {
             return(item);
         }
     }
     return(new Line());
 }
Exemplo n.º 3
0
        internal static bool HitTest(PointF point, RectangleF rectangle, SpatialTransform transform)
        {
            GraphicsPath path = new GraphicsPath();

            path.AddRectangle(RectangleUtilities.ConvertToPositiveRectangle(rectangle));

            Pen  pen    = new Pen(Brushes.White, HitTestDistance / transform.CumulativeScale);
            bool result = path.IsOutlineVisible(point, pen);

            path.Dispose();
            pen.Dispose();

            return(result);
        }
Exemplo n.º 4
0
        public bool Contains(PointF point, Edge edge)
        {
            if (edge.EdgeConfig.LinePoints.Count == 0)
            {
                return(false);
            }

            var path = new GraphicsPath();

            path.AddLines(edge.EdgeConfig.LinePoints.ToArray());
            Pen pen = edge.EdgeConfig.Selected ? edge.EdgeConfig.SelectedEdgePen : edge.EdgeConfig.EdgePen;

            return(path.IsOutlineVisible(point, new Pen(pen.Color, pen.Width + 15)));
        }
Exemplo n.º 5
0
        public override bool hitTest(Point p, Transform t)
        {
            if (x.Count() < 2)
            {
                return(false);
            }

            var points = x.Zip(y, (px, py) => t.transform(new PointF((float)px, (float)py)));

            GraphicsPath gp = new GraphicsPath();

            gp.AddLines(points.ToArray());
            return(gp.IsVisible(p) || gp.IsOutlineVisible(p, Stroke));
        }
Exemplo n.º 6
0
        private void SelectElement(MouseEventArgs e)
        {
            foreach (FurnitureData furniture in FurnitureList)
            {
                if (furniture is WallData)
                {
                    using (var p = new GraphicsPath())
                    {
                        p.AddLines((furniture as WallData).anchors.ToArray());

                        Matrix transformMatrix = new Matrix();
                        transformMatrix.Translate(furniture.x, furniture.y);
                        transformMatrix.Rotate(furniture.angle);
                        p.Transform(transformMatrix);

                        if (p.IsOutlineVisible(e.Location, new Pen(Brushes.Black, WallThickness)))
                        {
                            listBox1.SelectedItem = furniture;
                            //DrawDesign();
                            return;
                        }
                    }
                }
                else
                {
                    using (var p = new GraphicsPath())
                    {
                        p.AddRectangle(new Rectangle(-furniture.image.Width / 2,
                                                     -furniture.image.Height / 2,
                                                     furniture.image.Width,
                                                     furniture.image.Height));

                        Matrix transformMatrix = new Matrix();
                        transformMatrix.Translate(furniture.x, furniture.y);
                        transformMatrix.Rotate(furniture.angle);
                        p.Transform(transformMatrix);

                        if (p.IsVisible(e.Location))
                        {
                            listBox1.SelectedItem = furniture;
                            //DrawDesign();
                            return;
                        }
                    }
                }
            }
            listBox1.SelectedItem = null;
            //DrawDesign();
        }
Exemplo n.º 7
0
        /// <summary>
        /// check particular point is in the control range or not, not used now
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool HitTest(Point p)
        {
            bool hit = false;
            //this.ConstructGraphicsPath(null);
            GraphicsPath gp  = new GraphicsPath();
            Pen          pen = new Pen(Color.Black, UI.CONNECTION_WIDTH);

            //hit = regionGP.IsOutlineVisible(p, pen);
            hit = gp.IsOutlineVisible(p, pen);

            pen.Dispose();
            gp.Dispose();

            return(hit);
        }
Exemplo n.º 8
0
        public override bool isPointBelongPrecisely(Point p)
        {
            if (points.Count != 3 || rect_bound.Width == 0 || rect_bound.Height == 0)
            {
                return(false);
            }

            using (GraphicsPath path = new GraphicsPath())
                using (Pen pen = new Pen(penAttr.color, penAttr.width))
                {
                    pen.DashStyle = penAttr.dashStyle;
                    path.AddArc(rect_bound, startAngle, sweepAngle);
                    return(path.IsOutlineVisible(pointBeforeScaleRotate(p), pen));
                }
        }
Exemplo n.º 9
0
        public override bool ClickableAt(int x, int y)
        {
            bool returnValue = base.ClickableAt(x, y);

            if (returnValue)
            {
                int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
                using (Pen pen = new Pen(Color.White))
                {
                    pen.Width   = lineThickness + 10;
                    returnValue = freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
                }
            }
            return(returnValue);
        }
Exemplo n.º 10
0
        // </snippet21>

        // Snippet for: M:System.Drawing.Drawing2D.GraphicsPath.IsOutlineVisible(System.Int32,System.Int32,System.Drawing.Pen,System.Drawing.Graphics)
        // <snippet22>
        public void IsOutlineVisibleExample(PaintEventArgs e)
        {
            GraphicsPath myPath = new GraphicsPath();
            Rectangle    rect   = new Rectangle(20, 20, 100, 100);

            myPath.AddRectangle(rect);
            Pen testPen = new Pen(Color.Black, 20);

            myPath.Widen(testPen);
            e.Graphics.FillPath(Brushes.Black, myPath);
            bool visible = myPath.IsOutlineVisible(100, 50, testPen,
                                                   e.Graphics);

            MessageBox.Show("visible = " + visible.ToString());
        }
Exemplo n.º 11
0
 public override bool PointInFigure(PointF point)
 {
     using (var gp = new GraphicsPath())
     {
         var ps = GetPoints();
         for (var i = 1; i < ps.Length; i++)
         {
             gp.StartFigure();
             gp.AddLine(ps[i - 1], ps[i]);
             gp.CloseFigure();
         }
         using (var pen = new Pen(Color.Black, Stroke.Width * 5f))
             return(gp.IsOutlineVisible(point, pen));
     }
 }
Exemplo n.º 12
0
        public override bool isHit(Point location)
        {
            using (GraphicsPath path = graphicsPath)
            {
                if (!this.isFill)
                {
                    return(path.IsOutlineVisible(location, myPen));
                }

                else
                {
                    return(path.IsVisible(location));
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Determines if the given Point is near any of the lines in
        /// Lines.LinesList. Sets HitLine to the first found or null if
        /// none found.
        /// </summary>
        /// <param name="point">The input point in PictureBox coordinates.</param>
        /// <returns>If found.</returns>
        public bool hitTestLine(Point point)
        {
            if (ActiveMode != Mode.EDIT)
            {
                return(false);
            }
            Point imgPoint = imagePoint(point);
            bool  res;

            HitLine  = null;
            HitPoint = null;
            Debug.WriteLine("hitTestLine: ActiveMode=" + ActiveMode
                            + " ZoomFactor=" + ZoomFactor + NL
                            + "    point=" + point + " imgPoint=" + imgPoint + NL
                            + "    LINE_WIDTH=" + LINE_WIDTH + " HIT_TOLERANCE=" + HIT_TOLERANCE);
            foreach (Line line in Lines.LinesList)
            {
                // First check the points
                // (Tolerance does not extend past the ends as it does transverse.)
                Region region;
                foreach (Point point1 in line.Points)
                {
                    region = new Region(centeredSquare(point1, HIT_TOLERANCE));
                    res    = region.IsVisible(imgPoint);
                    if (res)
                    {
                        HitPoint = new HitPoint(line, line.Points.IndexOf(point1));
                        HitLine  = line;
                        return(true);
                    }
                }
                // Then check the lines.
                using (var path = new GraphicsPath())
                    using (var pen = new Pen(Color.Black, HIT_TOLERANCE)) {
                        for (int i = 1; i < line.NPoints; i++)
                        {
                            path.AddLine(line.Points[i - 1], line.Points[i]);
                        }
                        res = path.IsOutlineVisible(imgPoint, pen);
                        if (res)
                        {
                            HitLine = line;
                            return(true);
                        }
                    }
            }
            return(false);
        }
        private int WhichSegmentIsVisible(Point p)
        {
            GraphicsPath g = new GraphicsPath();
            int          i = 0;

            for (i = 0; i < this.ConnectorSegmentTypes.Count; i++)
            {
                g.Reset();
                g.AddLine(this.Corners[i].Location, this.Corners[i + 1].Location);
                if (g.IsOutlineVisible(p, visiblePen))
                {
                    break;
                }
            }
            return(i);
        }
Exemplo n.º 15
0
        public override bool ContainsPoint(Point p)
        {
            GraphicsPath myPath = new GraphicsPath();

            myPath.AddLine(StartOrigin, EndOrigin);
            bool pointWithinLine = myPath.IsOutlineVisible(p, new Pen(ChosenColor, ShapeSize));

            if (pointWithinLine)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 16
0
        public bool HitTestLiquidOut(Point p)
        {
            bool         hit  = false;
            Point        slot = this.GetLiquidOutSlotPoint();
            GraphicsPath gp   = new GraphicsPath();

            gp.AddLine(slot.X - UI.SLOT_DELTA, this.Height, slot.X + UI.SLOT_DELTA, this.Height);
            //Pen pen = new Pen(Color.Black, 20);
            //Graphics g = this.CreateGraphics();
            hit = gp.IsOutlineVisible(p, penBlack20, g);

            //pen.Dispose();
            //g.Dispose();
            gp.Dispose();
            return(hit);
        }
Exemplo n.º 17
0
        public bool Inside(Point p, Rectangle boundingBox)
        {
            bool         res  = false;
            GraphicsPath path = this.GetGraphicsPath(boundingBox);

            if (isFill)
            {
                res = path.IsVisible(p);
            }
            else
            {
                Pen pen = new Pen(borderColor, width + 5);
                res = path.IsOutlineVisible(p, pen);
            }
            return(res);
        }
Exemplo n.º 18
0
        public override bool ClickableAt(int x, int y)
        {
            int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS) + 5;

            if (lineThickness > 0)
            {
                using (Pen pen = new Pen(Color.White)) {
                    pen.Width = lineThickness;
                    using (GraphicsPath path = new GraphicsPath()) {
                        path.AddLine(Left, Top, Left + Width, Top + Height);
                        return(path.IsOutlineVisible(x, y, pen));
                    }
                }
            }
            return(false);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Judge which truss member has been selected via location of mouse
        /// </summary>
        /// <param name="x">X coordinate of mouse location</param>
        /// <param name="y">Y coordinate of mouse location</param>
        /// <returns>index of selected member</returns>
        public int SelectTrussMember(int x, int y)
        {
            Point point = new Point(x, y);

            for (int i = 0; i < m_graphicsPaths.Count; i++)
            {
                GraphicsPath path = (GraphicsPath)m_graphicsPaths[i];
                if (path.IsOutlineVisible(point, Pens.Blue))
                {
                    m_selectMemberIndex = i;
                    return(m_selectMemberIndex);
                }
            }
            m_selectMemberIndex = -1;
            return(m_selectMemberIndex);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Получить список смежных одинаково ориентированных рёбер с ребром, на которую указывает курсор
 /// </summary>
 /// <param name="location"></param>
 /// <param name="width"></param>
 /// <returns></returns>
 private List <Edge> GetAjacentEdges(Point location, SplitKind splitKind, float width = Helper.Epsilon)
 {
     if (splitKind == SplitKind.None)
     {
         return(new List <Edge>());
     }
     using (var grp = new GraphicsPath())
         using (var pen = new Pen(Color.Black, width))
         {
             foreach (var item in Edges.Where(edge => splitKind == SplitKind.Vertical && edge.IsVertical ||
                                              splitKind == SplitKind.Horizontal && edge.IsHorizontal))
             {
                 var edge = item;
                 grp.Reset();
                 grp.AddLine(edge.Node1.Offset, edge.Node2.Offset);
                 if (grp.IsOutlineVisible(location, pen))
                 {
                     var result = new List <Edge>();
                     var queue  = new Queue <Edge>();
                     queue.Enqueue(edge);
                     while (true)
                     {
                         if (queue.Count == 0)
                         {
                             break;
                         }
                         edge = queue.Dequeue();
                         var pn1 = edge.Node1;
                         var pn2 = edge.Node2;
                         // найти все рёбра, разделяющие общие узловые точки
                         var list = Edges.Where(e => !result.Contains(e) && e.IsSameOrientation(edge) &&
                                                (e.Node1 == pn1 || e.Node1 == pn2 || e.Node2 == pn1 || e.Node2 == pn2)).ToList();
                         if (list.Count > 0)
                         {
                             foreach (var e in list)
                             {
                                 queue.Enqueue(e);
                             }
                             result.AddRange(list);
                         }
                     }
                     return(result);
                 }
             }
         }
     return(new List <Edge>());
 }
Exemplo n.º 21
0
        /// <summary>
        /// Determine if the specified screen point lies inside the bounding box of this
        /// <see cref="PolyObj"/>.
        /// </summary>
        /// <param name="pt">The screen point, in pixels</param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <returns>true if the point lies in the bounding box, false otherwise</returns>
        override public bool PointInBox(PointF pt, PaneBase pane, Graphics g, float scaleFactor)
        {
            if (_points != null && _points.Count > 1)
            {
                //if (!base.PointInBox(pt, pane, g, scaleFactor))
                //    return false;

                using (GraphicsPath path = MakePath(pane))
                {
                    return(path.IsVisible(pt) || path.IsOutlineVisible(pt, new Pen(Color.AliceBlue, 2)));
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 22
0
        public bool HitTestGasIn(Point p)
        {
            bool         hit  = false;
            Point        slot = this.GetGasInSlotPoint();
            GraphicsPath gp   = new GraphicsPath();

            gp.AddLine(0, slot.Y - UI.SLOT_DELTA, 0, slot.Y + UI.SLOT_DELTA);
            Pen      pen = new Pen(Color.Black, 20);
            Graphics g   = this.CreateGraphics();

            hit = gp.IsOutlineVisible(p, pen, g);

            pen.Dispose();
            g.Dispose();
            gp.Dispose();
            return(hit);
        }
Exemplo n.º 23
0
        private bool closeButtonHitTest(int x, int y)
        {
            bool hit = false;

            using (GraphicsPath gp = new GraphicsPath()) {
                gp.StartFigure();
                gp.AddLines(this.m_closeButtonBounds);
                gp.CloseFigure();
                using (Pen borderpen = new Pen(Color.Black, 1)) {
                    if (gp.IsOutlineVisible(x, y, borderpen) || gp.IsVisible(x, y))
                    {
                        hit = true;
                    }
                }
            }
            return(hit);
        }
Exemplo n.º 24
0
        public override bool IsHit(PointF point)
        {
            bool res = false;

            using (GraphicsPath path = GraphicsPath)
            {
                if (!Filled)
                {
                    res = path.IsOutlineVisible(point, myPen);
                }
                else
                {
                    res = path.IsVisible(point);
                }
            }
            return(res);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Shows whether a certain point from the select square in the main form
        /// is on the line.
        /// </summary>
        /// <param name="p">Location of the point</param>
        public void selectRectangle(Point p)
        {
            var isOnLine = false;

            using (var path = new GraphicsPath())
            {
                using (var pen = new Pen(Brushes.Black, BorderWidth))
                {
                    path.AddLine(X1, Y1, X2, Y2);
                    isOnLine = path.IsOutlineVisible(p, pen);
                }
            }
            if (!Selected)
            {
                Selected = isOnLine;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Вставка новой вершины в контур фигуры
        /// </summary>
        /// <param name="owner">Фигура</param>
        /// <param name="point">Положение указателя мышки</param>
        public void InsertVertex(Figure owner, PointF point)
        {
            //можем менять положение вершин?
            var allowVertex = Geometry.AllowedOperations.HasFlag(AllowedOperations.Vertex);

            if (!allowVertex)
            {
                return; //не можем менять положение вершин
            }
            var polygone = owner.Geometry as PolygoneGeometry;

            if (polygone == null)
            {
                return; //работаем только с полигонами
            }
            //get points in world coordinates
            var points = polygone.GetTransformedPoints(owner).ToList();

            using (var pen = new Pen(Color.Black, 5))
            {
                // поищем, на какой стороне фигуры добавлять новую вершину
                var k = polygone.IsClosed ? 0 : 1;
                for (var i = k; i < points.Count; i++)
                {
                    // замыкаем контур отрезком, соединяющим начало и конец фигуры
                    var pt1 = i == 0 ? points[points.Count - 1] : points[i - 1];
                    var pt2 = points[i];
                    using (var path = new GraphicsPath())
                    {
                        path.AddLine(pt1, pt2);
                        if (!path.IsOutlineVisible(point, pen))
                        {
                            continue;
                        }
                        // вставляем новую точку
                        points.Insert(i, point);
                        //push
                        polygone.SetTransformedPoints(owner, points.ToArray());
                        break;
                    }
                }
            }

            //
            GrabGeometry();
        }
Exemplo n.º 27
0
 /// <summary>
 /// Определяем попадание точки на контур фигуры
 /// </summary>
 /// <param name="mousePosition"></param>
 /// <returns></returns>
 public override bool Contained(Point mousePosition)
 {
     using (var path = new GraphicsPath())
     {
         // добавляем в путь контур полилинии
         path.AddLines(markers.Select(x => x.Location).ToArray());
         path.AddRectangles(markers.Select(x => x.Bounds).ToArray());
         // ширина линии для поиска попадания равна размеру маркера
         using (var pen = new Pen(Color.Black, 5f))
         {
             pen.LineJoin = LineJoin.Round;
             pen.StartCap = LineCap.RoundAnchor;
             pen.EndCap   = LineCap.RoundAnchor;
             return(path.IsOutlineVisible(mousePosition, pen));
         }
     }
 }
Exemplo n.º 28
0
 public override bool ClickableAt(int x, int y)
 {
     int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS) + 10;
     if (lineThickness > 0)
     {
         using (Pen pen = new Pen(Color.White))
         {
             pen.Width = lineThickness;
             SetArrowHeads((ArrowHeadCombination)GetFieldValue(FieldType.ARROWHEADS), pen);
             using (GraphicsPath path = new GraphicsPath())
             {
                 path.AddLine(Left, Top, Left + Width, Top + Height);
                 return path.IsOutlineVisible(x, y, pen);
             }
         }
     }
     return false;
 }
Exemplo n.º 29
0
        private static GraphicsPath BasicDividePath(List <GraphicsPath> paths, IEnumerable <PointF> ins, PointF[] points, byte[] types, int begin, int len)
        {
            //divide figure
            PointF[] ps = new PointF[len];
            byte[]   ts = new byte[len];
            Array.Copy(points, begin, ps, 0, len);
            Array.Copy(types, begin, ts, 0, len);
            GraphicsPath path = new GraphicsPath(ps, ts);

            //no interscetion
            if ((ins != null) && ins.Any(t => path.IsOutlineVisible(t, OutlinePen)))
            {
                return(path);
            }

            paths.Add(path);
            return(null);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Determine if the specified screen point lies inside the bounding box of this
        /// <see cref="LineObj"/>.
        /// </summary>
        /// <remarks>The bounding box is calculated assuming a distance
        /// of <see cref="GraphPane.Default.NearestTol"/> pixels around the arrow segment.
        /// </remarks>
        /// <param name="pt">The screen point, in pixels</param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <returns>true if the point lies in the bounding box, false otherwise</returns>
        public override bool PointInBox(PointF pt, PaneBase pane, Graphics g, float scaleFactor)
        {
            if (!base.PointInBox(pt, pane, g, scaleFactor))
            {
                return(false);
            }

            // transform the x,y location from the user-defined
            // coordinate frame to the screen pixel location
            var pix  = _location.TransformTopLeft(pane);
            var pix2 = _location.TransformBottomRight(pane);

            using (var pen = new Pen(Color.Black, (float)GraphPane.Default.NearestTol * 2.0F))
                using (var path = new GraphicsPath()) {
                    path.AddLine(pix, pix2);
                    return(path.IsOutlineVisible(pt, pen));
                }
        }