예제 #1
0
파일: ShapeUtils.cs 프로젝트: stewmc/vixen
		/// <summary>
		/// Inflates the bounding rectangle by the width of the given line style.
		/// </summary>
		public static void InflateBoundingRectangle(ref Rectangle boundingRectangle, ILineStyle lineStyle)
		{
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			Geometry.AssertIsValid(boundingRectangle);
			if (lineStyle.LineWidth > 2) {
				int halfLineWidth = (int) Math.Ceiling(lineStyle.LineWidth/2f) - 1;
				boundingRectangle.Inflate(halfLineWidth, halfLineWidth);
			}
		}
예제 #2
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, ILineString line, ILineStyle style)
        {
            if (line == null || style == null)
                return;

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //TODO: Does not seems to add a single long line, but multiple line segments
            gp.AddLines(RenderUtil.CoordToPoint(line.Coordinates));

            if (style.Outlines != null)
                foreach(IOutline linestyle in style.Outlines)
                    RenderUtil.RenderOutline(engine, graphics, gp, linestyle);
        }
예제 #3
0
		/// <summary>
		/// Finds and returns the <see cref="T:System.Drawing.Drawing2D.CustomLineCap" /> for the given <see cref="T:Dataweb.NShape.ICapStyle" /> and <see cref="T:Dataweb.NShape.ILineStyle" />.
		/// </summary>
		public static CustomLineCap GetCustomLineCap(ICapStyle capStyle, ILineStyle lineStyle) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");

			// build CapKey
			CapKey capKey;
			capKey.CapStyle = capStyle;
			capKey.LineStyle = lineStyle;
			// get GraphicsPath for the CustomLineCap
			GraphicsPath capPath = GetCapPath(capStyle, lineStyle);
			// find/create CustomLineCap
			CustomLineCap customCap = null;
			capCache.TryGetValue(capKey, out customCap);
			if (customCap == null) {
				customCap = new CustomLineCap(null, capPath);
				customCap.StrokeJoin = lineStyle.LineJoin;
				customCap.WidthScale = 1;
				rectFBuffer = capPath.GetBounds();
				if (capStyle.CapShape == CapShape.ArrowOpen)
					customCap.BaseInset = 0;
				else 
					customCap.BaseInset = (float)(rectFBuffer.Height - (rectFBuffer.Height + rectFBuffer.Y));
				capCache.Add(capKey, customCap);
			}
			return customCap;
		}
예제 #4
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ILineStyle lineStyle) {
			Pen linePen = ToolCache.GetPen(lineStyle, null, null);
			int height = lineStyle.LineWidth + 2;
			bool scalePen = (height > previewBounds.Height);
			if (scalePen) {
				float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
				linePen.ScaleTransform(scale, scale);
			}
			gfx.DrawLine(linePen, previewBounds.X, previewBounds.Y + (previewBounds.Height / 2), previewBounds.Right, previewBounds.Y + (previewBounds.Height / 2));
			if (scalePen) linePen.ResetTransform();
		}
예제 #5
0
 protected BaseShape(Rect frame, ILineStyle lineStyle = null, IStyle fillStyle = null)
 {
     _frame    = frame;
     LineStyle = lineStyle ?? new LineStyle(Color.Empty, thickness: 0);
     FillStyle = fillStyle ?? new BaseStyle(Color.Empty);
 }
예제 #6
0
		private static void SetLineCap(Pen pen, ILineStyle lineStyle, ICapStyle capStyle, bool isStartCap) {
			if (pen == null) throw new ArgumentNullException("pen");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			LineCap cap = LineCap.Round;
			if (capStyle != null) {
				switch (capStyle.CapShape) {
					case CapShape.None:
						cap = LineCap.Round;
						break;
					default:
						cap = LineCap.Custom;
						break;
				}
			}
			if (isStartCap) {
				pen.StartCap = cap;
				if (cap == LineCap.Custom)
					pen.CustomStartCap = GetCustomLineCap(capStyle, lineStyle);
			} else {
				pen.EndCap = cap;
				if (cap == LineCap.Custom)
					pen.CustomEndCap = GetCustomLineCap(capStyle, lineStyle);
			}
		}
