private void DrawFillStyleItem(IFillStyle fillStyle, DrawItemEventArgs e) { Brush fillBrush = ToolCache.GetBrush(fillStyle); // Transform if (fillBrush is LinearGradientBrush) { float srcGradLen = ((LinearGradientBrush)fillBrush).Rectangle.Width; //float dstGradLen = previewRect.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle)); float dstGradLen = (float)Math.Sqrt((previewRect.Width * previewRect.Width) + (previewRect.Height * previewRect.Height)); float scale = dstGradLen / srcGradLen; ((LinearGradientBrush)fillBrush).ResetTransform(); ((LinearGradientBrush)fillBrush).TranslateTransform(previewRect.X, previewRect.Y); ((LinearGradientBrush)fillBrush).ScaleTransform(scale, scale); ((LinearGradientBrush)fillBrush).RotateTransform(fillStyle.GradientAngle); } else if (fillBrush is TextureBrush) { float scaleX = (float)previewRect.Width / ((TextureBrush)fillBrush).Image.Width; float scaleY = (float)previewRect.Height / ((TextureBrush)fillBrush).Image.Height; ((TextureBrush)fillBrush).ResetTransform(); ((TextureBrush)fillBrush).TranslateTransform(previewRect.X, previewRect.Y); ((TextureBrush)fillBrush).ScaleTransform(scaleX, scaleY); } // Draw if (fillBrush != Brushes.Transparent) { e.Graphics.FillRectangle(fillBrush, previewRect); } e.Graphics.DrawRectangle(ItemBorderPen, previewRect); e.Graphics.DrawRectangle(Pens.Black, previewRect); e.Graphics.DrawString(fillStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter); }
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); }
public static void Compare(IStyleSet designA, IStyleSet designB, int version) { foreach (ICapStyle styleA in designA.CapStyles) { ICapStyle styleB = designB.CapStyles[styleA.Name]; Compare(styleA, styleB, version); } foreach (ICharacterStyle styleA in designA.CharacterStyles) { ICharacterStyle styleB = designB.CharacterStyles[styleA.Name]; Compare(styleA, styleB, version); } foreach (IColorStyle styleA in designA.ColorStyles) { IColorStyle styleB = designB.ColorStyles[styleA.Name]; Compare(styleA, styleB, version); } foreach (IFillStyle styleA in designA.FillStyles) { IFillStyle styleB = designB.FillStyles[styleA.Name]; Compare(styleA, styleB, version); } foreach (ILineStyle styleA in designA.LineStyles) { ILineStyle styleB = designB.LineStyles[styleA.Name]; Compare(styleA, styleB, version); } foreach (IParagraphStyle styleA in designA.ParagraphStyles) { IParagraphStyle styleB = designB.ParagraphStyles[styleA.Name]; Compare(styleA, styleB, version); } }
public LineStyle2(SwfReader r, ShapeType shapeType) { this.Width = r.GetUI16(); this.StartCapStyle = (CapStyle)r.GetBits(2); this.JoinStyle = (JoinStyle)r.GetBits(2); this.HasFillFlag = r.GetBit(); this.NoHScaleFlag = r.GetBit(); this.NoVScaleFlag = r.GetBit(); this.PixelHintingFlag = r.GetBit(); r.GetBits(5); // skip this.NoClose = r.GetBit(); this.EndCapStyle = (CapStyle)r.GetBits(2); if (this.JoinStyle == JoinStyle.MiterJoin) { this.MiterLimitFactor = (float)((r.GetByte() / 0x100) + r.GetByte()); } if (this.HasFillFlag) { this.FillStyle = FillStyleArray.ParseFillStyle2(r, shapeType); } else { this.Color = new RGBA(r.GetByte(), r.GetByte(), r.GetByte(), r.GetByte()); } }
private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IFillStyle fillStyle) { Brush fillBrush = ToolCache.GetBrush(fillStyle); // Transform if (fillBrush is LinearGradientBrush) { float srcGradLen = ((LinearGradientBrush)fillBrush).Rectangle.Width; float dstGradLen = previewBounds.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle)); float scale = dstGradLen / srcGradLen; ((LinearGradientBrush)fillBrush).ResetTransform(); ((LinearGradientBrush)fillBrush).ScaleTransform(scale, scale); ((LinearGradientBrush)fillBrush).RotateTransform(fillStyle.GradientAngle); } else if (fillBrush is TextureBrush) { if (fillStyle.ImageLayout == ImageLayoutMode.Stretch) { float scaleX = (float)previewBounds.Width / ((TextureBrush)fillBrush).Image.Width; float scaleY = (float)previewBounds.Height / ((TextureBrush)fillBrush).Image.Height; ((TextureBrush)fillBrush).ScaleTransform(scaleX, scaleY); } else { float scale = Geometry.CalcScaleFactor(((TextureBrush)fillBrush).Image.Width, ((TextureBrush)fillBrush).Image.Height, previewBounds.Width, previewBounds.Height); ((TextureBrush)fillBrush).ScaleTransform(scale, scale); ((TextureBrush)fillBrush).TranslateTransform((((TextureBrush)fillBrush).Image.Width * scale) / 2, (((TextureBrush)fillBrush).Image.Height * scale) / 2); } } // Draw if (fillBrush != Brushes.Transparent) { gfx.FillRectangle(fillBrush, previewBounds); } }
/// <summary> /// Deletes all tools based on the given FillStyle. /// </summary> private static void NotifyFillStyleChanged(IFillStyle fillStyle) { Debug.Assert(fillStyle != null); BrushKey brushKey; brushKey.FillStyle = fillStyle; brushKey.Image = null; // Delete affected brushes while (_brushCache.ContainsKey(brushKey)) { Brush brush = _brushCache[brushKey]; _brushCache.Remove(brushKey); brush.Dispose(); brush = null; } // Delete affected ImageAttributes while (_imageAttribsCache.ContainsKey(brushKey)) { ImageAttributes imgAttribs = _imageAttribsCache[brushKey]; _imageAttribsCache.Remove(brushKey); imgAttribs.Dispose(); imgAttribs = null; } }
public static void Compare(IStyleSet savedDesign, IStyleSet loadedDesign, int version) { foreach (ICapStyle savedStyle in savedDesign.CapStyles) { ICapStyle loadedStyle = loadedDesign.CapStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } foreach (ICharacterStyle savedStyle in savedDesign.CharacterStyles) { ICharacterStyle loadedStyle = loadedDesign.CharacterStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } foreach (IColorStyle savedStyle in savedDesign.ColorStyles) { IColorStyle loadedStyle = loadedDesign.ColorStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } foreach (IFillStyle savedStyle in savedDesign.FillStyles) { IFillStyle loadedStyle = loadedDesign.FillStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } foreach (ILineStyle savedStyle in savedDesign.LineStyles) { ILineStyle loadedStyle = loadedDesign.LineStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } foreach (IParagraphStyle savedStyle in savedDesign.ParagraphStyles) { IParagraphStyle loadedStyle = loadedDesign.ParagraphStyles[savedStyle.Name]; Compare(savedStyle, loadedStyle, version); } }
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); }
/// <override></override> protected override void InitializeToDefault(IStyleSet styleSet) { base.InitializeToDefault(styleSet); FillStyle = styleSet.FillStyles.Transparent; Width = 40; Height = 70; }
void Initialize( IFillStyle style, int width, int height) { ID = (style?? FillStyles.Black).GetBrushKey(width, height); Width = width; Height = height; this.style = style; Length = GetSize(); Data = Fill(); }
public ShapeTag(string Id, object Object, ILineStyle LineStyle, IFillStyle FillStyle, ICapStyle CapStyle) { this.Id = Id; this.Object = Object; this.LineStyle = LineStyle; this.FillStyle = FillStyle; this.CapStyle = CapStyle; }
public static Shape RenderNode(Neo4j.Driver.V1.INode Node, Dataweb.NShape.WinFormsUI.Display Display) { //Globals Project project = Display.Project; Diagram diagram = Display.Diagram; Design design = project.Design; Layer layer = diagram.Layers["NETWORK"]; // //Defaults Point position = new Point(diagram.Width / 2, diagram.Height / 2); int diameter = 100; IFillStyle fill = design.FillStyles.Transparent; ILineStyle stroke = design.LineStyles.Normal; string caption = ""; // //Node Labels if (Node.Labels.Contains("Node")) { diameter = 600; fill = design.FillStyles.Blue; stroke = design.LineStyles.None; caption = Node.Properties["Node_Name"].As <string>(); } else if (Node.Labels.Contains("Pseudonode")) { diameter = 60; fill = design.FillStyles.Black; stroke = design.LineStyles.None; } // Shape exists = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Node.Id.As <string>(), null, stroke, fill, Display.Project.Design.CapStyles.None), "Circle", Display); if (exists != null) { //Update Node -- TODO: Move this somewhere else ((Circle)exists).Diameter = diameter; ((Circle)exists).FillStyle = fill; exists.LineStyle = stroke; // return(exists); } else { return(NShapeHelper.DrawCircle(diameter, position.X, position.Y, fill, stroke, caption, new display.UI.ShapeTag(Node.Id.As <string>(), Node, stroke, fill, Display.Project.Design.CapStyles.None), 'B', Display, project, layer)); } }
public static IBrush CreateInstance( IFillStyle style, int width, int height) { var ID = (style ?? FillStyles.Black).GetBrushKey(width, height); if (!Factory.Get(ID, out IBrush b, ObjType.Buffer)) { var brush = new Brush(); brush.Initialize(style, width, height); return brush; } return b; }
/// <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); } }
public static void Compare(IFillStyle savedStyle, IFillStyle loadedStyle, int version) { CompareBaseStyle(savedStyle, loadedStyle, version); Compare(savedStyle.BaseColorStyle, loadedStyle.BaseColorStyle, version); Compare(savedStyle.AdditionalColorStyle, loadedStyle.AdditionalColorStyle, version); if (version > 2) { Assert.AreEqual <bool>(savedStyle.ConvertToGrayScale, loadedStyle.ConvertToGrayScale); } Assert.AreEqual <FillMode>(savedStyle.FillMode, loadedStyle.FillMode); Assert.AreEqual <System.Drawing.Drawing2D.HatchStyle>(savedStyle.FillPattern, loadedStyle.FillPattern); Assert.AreEqual <short>(savedStyle.GradientAngle, loadedStyle.GradientAngle); CompareNamedImage(savedStyle.Image, loadedStyle.Image, version); Assert.AreEqual <float>(savedStyle.ImageGammaCorrection, loadedStyle.ImageGammaCorrection); Assert.AreEqual <ImageLayoutMode>(savedStyle.ImageLayout, loadedStyle.ImageLayout); Assert.AreEqual <byte>(savedStyle.ImageTransparency, loadedStyle.ImageTransparency); }
public IImage[] GetImages() { ListSet <IImage> images = new ListSet <IImage>(); if (this.StartShape == null || this.EndShape == null) { return(new IImage[0]); } foreach (ShapeDef sd in new ShapeDef[] { this.StartShape, this.EndShape }) { foreach (IFillStyle fs in sd.FillStyles) { if (fs.Bitmap != null) { images.AddIfNotAlredy(fs.Bitmap); } } foreach (IShapeRecord sr in sd.Records) { if (sr is StyleChange) { StyleChange sc = (StyleChange)sr; IFillStyle fs = sc.FillStyle0; if (fs != null && fs.Bitmap != null) { images.AddIfNotAlredy(fs.Bitmap); } fs = sc.FillStyle1; if (fs != null && fs.Bitmap != null) { images.AddIfNotAlredy(fs.Bitmap); } } } } return(images.ToArray()); }
public static void Compare(IFillStyle styleA, IFillStyle styleB, int version) { if (styleA == null && styleB == null) { return; } CompareBaseStyle(styleA, styleB, version); Compare(styleA.BaseColorStyle, styleB.BaseColorStyle, version); Compare(styleA.AdditionalColorStyle, styleB.AdditionalColorStyle, version); if (version >= 3) { Assert.AreEqual <bool>(styleA.ConvertToGrayScale, styleB.ConvertToGrayScale); } Assert.AreEqual <FillMode>(styleA.FillMode, styleB.FillMode); Assert.AreEqual <System.Drawing.Drawing2D.HatchStyle>(styleA.FillPattern, styleB.FillPattern); Assert.AreEqual <short>(styleA.GradientAngle, styleB.GradientAngle); CompareNamedImage(styleA.Image, styleB.Image, version); CompareFloat(styleA.ImageGammaCorrection, styleB.ImageGammaCorrection); Assert.AreEqual <ImageLayoutMode>(styleA.ImageLayout, styleB.ImageLayout); Assert.AreEqual <byte>(styleA.ImageTransparency, styleB.ImageTransparency); }
public static Shape DrawCircleRadialTree(int Diameter, int LayerShapeCount, int LayerShapeIndex, int LayerDistanceFromCenter, Point LayerCenter, IFillStyle FillStyle, ILineStyle LineStyle, String Caption, Object Tag, Char SecurityDomain, Dataweb.NShape.WinFormsUI.Display Display, Dataweb.NShape.Project Project, Layer Layer) { Point DiagramCenter = new Point(Display.Diagram.Width / 2, Display.Diagram.Height / 2); Point result = new Point(); double angle = 0; if (LayerShapeCount == 1) { angle = 2 * Math.PI / LayerShapeCount; //between 0 and 2 * PI (~6.2832), angle is in radians if (LayerCenter.X < DiagramCenter.X) { angle += Math.PI; } } if (LayerShapeCount > 1) { angle = 2 * Math.PI / LayerShapeCount * LayerShapeIndex; //between 0 and 2 * PI (~6.2832), angle is in radians if (LayerCenter.X < DiagramCenter.X) { angle = (Math.PI / LayerShapeCount * LayerShapeIndex) + (0.5 * Math.PI); } if (LayerCenter.X > DiagramCenter.X) { angle = ((Math.PI / LayerShapeCount) * LayerShapeIndex) + (1.5 * Math.PI); } } result.Y = (int)Math.Round(LayerCenter.Y + LayerDistanceFromCenter * Math.Sin(angle)); result.X = (int)Math.Round(LayerCenter.X + LayerDistanceFromCenter * Math.Cos(angle)); return(DrawCircle(Diameter, result.X, result.Y, FillStyle, LineStyle, Caption, Tag, SecurityDomain, Display, Project, Layer)); }
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); }
/// <summary> /// Deletes all tools based on the given FillStyle. /// </summary> private static void NotifyFillStyleChanged(IFillStyle fillStyle) { Debug.Assert(fillStyle != null); BrushKey brushKey; brushKey.FillStyle = fillStyle; brushKey.Image = null; while (brushCache.ContainsKey(brushKey)) { Brush brush = brushCache[brushKey]; brushCache.Remove(brushKey); brush.Dispose(); brush = null; } while (imageAttribsCache.ContainsKey(brushKey)) { ImageAttributes imgAttribs = imageAttribsCache[brushKey]; imageAttribsCache.Remove(brushKey); imgAttribs.Dispose(); imgAttribs = null; } }
public static IFillStyle ParseFillStyle2(SwfReader r, ShapeType shapeType) { IFillStyle result = null; FillType fsType = (FillType)r.GetByte(); bool useAlpha = shapeType > ShapeType.DefineShape2; switch (fsType) { case FillType.Solid: result = new SolidFill(r, useAlpha); break; case FillType.Linear: result = new Gradient(r, fsType, useAlpha); break; case FillType.Radial: result = new Gradient(r, fsType, useAlpha); break; case FillType.Focal: result = null; //throw new NotSupportedException("Currently FillType.Focal is not supported"); break; case FillType.RepeatingBitmap: case FillType.ClippedBitmap: case FillType.NSRepeatingBitmap: case FillType.NSClippedBitmap: uint charId = r.GetUI16(); Matrix bmpMatrix = new Matrix(r); result = new BitmapFill(charId, bmpMatrix, fsType); break; } return(result); }
/// <summary> /// Finds and returns the <see cref="T:System.Drawing.Brush" /> for the given <see cref="T:Dataweb.NShape.IFillStyle" />. /// The <see cref="T:System.Drawing.Brush" /> will be translated, scaled and rotated. /// </summary> /// <param name="fillStyle">Specifies the <see cref="T:Dataweb.NShape.IFillStyle" /> the brush belongs to.</param> /// <param name="unrotatedBounds">Specifies the axis aligned bounding rectangle of the unrotated shape.</param> /// <param name="center">Specifies the rotation center.</param> /// <param name="angle">Specifies the rotation angle in tenths of degrees.</param> public static Brush GetTransformedBrush(IFillStyle fillStyle, Rectangle unrotatedBounds, Point center, int angle) { if (fillStyle == null) { throw new ArgumentNullException("fillStyle"); } Brush brush = GetBrush(fillStyle); float angleDeg = Geometry.TenthsOfDegreeToDegrees(angle); if (brush is LinearGradientBrush) { GdiHelpers.TransformLinearGradientBrush((LinearGradientBrush)brush, fillStyle.GradientAngle, unrotatedBounds, center, angleDeg); } else if (brush is PathGradientBrush) { GdiHelpers.TransformPathGradientBrush((PathGradientBrush)brush, unrotatedBounds, center, angleDeg); } else if (brush is TextureBrush) { GdiHelpers.TransformTextureBrush((TextureBrush)brush, fillStyle.ImageLayout, unrotatedBounds, center, angleDeg); } return(brush); }
public virtual IBrush newBrush(IFillStyle style, int width, int height) => Brush.CreateInstance(style ?? FillStyles.Black, width, height);
/// <summary> /// Creates a brush from the given <see cref="T:Dataweb.NShape.IFillStyle"/>. /// Depending of the fill mode of the fill style, the result can be a <see cref="T:System.Drawing.SolidBrush"/>, /// a <see cref="T:System.Drawing.Drawing2D.HatchBrush"/>, a a <see cref="T:System.Drawing.Drawing2D.LinerGradientBrush"/> or /// a <see cref="T:System.Drawing.TextureBrush"/>. /// </summary> public static Brush GetBrush(IFillStyle fillStyle) { if (fillStyle == null) { throw new ArgumentNullException("fillStyle"); } BrushKey brushKey; brushKey.FillStyle = fillStyle; brushKey.Image = null; Brush brush = null; if (!_brushCache.TryGetValue(brushKey, out brush)) { switch (fillStyle.FillMode) { case FillMode.Solid: brush = new SolidBrush(GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale)); break; case FillMode.Pattern: brush = new HatchBrush(fillStyle.FillPattern, GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale), GetColor(fillStyle.AdditionalColorStyle, fillStyle.ConvertToGrayScale)); break; case FillMode.Gradient: _rectBuffer.X = 0; _rectBuffer.Y = 0; _rectBuffer.Width = 100; _rectBuffer.Height = 100; brush = new LinearGradientBrush(_rectBuffer, GetColor(fillStyle.AdditionalColorStyle, fillStyle.ConvertToGrayScale), GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale), fillStyle.GradientAngle); break; case FillMode.Image: if (NamedImage.IsNullOrEmpty(fillStyle.Image)) { brush = new SolidBrush(Color.Transparent); } else { // Get ImageAttributes ImageAttributes imgAttribs = null; if (!_imageAttribsCache.TryGetValue(brushKey, out imgAttribs)) { imgAttribs = GdiHelpers.GetImageAttributes(fillStyle.ImageLayout, fillStyle.ImageGammaCorrection, fillStyle.ImageTransparency, fillStyle.ConvertToGrayScale); _imageAttribsCache.Add(brushKey, imgAttribs); } // Create Brush _rectBuffer.X = 0; _rectBuffer.Y = 0; _rectBuffer.Width = fillStyle.Image.Width; _rectBuffer.Height = fillStyle.Image.Height; brush = new TextureBrush(fillStyle.Image.Image, _rectBuffer, imgAttribs); } break; default: throw new NShapeUnsupportedValueException(fillStyle.FillMode); } // Add created brush to the BrushCache _brushCache.Add(brushKey, brush); } return(brush); }
/// <ToBeCompleted></ToBeCompleted> public static Brush GetBrush(IFillStyle fillStyle) { if (fillStyle == null) throw new ArgumentNullException("fillStyle"); BrushKey brushKey; brushKey.FillStyle = fillStyle; brushKey.Image = null; Brush brush = null; brushCache.TryGetValue(brushKey, out brush); if (brush == null) { switch (fillStyle.FillMode) { case FillMode.Solid: brush = new SolidBrush(GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale)); break; case FillMode.Pattern: brush = new HatchBrush(fillStyle.FillPattern, GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale), GetColor(fillStyle.AdditionalColorStyle, fillStyle.ConvertToGrayScale)); break; case FillMode.Gradient: rectBuffer.X = 0; rectBuffer.Y = 0; rectBuffer.Width = 100; rectBuffer.Height = 100; brush = new LinearGradientBrush(rectBuffer, GetColor(fillStyle.AdditionalColorStyle, fillStyle.ConvertToGrayScale), GetColor(fillStyle.BaseColorStyle, fillStyle.ConvertToGrayScale), fillStyle.GradientAngle); break; case FillMode.Image: if (NamedImage.IsNullOrEmpty(fillStyle.Image)) brush = new SolidBrush(Color.Transparent); else { // First, get ImageAttributes ImageAttributes imgAttribs = null; imageAttribsCache.TryGetValue(brushKey, out imgAttribs); if (imgAttribs == null) { imgAttribs = GdiHelpers.GetImageAttributes(fillStyle.ImageLayout, fillStyle.ImageGammaCorrection, fillStyle.ImageTransparency, fillStyle.ConvertToGrayScale); imageAttribsCache.Add(brushKey, imgAttribs); } // Create Brush rectBuffer.X = 0; rectBuffer.Y = 0; rectBuffer.Width = fillStyle.Image.Width; rectBuffer.Height = fillStyle.Image.Height; brush = new TextureBrush(fillStyle.Image.Image, rectBuffer, imgAttribs); } break; default: throw new NShapeUnsupportedValueException(fillStyle.FillMode); } // add created brush to the BrushCache if (brushCache.ContainsKey(brushKey)) brushCache[brushKey] = brush; else brushCache.Add(brushKey, brush); } return brush; }
public static void SetAllCirclesFillStyle(Dataweb.NShape.WinFormsUI.Display Display, IFillStyle FillStyle, Project Project) { List <Shape> shapes = Display.Diagram.Shapes.Where(s => s.Type == Project.ShapeTypes["Circle"]).ToList(); foreach (Shape shape in shapes) { ((Circle)shape).FillStyle = FillStyle; } }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is IPlanarShape) { IPlanarShape src = (IPlanarShape)source; // Copy regular properties this.angle = src.Angle; // Copy templated properties this.privateFillStyle = (Template != null && src.FillStyle == ((IPlanarShape)Template.Shape).FillStyle) ? null : src.FillStyle; } }
public static Shape RenderNode(yggdrasil2.Topology.Node.Node Node, Dataweb.NShape.WinFormsUI.Display Display) { //Globals Project project = Display.Project; Diagram diagram = Display.Diagram; Design design = project.Design; Layer layer = diagram.Layers["NETWORK"]; // //Defaults Point position = new Point(diagram.Width / 2, diagram.Height / 2); int diameter = 100; IFillStyle fill = design.FillStyles.Transparent; ILineStyle stroke = design.LineStyles.Normal; string caption = ""; // //Node Labels if (!Node.IsPseudonode) { diameter = 600; fill = design.FillStyles.Blue; stroke = design.LineStyles.None; caption = Node.NodeName; } else { diameter = 60; fill = design.FillStyles.Black; stroke = design.LineStyles.None; } // if (!Node.OperationalStatus) { fill = design.FillStyles.Red; } Shape exists = NShapeHelper.FindShapeByShapeTag(new display.UI.ShapeTag(Node.Id.As <string>(), null), "Circle", Display); if (exists != null) { try { //Update Node -- TODO: Move this somewhere else ((Circle)exists).Diameter = diameter; ((Circle)exists).FillStyle = fill; ((Circle)exists).LineStyle = stroke; ((display.UI.ShapeTag)exists.Tag).LineStyle = stroke; // } catch (Exception) { System.Threading.Thread.Sleep(1); RenderNode(Node, Display); } return(exists); } else { return(NShapeHelper.DrawCircle(diameter, position.X, position.Y, fill, stroke, caption, new display.UI.ShapeTag(Node.Id.As <string>(), Node, stroke, fill, Display.Project.Design.CapStyles.None), 'B', Display, project, layer)); } }
/// <override></override> public override void MakePreview(IStyleSet styleSet) { base.MakePreview(styleSet); charStyle = styleSet.GetPreviewStyle(CharacterStyle); paragraphStyle = styleSet.GetPreviewStyle(ParagraphStyle); fillStyle = styleSet.GetPreviewStyle(FillStyle); }
private void DrawFillStyleItem(IFillStyle fillStyle, DrawItemEventArgs e) { Brush fillBrush = ToolCache.GetBrush(fillStyle); // Transform if (fillBrush is LinearGradientBrush) { float srcGradLen = ((LinearGradientBrush) fillBrush).Rectangle.Width; //float dstGradLen = previewRect.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle)); float dstGradLen = (float) Math.Sqrt((previewRect.Width*previewRect.Width) + (previewRect.Height*previewRect.Height)); float scale = dstGradLen/srcGradLen; ((LinearGradientBrush) fillBrush).ResetTransform(); ((LinearGradientBrush) fillBrush).TranslateTransform(previewRect.X, previewRect.Y); ((LinearGradientBrush) fillBrush).ScaleTransform(scale, scale); ((LinearGradientBrush) fillBrush).RotateTransform(fillStyle.GradientAngle); } else if (fillBrush is TextureBrush) { float scaleX = (float) previewRect.Width/((TextureBrush) fillBrush).Image.Width; float scaleY = (float) previewRect.Height/((TextureBrush) fillBrush).Image.Height; ((TextureBrush) fillBrush).ResetTransform(); ((TextureBrush) fillBrush).TranslateTransform(previewRect.X, previewRect.Y); ((TextureBrush) fillBrush).ScaleTransform(scaleX, scaleY); } // Draw if (fillBrush != Brushes.Transparent) e.Graphics.FillRectangle(fillBrush, previewRect); e.Graphics.DrawRectangle(ItemBorderPen, previewRect); e.Graphics.DrawRectangle(Pens.Black, previewRect); e.Graphics.DrawString(fillStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter); }
/// <override></override> protected internal override void InitializeToDefault(IStyleSet styleSet) { base.InitializeToDefault(styleSet); w = image.Width; h = image.Height; Fit(0, 0, 100, 100); charStyle = styleSet.CharacterStyles.Normal; paragraphStyle = styleSet.ParagraphStyles.Title; fillStyle = styleSet.FillStyles.Transparent; }
/// <override></override> protected override void LoadFieldsCore(IRepositoryReader reader, int version) { base.LoadFieldsCore(reader, version); fillStyle = reader.ReadFillStyle(); charStyle = reader.ReadCharacterStyle(); paragraphStyle = reader.ReadParagraphStyle(); string txt = reader.ReadString(); if (caption == null) caption = new Caption(txt); else caption.Text = txt; w = reader.ReadInt32(); h = reader.ReadInt32(); }
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; } } }
/// <override></override> protected override void ProcessExecModelPropertyChange(IModelMapping propertyMapping) { switch (propertyMapping.ShapePropertyId) { case PropertyIdAngle: Angle = propertyMapping.GetInteger(); break; case PropertyIdFillStyle: // assign private stylebecause if the style matches the template's style, it would not be assigned. privateFillStyle = (IFillStyle)propertyMapping.GetStyle(); Invalidate(); break; default: base.ProcessExecModelPropertyChange(propertyMapping); break; } }
public static void SetCircleFillStyleByTagString(String Tag, Dataweb.NShape.WinFormsUI.Display Display, IFillStyle FillStyle, Project Project) { List <Shape> shapes = Display.Diagram.Shapes.Where(s => s.Tag.ToString().Contains(Tag) && s.Type == Project.ShapeTypes["Circle"]).ToList(); foreach (Shape shape in shapes) { ((Circle)shape).FillStyle = FillStyle; } }
/// <override></override> protected internal override void InitializeToDefault(IStyleSet styleSet) { base.InitializeToDefault(styleSet); Debug.Assert(image is Metafile); metafileDataSize = 20; metafileData = new byte[metafileDataSize]; LineStyle = styleSet.LineStyles.Normal; FillStyle = styleSet.FillStyles.Red; }
/// <override></override> public override void MakePreview(IStyleSet styleSet) { base.MakePreview(styleSet); privateFillStyle = styleSet.GetPreviewStyle(FillStyle); }
public static IBrush newBrush(this IFactory factory, IFillStyle style, float width, float height) => factory.newBrush(style, width.Ceiling(), height.Ceiling());
/// <override></override> protected override void LoadFieldsCore(IRepositoryReader reader, int version) { base.LoadFieldsCore(reader, version); angle = reader.ReadInt32(); privateFillStyle = reader.ReadFillStyle(); }
/// <summary> /// Finds and returns the <see cref="T:System.Drawing.Brush" /> for the given <see cref="T:Dataweb.NShape.IFillStyle" />. /// The <see cref="T:System.Drawing.Brush" /> will be translated, scaled and rotated. /// </summary> /// <param name="fillStyle">Specifies the <see cref="T:Dataweb.NShape.IFillStyle" /> the brush belongs to.</param> /// <param name="unrotatedBounds">Specifies the axis aligned bounding rectangle of the unrotated shape.</param> /// <param name="center">Specifies the rotation center.</param> /// <param name="angle">Specifies the rotation angle in tenths of degrees.</param> public static Brush GetTransformedBrush(IFillStyle fillStyle, Rectangle unrotatedBounds, Point center, int angle) { if (fillStyle == null) throw new ArgumentNullException("fillStyle"); Brush brush = GetBrush(fillStyle); float angleDeg = Geometry.TenthsOfDegreeToDegrees(angle); if (brush is LinearGradientBrush) GdiHelpers.TransformLinearGradientBrush((LinearGradientBrush)brush, fillStyle.GradientAngle, unrotatedBounds, center, angleDeg); else if (brush is PathGradientBrush) GdiHelpers.TransformPathGradientBrush((PathGradientBrush)brush, unrotatedBounds, center, angleDeg); else if (brush is TextureBrush) GdiHelpers.TransformTextureBrush((TextureBrush)brush, fillStyle.ImageLayout, unrotatedBounds, center, angleDeg); return brush; }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is IPlanarShape) { IPlanarShape src = (IPlanarShape)source; // Copy regular properties this.angle = src.Angle; // Copy templated properties this.fillStyle = (Template != null && src.FillStyle == ((IPlanarShape)Template.Shape).FillStyle) ? null : src.FillStyle; } if (source is ICaptionedShape) { // Copy as many captions as possible. Leave the rest untouched. int ownCaptionCnt = CaptionCount; int srcCaptionCnt = ((ICaptionedShape)source).CaptionCount; int cnt = Math.Min(ownCaptionCnt, srcCaptionCnt); for (int i = 0; i < cnt; ++i) { this.SetCaptionText(i, ((ICaptionedShape)source).GetCaptionText(i)); this.SetCaptionCharacterStyle(i, ((ICaptionedShape)source).GetCaptionCharacterStyle(i)); this.SetCaptionParagraphStyle(i, ((ICaptionedShape)source).GetCaptionParagraphStyle(i)); } } if (source is ImageBasedShape) { w = ((ImageBasedShape)source).w; h = ((ImageBasedShape)source).h; if (((ImageBasedShape)source).image != null) image = (Image)((ImageBasedShape)source).image.Clone(); } else { Rectangle r = source.GetBoundingRectangle(true); Fit(r.X, r.Y, r.Width, r.Height); } }
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; }
private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IFillStyle fillStyle) { Brush fillBrush = ToolCache.GetBrush(fillStyle); // Transform if (fillBrush is LinearGradientBrush) { float srcGradLen = ((LinearGradientBrush)fillBrush).Rectangle.Width; float dstGradLen = previewBounds.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle)); float scale = dstGradLen / srcGradLen; ((LinearGradientBrush)fillBrush).ResetTransform(); ((LinearGradientBrush)fillBrush).ScaleTransform(scale, scale); ((LinearGradientBrush)fillBrush).RotateTransform(fillStyle.GradientAngle); } else if (fillBrush is TextureBrush) { if (fillStyle.ImageLayout == ImageLayoutMode.Stretch) { float scaleX = (float)previewBounds.Width / ((TextureBrush)fillBrush).Image.Width; float scaleY = (float)previewBounds.Height / ((TextureBrush)fillBrush).Image.Height; ((TextureBrush)fillBrush).ScaleTransform(scaleX, scaleY); } else { float scale = Geometry.CalcScaleFactor(((TextureBrush)fillBrush).Image.Width, ((TextureBrush)fillBrush).Image.Height, previewBounds.Width, previewBounds.Height); ((TextureBrush)fillBrush).ScaleTransform(scale, scale); ((TextureBrush)fillBrush).TranslateTransform((((TextureBrush)fillBrush).Image.Width * scale) / 2, (((TextureBrush)fillBrush).Image.Height * scale) / 2); } } // Draw if (fillBrush != Brushes.Transparent) gfx.FillRectangle(fillBrush, previewBounds); }
public bool Equals(IFillStyle other) => other.Key == Key;