Ejemplo n.º 1
0
        internal D2dStrokeStyle(StrokeStyle strokeStyle)
        {
            if (strokeStyle == null)
                throw new ArgumentNullException("strokeStyle");

            m_strokeStyle = strokeStyle;
        }
Ejemplo n.º 2
0
 protected override void Draw()
 {
     RenderTarget.BeginDraw();
     RenderTarget.Transform = Matrix3x2.Identity;
     Random random = new Random();
     RenderTarget.Clear(new Color4(0.5f, 0.5f, 0.5f, 0.0f));
     RenderTarget.AntialiasMode = AntialiasMode.Aliased;
     StrokeStyleProperties properties = new StrokeStyleProperties();
     properties.LineJoin = LineJoin.MiterOrBevel;
     StrokeStyle strokeStyle = new StrokeStyle(RenderTarget.Factory, properties);
     foreach (DirectPath path in paths)
     {
         if (path.Geometry != null && path.Brush != null)
         {
             if (path is DirectPathScatter)
             {
                 (path as DirectPathScatter).RenderScatterGeometry(RenderTarget);
             }
             else
             {
                 if (path.QuickStrokeDash != QuickStrokeDash.None)
                 {
                     RenderTarget.DrawGeometry(path.Geometry, path.Brush, (float)path.StrokeThickness, strokeStyle);
                 }
             }
         }
     }
     RenderTarget.EndDraw();
     graphicsDeviceService10.CopyTextureAcross();
     graphicsDeviceService10.Device.Flush();
 }
Ejemplo n.º 3
0
 public LineMarker(D2D.RenderTarget render, D2D.SolidColorBrush brush, D2D.StrokeStyle stroke, float thickness)
 {
     this.brush     = brush;
     this.stroke    = stroke;
     this.thickness = thickness;
     this.render    = render;
 }
Ejemplo n.º 4
0
 public void RenderScatterGeometry(RenderTarget renderTarget)
 {
     double[] x = curve.X;
     double[] y = curve.Y;
     int length = x.Length;
     double xScale, xOffset, yScale, yOffset;
     xScale = graphToCanvas.Matrix.M11;
     xOffset = graphToCanvas.Matrix.OffsetX - this.xOffsetMarker;
     yScale = graphToCanvas.Matrix.M22;
     yOffset = graphToCanvas.Matrix.OffsetY - this.yOffsetMarker;
     bool[] include = curve.includeMarker;
     StrokeStyleProperties properties = new StrokeStyleProperties();
     properties.LineJoin = LineJoin.MiterOrBevel;
     StrokeStyle strokeStyle = new StrokeStyle(renderTarget.Factory, properties);
     for (int i = 0; i < length; ++i)
     {
         if (include[i])
         {
             renderTarget.Transform = (Matrix3x2)Matrix.Translation((float)(x[i] * xScale + xOffset), (float)(y[i] * yScale + yOffset), 0);
             renderTarget.FillGeometry(Geometry, FillBrush);
             renderTarget.DrawGeometry(Geometry, Brush, (float)StrokeThickness, strokeStyle);
         }
     }
     renderTarget.Transform = Matrix3x2.Identity;
 }
Ejemplo n.º 5
0
 void Reset()
 {
     if (strokeStyle != null)
     {
         strokeStyle.Dispose();
         strokeStyle = null;
     }
 }
Ejemplo n.º 6
0
		void Reset()
		{
			if (strokeStyle != null)
			{
				strokeStyle.Dispose();
				strokeStyle = null;
			}
		}
Ejemplo n.º 7
0
 public override void Dispose()
 {
     if (Style != null)
     {
         Style.Dispose();
         Style = null;
     }
     base.Dispose();
 }
Ejemplo n.º 8
0
        private void Update(bool forceUpdate = false)
        {
            if (isUpdated || forceUpdate)
            {
                isUpdated = false;

                strokeBrush?.Dispose();
                strokeBrush = new d2.SolidColorBrush(Renderer.Device, _stroke.ToColor4());

                strokeStyle?.Dispose();
                strokeStyle = new d2.StrokeStyle(Renderer.Factory, _strokeStyleProp);
            }
        }
Ejemplo n.º 9
0
        public void Dispose()
        {
            if (Brush != null)
            {
                Brush.Dispose();
                Brush = null;
            }

            if (strokeStyle != null)
            {
                strokeStyle.Dispose();
                strokeStyle = null;
            }
        }