예제 #7
0
		/// <summary>
		/// Deletes all tools based on the given LineStyle.
		/// </summary>
		private static void NotifyLineStyleChanged(ILineStyle lineStyle) {
			Debug.Assert(lineStyle != null);

			// collect affected PenKeys
			List<PenKey> penKeys = new List<PenKey>();
			foreach (KeyValuePair<PenKey, Pen> item in penCache)
				if (item.Key.LineStyle == lineStyle)
					penKeys.Add(item.Key);
			// delete affected Pens
			foreach (PenKey penKey in penKeys) {
				Pen pen = penCache[penKey];
				penCache.Remove(penKey);
				pen.Dispose();
				pen = null;
			}
			penKeys.Clear();

			// collect affected CustomLineCaps
			List<CapKey> capKeys = new List<CapKey>();
			foreach (KeyValuePair<CapKey, CustomLineCap> item in capCache)
				if (item.Key.LineStyle == lineStyle)
					capKeys.Add(item.Key);
			// delete affected CustomLineCaps and their GraphicsPaths
			foreach (CapKey capKey in capKeys)
				NotifyCapStyleChanged(capKey.CapStyle);
			capKeys.Clear();
		}
예제 #8
0
		/// <ToBeCompleted></ToBeCompleted>
		public static Pen GetPen(ILineStyle lineStyle, ICapStyle startCapStyle, ICapStyle endCapStyle) {
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			
			PenKey penKey;
			penKey.LineStyle = lineStyle;
			penKey.StartCapStyle = startCapStyle;
			penKey.EndCapStyle = endCapStyle;

			Pen pen = null;
			penCache.TryGetValue(penKey, out pen);
			if (pen == null) {
				// If the corresponding pen was not found, create a new pen based on the given LineStyle
				pen = new Pen(GetColor(lineStyle.ColorStyle, lineStyle.ColorStyle.ConvertToGray), lineStyle.LineWidth);
				// "PenAlignment.Inset" does not draw exactly along the outline of the shape and
				// causes GraphicsPath.Widen(Pen pen) to produce strance results
				//pen.Alignment = PenAlignment.Inset;
				pen.LineJoin = lineStyle.LineJoin;
				pen.DashCap = lineStyle.DashCap;
				if (lineStyle.DashType == DashType.Solid)
					pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
				else {
					pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
					pen.DashPattern = lineStyle.DashPattern;
				}
				// Create LineCaps
				SetLineCap(pen, lineStyle, startCapStyle, true);
				SetLineCap(pen, lineStyle, endCapStyle, false);

				// Add created pen to the PenCache
				penCache.Add(penKey, pen);
			}
			return pen;
		}
예제 #9
0
        public static Polyline DrawParallelArrow(Polyline Shape, Object Tag, Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project, ILineStyle LineStyle, Layer Layer)
        {
            Polyline parallel = (Polyline)Project.ShapeTypes["Polyline"].CreateInstance();

            parallel.StartCapStyle      = Project.Design.CapStyles.OpenArrow;
            parallel.LineStyle          = LineStyle;
            parallel.Tag                = Tag;
            parallel.SecurityDomainName = 'B';

            Point p0 = Shape.GetControlPointPosition(ControlPointId.FirstVertex);
            Point p1 = Shape.GetControlPointPosition(ControlPointId.LastVertex);

            Point n0 = Shape.CalcNormalVector(p0);
            Point n1 = Shape.CalcNormalVector(p1);

            parallel.MoveControlPointTo(ControlPointId.FirstVertex, n0.X, n0.Y, ResizeModifiers.None);
            parallel.MoveControlPointTo(ControlPointId.LastVertex, n1.X, n1.Y, ResizeModifiers.None);

            Display.Diagram.Shapes.Add(parallel);

            Display.Diagram.AddShapeToLayers(parallel, Layer.Id);

            Project.Repository.Insert((Shape)parallel, Display.Diagram);

            return(parallel);
        }
