/// <summary>
		/// 将给定的几何图形组合并为一个组。
		/// </summary>
		/// <param name="geometies">要合并集合图形组。</param>
		/// <returns>合并得到的集合图形组。</returns>
		public static GeometryGroup Merge(params GeometryGroup[] geometies)
		{
			int[] idx = new int[geometies.Length];
			for (int i = 0; i < geometies.Length; i++)
			{
				if (i == 0)
				{
					idx[i] = geometies[i].SourceGeometryCount;
				}
				else
				{
					idx[i] = idx[i - 1] + geometies[i].SourceGeometryCount;
				}
			}
			Geometry[] geoms = new Geometry[idx[idx.Length - 1]];
			for (int i = 0; i < geometies.Length; i++)
			{
				if (i == 0)
				{
					geometies[i].GetSourceGeometry().CopyTo(geoms, 0);
				}
				else
				{
					geometies[i].GetSourceGeometry().CopyTo(geoms, idx[i - 1]);
				}
			}
			return new GeometryGroup(geometies[0].Factory, FillMode.Winding, geoms);
		}
Example #2
0
 internal ComplexLayer(D2D1.RenderTarget target, ref DXM.RawRectangleF clipBounds, D2D1.Geometry geometryPath,
                       float opacity)
 {
     _target   = target;
     _geometry = geometryPath;
     target.PushLayer(clipBounds, geometryPath, opacity);
 }
Example #3
0
        public List<Pos3Norm3VertexSDX> GetVertices(D2DGeometry geometry, float height = 24.0f)
        {
            List<Pos3Norm3VertexSDX> vertices = new List<Pos3Norm3VertexSDX>();

            //Empty mesh
            if (geometry == null)
            {
                Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX();
                vertices.Add(zero);
                vertices.Add(zero);
                vertices.Add(zero);
                return vertices;
            }

            D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance);

            D2DGeometry outlinedGeometry = this.OutlineGeometry(flattenedGeometry);

            //Add snap here

            ExtrudingSink sink = new ExtrudingSink(vertices, height);

            outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink);

            outlinedGeometry.Tessellate(sink);

            flattenedGeometry.Dispose();
            outlinedGeometry.Dispose();

            return vertices;
        }
Example #4
0
        public void AddEllipse(float x, float y, float width, float height)
        {
            CloseSink();
            var ellipse = new sd.Ellipse(new s.Vector2(x + width / 2, y + height / 2), width / 2, height / 2);

            geometries.Add(new sd.EllipseGeometry(SDFactory.D2D1Factory, ellipse));
            control = null;
        }
        /// <summary>
        /// A very simple collision check between this geometry and the given one.
        /// </summary>
        /// <param name="other">The other geometry.</param>
        /// <param name="otherTransform">The matrix which is used to transform the given geometry bevore checking.</param>
        public bool IntersectsWith(Geometry2DResourceBase other, Matrix3x2 otherTransform)
        {
            this.EnsureNotNullOrDisposed("this");
            other.EnsureNotNullOrDisposed(nameof(other));

            D2D.Geometry geometryThis  = this.GetGeometry();
            D2D.Geometry geometryOther = other.GetGeometry();

            return(geometryThis.Compare(geometryOther, otherTransform.ToDXMatrix(), 1f) != D2D.GeometryRelation.Disjoint);
        }
Example #6
0
        public IEnumerable <Pos3Norm3VertexSDX> GetVertices(D2DGeometry geometry, float height = 1f)
        {
            List <Pos3Norm3VertexSDX> vertices = new List <Pos3Norm3VertexSDX>();

            //Empty mesh
            if (geometry == null)
            {
                Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX();
                vertices.Add(zero);
                vertices.Add(zero);
                vertices.Add(zero);
                return(vertices);
            }

            if (height > 0)
            {
                D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance);
                D2DGeometry outlinedGeometry  = this.OutlineGeometry(flattenedGeometry);

                //Add snap here

                var sink = new ExtrudingSink(vertices, height);

                outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink);

                var bounds  = flattenedGeometry.GetBounds();
                var scaling = Math.Min(1 / Math.Abs(bounds.Bottom - bounds.Top), 1);

                outlinedGeometry.Tessellate(sink);

                outlinedGeometry.Dispose();
                flattenedGeometry.Dispose();

                sink.Dispose();

                return(vertices.Select(v => v.Scale(scaling).AssignTexCd()).Reverse());
            }
            else
            {
                D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance);

                //Add snap here
                var sink = new FlatSink(vertices);

                var bounds  = flattenedGeometry.GetBounds();
                var scaling = Math.Min(1 / Math.Abs(bounds.Bottom - bounds.Top), 1);

                flattenedGeometry.Tessellate(sink);

                flattenedGeometry.Dispose();
                sink.Dispose();

                return(vertices.Select(v => v.Scale(scaling).AssignTexCd()).Reverse());
            }
        }
