protected void InitializeDirect2D(Panel holder)                       //用控件初始化Direct2D变量
        {
            Factory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); //创建工厂
            var rtps = new RenderTargetProperties();
            var hrtp = new HwndRenderTargetProperties(holder.Handle, new SizeU((uint)holder.Width, (uint)holder.Height), PresentOptions.None);

            Canvas = Factory.CreateHwndRenderTarget(rtps, hrtp);
        }
Esempio n. 2
0
        private void InitializeDisplayerState()
        {
            var rtps = new RenderTargetProperties();
            var hrtp = new HwndRenderTargetProperties(Panel.Handle, new SizeU((uint)Panel.Width, (uint)Panel.Height), PresentOptions.None);

            Factory              = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded); //创建工厂
            rt                   = Factory.CreateHwndRenderTarget(rtps, hrtp);
            rt.AntiAliasMode     = AntiAliasMode.Aliased;
            rt.TextAntiAliasMode = TextAntiAliasMode.Aliased;
            (rt as HwndRenderTarget).Resize(new SizeU((uint)Panel.Width, (uint)Panel.Height));
            rt.Transform = Matrix3x2F.Scale(rt.Size.Width / Panel.Width, rt.Size.Height / Panel.Height);
        }
Esempio n. 3
0
        void host_Loaded(object sender, RoutedEventArgs e)
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

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

            // Start rendering now!
            host.Render = Render;
            host.InvalidateVisual();
        }
Esempio n. 4
0
 public void Initialize()
 {
     d2DFactory    = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);
     dwriteFactory = DWriteFactory.CreateFactory();
     InitializeRenderTarget();
     FillFontFamilies();
     if (FixedItemHeight)
     {
         DropDownHeight = (int)maxHeight * 10;
     }
     DrawMode     = DrawMode.OwnerDrawVariable;
     MeasureItem += FontEnumComboBox_MeasureItem;
     DrawItem    += FontEnumComboBox_DrawItem;
 }
Esempio n. 5
0
        void CreateDeviceIndependentResources()
        {
            // Create a Direct2D factory.
            d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create a DirectWrite factory.
            dWriteFactory = DWriteFactory.CreateFactory();

            // Create a DirectWrite text format object.
            textFormat = dWriteFactory.CreateTextFormat("Calibri", 50, DWrite.FontWeight.Bold, DWrite.FontStyle.Normal, DWrite.FontStretch.Normal);

            // Center the text both horizontally and vertically.
            textFormat.TextAlignment      = DWrite.TextAlignment.Leading;
            textFormat.ParagraphAlignment = ParagraphAlignment.Near;
        }
Esempio n. 6
0
        private void CreateFactories()
        {
            //reuse factories except for random cases
            if (random.NextDouble() < 0.5)
            {
                lock (sharedSyncObject)
                {
                    if (sharedD2DFactory == null)
                    {
                        // Create the D2D Factory
                        sharedD2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

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

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

                        Debug.Assert(sharedD2DFactory.NativeInterface != IntPtr.Zero);
                        Debug.Assert(sharedDwriteFactory.NativeInterface != IntPtr.Zero);
                        Debug.Assert(sharedWicFactory.NativeInterface != IntPtr.Zero);
                    }
                    sharedRefCount++;
                }
                d2DFactory    = sharedD2DFactory;
                dwriteFactory = sharedDwriteFactory;
                wicFactory    = sharedWicFactory;
                Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero);
            }
            else
            {
                // Create the D2D Factory
                d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);

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

                // Create the WIC Factory
                wicFactory = ImagingFactory.Create();
                Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero);
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        private void CreateDeviceIndependentResources()
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

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

            wicFactory = ImagingFactory.Create();

            string text = "Inline Object * Sample";

            textFormat = dwriteFactory.CreateTextFormat("Gabriola", 72);

            textFormat.TextAlignment      = DWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = DWrite.ParagraphAlignment.Center;

            textLayout = dwriteFactory.CreateTextLayout(
                text,
                textFormat,
                (float)host.ActualWidth,
                (float)host.ActualHeight);
        }