예제 #10
0
        public static Shape DrawLabel(int Height, int Width, int X, int Y, IFillStyle FillStyle, ILineStyle LineStyle,
                                      String Caption, Object Tag, Char SecurityDomain, Dataweb.NShape.WinFormsUI.Display Display,
                                      Dataweb.NShape.Project Project, Layer Layer)
        {
            Dataweb.NShape.GeneralShapes.Label shape;
            shape        = (Dataweb.NShape.GeneralShapes.Label)Project.ShapeTypes["Label"].CreateInstance();
            shape.Height = Height;
            shape.Width  = Width;

            shape.X = X;

            shape.Y = Y;

            shape.FillStyle = FillStyle;

            shape.SetCaptionText(0, Caption);

            shape.CharacterStyle = Project.Design.CharacterStyles.Heading3;

            shape.Tag = Tag;

            shape.SecurityDomainName = SecurityDomain;

            Display.Diagram.Shapes.Add(shape, 10);

            Display.Diagram.AddShapeToLayers(shape, Layer.Id);

            Project.Repository.Insert((Shape)shape, Display.Diagram);

            return(shape);
        }
예제 #11
0
        public static Shape DrawBox(int Height, int Width, int X, int Y, IFillStyle FillStyle, ILineStyle LineStyle, ICharacterStyle CharacterStyle, IParagraphStyle ParagraphStyle,
                                    String Caption, Object Tag, Char SecurityDomain, Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project)
        {
            Box shape;

            shape        = (Box)Project.ShapeTypes["Box"].CreateInstance();
            shape.Height = Height;
            shape.Width  = Width;

            shape.X = X;

            shape.Y = Y;

            shape.FillStyle = FillStyle;

            shape.CharacterStyle = CharacterStyle;

            shape.ParagraphStyle = ParagraphStyle;

            shape.SetCaptionText(0, Caption);

            shape.Tag = Tag;

            shape.SecurityDomainName = SecurityDomain;

            Display.Diagram.Shapes.Add(shape);

            Project.Repository.Insert((Shape)shape, Display.Diagram);

            return(shape);
        }
예제 #12
0
        private ShapeDef ReadShapeDef(SWFDataTypeReader shapeReader, Tag format, bool withStyle, IFillStyle[] fillStyles, ILineStyle[] lineStyles)
        {
            ShapeDef shapeDef = new ShapeDef();

            /* Shapes either don't have fill styles (Font glyphs), they come with a bunch of fill styles
             * (Regular shapes) or are preceeded by fill styles which are passed into this method
             * (Morph shapes). Could probably be tidier... */

            if (fillStyles != null)
            {
                shapeDef.FillStyles.AddRange(fillStyles);
            }

            if (lineStyles != null)
            {
                shapeDef.LineStyles.AddRange(lineStyles);
            }

            if (withStyle)
            {
                shapeDef.FillStyles.AddRange(this.ReadFillStyleArray(shapeReader, format));
                shapeReader.Align8();
                shapeDef.LineStyles.AddRange(this.ReadLineStyleArray(shapeReader, format));
                shapeReader.Align8();
            }

            /* Read the shape stuff... */

            int fillBits = (int)shapeReader.ReadUBits(4);
            int lineBits = (int)shapeReader.ReadUBits(4);

            this.ReadShapeRecordsInto(shapeDef, shapeReader, ref fillBits, ref lineBits, format);

            return shapeDef;
        }
예제 #13
0
		/// <ToBeCompleted></ToBeCompleted>
		protected virtual void DrawGluePointLine(Graphics graphics, ILineStyle lineStyle, ICapStyle capStyle) {
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			Pen pen = ToolCache.GetPen(LineStyle, null, capStyle);
			DrawGluePointLine(graphics, pen);
		}
