protected void btnSelectAll_onClick()
        {
            //ChangeObjectsSelection(true);
            RectD unionRect = ObjectsList.First().BoundingRectD();

            foreach (BPaintObject obj in ObjectsList)
            {
                unionRect = unionRect.UnionWith(obj.BoundingRectD());
            }

            bpSelectionRectangle = new BPaintRectangle()
            {
                ObjectID = 999
            };

            BPaintVertex startVertex = new BPaintVertex(new PointD(unionRect.x - 10, unionRect.y - 10), "magenta");

            SelectionVerticesList.Add(startVertex);

            bpSelectionRectangle.Selected  = false;
            bpSelectionRectangle.EditMode  = true;
            bpSelectionRectangle.Color     = "red";
            bpSelectionRectangle.LineWidth = 2;
            bpSelectionRectangle.Position  = startVertex;
            BPaintVertex endVertex = new BPaintVertex(new PointD(unionRect.x + unionRect.width + 10, unionRect.y + unionRect.height + 10), "magenta");

            bpSelectionRectangle.end = endVertex;
            SelectionVerticesList.Add(endVertex);
            bpSelectionVertexUnderMousePointer = endVertex;

            ProcessSelection();
            cmd_RefreshSVG();
            StateHasChanged();
        }
Esempio n. 2
0
        public static RectD Get_Border_Points(BPaintRectangle Par_obj, bool padding = true)
        {
            RectD result = new RectD();

            List <PointD> data = new List <PointD>();

            data.Add(Par_obj.Position.PtD);
            data.Add(Par_obj.end.PtD);

            result.x      = data.Min(j => j.X);
            result.y      = data.Min(j => j.Y);
            result.width  = data.Max(j => j.X) - result.x;
            result.height = data.Max(j => j.Y) - result.y;

            if (padding)
            {
                Set_Padding(result);
            }

            return(result);
        }
        public void onMouseDown(MouseEventArgs e)
        {
            if (CurrOperationalMode == OperationalMode.select)
            {
                if (CurrSelectionMode == SelectionMode.idle)
                {
                    if (bpSelectionRectangle != null)
                    {
                        foreach (BPaintVertex vertex in bpSelectionRectangle.VerticesList)
                        {
                            SelectionVerticesList.RemoveAll(x => true);
                        }
                        bpSelectionRectangle = null;
                    }

                    PointD CurrPosition = new PointD(e.ClientX - LocalData.SVGPosition.X, e.ClientY - LocalData.SVGPosition.Y);

                    bpSelectionRectangle = new BPaintRectangle()
                    {
                        ObjectID = 999
                    };

                    BPaintVertex startVertex = new BPaintVertex(CurrPosition, "magenta");
                    SelectionVerticesList.Add(startVertex);

                    bpSelectionRectangle.Selected  = false;
                    bpSelectionRectangle.EditMode  = true;
                    bpSelectionRectangle.Color     = "red";
                    bpSelectionRectangle.LineWidth = 2;
                    bpSelectionRectangle.Position  = startVertex;
                    BPaintVertex endVertex = new BPaintVertex(CurrPosition, "magenta");
                    bpSelectionRectangle.end = endVertex;
                    SelectionVerticesList.Add(endVertex);
                    CurrSelectionMode = SelectionMode.movingAnElement;
                    bpSelectionVertexUnderMousePointer = endVertex;
                }
                else if (CurrSelectionMode == SelectionMode.hoveredAVertex)
                {
                    if (bpSelectionVertexUnderMousePointer != null)
                    {
                        BPaintVertex currVertex = bpSelectionVertexUnderMousePointer as BPaintVertex;
                        currVertex.Selected = true;
                        CurrSelectionMode   = SelectionMode.movingAnElement;
                    }
                }
                StateHasChanged();
            }
            else
            {
                if (CurrPaintMode == BPaintMode.idle)
                {
                    if (!ObjectsList.Any(o => o.EditMode))
                    {
                        switch (FigureCode)
                        {
                        case 2:
                            startLine(e);
                            break;

                        case 3:
                            BPaintVertex newVertex = makeVertex(e);
                            CurrPaintMode = BPaintMode.idle;
                            break;

                        case 4:
                            startCircle(e);
                            break;

                        case 5:
                            //cmd_prepareEllipse(e);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        BPaintObject currBPaintObject = ObjectsList.Single(o => o.EditMode);
                        BPaintVertex newVertex        = makeVertex(e);

                        switch (currBPaintObject.ObjectType)
                        {
                        case BPaintOpbjectType.Ellipse:
                            BPaintEllipse currEllipse = currBPaintObject as BPaintEllipse;
                            currEllipse.pt3      = newVertex;
                            currEllipse.EditMode = false;
                            break;

                        default:
                            break;
                        }

                        CurrPaintMode = BPaintMode.idle;
                    }
                }
                else if (CurrPaintMode == BPaintMode.hoveredAVertex)
                {
                    if (bpVertexUnderMousePointer != null)
                    {
                        BPaintVertex currVertex = bpVertexUnderMousePointer as BPaintVertex;
                        currVertex.Selected = true;
                        CurrPaintMode       = BPaintMode.movingAnElement;
                    }
                }

                StateHasChanged();
            }
        }
        public void onMouseUp(MouseEventArgs e)
        {
            if (CurrOperationalMode == OperationalMode.select)
            {
                switch (CurrSelectionMode)
                {
                case SelectionMode.movingAnElement:
                    CurrSelectionMode = SelectionMode.idle;

                    if (!bpSelectionRectangle.IsValid())
                    {
                        bpSelectionRectangle = null;
                        SelectionVerticesList.RemoveAll(x => true);
                    }

                    break;

                default:
                    break;
                }

                ProcessSelection();
                cmd_RefreshSVG();
                StateHasChanged();
            }
            else
            {
                switch (CurrPaintMode)
                {
                case BPaintMode.idle:
                    // this can be if the object to create need more than 2 vertices
                    switch (FigureCode)
                    {
                    case 5:
                        startEllipse(e);
                        break;

                    default:
                        break;
                    }

                    break;

                case BPaintMode.movingAnElement:
                    if (ObjectsList.Any(o => o.EditMode))
                    {
                        BPaintObject currObjectEditing = ObjectsList.Single(o => o.EditMode);
                        if (currObjectEditing.MandatoryVerticesCount > 2)
                        {
                            CurrPaintMode = BPaintMode.idle;
                        }
                        else
                        {
                            CurrPaintMode = BPaintMode.idle;
                        }
                    }
                    else
                    {
                        CurrPaintMode = BPaintMode.hoveredAVertex;
                        cmd_Clear_Editing();
                    }

                    ProcessSelection();
                    cmd_RefreshSVG();
                    break;

                case BPaintMode.drawing:
                    switch (FigureCode)
                    {
                    case 5:
                        continueEllipse(e);
                        break;

                    default:
                        break;
                    }

                    break;

                default:
                    break;
                }

                StateHasChanged();
            }
        }