Example #7
0
        private static IDisposable Create(D2D1.RenderTarget target, D2D1.Geometry geometryPath, float opacity, bool clipElement, ref DXM.RawRectangleF clipBounds)
        {
            var complexClip = geometryPath != null || opacity < 1.0f;
            var simpleClip  = !complexClip && clipElement;

            return(complexClip
        ? new ComplexLayer(target, ref clipBounds, geometryPath, opacity)
        : simpleClip
          ? new SimpleLayer(target, ref clipBounds)
          : (IDisposable)null);
        }
Example #8
0
        private D2DGeometry FlattenGeometry(D2DGeometry geometry, float tolerance)
        {
            PathGeometry path = new PathGeometry(this.factory);

            using (GeometrySink sink = path.Open())
            {
                geometry.Simplify(GeometrySimplificationOption.Lines, tolerance, sink);
                sink.Close();
            }
            return(path);
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayerParameters1"/> struct.
 /// </summary>
 /// <param name="contentBounds">The content bounds.</param>
 /// <param name="geometryMask">The geometry mask.</param>
 /// <param name="maskAntialiasMode">The mask antialias mode.</param>
 /// <param name="maskTransform">The mask transform.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="opacityBrush">The opacity brush.</param>
 /// <param name="layerOptions">The layer options.</param>
 public LayerParameters1(RawRectangleF contentBounds, Geometry geometryMask, AntialiasMode maskAntialiasMode, RawMatrix3x2 maskTransform, float opacity, Brush opacityBrush, LayerOptions1 layerOptions)
     : this()
 {
     ContentBounds = contentBounds;
     geometricMask_ = geometryMask.NativePointer;
     MaskAntialiasMode = maskAntialiasMode;
     MaskTransform = maskTransform;
     Opacity = opacity;
     opacityBrush_ = opacityBrush.NativePointer;
     LayerOptions = layerOptions;
 }
Example #10
0
        private D2DGeometry FlattenGeometry(D2DGeometry geometry, float tolerance)
        {
            PathGeometry path = new PathGeometry(this.factory);

            GeometrySink sink = path.Open();

            geometry.Simplify(GeometrySimplificationOption.Lines, tolerance, sink);

            sink.Close();

            return path;
        }
Example #11
0
        private D2DGeometry OutlineGeometry(D2DGeometry geometry)
        {
            PathGeometry path = new PathGeometry(this.factory);

            using (GeometrySink sink = path.Open())
            {
                geometry.Outline(sink);
                sink.Close();
            }

            return(path);
        }
Example #12
0
        public void Tessellate(DxGeometry resolvedSource, ITessellationSink sink, float tolerance)
        {
            Contract.Requires(resolvedSource != null);
            Contract.Requires(sink != null);
            Contract.Requires(Check.IsPositive(tolerance));

            _Sink = sink;

            _Sink.Begin();

            resolvedSource.Tessellate(tolerance, this);

            _Sink = null;
        }
        public D2D.GeometryRealization CreateSymbol(ShowSymbol sym, DW.TextFormat format)
        {
            D2D.GeometryRealization cached_geo = null;
            bool result = symbol_cache.TryGetValue(sym, out cached_geo);

            if (!result)
            {
                const int        margin = 2;
                D2D.Geometry     geo    = null;
                DW.TextLayout    layout = null;
                D2D.PathGeometry path   = null;
                DW.TextMetrics   metrics;
                D2D.StrokeStyle  stroke = null;
                switch (sym)
                {
                case ShowSymbol.FullSpace:
                    layout  = new DW.TextLayout(this._DWFactory, " ", format, float.MaxValue, float.MaxValue);
                    metrics = layout.Metrics;
                    Rectangle rect = new Rectangle(margin, margin, Math.Max(1, metrics.WidthIncludingTrailingWhitespace - margin * 2), Math.Max(1, metrics.Height - margin * 2));
                    geo    = new D2D.RectangleGeometry(this.Factory, rect);
                    stroke = this.GetStroke(HilightType.Dash);
                    break;

                case ShowSymbol.HalfSpace:
                    layout  = new DW.TextLayout(this._DWFactory, " ", format, float.MaxValue, float.MaxValue);
                    metrics = layout.Metrics;
                    rect    = new Rectangle(margin, margin, Math.Max(1, metrics.WidthIncludingTrailingWhitespace - margin * 2), Math.Max(1, metrics.Height - margin * 2));
                    geo     = new D2D.RectangleGeometry(this.Factory, rect);
                    stroke  = this.GetStroke(HilightType.Sold);
                    break;

                case ShowSymbol.Tab:
                    layout  = new DW.TextLayout(this._DWFactory, "0", format, float.MaxValue, float.MaxValue);
                    metrics = layout.Metrics;
                    path    = new D2D.PathGeometry(this.Factory);
                    var sink = path.Open();
                    sink.BeginFigure(new SharpDX.Mathematics.Interop.RawVector2(1, 1), D2D.FigureBegin.Filled);     //少し隙間を開けないと描写されない
                    sink.AddLine(new SharpDX.Mathematics.Interop.RawVector2((float)1, (float)metrics.Height));
                    sink.EndFigure(D2D.FigureEnd.Closed);
                    sink.Close();
                    geo    = path;
                    stroke = this.GetStroke(HilightType.Sold);
                    break;
                }
                cached_geo = new D2D.GeometryRealization(this.Device, geo, 1.0f, 1.0f, stroke);
                this.symbol_cache.Add(sym, cached_geo);
            }
            return(cached_geo);
        }
Example #14
0
        public void SetClip(IGraphicsPath path)
        {
            ResetClip();
            clipBounds = path.Bounds;
            var parameters = new sd.LayerParameters
            {
                ContentBounds     = clipBounds.ToDx(),
                GeometricMask     = clipGeometry = path.ToGeometry(),
                MaskAntialiasMode = Control.AntialiasMode,
                MaskTransform     = s.Matrix3x2.Identity,
                Opacity           = 1f
            };

            clipParams = parameters;
            Control.PushLayer(ref parameters, HelperLayer);
        }
Example #15
0
        public Shape CreateSimplification(DxGeometry resolvedSource, float tolerance)
        {
            Contract.Requires(resolvedSource != null);
            Contract.Requires(Check.IsPositive(tolerance));
            Contract.Ensures(Contract.Result<Shape>() != null);

            _Builder = Shape.Create();

            resolvedSource.Simplify(GeometrySimplificationOption.Lines, tolerance, this);

            Shape result = _Builder.Build();

            _Builder = null;

            return result;
        }
Example #16
0
        public void Build(Shape shape, out DxGeometry result)
        {
            Contract.Requires(shape != null);
            Contract.Ensures(Contract.ValueAtReturn(out result) != null);

            try
            {
                shape.ExtractTo(this);
            }
            finally
            {
                result = _Path;

                _PathSink = null;
                _Path = null;
            }
        }
Example #17
0
        public void AddPath(IGraphicsPath path, bool connect)
        {
            var inputGeometry = path.ToHandler();

            if (connect)
            {
                // TODO: how do we attach to the existing sink?  throws an exception otherwise
                StartFigure();
                inputGeometry.Control.Simplify(sd.GeometrySimplificationOption.CubicsAndLines, Sink);
            }
            else
            {
                CloseSink();
                geometries.Add(inputGeometry.Control);
            }
            control = null;
        }
Example #18
0
        public static void PushLayer(
            this D2D1.RenderTarget target,
            DXM.RawRectangleF clipBounds,
            D2D1.Geometry geometryPath,
            float opacity)
        {
            var layerParameters = new D2D1.LayerParameters()
            {
                GeometricMask = geometryPath,
                MaskTransform = Identity,
                ContentBounds = clipBounds,
                LayerOptions  = D2D1.LayerOptions.None,
                Opacity       = opacity,
                OpacityBrush  = null
            };

            target.PushLayer(ref layerParameters, null);
        }
Example #19
0
 public void Transform(IMatrix matrix)
 {
     if (matrix != null)
     {
         if (transform != null)
         {
             transform.Prepend(matrix);
         }
         else
         {
             transform = matrix.Clone();
         }
     }
     else
     {
         transform = null;
     }
     control = null;
 }
        protected void AddGeometry(D2DGeometry geom)
        {
            if (this.geometry == null)
            {
                this.geometry = geom;
            }
            else
            {
                PathGeometry pg = new PathGeometry(this.factory);

                GeometrySink sink = pg.Open();

                this.geometry.Combine(geom, CombineMode.Union, sink);

                sink.Close();

                this.geometry = pg;
            }
        }
Example #21
0
        public Shape CreateCombination(
			DxGeometry resolvedDestination,
			DxGeometry resolvedSource,
			CombinationOperation combination,
			float tolerance)
        {
            Contract.Requires(resolvedDestination != null);
            Contract.Requires(resolvedSource != null);
            Contract.Requires(Check.IsPositive(tolerance));
            Contract.Ensures(Contract.Result<Shape>() != null);

            _Builder = Shape.Create();

            CombineMode mode = CombineMode.Union;

            switch(combination)
            {
                case CombinationOperation.Intersect:
                    mode = CombineMode.Intersect;
                    break;
                case CombinationOperation.Combine:
                    mode = CombineMode.Union;
                    break;
                case CombinationOperation.Exclude:
                    mode = CombineMode.Exclude;
                    break;
                case CombinationOperation.Xor:
                    mode = CombineMode.Xor;
                    break;
            }

            resolvedDestination.Combine(resolvedSource, mode, tolerance, this);

            Shape result = _Builder.Build();

            _Builder = null;

            return result;
        }
Example #22
0
        public void GetVertices(D2DGeometry geometry, List <Pos3Norm3VertexSDX> vertices, float height = 24.0f)
        {
            vertices.Clear();
            //Empty mesh
            if (geometry == null)
            {
                Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX();
                vertices.Add(zero);
                vertices.Add(zero);
                vertices.Add(zero);
            }

            using (D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance))
            {
                using (D2DGeometry outlinedGeometry = this.OutlineGeometry(flattenedGeometry))
                {
                    using (ExtrudingSink sink = new ExtrudingSink(vertices, height))
                    {
                        outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink);
                        outlinedGeometry.Tessellate(sink);
                    }
                }
            }
        }
 public void DrawGeometry(Geometry geometry, SolidColorBrush brush, int width)
 {
     d2dContext.DrawGeometry(geometry, brush, width);
 }