예제 #14
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, ILineString line, ILineStyle style)
        {
            if (line == null || style == null)
            {
                return;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //TODO: Does not seems to add a single long line, but multiple line segments
            gp.AddLines(RenderUtil.CoordToPoint(line.Coordinates));

            if (style.Outlines != null)
            {
                foreach (IOutline linestyle in style.Outlines)
                {
                    RenderUtil.RenderOutline(engine, graphics, gp, linestyle);
                }
            }
        }
예제 #15
0
		/// <summary>
		/// Returns the untransformed axis aligned bounding rectangle of the line cap defined by the given styles.
		/// </summary>
		public static Rectangle GetCapBounds(ICapStyle capStyle, ILineStyle lineStyle, float angleDeg) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			Rectangle result = Rectangle.Empty;
			GetCapPoints(capStyle, lineStyle, ref pointFBuffer);

			// Transform cap points
			matrix.Reset();
			matrix.RotateAt(angleDeg + 90, Point.Empty);
			// Scale GraphicsPath up for correcting the automatic scaling that is applied to
			// LineCaps by GDI+ when altering the LineWidth of the pen
			matrix.Scale(lineStyle.LineWidth, lineStyle.LineWidth);
			matrix.TransformPoints(pointFBuffer);

			Geometry.CalcBoundingRectangle(pointFBuffer, out result);
			return result;
		}
예제 #16
0
        public static CircularArc ConnectShapesArc(Shape Start, Shape End, ICapStyle StartCapStyle, ICapStyle EndCapStyle, Object Tag,
                                                   Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project, ILineStyle LineStyle, Layer Layer)
        {
            CircularArc arc = (CircularArc)Project.ShapeTypes["CircularArc"].CreateInstance();

            arc.LineStyle          = LineStyle;
            arc.Tag                = Tag;
            arc.SecurityDomainName = 'B';


            Display.Diagram.Shapes.Add(arc);
            arc.StartCapStyle = StartCapStyle;
            arc.EndCapStyle   = EndCapStyle;
            arc.Connect(ControlPointId.FirstVertex, Start, ControlPointId.Reference);
            arc.Connect(ControlPointId.LastVertex, End, ControlPointId.Reference);

            Point firstPt = arc.GetControlPointPosition(ControlPointId.FirstVertex);
            Point lastPt  = arc.GetControlPointPosition(ControlPointId.LastVertex);
            Point dstPos  = Point.Empty;

            dstPos.X = ((firstPt.X + lastPt.X) / 2) + 1;
            dstPos.Y = ((firstPt.Y + lastPt.Y) / 2) + 1;

            arc.InsertVertex(ControlPointId.LastVertex, dstPos.X, dstPos.Y);

            Display.Diagram.AddShapeToLayers(arc, Layer.Id);

            Project.Repository.Insert((Shape)arc, Display.Diagram);

            return(arc);
        }
예제 #17
0
		/// <ToBeCompleted></ToBeCompleted>
		public static void GetCapPoints(ICapStyle capStyle, ILineStyle lineStyle, ref PointF[] capPoints) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			
			GraphicsPath capPath = GetCapPath(capStyle, lineStyle);
			if (capPoints == null)
				capPoints = new PointF[capPath.PointCount];
			else if (capPoints.Length != capPath.PointCount)
				Array.Resize(ref capPoints, capPath.PointCount);
			Array.Copy(capPath.PathPoints, capPoints, capPoints.Length);
		}
예제 #18
0
        public static Shape DrawCircle(int Diameter, int X, int Y, IFillStyle FillStyle, ILineStyle LineStyle,
                                       String Caption, Object Tag, Char SecurityDomain, Dataweb.NShape.WinFormsUI.Display Display,
                                       Dataweb.NShape.Project Project, Layer Layer)
        {
            CircleBase shape;

            shape          = (CircleBase)Project.ShapeTypes["Circle"].CreateInstance();
            shape.Diameter = Diameter;

            shape.X = X;

            shape.Y = Y;

            shape.FillStyle = FillStyle;

            shape.SetCaptionText(0, Caption);

            shape.CharacterStyle = Project.Design.CharacterStyles.Heading3;

            shape.Tag = Tag;

            shape.SecurityDomainName = SecurityDomain;


            if (Display.InvokeRequired)
            {
                Display.BeginInvoke(new MethodInvoker(() => AddShape(Display, Project, shape)));
            }
            else
            {
                Display.Diagram.Shapes.Add(shape);
                Display.Diagram.AddShapeToLayers(shape, Layer.Id);

                Project.Repository.Insert((Shape)shape, Display.Diagram);
            }


            return(shape);
        }