Ejemplo n.º 10
0
        public Clock(Size clientSize)
        {
            ClientSize = clientSize;

            g_center = new PointF(ClientSize.Width / 2f, ClientSize.Height / 2f);

            // Create brushes
            blueBrush1 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.3f, 0.4f, 0.9f, 1));
            blueBrush2 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.45f, 0.6f, 0.95f, 1));
            blueBrush3 = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.6f, 0.8f, 1f, 1));
            whiteBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(1f, 1f, 1f, 0.5f));
            redBrush   = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0.99f, 0.16f, 0.3f, 0.7f));

            // Create ellipses
            ellipseCentre = new D2D.Ellipse(new Mathe.RawVector2(g_center.X, g_center.Y), 120, 120);

            // Create text formats
            textFormat = new DW.TextFormat(RenderForm.FactoryWrite, "Berlin Sans FB", 36);


            strokeProperties = new D2D.StrokeStyleProperties
            {
                StartCap = D2D.CapStyle.Round,
                EndCap   = D2D.CapStyle.Triangle
            };
            strokeStyle = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties);

            strokeProperties2 = new D2D.StrokeStyleProperties
            {
                StartCap  = D2D.CapStyle.Round,
                EndCap    = D2D.CapStyle.Round,
                DashStyle = D2D.DashStyle.Dash
            };
            strokeStyle2 = new D2D.StrokeStyle(RenderForm.Factory, strokeProperties2);

            int len = 110;

            for (int i = 0; i < 60; i++)
            {
                int   r = i % 5 == 0 ? 10 : 5;
                float deg, rad;
                deg     = (i / 60f * 360 - 90);
                rad     = deg / 180 * (float)Math.PI;
                lim[i]  = new PointF(g_center.X + (float)Math.Cos(rad) * (len - r), g_center.Y + (float)Math.Sin(rad) * (len - r));
                lim2[i] = new PointF(g_center.X + (float)Math.Cos(rad) * (len), g_center.Y + (float)Math.Sin(rad) * (len));
            }

            sw = new Stopwatch();
            sw.Start();
        }
Ejemplo n.º 11
0
        public void Dispose()
        {
            if (Brush != null)
            {
                Brush.Dispose();
                Brush = null;
            }

            if (strokeStyle != null)
            {
                strokeStyle.Dispose();
                strokeStyle = null;
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public virtual void Initialize(DeviceManager deviceManager)
        {
            TouchCapabilities = new Windows.Devices.Input.TouchCapabilities();

            // Initialize a TextFormat
            textFormat = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center };
            textFormat2 = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center };

            sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.Tomato);

            strokeProperties = new StrokeStyleProperties();
            strokeProperties.StartCap = CapStyle.Round;
            strokeProperties.EndCap = CapStyle.Round;
            strokeProperties.LineJoin = LineJoin.Round;

            strokeStyle = new StrokeStyle(deviceManager.FactoryDirect2D, strokeProperties);
        }
Ejemplo n.º 14
0
        public D2D.StrokeStyle GetStroke(HilightType type)
        {
            D2D.StrokeStyle stroke;
            if (this.stroke_cache.TryGetValue(type, out stroke))
            {
                return(stroke);
            }

            D2D.StrokeStyleProperties prop = new D2D.StrokeStyleProperties();
            prop.DashCap    = D2D.CapStyle.Flat;
            prop.DashOffset = 0;
            prop.DashStyle  = D2D.DashStyle.Solid;
            prop.EndCap     = D2D.CapStyle.Flat;
            prop.LineJoin   = D2D.LineJoin.Miter;
            prop.MiterLimit = 0;
            prop.StartCap   = D2D.CapStyle.Flat;
            switch (type)
            {
            case HilightType.Sold:
            case HilightType.Url:
            case HilightType.Squiggle:
                prop.DashStyle = D2D.DashStyle.Solid;
                break;

            case HilightType.Dash:
                prop.DashStyle = D2D.DashStyle.Dash;
                break;

            case HilightType.DashDot:
                prop.DashStyle = D2D.DashStyle.DashDot;
                break;

            case HilightType.DashDotDot:
                prop.DashStyle = D2D.DashStyle.DashDotDot;
                break;

            case HilightType.Dot:
                prop.DashStyle = D2D.DashStyle.Dot;
                break;
            }
            stroke = new D2D.StrokeStyle(this.Factory, prop);
            this.stroke_cache.Add(type, stroke);
            return(stroke);
        }