Example #24
0
 public DirectPath()
 {
     this.geometry = null;
     this.directImage = null;
 }
Example #25
0
 internal void DisposeDisposables()
 {
     if (brush != null)
     {
         brush.Dispose();
         brush = null;
     }
     if (fillBrush != null)
     {
         fillBrush.Dispose();
         fillBrush = null;
     }
     if (geometry != null)
     {
         geometry.Dispose();
         geometry = null;
     }
 }
Example #26
0
        private D2DGeometry OutlineGeometry(D2DGeometry geometry)
        {
            PathGeometry path = new PathGeometry(this.factory);

            GeometrySink sink = path.Open();

            geometry.Outline(sink);

            sink.Close();

            return path;
        }
Example #27
0
 /// <summary>
 /// Default Constructor for a <see cref = "SharpDX.Direct2D1.TransformedGeometry" />.
 /// </summary>
 /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory" /></param>
 /// <param name="geometrySource"></param>
 /// <param name="matrix3X2"></param>
 public TransformedGeometry(Factory factory, Geometry geometrySource, RawMatrix3x2 matrix3X2) : base(IntPtr.Zero)
 {
     factory.CreateTransformedGeometry(geometrySource, ref matrix3X2, this);
 }
Example #28
0
 /// <unmanaged>HRESULT ID2D1CommandSink::FillGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[In, Optional] ID2D1Brush* opacityBrush)</unmanaged>	
 public void FillGeometry(Geometry geometry, Brush brush, Brush opacityBrush)
 {
     FillGeometry_(geometry, brush, opacityBrush);
 }