예제 #19
0
		/// <ToBeCompleted></ToBeCompleted>
		public static Brush GetBrush(IColorStyle colorStyle, ILineStyle lineStyle) {
			if (colorStyle == null) throw new ArgumentNullException("colorStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");
			if (colorStyle == ColorStyle.Empty)
				return GetBrush(lineStyle.ColorStyle);
			else return GetBrush(colorStyle);
		}
예제 #20
0
        public static void HighlightShapeByTagString(String Tag, Dataweb.NShape.WinFormsUI.Display Display, ILineStyle LineStyle, Layer Layer)
        {
            Shape shape = Display.Diagram.Shapes.Where(s => s.Tag.ToString() == Tag && Display.Diagram.Layers.GetLayer(Display.Diagram.GetShapeLayers(s)).Id == Layer.Id).SingleOrDefault();

            shape.LineStyle = LineStyle;
        }
예제 #21
0
		private static GraphicsPath GetCapPath(ICapStyle capStyle, ILineStyle lineStyle) {
			if (capStyle == null) throw new ArgumentNullException("capStyle");
			if (lineStyle == null) throw new ArgumentNullException("lineStyle");

			// build CapKey
			CapKey capKey;
			capKey.CapStyle = capStyle;
			capKey.LineStyle = lineStyle;
			// find/create CapPath
			GraphicsPath capPath;
			capPathCache.TryGetValue(capKey, out capPath);
			if (capPath == null) {
				CalcCapShape(ref capPath, capStyle.CapShape, capStyle.CapSize);
				// Scale GraphicsPath down for correcting the automatic scaling that is applied to
				// LineCaps by GDI+ when altering the LineWidth of the pen
				matrix.Reset();
				matrix.Scale(1f / lineStyle.LineWidth, 1f / lineStyle.LineWidth);
				capPath.Transform(matrix);
				capPathCache.Add(capKey, capPath);
			}
			return capPath;
		}
예제 #22
0
        public static void DimUnhighlightedShapes(Dataweb.NShape.WinFormsUI.Display Display, ILineStyle HighlightLineStyle, ILineStyle DimLineStyle, IFillStyle DimFillStyle, Layer Layer)
        {
            List <Shape> shapes = Display.Diagram.Shapes.Where(s => s.LineStyle != HighlightLineStyle && Display.Diagram.Layers.GetLayer(Display.Diagram.GetShapeLayers(s)).Id == Layer.Id).ToList();

            foreach (Shape shape in shapes)
            {
                shape.LineStyle = DimLineStyle;

                if (shape.Type.Name == "Circle")
                {
                    ((Circle)shape).FillStyle = DimFillStyle;
                }
            }
        }
예제 #23
0
 /// <summary>
 /// Draws the calculated GraphicsPath. If the GaphicsPath is not calculated yet, UpdateDrawCache will be called.
 /// </summary>
 protected void DrawPath(Graphics graphics, ILineStyle lineStyle, IFillStyle fillStyle)
 {
     UpdateDrawCache();
     if (fillStyle != null) {
         Brush brush = ToolCache.GetTransformedBrush(FillStyle, boundingRectangleUnrotated, Center, Angle);
         graphics.FillPath(brush, Path);
     }
     if (lineStyle != null) {
         Pen pen = ToolCache.GetPen(lineStyle, null, null);
         graphics.DrawPath(pen, Path);
     }
 }
예제 #24
0
 public Ellipse(Rect frame, ILineStyle lineStyle = null, IStyle fillStyle = null)
     : base(frame, lineStyle, fillStyle)
 {
 }