protected void cmd_duplicate_object() { if (ObjectsList.Any()) { if (ObjectsList.Any(x => x.Selected)) { BPaintObject old_o = ObjectsList.Where(x => x.Selected).First(); foreach (var item in ObjectsList.Where(x => x.Selected)) { item.Selected = false; } BPaintObject new_o = BPaintFunctions.CopyObject <BPaintObject>(old_o); new_o.ObjectID = ObjectsList.Max(x => x.ObjectID) + 1; new_o.Selected = true; new_o.PositionChange.x += 20; new_o.PositionChange.y += 20; ObjectsList.Add(new_o); cmd_RefreshSVG(); } } }
protected override void BuildRenderTree(RenderTreeBuilder builder) { BPaintObject curr_object = (parent as CompBlazorPaint).ObjectsList.Single(x => x.ObjectID == Par_ID); int k = -1; builder.OpenElement(k++, "div"); builder.AddAttribute(k++, "id", "listitem" + Par_ID); // + Guid.NewGuid().ToString("d").Substring(1, 4)); builder.AddAttribute(k++, "style", "width:400px;max-height:26px;position:relative;margin:5px"); builder.OpenElement(k++, "span"); if (curr_object.Selected) { builder.AddAttribute(k++, "style", "position:absolute;top:0px;cursor:pointer;background-color:yellow;color:blue;border-style:solid;border-width:1px;border-color:red;"); } else { builder.AddAttribute(k++, "style", "position:absolute;top:0px;cursor:pointer;"); } builder.AddAttribute(k++, "onclick", e => Cmd_Item_Select(curr_object.ObjectID)); builder.AddContent(k++, curr_object.ObjectID + "_" + curr_object.ObjectType.ToString()); builder.CloseElement(); builder.CloseElement(); base.BuildRenderTree(builder); }
protected void cmd_delete_object() { if (ObjectsList.Any()) { if (ObjectsList.Any(x => x.Selected)) { ObjectsList.Remove(ObjectsList.Where(x => x.Selected).First()); BPaintObject b = ObjectsList.Single(i => i.ObjectID == ObjectsList.Min(x => x.ObjectID)); b.Selected = true; cmd_RefreshSVG(); } } }
protected void cmd_delete_object() { if (ObjectsList.Any()) { if (ObjectsList.Any(x => x.Selected)) { BPaintObject bpObjectToDelete = ObjectsList.Where(x => x.Selected).First(); foreach (BPaintVertex vertex in bpObjectToDelete.VerticesList) { VerticesList.Remove(vertex); } ObjectsList.Remove(bpObjectToDelete); BPaintObject b = ObjectsList.Single(i => i.ObjectID == ObjectsList.Min(x => x.ObjectID)); b.Selected = true; cmd_RefreshSVG(); } } }
public void cmd_onmouseup(UIMouseEventArgs e) { Curr_Mode = BPaintMode.none; if (ObjectsList.Any()) { BPaintObject o = ObjectsList.Single(x => x.EditMode == true); switch (o.ObjectType) { case BPaintOpbjectType.HandDraw: if (!(o as BPaintHandDraw).IsValid()) { ObjectsList.Remove(o); } break; case BPaintOpbjectType.Line: if (!(o as BPaintLine).IsValid()) { ObjectsList.Remove(o); } break; default: break; } } cmd_Clear_Editing(); cmd_RefreshSVG(); }
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(); } }