Example #29
0
		public void AddPath(IGraphicsPath path, bool connect)
		{
			var inputGeometry = path.ToHandler();
			if (connect)
			{
				// TODO: how do we attach to the existing sink?  throws an exception otherwise
				StartFigure();
				inputGeometry.Control.Simplify(sd.GeometrySimplificationOption.CubicsAndLines, Sink);
			}
			else
			{
				CloseSink();
				geometries.Add(inputGeometry.Control);
			}
			control = null;
		}
Example #30
0
 /// <summary>	
 /// Draws the outline of the specified geometry. 	
 /// </summary>	
 /// <remarks>	
 /// This method doesn't return an error code if it fails. To determine whether a drawing operation (such as DrawGeometry) failed, check the result returned by the <see cref="M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@)" /> or <see cref="M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@)" /> methods.  	
 /// </remarks>	
 /// <param name="geometry">The geometry to draw. </param>
 /// <param name="brush">The brush used to paint the geometry's stroke. </param>
 /// <unmanaged>void ID2D1RenderTarget::DrawGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawGeometry(Geometry geometry, Brush brush)
 {
     DrawGeometry(geometry, brush, StrokeWidth, null);
 }
Example #31
0
 /// <summary>	
 /// Draws the outline of the specified geometry. 	
 /// </summary>	
 /// <remarks>	
 /// This method doesn't return an error code if it fails. To determine whether a drawing operation (such as DrawGeometry) failed, check the result returned by the <see cref="M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@)" /> or <see cref="M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@)" /> methods.  	
 /// </remarks>	
 /// <param name="geometry">The geometry to draw. </param>
 /// <param name="brush">The brush used to paint the geometry's stroke. </param>
 /// <param name="strokeWidth">The thickness of the geometry's stroke. The stroke is centered on the geometry's outline. </param>
 /// <unmanaged>void ID2D1RenderTarget::DrawGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawGeometry(Geometry geometry, Brush brush, float strokeWidth)
 {
     DrawGeometry(geometry, brush, strokeWidth, null);
 }
