Ejemplo n.º 1
0
        private SimplifiedGeometryShape(List<GeometryFigure> figures, StrokeStyle strokeStyle, float strokeWidth)
        {
            if (figures.Count < 1)
            {
                polygons = null;
                return;
            }

            polygons = figures[0].Outline(strokeStyle, strokeWidth, out tree);

            var currentFigures = new List<List<Vector2>>();
            for (int i = 1; i < figures.Count; i++)
            {
                currentFigures.AddRange(figures[i].Outline(strokeStyle, strokeWidth, out tree));
            }

            polygons = ClipperHelper.Combine(polygons,
                    currentFigures,
                    FillMode.Alternate,
                    FillMode.Winding,
                    CombineMode.Union,
                    out tree);

            Triangulated = false;
        }
Ejemplo n.º 2
0
 void MainWindow_Load(object sender, EventArgs e)
 {
     this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
     StrokeStyleProperties ssp = new StrokeStyleProperties(LineCapStyle.Round, LineCapStyle.Round,
         LineCapStyle.Round, LineJoin.Round, 10, DashStyle.Solid, 0);
     this._strokeStyle = this._factory.CreateStrokeStyle(ssp, null);
     this._renderTarget = this._factory.CreateWindowRenderTarget(this);
     this.Resize += new EventHandler(MainWindow_Resize);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeometryRenderUnit" /> class.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="stroke">The stroke.</param>
 /// <param name="fill">The fill.</param>
 /// <param name="strokeWidth">The stroke width.</param>
 /// <param name="strokeStyle">The stroke style.</param>
 public GeometryRenderUnit(Geometry geometry, Brush stroke, Brush fill, float strokeWidth, StrokeStyle strokeStyle)
 {
     this.geometry = geometry;
     this.fill = fill;
     this.stroke = stroke;
     this.strokeWidth = strokeWidth;
     this.strokeStyle = strokeStyle;
     var raw = geometry.GetBounds();
     this.bounds = new RectangleF(raw.Left, raw.Top, raw.Right - raw.Left, raw.Bottom - raw.Top);
 }
Ejemplo n.º 4
0
        public static List<List<Vector2>> Outline(List<Vector2> polygon, FillMode fillMode, bool closed, StrokeStyle strokeStyle, float strokeWidth, out PolyTree tree)
        {
            List<List<Vector2>> simplified = Clipper.SimplifyPolygon(polygon, fillMode.ToPolyFillType());

            Offsetter.Clear();
            Offsetter.MiterLimit = strokeStyle.MiterLimit;
            Offsetter.AddPaths(simplified, (JoinType)strokeStyle.LineJoin, closed ? EndType.etClosedLine : strokeStyle.CapStyle.ToEndType());

            tree = new PolyTree();
            Offsetter.Execute(ref tree, strokeWidth / 2);
            return Clipper.ClosedPathsFromPolyTree(tree);
        }
Ejemplo n.º 5
0
        void MainWindow_Load(object sender, EventArgs e)
        {
            DirectWriteFactory f = DirectWriteFactory.Create(DirectWriteFactoryType.Shared);
            _textFormat = f.CreateTextFormat("Verdana", null, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 110, null);
            _textFormat.ParagraphAlignment = ParagraphAlignment.Far;
            _textFormat.TextAlignment = TextAlignment.Center;

            this.ClientSize = new System.Drawing.Size(600, 600);
            this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);

            this._renderTarget = this._factory.CreateWindowRenderTarget(this, PresentOptions.None, RenderTargetProperties.Default);
            AntialiasMode amode = this._renderTarget.AntialiasMode;
            TextAntialiasMode tamode = this._renderTarget.TextAntialiasMode;
            this._strokeBrush = this._renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Cyan, 1));
            this._strokeStyle = this._factory.CreateStrokeStyle(new StrokeStyleProperties(LineCapStyle.Flat,
                LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0), null);

            this.Resize += new EventHandler(MainWindow_Resize);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting
        /// unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (this.strokeStyle != null)
            {
                this.strokeStyle.Dispose();
            }

            this.geometry.Dispose();

            this.fill = null;
            this.geometry = null;
            this.stroke = null;
            this.strokeStyle = null;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Defines this stroke as a new kind of stroke.
 /// </summary>
 /// <param name="style"></param>
 public void CreateNew(StrokeStyle style)
 {
     switch (style)
     {
         case StrokeStyle.Simple:
             _innerStroke = new SimpleStroke();
             break;
         case StrokeStyle.Catographic:
             _innerStroke = new CartographicStroke();
             break;
     }
 }
Ejemplo n.º 8
0
 public override void DevIndepRelease()
 {
     SliderThumb_StrokeStyle = null;
 }
