public ThingEditorCtrl(GraphicThing graphicThing) { this.graphicThing = graphicThing; InitContextMenu(); colorNormalSegment = Color.FromArgb(220, 220, 255); backgrndColor = Color.FromArgb(170, 170, 200); gridColor = Color.Black; textAreaContourColor = Color.FromArgb(100, 180, 180, 100); mainContourColor = Color.FromArgb(100, 220, 220, 255); dragging = false; flagShowPoints = true; flagShowGrid = true; flagDefineTextArea = false; distanceToLine = 10; distanceToTextArea = 10; decorationWidth = 100; gridSize = 16; saveGridSize = gridSize; gridStyle = EGridStyle.GrdLine; vScrollBar = null; hScrollBar = null; if (graphicThing != null) { outLines = new ArrayList(); if (graphicThing.Elements.Count > 0) { Contour elements = new Contour(graphicThing.FrameColor, graphicThing.Elements); outLines.Add(elements); elements.Changed += new OutlineChangeEventHandler(onContourChanged); } else { outLines = new ArrayList(); Contour contour = new Contour(mainContourColor, gridSize); outLines.Add(contour); contour.Changed += new OutlineChangeEventHandler(onContourChanged); } if (graphicThing.Decorations.Count > 0) { PolyLine polyLine = null; foreach (Element element in graphicThing.Decorations) { if (element is Line) { if (polyLine == null) { polyLine = new PolyLine(element as Line); } else { if (!polyLine.Add(element as Line)) // couldn't add because ends don't connect, start a new one. { outLines.Add(polyLine); polyLine.Changed += new OutlineChangeEventHandler(onContourChanged); polyLine = new PolyLine(element as Line); } } } } if (polyLine != null) { outLines.Add(polyLine); polyLine.Changed += new OutlineChangeEventHandler(onContourChanged); } } if (graphicThing.TextArea.Count > 0) { Contour textArea = new Contour(graphicThing.FrameColor, graphicThing.TextArea); outLines.Add(textArea); textArea.Changed += new OutlineChangeEventHandler(onContourChanged); } } RectangleF tempRect = getBoundingRect(); MinX = tempRect.Left; MinY = tempRect.Top; MaxX = tempRect.Right; MaxY = tempRect.Bottom; onShapeChanged(this, null); }
private void DefineTextArea() { flagDefineTextArea = !flagDefineTextArea; menuItemDefineTextArea.Visible = false; menuItemClearTextArea.Visible = true; ArrayList arr = new ArrayList(); arr = ((Outline)outLines[0] as Contour).getSegments(); RectangleF rect = ((Outline)outLines[0] as Contour).getBoundingRect(); float middleCenterRectX = (Math.Abs(rect.Right - rect.Left)) / 2.0F + rect.Left; float middleCenterRectY = (Math.Abs(rect.Bottom - rect.Top)) / 2.0F + rect.Top; PointF[] pStart = new PointF[arr.Count]; PointF[] pEnd = new PointF[arr.Count]; PointF[] point1 = new PointF[arr.Count]; PointF[] point2 = new PointF[arr.Count]; for (int i = 0; i < arr.Count; ++i) { Segment s = (Segment)arr[i]; if (s is BezierSegment) { if ((s as BezierSegment).points[1].X < middleCenterRectX) { point1[i].X = (s as BezierSegment).points[1].X + distanceToTextArea; } if ((s as BezierSegment).points[1].X >= middleCenterRectX) { point1[i].X = (s as BezierSegment).points[1].X - distanceToTextArea; } if ((s as BezierSegment).points[1].Y < middleCenterRectY) { point1[i].Y = (s as BezierSegment).points[1].Y + distanceToTextArea; } if ((s as BezierSegment).points[1].Y >= middleCenterRectY) { point1[i].Y = (s as BezierSegment).points[1].Y - distanceToTextArea; } if ((s as BezierSegment).points[2].X < middleCenterRectX) { point2[i].X = (s as BezierSegment).points[2].X + distanceToTextArea; } if ((s as BezierSegment).points[2].X >= middleCenterRectX) { point2[i].X = (s as BezierSegment).points[2].X - distanceToTextArea; } if ((s as BezierSegment).points[2].Y < middleCenterRectY) { point2[i].Y = (s as BezierSegment).points[2].Y + distanceToTextArea; } if ((s as BezierSegment).points[2].Y >= middleCenterRectY) { point2[i].Y = (s as BezierSegment).points[2].Y - distanceToTextArea; } } PointF tempStart = s.GetStartPoint(); PointF tempEnd = s.GetEndPoint(); if (tempStart.X < middleCenterRectX) { pStart[i].X = tempStart.X + distanceToTextArea; } if (tempStart.X >= middleCenterRectX) { pStart[i].X = tempStart.X - distanceToTextArea; } if (tempEnd.X < middleCenterRectX) { pEnd[i].X = tempEnd.X + distanceToTextArea; } if (tempEnd.X >= middleCenterRectX) { pEnd[i].X = tempEnd.X - distanceToTextArea; } if (tempStart.Y < middleCenterRectY) { pStart[i].Y = tempStart.Y + distanceToTextArea; } if (tempStart.Y >= middleCenterRectY) { pStart[i].Y = tempStart.Y - distanceToTextArea; } if (tempEnd.Y < middleCenterRectY) { pEnd[i].Y = tempEnd.Y + distanceToTextArea; } if (tempEnd.Y >= middleCenterRectY) { pEnd[i].Y = tempEnd.Y - distanceToTextArea; } } Contour contour = new Contour(textAreaContourColor, arr, pStart, point1, point2, pEnd); outLines.Add(contour); contour.Changed += new OutlineChangeEventHandler(onContourChanged); }
private void DefineTextArea() { flagDefineTextArea = !flagDefineTextArea; menuItemDefineTextArea.Visible = false; menuItemClearTextArea.Visible = true; ArrayList arr = new ArrayList(); arr = ((Outline)outLines[0] as Contour).getSegments(); RectangleF rect = ((Outline)outLines[0] as Contour).getBoundingRect(); float middleCenterRectX = (Math.Abs(rect.Right - rect.Left)) / 2.0F + rect.Left; float middleCenterRectY = (Math.Abs(rect.Bottom - rect.Top)) / 2.0F + rect.Top; PointF[] pStart = new PointF[arr.Count]; PointF[] pEnd = new PointF[arr.Count]; PointF[] point1 = new PointF[arr.Count]; PointF[] point2 = new PointF[arr.Count]; for (int i = 0; i < arr.Count; ++i) { Segment s = (Segment)arr[i]; if (s is BezierSegment) { if ((s as BezierSegment).points[1].X < middleCenterRectX) point1[i].X = (s as BezierSegment).points[1].X + distanceToTextArea; if ((s as BezierSegment).points[1].X >= middleCenterRectX) point1[i].X = (s as BezierSegment).points[1].X - distanceToTextArea; if ((s as BezierSegment).points[1].Y < middleCenterRectY) point1[i].Y = (s as BezierSegment).points[1].Y + distanceToTextArea; if ((s as BezierSegment).points[1].Y >= middleCenterRectY) point1[i].Y = (s as BezierSegment).points[1].Y - distanceToTextArea; if ((s as BezierSegment).points[2].X < middleCenterRectX) point2[i].X = (s as BezierSegment).points[2].X + distanceToTextArea; if ((s as BezierSegment).points[2].X >= middleCenterRectX) point2[i].X = (s as BezierSegment).points[2].X - distanceToTextArea; if ((s as BezierSegment).points[2].Y < middleCenterRectY) point2[i].Y = (s as BezierSegment).points[2].Y + distanceToTextArea; if ((s as BezierSegment).points[2].Y >= middleCenterRectY) point2[i].Y = (s as BezierSegment).points[2].Y - distanceToTextArea; } PointF tempStart = s.GetStartPoint(); PointF tempEnd = s.GetEndPoint(); if (tempStart.X < middleCenterRectX) pStart[i].X = tempStart.X + distanceToTextArea; if (tempStart.X >= middleCenterRectX) pStart[i].X = tempStart.X - distanceToTextArea; if (tempEnd.X < middleCenterRectX) pEnd[i].X = tempEnd.X + distanceToTextArea; if (tempEnd.X >= middleCenterRectX) pEnd[i].X = tempEnd.X - distanceToTextArea; if (tempStart.Y < middleCenterRectY) pStart[i].Y = tempStart.Y + distanceToTextArea; if (tempStart.Y >= middleCenterRectY) pStart[i].Y = tempStart.Y - distanceToTextArea; if (tempEnd.Y < middleCenterRectY) pEnd[i].Y = tempEnd.Y + distanceToTextArea; if (tempEnd.Y >= middleCenterRectY) pEnd[i].Y = tempEnd.Y - distanceToTextArea; } Contour contour = new Contour(textAreaContourColor, arr, pStart, point1, point2, pEnd); outLines.Add(contour); contour.Changed += new OutlineChangeEventHandler(onContourChanged); }
public void DeleteAllDecorations(object sender) { InitContextMenu(); if (HScrollBar != null) HScrollBar.Value = 0; if (VScrollBar != null) VScrollBar.Value = 0; scrollX = 0; scrollY = 0; outLines.Clear(); Contour contour = new Contour(mainContourColor, GridSize); outLines.Add(contour); contour.Changed += new OutlineChangeEventHandler(onContourChanged); changeContour(sender); }