Example #32
0
 /// <summary>	
 /// Retrieves the geometries in the geometry group. 	
 /// </summary>	
 /// <remarks>	
 /// The returned geometries are referenced and  counted, and the caller must release them. 	
 /// </remarks>	
 /// <param name="geometriesCount">A value indicating the number of geometries to return in the geometries array. If this value is less than the number of geometries in the geometry group, the remaining geometries are omitted. If this value is larger than the number of geometries in the geometry group, the extra geometries are set to NULL. To obtain the number of geometries currently in the geometry group, use the {{GetSourceGeometryCount}} method. </param>
 /// <returns>an array of geometries to be filled by this method. The length of the array is specified by the geometryCount parameter.</returns>
 /// <unmanaged>void ID2D1GeometryGroup::GetSourceGeometries([Out, Buffer] ID2D1Geometry** geometries,[None] int geometriesCount)</unmanaged>
 public SharpDX.Direct2D1.Geometry[] GetSourceGeometry(int geometriesCount)
 {
     Geometry[] geometries = new Geometry[geometriesCount];
     GetSourceGeometries(geometries, geometriesCount);
     return geometries;
 }
Example #33
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawGeometry(Geometry geometry, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawGeometry_(geometry, brush, strokeWidth, strokeStyle);
 }
 /// <summary>	
 /// <p>Creates a device-dependent representation of the fill of the geometry that can be subsequently rendered.</p>	
 /// </summary>
 /// <param name="context">The device context where the created instance should be attached to.</param>
 /// <param name="geometry"><dd>  <p>The geometry to realize.</p> </dd></param>	
 /// <param name="flatteningTolerance"><dd>  <p>The flattening tolerance to use when converting Beziers to line segments. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param>	
 /// <returns><p>The method returns an <strong><see cref="SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref="SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref="SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns>	
 /// <remarks>	
 /// <p>This method is used in conjunction with <strong><see cref="SharpDX.Direct2D1.DeviceContext1.DrawGeometryRealization"/></strong>. The <strong>D2D1::ComputeFlatteningTolerance</strong> helper API may be used to determine the proper flattening tolerance.</p><p>If the provided stroke style specifies a stroke transform type other than <strong><see cref="SharpDX.Direct2D1.StrokeTransformType.Normal"/></strong>, then the stroke will be realized assuming the identity transform and a DPI of 96.</p>	
 /// </remarks>	
 /// <include file='.\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1DeviceContext1::CreateFilledGeometryRealization']/*"/>	
 /// <msdn-id>dn280462</msdn-id>	
 /// <unmanaged>HRESULT ID2D1DeviceContext1::CreateFilledGeometryRealization([In] ID2D1Geometry* geometry,[In] float flatteningTolerance,[Out, Fast] ID2D1GeometryRealization** geometryRealization)</unmanaged>	
 /// <unmanaged-short>ID2D1DeviceContext1::CreateFilledGeometryRealization</unmanaged-short>	
 public GeometryRealization(DeviceContext1 context, Geometry geometry, float flatteningTolerance)
     : this(IntPtr.Zero)
 {
     context.CreateFilledGeometryRealization(geometry, flatteningTolerance, this);
 }