Esempio n. 9
0
        private void Situation_Load(object sender, EventArgs e)
        {
            Console.WriteLine("load!!");
            // create factory (un-managed resource)
            d2DFactory    = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);
            dwriteFactory = DWriteFactory.CreateFactory();

            // target
            RenderTargetProperties renderTargetProperties = new RenderTargetProperties
            {
                PixelFormat      = new PixelFormat(),
                Usage            = RenderTargetUsages.None,
                RenderTargetType = RenderTargetType.Default
            };

            // handle
            HwndRenderTargetProperties hwndRenderTargetProperties1 = new HwndRenderTargetProperties
            {
                WindowHandle   = this.pictureBox1.Handle,
                PixelSize      = new SizeU((uint)this.pictureBox1.Width, (uint)this.pictureBox1.Height),
                PresentOptions = PresentOptions.Immediately
            };

            renderTarget = d2DFactory.CreateHwndRenderTarget(renderTargetProperties, hwndRenderTargetProperties1);

            // create blushes
            blackBlush = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 0.0f, 0.0f));
            redBlush   = renderTarget.CreateSolidColorBrush(new ColorF(1.0f, 0.0f, 0.0f));
            greenBlush = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 1.0f, 0.0f));
            blueBlush  = renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 0.0f, 1.0f));

            // define and start onPaintTimer
            onPaintTimer          = new Timer();
            onPaintTimer.Interval = 500;
            onPaintTimer.Tick    += Render;
            onPaintTimer.Start();
        }
Esempio n. 10
0
        void CreateDeviceIndependentResources()
        {
            string msc_fontName = "Verdana";
            float  msc_fontSize = 50;

            string fps_fontName = "Courier New";
            float  fps_fontSize = 12;

            GeometrySink spSink;

            // Create D2D factory
            d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

            // Create WIC factory
            imagingFactory = ImagingFactory.Create();

            // Create DWrite factory
            dWriteFactory = DWriteFactory.CreateFactory();

            // Create DWrite text format object
            textFormat = dWriteFactory.CreateTextFormat(
                msc_fontName,
                msc_fontSize);

            textFormat.TextAlignment      = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Center;
            textFormat.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Center;


            // Create DWrite text format object
            textFormatFps = dWriteFactory.CreateTextFormat(
                fps_fontName,
                fps_fontSize);

            textFormatFps.TextAlignment      = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.TextAlignment.Leading;
            textFormatFps.ParagraphAlignment = Microsoft.WindowsAPICodePack.DirectX.DirectWrite.ParagraphAlignment.Near;

            // Create the path geometry.
            pathGeometry = d2DFactory.CreatePathGeometry();

            // Write to the path geometry using the geometry sink. We are going to create an
            // hour glass.
            spSink = pathGeometry.Open();

            spSink.SetFillMode(Microsoft.WindowsAPICodePack.DirectX.Direct2D1.FillMode.Alternate);

            spSink.BeginFigure(
                new Point2F(0, 0),
                FigureBegin.Filled
                );

            spSink.AddLine(new Point2F(200, 0));

            spSink.AddBezier(
                new BezierSegment(
                    new Point2F(150, 50),
                    new Point2F(150, 150),
                    new Point2F(200, 200)
                    ));

            spSink.AddLine(
                new Point2F(0,
                            200)
                );

            spSink.AddBezier(
                new BezierSegment(
                    new Point2F(50, 150),
                    new Point2F(50, 50),
                    new Point2F(0, 0)
                    ));

            spSink.EndFigure(
                FigureEnd.Closed
                );

            spSink.Close(
                );
        }
Esempio n. 11
0
 private RenderTarget _renderTarget; //渲染窗口,ID2D1HwndRenderTarget接口。
 /// <summary>
 /// 构造函数,创建一个D2D工厂对象。
 /// </summary>
 public Direct2DFactoryBase()
 {
     _d2dFactory = D2DFactory.CreateFactory();
 }
 /// <summary>
 /// Device independent resources are not specific to a particular device. For example, factory and font.
 /// </summary>
 private void CreateDeviceIndependentResource()
 {
     //Create Direct 2D factory.
     this._d2DFactory = D2DFactory.CreateFactory();
 }
Esempio n. 13
0
 /// <summary>
 ///         Initializes a new instance of the Scene class.
 /// </summary>
 protected Sence()
 {
     // We'll create a multi-threaded one to make sure it plays nicely with WPF
     _factory = D2DFactory.CreateFactory(D2DFactoryType.Multithreaded);
 }