Ejemplo n.º 15
0
 /// <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);
 }
Ejemplo n.º 16
0
        private void ReconfigureStrokeStyle()
        {
            _StrokeStyle.SafeDispose();

            StrokeStyleProperties newStyle = new StrokeStyleProperties
            {
                LineJoin = ActiveStrokeJoin.ToDirectWrite(),
                MiterLimit = ActiveMiterLimit,
                DashCap = ActiveDashCap.ToDirectWrite(),
                EndCap = ActiveStrokeCap.ToDirectWrite(),
                StartCap = ActiveStrokeCap.ToDirectWrite(),
                DashStyle = ActiveLineStyle.ToDirectWrite()
            };

            _StrokeStyle = new StrokeStyle(_Factory2D, newStyle, new float[0]);
        }
Ejemplo n.º 17
0
		/// <summary>
		/// 初始化 <see cref="GameManager"/> 类的新实例。
		/// </summary>
		/// <param name="devices">设备管理器。</param>
		public GameManager(DeviceManager devices, JigsawRenderPanel renderPanel, JigsawRendererType rendererType)
		{
			this.devices = devices;
			this.renderPanel = renderPanel;
			// 初始化设备。
			this.renderPanel.Devices = devices;
			this.renderPanel.Paint += this.renderPanel_Paint;
			this.renderTarget = devices.RenderTarget;
			// 初始化画刷。
			selectionRectBrush = new SolidColorBrush(renderTarget, Color.Black);
			selectionRectStyle = new StrokeStyle(this.devices.D2DFactory,
				new StrokeStyleProperties() { DashStyle = DashStyle.Dash });
			this.RendererType = rendererType;
		}
Ejemplo n.º 18
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);
 }
Ejemplo n.º 19
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(RawVector2 point, float strokeWidth, StrokeStyle strokeStyle, RawMatrix3x2 transform)
 {
     return StrokeContainsPoint(point, strokeWidth, strokeStyle, transform, FlatteningTolerance);            
 }
Ejemplo n.º 20
0
 public void DrawLine(Point from, Point to)
 {
     D2D.Brush       brush  = this._factory.GetSolidColorBrush(this.Foreground);
     D2D.StrokeStyle stroke = this._factory.GetStroke(HilightType.Sold);
     this.render.DrawLine(from, to, brush, 1.0f, stroke);
 }