Example #35
0
		public void Transform(IMatrix matrix)
		{
			if (matrix != null)
			{
				if (transform != null)
					transform.Prepend(matrix);
				else
					transform = matrix.Clone();
			}
			else
				transform = null;
			control = null;
		}
Example #36
0
 public void AddRectangle(float x, float y, float width, float height)
 {
     CloseSink();
     geometries.Add(new sd.RectangleGeometry(SDFactory.D2D1Factory, new s.RectangleF(x, y, width, height)));
     control = null;
 }
Example #37
0
		public void AddEllipse(float x, float y, float width, float height)
		{
			CloseSink();
			var ellipse = new sd.Ellipse(new s.Vector2(x + width / 2, y + height / 2), width / 2, height / 2);
			geometries.Add(new sd.EllipseGeometry(SDFactory.D2D1Factory, ellipse));
			control = null;
		}
        public override void Update(long ticks)
        {
            base.Update(ticks);
            if (_recalculateGeometry) {
                if (_backgroundGeometry != null && !_backgroundGeometry.IsDisposed)
                    _backgroundGeometry.Dispose();

                var rect = new DrawingRectangleF(0f, 0f, Width, Height);
                if (IsRounded) {
                    _backgroundGeometry = new RoundedRectangleGeometry(_assetManager.Factory2D, new RoundedRectangle() {
                        Rect = rect,
                        RadiusX = ControlManager.Config.WindowCornerRadius,
                        RadiusY = ControlManager.Config.WindowCornerRadius
                    });
                } else {
                    _backgroundGeometry = new RectangleGeometry(_assetManager.Factory2D, rect);
                }
                _recalculateGeometry = false;
            }
            if (_hasTextChanged && !String.IsNullOrEmpty(_text)) {
                if (RenderedText != null && !RenderedText.IsDisposed)
                    RenderedText.Dispose();

                RenderedText = _assetManager.MakeTextLayout(Font.Resource, _text, Width, Height);
                RenderedText.TextAlignment = this.TextAlignment;
                RenderedText.ParagraphAlignment = this.ParagraphAlignment;
                _hasTextChanged = false;
            }
            if (IsActive) {
                CurrentFontBrush = _activeFontBrush;
                if (IsPressed) {
                    CurrentBackgroundBrush = _pressedBackgroundBrush;
                    CurrentBorderBrush = _pressedBorderBrush;
                    CurrentBitmap = _pressedTexture;
                } else {
                    CurrentBackgroundBrush = _activeBackgroundBrush;
                    CurrentBorderBrush = _activeBorderBrush;
                    CurrentBitmap = _activeTexture;
                }
            } else {
                CurrentBackgroundBrush = _inactiveBackgroundBrush;
                CurrentBorderBrush = _inactiveBorderBrush;
                CurrentFontBrush = _inactiveFontBrush;
                CurrentBitmap = _inactiveTexture;
            }
        }