Ejemplo n.º 9
0
 /// <summary>	
 /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. 	
 /// </summary>	
 /// <param name="point">The point to test for containment. </param>
 /// <param name="strokeWidth">The thickness of the stroke to apply. </param>
 /// <param name="strokeStyle">The style of stroke to apply. </param>
 /// <param name="transform">The transform to apply to the stroked geometry.  </param>
 /// <returns>When this method returns, contains a boolean value set to true if the geometry's stroke contains the specified point; otherwise, false. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::StrokeContainsPoint([None] D2D1_POINT_2F point,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] BOOL* contains)</unmanaged>
 public bool StrokeContainsPoint(DrawingPointF point, float strokeWidth, StrokeStyle strokeStyle, Matrix3x2 transform)
 {
     return StrokeContainsPoint(point, strokeWidth, strokeStyle, transform, FlatteningTolerance);            
 }
Ejemplo n.º 10
0
 /// <summary>	
 /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. 	
 /// </summary>	
 /// <param name="point">The point to test for containment. </param>
 /// <param name="strokeWidth">The thickness of the stroke to apply. </param>
 /// <param name="strokeStyle">The style of stroke to apply. </param>
 /// <returns>When this method returns, contains a boolean value set to true if the geometry's stroke contains the specified point; otherwise, false. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::StrokeContainsPoint([None] D2D1_POINT_2F point,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] BOOL* contains)</unmanaged>
 public bool StrokeContainsPoint(DrawingPoint point, float strokeWidth, StrokeStyle strokeStyle)
 {
     return StrokeContainsPoint(new DrawingPointF(point.X, point.Y), strokeWidth, strokeStyle);            
 }
Ejemplo n.º 11
0
 public static SimplifiedGeometryShape FromOutlines(List<GeometryFigure> figures, StrokeStyle strokeStyle, float strokeWidth)
 {
     return new SimplifiedGeometryShape(figures, strokeStyle, strokeWidth);
 }
Ejemplo n.º 12
0
 public override void DevIndepRelease()
 {
     Ruler_TextFormat         = null;
     Ruler_MeasureStrokeStyle = null;
 }
Ejemplo n.º 13
0
        Connector DrawConnector(Node Src, Node Trgt, Port srcport, Port trgtport, SegmentType type, Color strokeColor, StrokeStyle style, DecoratorType decorator, Color fillColor, Color strokeFill, float sw)
        {
            var Conn = new Connector();

            Conn.SourceNode                           = Src;
            Conn.TargetNode                           = Trgt;
            Conn.SourcePort                           = srcport;
            Conn.TargetPort                           = trgtport;
            Conn.SegmentType                          = type;
            Conn.TargetDecoratorType                  = decorator;
            Conn.TargetDecoratorStyle.Fill            = fillColor;
            Conn.TargetDecoratorStyle.Stroke          = strokeFill;
            Conn.Style.StrokeWidth                    = 1 * DiagramUtility.factor;
            Conn.Style.StrokeBrush                    = new SolidBrush(strokeColor);
            Conn.Style.StrokeStyle                    = style;
            Conn.TargetDecoratorStyle.Width           = sw * DiagramUtility.factor;
            Conn.TargetDecoratorStyle.StrokeThickness = 1 * DiagramUtility.factor;
            return(Conn);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeometryRenderUnit" /> class.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="fill">The fill.</param>
        /// <param name="strokeWidth">The stroke width.</param>
        /// <param name="strokeStyle">The stroke style.</param>
        public GeometryRenderUnit(Geometry geometry, Brush stroke, Brush fill, float strokeWidth, StrokeStyle strokeStyle)
        {
            this.geometry    = geometry;
            this.fill        = fill;
            this.stroke      = stroke;
            this.strokeWidth = strokeWidth;
            this.strokeStyle = strokeStyle;
            var raw = geometry.GetBounds();

            this.bounds = new RectangleF(raw.Left, raw.Top, raw.Right - raw.Left, raw.Bottom - raw.Top);
        }
Ejemplo n.º 15
0
 /// <summary>	
 /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. 	
 /// </summary>	
 /// <param name="point">The point to test for containment. </param>
 /// <param name="strokeWidth">The thickness of the stroke to apply. </param>
 /// <param name="strokeStyle">The style of stroke to apply. </param>
 /// <returns>When this method returns, contains a boolean value set to true if the geometry's stroke contains the specified point; otherwise, false. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::StrokeContainsPoint([None] D2D1_POINT_2F point,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] BOOL* contains)</unmanaged>
 public bool StrokeContainsPoint(Point point, float strokeWidth, StrokeStyle strokeStyle)
 {
     return StrokeContainsPoint(new Vector2(point.X, point.Y), strokeWidth, strokeStyle);            
 }
Ejemplo n.º 16
0
 /// <summary>	
 /// Gets the bounds of the geometry after it has been widened by the specified stroke width and style and transformed by the specified matrix.	
 /// </summary>	
 /// <param name="strokeWidth">The amount by which to widen the geometry by stroking its outline. </param>
 /// <param name="strokeStyle">The style of the stroke that widens the geometry. </param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.  </param>
 /// <returns>When this method returns, contains the bounds of the widened geometry. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::GetWidenedBounds([None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] D2D1_RECT_F* bounds)</unmanaged>
 public RectangleF GetWidenedBounds(float strokeWidth, StrokeStyle strokeStyle, float flatteningTolerance)
 {
     return GetWidenedBounds(strokeWidth, strokeStyle, null, flatteningTolerance);
 }
Ejemplo n.º 17
0
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);
            this._textFormat = DirectWriteFactory.CreateTextFormat("Verdana", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 10.5f);
            this._textFormat.TextAlignment = TextAlignment.Center;

            float[] dashes = new float[] { 1, 1, 2, 3, 5 };
            this._strokeStyle = factory.CreateStrokeStyle(
                new StrokeStyleProperties(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Round, 10, DashStyle.Custom, 0),
                dashes);
            CreateGeometries(factory);
        }