Ejemplo n.º 21
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawLine([In] D2D_POINT_2F point0,[In] D2D_POINT_2F point1,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>	
 public void DrawLine(RawVector2 point0, RawVector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawLine_(point0, point1, brush, strokeWidth, strokeStyle);
 }
Ejemplo n.º 22
0
        public void Stroke(Shape shape, Brush brush, StrokeStyle style, float strokeWidth)
        {
            Contract.Requires(shape != null);
            Contract.Requires(brush != null);
            Contract.Requires(style != null);
            Contract.Requires(Check.IsPositive(strokeWidth));
            Contract.Assert(_Target != null);

            DxGeometry resolved = _GeometryCache.ResolveGeometry(shape);

            Contract.Assert(resolved != null);

            _Target.DrawGeometry(resolved, brush, strokeWidth, style);
        }
Ejemplo n.º 23
0
        public void Stroke(
			Point lineStart, Point lineEnd, Brush brush, StrokeStyle style, float strokeWidth)
        {
            Contract.Requires(brush != null);
            Contract.Requires(style != null);
            Contract.Requires(Check.IsPositive(strokeWidth));
            Contract.Assert(_Target != null);

            DrawingPointF start = new DrawingPointF { X = lineStart.X, Y = lineStart.Y };
            DrawingPointF end = new DrawingPointF { X = lineEnd.X, Y = lineEnd.Y };

            _Target.DrawLine(start, end, brush, strokeWidth, style);
        }
Ejemplo n.º 24
0
        public Renderer(Game game, SharpDX.Windows.RenderForm renderForm)
        {
            this.game = game;
            int width = renderForm.ClientSize.Width, height = renderForm.ClientSize.Height;

            ResolutionX = width; ResolutionY = height;

            #region 3d device & context
            D3D11.DeviceCreationFlags creationFlags = D3D11.DeviceCreationFlags.BgraSupport;
            #if DEBUG
            creationFlags |= D3D11.DeviceCreationFlags.Debug;
            #endif
            DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription()
            {
                ModeDescription   = new DXGI.ModeDescription(width, height, new DXGI.Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm),
                SampleDescription = new DXGI.SampleDescription(SampleCount, SampleQuality),
                Usage             = DXGI.Usage.RenderTargetOutput,
                BufferCount       = 1,
                OutputHandle      = renderForm.Handle,
                IsWindowed        = true,
                SwapEffect        = DXGI.SwapEffect.Discard
            };
            D3D11.Device device;
            D3D11.Device.CreateWithSwapChain(DriverType.Hardware, creationFlags, swapChainDesc, out device, out swapChain);
            Device  = device;
            Context = Device.ImmediateContext;
            #endregion
            #region 2d device & context
            DXGI.Device dxgiDevice = Device.QueryInterface <D3D11.Device1>().QueryInterface <DXGI.Device2>();
            D2DDevice  = new D2D1.Device(dxgiDevice);
            D2DContext = new D2D1.DeviceContext(D2DDevice, D2D1.DeviceContextOptions.None);
            D2DFactory = D2DDevice.Factory;
            #endregion
            #region 2d brushes/fonts
            Brushes = new Dictionary <string, D2D1.Brush>();
            Brushes.Add("Red", new D2D1.SolidColorBrush(D2DContext, Color.Red));
            Brushes.Add("Green", new D2D1.SolidColorBrush(D2DContext, Color.Green));
            Brushes.Add("Blue", new D2D1.SolidColorBrush(D2DContext, Color.Blue));
            Brushes.Add("White", new D2D1.SolidColorBrush(D2DContext, Color.White));
            Brushes.Add("Black", new D2D1.SolidColorBrush(D2DContext, Color.Black));
            Brushes.Add("TransparentWhite", new D2D1.SolidColorBrush(D2DContext, new Color(1, 1, 1, .5f)));
            Brushes.Add("TransparentBlack", new D2D1.SolidColorBrush(D2DContext, new Color(0, 0, 0, .5f)));
            Brushes.Add("LightGray", new D2D1.SolidColorBrush(D2DContext, Color.LightGray));
            Brushes.Add("OrangeRed", new D2D1.SolidColorBrush(D2DContext, Color.OrangeRed));
            Brushes.Add("CornflowerBlue", new D2D1.SolidColorBrush(D2DContext, Color.CornflowerBlue));
            Brushes.Add("Yellow", new D2D1.SolidColorBrush(D2DContext, Color.Yellow));
            Brushes.Add("Magenta", new D2D1.SolidColorBrush(D2DContext, Color.Magenta));
            Brushes.Add("RosyBrown", new D2D1.SolidColorBrush(D2DContext, Color.RosyBrown));

            DashStyle = new D2D1.StrokeStyle(D2DFactory, new D2D1.StrokeStyleProperties()
            {
                StartCap   = D2D1.CapStyle.Flat,
                DashCap    = D2D1.CapStyle.Round,
                EndCap     = D2D1.CapStyle.Flat,
                DashStyle  = D2D1.DashStyle.Custom,
                DashOffset = 0,
                LineJoin   = D2D1.LineJoin.Round,
                MiterLimit = 1
            }, new float[] { 4f, 4f });

            FontFactory = new DWrite.Factory();
            SegoeUI24   = new DWrite.TextFormat(FontFactory, "Segoe UI", 24f);
            SegoeUI14   = new DWrite.TextFormat(FontFactory, "Segoe UI", 14f);
            Consolas14  = new DWrite.TextFormat(FontFactory, "Consolas", 14f);
            #endregion

            #region blend states
            D3D11.BlendStateDescription opaqueDesc = new D3D11.BlendStateDescription();
            opaqueDesc.RenderTarget[0].IsBlendEnabled        = false;
            opaqueDesc.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All;
            blendStateOpaque = new D3D11.BlendState(Device, opaqueDesc);

            D3D11.BlendStateDescription alphaDesc = new D3D11.BlendStateDescription();
            alphaDesc.RenderTarget[0].IsBlendEnabled        = true;
            alphaDesc.RenderTarget[0].SourceBlend           = D3D11.BlendOption.SourceAlpha;
            alphaDesc.RenderTarget[0].DestinationBlend      = D3D11.BlendOption.InverseSourceAlpha;
            alphaDesc.RenderTarget[0].BlendOperation        = D3D11.BlendOperation.Add;
            alphaDesc.RenderTarget[0].SourceAlphaBlend      = D3D11.BlendOption.One;
            alphaDesc.RenderTarget[0].DestinationAlphaBlend = D3D11.BlendOption.Zero;
            alphaDesc.RenderTarget[0].AlphaBlendOperation   = D3D11.BlendOperation.Add;
            alphaDesc.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All;
            blendStateTransparent = new D3D11.BlendState(Device, alphaDesc);
            #endregion
            #region rasterizer states
            rasterizerStateSolidCullBack = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Solid,
                CullMode = D3D11.CullMode.Back,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            rasterizerStateWireframeCullBack = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Wireframe,
                CullMode = D3D11.CullMode.Back,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            rasterizerStateSolidNoCull = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Solid,
                CullMode = D3D11.CullMode.None,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            rasterizerStateWireframeNoCull = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Wireframe,
                CullMode = D3D11.CullMode.None,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            rasterizerStateSolidCullFront = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Solid,
                CullMode = D3D11.CullMode.Front,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            rasterizerStateWireframeCullFront = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription()
            {
                FillMode = D3D11.FillMode.Wireframe,
                CullMode = D3D11.CullMode.Front,
                IsAntialiasedLineEnabled = true,
                IsDepthClipEnabled       = false,
                IsMultisampleEnabled     = true
            });
            #endregion

            #region depth stencil states
            depthStencilStateDefault = new D3D11.DepthStencilState(Device, new D3D11.DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthComparison  = D3D11.Comparison.Less,
                DepthWriteMask   = D3D11.DepthWriteMask.All
            });

            depthStencilStateNoDepth = new D3D11.DepthStencilState(Device, new D3D11.DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
                DepthComparison  = D3D11.Comparison.Less,
                DepthWriteMask   = D3D11.DepthWriteMask.All
            });

            Context.OutputMerger.SetDepthStencilState(depthStencilStateDefault);
            #endregion

            #region blank textures
            D3D11.Texture2D wtex   = new D3D11.Texture2D(Device, new D3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                Width             = 1,
                Height            = 1,
                Format            = DXGI.Format.R32G32B32A32_Float,
                CpuAccessFlags    = D3D11.CpuAccessFlags.None,
                MipLevels         = 0,
                Usage             = D3D11.ResourceUsage.Default,
                SampleDescription = new DXGI.SampleDescription(1, 0),
                BindFlags         = D3D11.BindFlags.ShaderResource,
                OptionFlags       = D3D11.ResourceOptionFlags.None
            });
            Context.UpdateSubresource(new Vector4[] { Vector4.One }, wtex);
            WhiteTextureView = new D3D11.ShaderResourceView(Device, wtex);

            D3D11.Texture2D btex = new D3D11.Texture2D(Device, new D3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                Width             = 1,
                Height            = 1,
                Format            = DXGI.Format.R32G32B32A32_Float,
                CpuAccessFlags    = D3D11.CpuAccessFlags.None,
                MipLevels         = 0,
                Usage             = D3D11.ResourceUsage.Default,
                SampleDescription = new DXGI.SampleDescription(1, 0),
                BindFlags         = D3D11.BindFlags.ShaderResource,
                OptionFlags       = D3D11.ResourceOptionFlags.None
            });
            Context.UpdateSubresource(new Vector4[] { new Vector4(0, 0, 0, 1) }, btex);
            BlackTextureView = new D3D11.ShaderResourceView(Device, btex);

            AnisotropicSampler = new D3D11.SamplerState(Device, new D3D11.SamplerStateDescription()
            {
                AddressU = D3D11.TextureAddressMode.Wrap,
                AddressV = D3D11.TextureAddressMode.Wrap,
                AddressW = D3D11.TextureAddressMode.Wrap,
                Filter   = D3D11.Filter.Anisotropic,
            });
            #endregion
            #region screen vertex & constants
            constants      = new CameraConstants();
            constantBuffer = D3D11.Buffer.Create(Device, D3D11.BindFlags.ConstantBuffer, ref constants);
            #endregion
            //swapChain.GetParent<DXGI.Factory>().MakeWindowAssociation(renderForm.Handle, DXGI.WindowAssociationFlags.);

            Cameras      = new List <Camera>();
            MainCamera   = Camera.CreatePerspective(MathUtil.DegreesToRadians(70), 16 / 9f);
            ActiveCamera = MainCamera;
            Cameras.Add(MainCamera);

            ShadowCamera       = Camera.CreateOrthographic(500, 1);
            ShadowCamera.zNear = 0;
            ShadowCamera.zFar  = 1000;
            ShadowCamera.CreateResources(Device, 1, 0, 1024, 1024);
            //Cameras.Add(ShadowCamera);
            // TODO: Shadow camera has no depth

            Resize(ResolutionX, ResolutionY);
        }