Example #39
0
		public void AddRectangle(float x, float y, float width, float height)
		{
			CloseSink();
			geometries.Add(new sd.RectangleGeometry(SDFactory.D2D1Factory, new s.RectangleF(x, y, width, height)));
			control = null;
		}
        public override void UnloadContent()
        {
            _activeBackgroundBrush.Dispose();
            _activeBorderBrush.Dispose();
            _inactiveBackgroundBrush.Dispose();
            _inactiveBorderBrush.Dispose();
            _pressedBackgroundBrush.Dispose();
            _pressedBorderBrush.Dispose();
            _activeFontBrush.Dispose();
            _inactiveFontBrush.Dispose();

            if(_activeTexture != null)
                _activeTexture.Dispose();

            if (_inactiveTexture != null)
                _inactiveTexture.Dispose();

            if (_pressedTexture != null)
                _pressedTexture.Dispose();

            Font.Dispose();

            _assetManager = null;

            // Some are created by this object, however.
            // Anything here should also be addressed in Dispose()
            if (RenderedText != null && !RenderedText.IsDisposed)
                RenderedText.Dispose();
            RenderedText = null;

            if (_backgroundGeometry != null && !_backgroundGeometry.IsDisposed)
                _backgroundGeometry.Dispose();
            _backgroundGeometry = null;

            base.UnloadContent();
        }
Example #41
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>	
 public void DrawGeometry(Geometry geometry, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawGeometry_(geometry, brush, strokeWidth, strokeStyle);
 }
 /// <summary>	
 /// <p>Creates a device-dependent representation of the stroke of a geometry that can be subsequently rendered.</p>	
 /// </summary>	
 /// <param name="context">The device context where the created instance should be attached to.</param>
 /// <param name="geometry"><dd>  <p>The geometry to realize.</p> </dd></param>	
 /// <param name="flatteningTolerance"><dd>  <p>The flattening tolerance to use when converting Beziers to line segments. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param>	
 /// <param name="strokeWidth"><dd>  <p>The width of the stroke. This parameter shares the same units as the coordinates of the geometry.</p> </dd></param>	
 /// <param name="strokeStyle"><dd>  <p>The stroke style (optional).</p> </dd></param>	
 /// <returns><p>The method returns an <strong><see cref="SharpDX.Result"/></strong>. Possible values include, but are not limited to, those in the following table.</p><table> <tr><th><see cref="SharpDX.Result"/></th><th>Description</th></tr> <tr><td><see cref="SharpDX.Result.Ok"/></td><td>No error occurred.</td></tr> <tr><td>E_OUTOFMEMORY</td><td>Direct2D could not allocate sufficient memory to complete the call.</td></tr> <tr><td>E_INVALIDARG</td><td>An invalid value was passed to the method.</td></tr> </table><p>?</p></returns>	
 /// <remarks>	
 /// <p>This method is used in conjunction with <strong><see cref="SharpDX.Direct2D1.DeviceContext1.DrawGeometryRealization"/></strong>. The <strong>D2D1::ComputeFlatteningTolerance</strong> helper API may be used to determine the proper flattening tolerance.</p><p>If the provided stroke style specifies a stroke transform type other than <strong><see cref="SharpDX.Direct2D1.StrokeTransformType.Normal"/></strong>, then the stroke will be realized assuming the identity transform and a DPI of 96.</p>	
 /// </remarks>	
 /// <include file='.\Documentation\CodeComments.xml' path="/comments/comment[@id='ID2D1DeviceContext1::CreateStrokedGeometryRealization']/*"/>	
 /// <msdn-id>dn280463</msdn-id>	
 /// <unmanaged>HRESULT ID2D1DeviceContext1::CreateStrokedGeometryRealization([In] ID2D1Geometry* geometry,[In] float flatteningTolerance,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[Out, Fast] ID2D1GeometryRealization** geometryRealization)</unmanaged>	
 /// <unmanaged-short>ID2D1DeviceContext1::CreateStrokedGeometryRealization</unmanaged-short>	
 public GeometryRealization(DeviceContext1 context, Geometry geometry, float flatteningTolerance, float strokeWidth, StrokeStyle strokeStyle)
     : this(IntPtr.Zero)
 {
     context.CreateStrokedGeometryRealization(geometry, flatteningTolerance, strokeWidth, strokeStyle, this);
 }