Ejemplo n.º 18
0
 /// <summary>	
 /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. 	
 /// </summary>	
 /// <param name="point">The point to test for containment. </param>
 /// <param name="strokeWidth">The thickness of the stroke to apply. </param>
 /// <param name="strokeStyle">The style of stroke to apply. </param>
 /// <returns>When this method returns, contains a boolean value set to true if the geometry's stroke contains the specified point; otherwise, false. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::StrokeContainsPoint([None] D2D1_POINT_2F point,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] BOOL* contains)</unmanaged>
 public bool StrokeContainsPoint(DrawingPointF point, float strokeWidth, StrokeStyle strokeStyle)
 {
     return StrokeContainsPoint(point, strokeWidth, strokeStyle, null, FlatteningTolerance);
 }
        private void LoadDeviceIndependentResource()
        {
            // Create the D2D Factory
            // This really needs to be set to type MultiThreaded if rendering is to be performed by multiple threads,
            // such as if used in a control similar to DirectControl sample control where rendering is done by a dedicated render thread,
            // especially if multiple such controls are used in one application, but also when multiple applications use D2D Factories.
            //
            // In this sample - SingleThreaded type is used because rendering is only done by the main/UI thread and only when required
            // (when the surface gets invalidated) making the risk of synchronization problems - quite low.
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);

            // Create the DWrite Factory
            dwriteFactory = DWriteFactory.CreateFactory();

            // Create the WIC Factory
            wicFactory = ImagingFactory.Create();

            TextBoxStroke = d2dFactory.CreateStrokeStyle(
                new StrokeStyleProperties(
                    CapStyle.Flat, CapStyle.Flat, CapStyle.Round,
                    LineJoin.Miter, 5.0f, DashStyle.Dash, 3f),
                    null);

        }
Ejemplo n.º 20
0
 /// <summary>	
 /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. 	
 /// </summary>	
 /// <param name="point">The point to test for containment. </param>
 /// <param name="strokeWidth">The thickness of the stroke to apply. </param>
 /// <param name="strokeStyle">The style of stroke to apply. </param>
 /// <param name="transform">The transform to apply to the stroked geometry.  </param>
 /// <param name="flatteningTolerance">The numeric accuracy with which the precise geometric path and path intersection is calculated. Points missing the stroke by less than the tolerance are still considered inside.  Smaller values produce more accurate results but cause slower execution. </param>
 /// <returns>When this method returns, contains a boolean value set to true if the geometry's stroke contains the specified point; otherwise, false. You must allocate storage for this parameter. </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::StrokeContainsPoint([None] D2D1_POINT_2F point,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] float flatteningTolerance,[Out] BOOL* contains)</unmanaged>
 public bool StrokeContainsPoint(DrawingPoint point, float strokeWidth, StrokeStyle strokeStyle, Matrix3x2 transform, float flatteningTolerance)
 {
     return StrokeContainsPoint(new DrawingPointF(point.X, point.Y), strokeWidth, strokeStyle, transform, flatteningTolerance);
 }
Ejemplo n.º 21
0
        Connector DrawConnector(Node Src, Node Trgt, Port srcport, Port trgtport, SegmentType type, UIColor strokeColor, StrokeStyle style, DecoratorType decorator, UIColor fillColor, UIColor strokeFill, float sw)
        {
            var Conn = new Connector(Src, Trgt);

            Conn.SourcePort                       = srcport;
            Conn.TargetPort                       = trgtport;
            Conn.SegmentType                      = type;
            Conn.TargetDecoratorType              = decorator;
            Conn.TargetDecoratorStyle.Fill        = fillColor;
            Conn.TargetDecoratorStyle.StrokeColor = strokeFill;
            Conn.Style.StrokeWidth                = 1;
            Conn.Style.StrokeBrush                = new SolidBrush(strokeColor);
            Conn.Style.StrokeStyle                = style;
            Conn.TargetDecoratorStyle.Size        = sw;
            Conn.TargetDecoratorStyle.StrokeWidth = 1;
            return(Conn);
        }