Ejemplo n.º 25
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawRectangle([In] const D2D_RECT_F* rect,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawRectangle(RawRectangleF rect, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawRectangle_(rect, brush, strokeWidth, strokeStyle);
 }
Ejemplo n.º 26
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawRectangle([In] const D2D_RECT_F* rect,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>	
 public void DrawRectangle(RawRectangleF rect, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawRectangle_(rect, brush, strokeWidth, strokeStyle);
 }
Ejemplo n.º 27
0
 public static void DrawLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, ILineString line, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map)
 {
     DrawLineString(renderTarget, factory, line, pen, penWidth, penStrokeStyle, map, 0);
 }
Ejemplo n.º 28
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(RawPoint point, float strokeWidth, StrokeStyle strokeStyle)
 {
     return StrokeContainsPoint(new RawVector2 { X = point.X, Y = point.Y }, strokeWidth, strokeStyle);            
 }
Ejemplo n.º 29
0
        public void Stroke(
			Rectangle rectangleRegion,
			Size roundedRectangleRadius,
			Brush brush,
			StrokeStyle style,
			float strokeWidth)
        {
            Contract.Requires(Check.IsPositive(roundedRectangleRadius.Width));
            Contract.Requires(Check.IsPositive(roundedRectangleRadius.Height));
            Contract.Requires(brush != null);
            Contract.Requires(style != null);
            Contract.Requires(Check.IsPositive(strokeWidth));
            Contract.Assert(_Target != null);

            Rectangle newRegion;

            ToStrokeable(ref rectangleRegion, strokeWidth, strokeWidth, out newRegion);

            FitStroke(ref newRegion, strokeWidth, strokeWidth, out newRegion);

            RectangleF rectangle = RectangleF.Empty;

            rectangle.Left = newRegion.Left;
            rectangle.Top = newRegion.Top;
            rectangle.Right = newRegion.Right;
            rectangle.Bottom = newRegion.Bottom;

            RoundedRectangle roundedRectangle = new RoundedRectangle
            {
                Rect = rectangle,
                RadiusX = roundedRectangleRadius.Width,
                RadiusY = roundedRectangleRadius.Height
            };

            _Target.DrawRoundedRectangle(roundedRectangle, brush, strokeWidth, style);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Renders a LineString to the map.
        /// </summary>
        /// <param name="renderTarget">The render target</param>
        /// <param name="factory">The factory to create shapes</param>
        /// <param name="line">LineString to render</param>
        /// <param name="pen">Pen style used for rendering</param>
        /// <param name="map">Map reference</param>
        /// <param name="offset">Offset by which line will be moved to right</param>
        public static void DrawLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, ILineString line, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map, float offset)
        {
            var points = TransformToImage(line, map);

            if (points.Length > 1)
            {
                using (var geom = new D2D1.PathGeometry(factory))
                {
                    using (var gs = geom.Open())
                    {
                        gs.BeginFigure(points[0], D2D1.FigureBegin.Filled);
                        gs.AddLines(points);
                        gs.EndFigure(D2D1.FigureEnd.Open);

                        gs.Close();
                    }

                    renderTarget.DrawGeometry(geom, pen, penWidth, penStrokeStyle);
                }
            }
        }
Ejemplo n.º 31
0
 public static void DrawMultiPolygon(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiPolygon pols, D2D1.Brush brush, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, bool clip, Map map)
 {
     for (var i = 0; i < pols.NumGeometries; i++)
     {
         var p = (IPolygon)pols[i];
         DrawPolygon(renderTarget, factory, p, brush, pen, penWidth, penStrokeStyle, clip, map);
     }
 }
Ejemplo n.º 32
0
        public static void DrawPolygon(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPolygon pol, D2D1.Brush brush, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, bool clip, Map map)
        {
            if (pol.ExteriorRing == null)
            {
                return;
            }

            Vector2[] points;
            var       startPoint = TransformToImage(pol.ExteriorRing, map, out points);

            if (points.Length > 1)
            {
                using (var geom = new D2D1.PathGeometry(factory))
                {
                    using (var gs = geom.Open())
                    {
                        gs.SetFillMode(D2D1.FillMode.Alternate);

                        gs.BeginFigure(startPoint, D2D1.FigureBegin.Filled);
                        gs.AddLines(points);
                        gs.EndFigure(D2D1.FigureEnd.Closed);

                        for (var i = 0; i < pol.NumInteriorRings; i++)
                        {
                            startPoint = TransformToImage(pol.GetInteriorRingN(i), map, out points);
                            if (points.Length > 1)
                            {
                                gs.BeginFigure(startPoint, D2D1.FigureBegin.Filled);
                                gs.AddLines(points);
                                gs.EndFigure(D2D1.FigureEnd.Closed);
                            }
                        }

                        gs.Close();
                    }

                    if (brush != null)
                    {
                        renderTarget.FillGeometry(geom, brush);
                    }
                    if (pen != null)
                    {
                        renderTarget.DrawGeometry(geom, pen, penWidth, penStrokeStyle);
                    }
                }
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 34
0
 public static void DrawMultiLineString(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IMultiLineString lines, D2D1.Brush pen, float penWidth, D2D1.StrokeStyle penStrokeStyle, Map map, float offset)
 {
     for (var i = 0; i < lines.NumGeometries; i++)
     {
         var line = (ILineString)lines[i];
         DrawLineString(renderTarget, factory, line, pen, penWidth, penStrokeStyle, map, offset);
     }
 }
Ejemplo n.º 35
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 RawRectangleF GetWidenedBounds(float strokeWidth, StrokeStyle strokeStyle, float flatteningTolerance)
 {
     return GetWidenedBounds(strokeWidth, strokeStyle, null, flatteningTolerance);
 }
Ejemplo n.º 36
0
 /// <summary>	
 /// Draws the outline of the specified rounded rectangle using the specified stroke style.	
 /// </summary>	
 /// <remarks>	
 /// This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{DrawRoundedRectangle}}) 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="roundedRect">The dimensions of the rounded rectangle to draw, in device-independent pixels. </param>
 /// <param name="brush">The brush used to paint the rounded rectangle's outline.  </param>
 /// <param name="strokeWidth">The width of the rounded rectangle's stroke. The stroke is centered on the rounded rectangle's outline. The default value is 1.0f.  </param>
 /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or NULL to paint a solid stroke. The default value is NULL. </param>
 /// <unmanaged>void ID2D1RenderTarget::DrawRoundedRectangle([In] const D2D1_ROUNDED_RECT* roundedRect,[In] ID2D1Brush* brush,[None] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawRoundedRectangle(RoundedRectangle roundedRect, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawRoundedRectangle(ref roundedRect, brush, strokeWidth, strokeStyle);
 }
Ejemplo n.º 37
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(RawVector2 point, float strokeWidth, StrokeStyle strokeStyle)
 {
     return StrokeContainsPoint(point, strokeWidth, strokeStyle, null, FlatteningTolerance);
 }
Ejemplo n.º 38
0
 /// <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);
 }
Ejemplo n.º 39
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(RawPoint point, float strokeWidth, StrokeStyle strokeStyle, RawMatrix3x2 transform, float flatteningTolerance)
 {
     return StrokeContainsPoint(new RawVector2 { X = point.X, Y = point.Y}, strokeWidth, strokeStyle, transform, flatteningTolerance);
 }
Ejemplo n.º 40
0
 /// <unmanaged>HRESULT ID2D1CommandSink::DrawLine([In] D2D_POINT_2F point0,[In] D2D_POINT_2F point1,[In] ID2D1Brush* brush,[In] float strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle)</unmanaged>
 public void DrawLine(RawVector2 point0, RawVector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
 {
     DrawLine_(point0, point1, brush, strokeWidth, strokeStyle);
 }