Example #43
0
        protected void AddGeometry(D2DGeometry geom)
        {
            if (this.geometry == null)
            {
                this.geometry = geom;
            }
            else
            {
                PathGeometry pg = new PathGeometry(this.factory);

                GeometrySink sink = pg.Open();

                this.geometry.Combine(geom, CombineMode.Union, sink);

                sink.Close();

                this.geometry = pg;
            }
        }
Example #44
0
 /// <summary>	
 /// Creates an <see cref="SharpDX.Direct2D1.GeometryGroup"/>, which is an object that holds other geometries.	
 /// </summary>	
 /// <remarks>	
 /// Geometry groups are a convenient way to group several geometries simultaneously so all figures of several distinct geometries are concatenated into one. To create a  <see cref="SharpDX.Direct2D1.GeometryGroup"/> object, call  the CreateGeometryGroup method on the <see cref="SharpDX.Direct2D1.Factory"/> object, passing in the fillMode with possible values of   <see cref="SharpDX.Direct2D1.FillMode.Alternate"/> (alternate) and D2D1_FILL_MODE_WINDING, an array of geometry objects to add to the geometry group, and the number of elements in this array. 	
 /// </remarks>	
 /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory" /></param>
 /// <param name="fillMode">A value that specifies the rule that a composite shape uses to determine whether a given point is part of the geometry. </param>
 /// <param name="geometries">An array containing the geometry objects to add to the geometry group. The number of elements in this array is indicated by the geometriesCount parameter.</param>
 public GeometryGroup(Factory factory, FillMode fillMode, Geometry[] geometries)
     : base(IntPtr.Zero)
 {
     factory.CreateGeometryGroup(fillMode, geometries, geometries.Length, this);
 }
Example #45
0
 /// <summary>	
 /// Describes the intersection between this geometry and the specified geometry. The comparison is performed by using the specified flattening tolerance.	
 /// </summary>	
 /// <remarks>	
 /// When interpreting the returned relation value, it is important to remember that the member <see cref="F:SharpDX.Direct2D1.GeometryRelation.IsContained" /> of the  D2D1_GEOMETRY_RELATION enumeration type means that this geometry is contained  inside inputGeometry, not that this geometry contains inputGeometry.  For  more information about how to interpret other possible return values, see <see cref="T:SharpDX.Direct2D1.GeometryRelation" />. 	
 /// </remarks>	
 /// <param name="inputGeometry">The geometry to test.  </param>
 /// <returns>When this method returns, contains a reference to a value that describes how this geometry is related to inputGeometry. You must allocate storage for this parameter.   </returns>
 /// <unmanaged>HRESULT ID2D1Geometry::CompareWithGeometry([In] ID2D1Geometry* inputGeometry,[In, Optional] const D2D1_MATRIX_3X2_F* inputGeometryTransform,[None] float flatteningTolerance,[Out] D2D1_GEOMETRY_RELATION* relation)</unmanaged>
 public GeometryRelation Compare(Geometry inputGeometry)
 {
     return Compare(inputGeometry, null, FlatteningTolerance);
 }
Example #46
0
 /// <unmanaged>HRESULT ID2D1CommandSink::FillGeometry([In] ID2D1Geometry* geometry,[In] ID2D1Brush* brush,[In, Optional] ID2D1Brush* opacityBrush)</unmanaged>
 public void FillGeometry(Geometry geometry, Brush brush, Brush opacityBrush)
 {
     FillGeometry_(geometry, brush, opacityBrush);
 }