예제 #1
0
        protected void DrawObjectUnselected(RenderTarget rt, LiveRect r)
        {
            var brush      = Color.Pink.SolidBrush(rt);
            var frameBrush = Color.White.SolidBrush(rt);

            rt.FillRectangle(r.Rectangle.ToRectF(), brush);
            rt.DrawRectangle(r.Rectangle.ToRectF(), frameBrush, 1);
            brush.Dispose();
            frameBrush.Dispose();

            var           textBrush        = Color.White.SolidBrush(rt);
            DWriteFactory dw               = DWriteFactory.CreateFactory();
            TextFormat    normalTextFormat = dw.CreateTextFormat("微软雅黑", 20);

            if (r.Rectangle.Bottom > Mapper.GetScreenY(0))
            {
                rt.DrawText(r.Value.ToString(), normalTextFormat, new RectangleF(r.Rectangle.X - 5, r.Rectangle.Top - 40, 100, 100).ToRectF(), textBrush);
            }
            else
            {
                rt.DrawText(r.Value.ToString(), normalTextFormat, new RectangleF(r.Rectangle.X - 5, r.Rectangle.Bottom + 20, 100, 100).ToRectF(), textBrush);
            }
            dw.Dispose();
            textBrush.Dispose();
            normalTextFormat.Dispose();
        }
예제 #2
0
        public TextTargetView(Target target, TextDisplayer displayer, Point2F drawPoint) : base(target)
        {
            _displayer   = displayer;
            leftTop      = drawPoint;
            _columnWidth = displayer.ColumnWidth;
            _rects       = CalculateRects();
            activeRect   = CalculateActiveRect();
            _texts       = new List <string>();
            TargetTrack track = (TargetTrack)target;

            _texts.Add(track.TrackId.ToString());
            _texts.Add(track.Az.ToString("0.0"));
            _texts.Add(track.El.ToString("0.0"));
            _texts.Add(track.Dis.ToString("0.0"));
            _texts.Add(track.Speed.ToString("0.0"));

            _borderBrush = displayer.Canvas.CreateSolidColorBrush(new ColorF(1, 1, 1));
            DWriteFactory dw = DWriteFactory.CreateFactory();

            _inactiveTextFormat = dw.CreateTextFormat("宋体", 20);
            _inactiveTextFormat.TextAlignment = TextAlignment.Center;
            _inactiveBrush = displayer.Canvas.CreateSolidColorBrush(new ColorF(0, 1, 1));

            _activeBrush = displayer.Canvas.CreateSolidColorBrush(new ColorF(0, 0, 1));
        }
예제 #3
0
        public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory)
            : base(initialRenderTarget, random, d2DFactory, bitmap)
        {
            this.dwriteFactory = dwriteFactory;
            layoutRect         = RandomRect(CanvasWidth, CanvasHeight);
            NiceGabriola       = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola");
            TextFormat         = dwriteFactory.CreateTextFormat(
                RandomFontFamily(),
                RandomFontSize(),
                RandomFontWeight(),
                RandomFontStyle(),
                RandomFontStretch(),
                System.Globalization.CultureInfo.CurrentUICulture);
            if (CoinFlip)
            {
                TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize);
            }
            Text = RandomString(Random.Next(1000, 1000));

            FillBrush       = RandomBrush();
            RenderingParams = RandomRenderingParams();

            if (CoinFlip)
            {
                Options = DrawTextOptions.None;
                if (CoinFlip)
                {
                    Options |= DrawTextOptions.Clip;
                }
                if (CoinFlip)
                {
                    Options |= DrawTextOptions.NoSnap;
                }
            }
        }
예제 #4
0
 public static TextFormat MakeFormat(this string fontName, float size)
 {
     using (var dw = DWriteFactory.CreateFactory())
     {
         return(dw.CreateTextFormat(fontName, size));
     }
 }
예제 #5
0
        public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory)
            : base(initialRenderTarget, random, d2DFactory, bitmap)
        {
            this.dwriteFactory = dwriteFactory;
            layoutRect = RandomRect(CanvasWidth, CanvasHeight);
            NiceGabriola = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola");
            TextFormat = dwriteFactory.CreateTextFormat(
                RandomFontFamily(),
                RandomFontSize(),
                RandomFontWeight(),
                RandomFontStyle(),
                RandomFontStretch(),
                System.Globalization.CultureInfo.CurrentUICulture);
            if (CoinFlip)
                TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize);
            Text = RandomString(Random.Next(1000, 1000));

            FillBrush = RandomBrush();
            RenderingParams = RandomRenderingParams();

            if (CoinFlip)
            {
                Options = DrawTextOptions.None;
                if (CoinFlip)
                    Options |= DrawTextOptions.Clip;
                if (CoinFlip)
                    Options |= DrawTextOptions.NoSnap;
            }
        }
예제 #6
0
 public virtual void Dispose()
 {
     _d2dFactory?.Dispose();
     DWriteFactory?.Dispose();
     WicFactory?.Dispose();
     DeviceContext?.Dispose();
     _d2dDevice?.Dispose();
 }
예제 #7
0
        protected override void InitializeComponents(RenderTarget rt)
        {
            base.InitializeComponents(rt);
            textBrush = DisplayModel.FontColor.SolidBrush(rt);
            DWriteFactory dw = DWriteFactory.CreateFactory();

            textFormat = dw.CreateTextFormat(DisplayModel.FontName, DisplayModel.FontSize);
            dw.Dispose();
        }
예제 #8
0
        public CameraSence(IdentityObject parent, string id, int width, int height, Camera camera)
            : base()             // Will probably only be about 67 fps due to the limitations of the timer
        {
            camera.MustNotNull();
            _camera = camera;

            writeFactory = DWriteFactory.CreateFactory();

            _bitmap = new Bitmap(this, "缓冲图像", width, height, PixelFormat.Bgra32);
        }
예제 #9
0
        public virtual void Dispose()
        {
            _d2dFactory?.Dispose();
            DWriteFactory?.Dispose();
            WicFactory.Dispose();
            WicFormatConverter.Dispose();

            WhiteBrush.Dispose();
            RedBrush.Dispose();
            DeviceContext?.Dispose();
            _d2dDevice?.Dispose();
        }
예제 #10
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;
 } 
예제 #11
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();
        }
예제 #12
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();
        }
예제 #13
0
        public MouseCoordinateDisplayer(OverViewDisplayer ovd)
        {
            displayer = ovd;
            displayer.DisplayControl.MouseMove += MoveMoveHandler;
            //mouseLocationCoordinateBitmap = displayer.Canvas.CreateCompatibleRenderTarget();
            coordinateBoardBrush         = displayer.Canvas.CreateSolidColorBrush(new ColorF(1, 1, 1));
            coordinateBoardBrush.Opacity = 0.5f;
            textBrush = displayer.Canvas.CreateSolidColorBrush(new ColorF(0, 1, 1));
            DWriteFactory dw = DWriteFactory.CreateFactory();

            idFormation = dw.CreateTextFormat("Berlin Sans FB Demi", 25);
        }
예제 #14
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;
 }
예제 #15
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;
        }
예제 #16
0
 protected override void InitializeComponents(RenderTarget rt)
 {
     base.InitializeComponents(rt);
     normalLineBrush   = Model.LineColor.SolidBrush(rt);
     selectedLineBrush = Model.SelectedLineColor.SolidBrush(rt);
     normalTextBrush   = Model.FontColor.SolidBrush(rt);
     selectedTextBrush = Model.SelectedFontColor.SolidBrush(rt);
     using (var dw = DWriteFactory.CreateFactory())
     {
         normalTextFormat   = dw.CreateTextFormat(Model.FontName, Model.FontSize);
         selectedTextFormat = dw.CreateTextFormat(Model.SelectedFontName, Model.SelectedFontSize);
     }
     strokeStyle = rt.Factory.CreateStrokeStyle(new StrokeStyleProperties {
         DashStyle = DashStyle.DashDot
     });
 }
예제 #17
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);
            }
        }
        public SideViewDisplayerBackground(RenderTarget canvas, D2DFactory factory, CoordinateSystem csp) : base(canvas, factory, csp)
        {
            axisBrush     = canvas.CreateSolidColorBrush(new ColorF(0, 255, 0));     //绿色
            dashLineBrush = canvas.CreateSolidColorBrush(new ColorF(128, 138, 135)); //冷灰

            DWriteFactory dw = DWriteFactory.CreateFactory();

            xTextFromation = dw.CreateTextFormat("Berlin Sans FB Demi", 15);
            yTextFromation = dw.CreateTextFormat("Berlin Sans FB Demi", 15);
            yTextFromation.TextAlignment = TextAlignment.Trailing;
            textBrush = canvas.CreateSolidColorBrush(new ColorF(new ColorI(128, 138, 135)));

            angleLines   = new float[] { 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330 };
            angleNumbers = new float[] { 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360 };

            distanceNumbers = new[] { 0, Distance / 6, Distance / 3, Distance / 2, Distance * 2 / 3, Distance * 5 / 6, Distance };

            dw.Dispose();
        }
예제 #19
0
        protected override void InitializeComponents(RenderTarget rt)
        {
            base.InitializeComponents(rt);
            normalLineBrush?.Dispose();
            selectedLineBrush?.Dispose();
            normalTextFormat?.Dispose();
            selectedTextFormat?.Dispose();
            normalTextBrush?.Dispose();
            selectedTextBrush?.Dispose();

            normalLineBrush   = Model.LineColor.SolidBrush(rt);
            selectedLineBrush = Model.SelectedLineColor.SolidBrush(rt);
            normalTextBrush   = Model.FontColor.SolidBrush(rt);
            selectedTextBrush = Model.SelectedFontColor.SolidBrush(rt);
            using (var dw = DWriteFactory.CreateFactory())
            {
                normalTextFormat   = dw.CreateTextFormat(Model.FontName, Model.FontSize);
                selectedTextFormat = dw.CreateTextFormat(Model.SelectedFontName, Model.SelectedFontSize);
            }
        }
예제 #20
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                //dispose of all layouts
                while (layouts.Keys.Count > 0)
                {
                    foreach (string key in layouts.Keys)
                    {
                        layouts[key].Dispose();
                        layouts.Remove(key);
                        break;
                    }
                }

                if (brush != null)
                {
                    brush.Dispose();
                }
                brush = null;
                if (dcRenderTarget != null)
                {
                    dcRenderTarget.Dispose();
                }
                dcRenderTarget = null;
                if (dwriteFactory != null)
                {
                    dwriteFactory.Dispose();
                }
                dwriteFactory = null;
                if (d2DFactory != null)
                {
                    d2DFactory.Dispose();
                }
                d2DFactory = null;
            }
            base.Dispose(disposing);
        }
예제 #21
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);
        }
예제 #22
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);
        }
예제 #23
0
        private void CreateDeviceIndependentResources()
        {
            // Create the D2D Factory
            d2dFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);

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

            wicFactory = new ImagingFactory();

            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);
        }
예제 #24
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();
        }
예제 #25
0
        /// <summary>
        /// Dispose of resources (IDisposable implementation)
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && !disposed)
            {
                lock (renderSyncObject)
                {
                    render = null;

                    lock (sharedSyncObject)
                    {
                        if (sharedD2DFactory != null && d2DFactory == sharedD2DFactory)
                            sharedRefCount--;

                        if (d2DFactory != null && d2DFactory != sharedD2DFactory)
                            d2DFactory.Dispose();
                        d2DFactory = null;

                        if (dwriteFactory != null && dwriteFactory != sharedDwriteFactory)
                            dwriteFactory.Dispose();
                        dwriteFactory = null;

                        if (wicFactory != null && wicFactory != sharedWicFactory)
                            wicFactory.Dispose();
                        wicFactory = null;

                        if (sharedRefCount == 0)
                        {
                            if (sharedD2DFactory != null)
                                sharedD2DFactory.Dispose();
                            sharedD2DFactory = null;

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

                            if (sharedWicFactory != null)
                                sharedWicFactory.Dispose();
                            sharedWicFactory = null;
                        }
                    }

                    foreach (DrawingShape shape in drawingShapes)
                    {
                        shape.Dispose();
                    }

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

                    if (dcRenderTarget != null)
                        dcRenderTarget.Dispose();
                    dcRenderTarget = null;
                    if (bitmapRenderTarget != null)
                        bitmapRenderTarget.Dispose();
                    bitmapRenderTarget = null;
                    if (hwndRenderTarget != null)
                        hwndRenderTarget.Dispose();
                    hwndRenderTarget = null;


                    disposed = true;
                }
            }
            base.Dispose(disposing);
        }
예제 #26
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);
            }
        }
예제 #27
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;
        }
예제 #28
0
 public MySence()
     : base(100)             // Will probably only be about 67 fps due to the limitations of the timer
 {
     writeFactory = DWriteFactory.CreateFactory();
 }
예제 #29
0
        private void CreateDeviceIndependentResources()
        {
            this.d2dFactory = D2D1Factory.Create(D2D1FactoryType.SingleThreaded);

            this.dwriteFactory = DWriteFactory.Create(DWriteFactoryType.Shared);
        }
        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);

        }
예제 #31
0
 public TextLayoutShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory)
     : base(initialRenderTarget, random, d2DFactory, bitmap, dwriteFactory)
 {
     RandomizeTextLayout();
     Point0 = RandomPoint();
 }
예제 #32
0
        /// <summary>
        /// Dispose of resources (IDisposable implementation)
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && !disposed)
            {
                lock (renderSyncObject)
                {
                    render = null;

                    lock (sharedSyncObject)
                    {
                        if (sharedD2DFactory != null && d2DFactory == sharedD2DFactory)
                        {
                            sharedRefCount--;
                        }

                        if (d2DFactory != null && d2DFactory != sharedD2DFactory)
                        {
                            d2DFactory.Dispose();
                        }
                        d2DFactory = null;

                        if (dwriteFactory != null && dwriteFactory != sharedDwriteFactory)
                        {
                            dwriteFactory.Dispose();
                        }
                        dwriteFactory = null;

                        if (wicFactory != null && wicFactory != sharedWicFactory)
                        {
                            wicFactory.Dispose();
                        }
                        wicFactory = null;

                        if (sharedRefCount == 0)
                        {
                            if (sharedD2DFactory != null)
                            {
                                sharedD2DFactory.Dispose();
                            }
                            sharedD2DFactory = null;

                            if (sharedDwriteFactory != null)
                            {
                                sharedDwriteFactory.Dispose();
                            }
                            sharedDwriteFactory = null;

                            if (sharedWicFactory != null)
                            {
                                sharedWicFactory.Dispose();
                            }
                            sharedWicFactory = null;
                        }
                    }

                    foreach (DrawingShape shape in drawingShapes)
                    {
                        shape.Dispose();
                    }

                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                    bitmap = null;

                    if (dcRenderTarget != null)
                    {
                        dcRenderTarget.Dispose();
                    }
                    dcRenderTarget = null;
                    if (bitmapRenderTarget != null)
                    {
                        bitmapRenderTarget.Dispose();
                    }
                    bitmapRenderTarget = null;
                    if (hwndRenderTarget != null)
                    {
                        hwndRenderTarget.Dispose();
                    }
                    hwndRenderTarget = null;


                    disposed = true;
                }
            }
            base.Dispose(disposing);
        }
예제 #33
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         //dispose of all layouts
         while (layouts.Keys.Count > 0)
             foreach (string key in layouts.Keys)
             {
                 layouts[key].Dispose();
                 layouts.Remove(key);
                 break;
             }
             
         if (brush != null)
             brush.Dispose();
         brush = null;
         if (dcRenderTarget != null)
             dcRenderTarget.Dispose();
         dcRenderTarget = null;
         if (dwriteFactory != null)
             dwriteFactory.Dispose();
         dwriteFactory = null;
         if (d2DFactory != null)
             d2DFactory.Dispose();
         d2DFactory = null;
     }
     base.Dispose(disposing);
 } 
예제 #34
0
 public GlyphRenderer()
     : base()
 {
     _systemFonts = DWriteFactory.GetSystemFontCollection(false);
 }
예제 #35
0
        private void CreateFactories()
        {
                // Create the D2D Factory
                d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.MultiThreaded);

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

                // Create the WIC Factory
                wicFactory = new ImagingFactory();
                Debug.Assert(d2DFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(dwriteFactory.NativeInterface != IntPtr.Zero);
                Debug.Assert(wicFactory.NativeInterface != IntPtr.Zero);
        }
예제 #36
0
 public static extern object DWriteCreateFactory(DWriteFactory.FactoryType factoryType,
     [MarshalAs(UnmanagedType.LPStruct)] Guid riid);
예제 #37
0
 public TextLayoutShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory)
     : base(initialRenderTarget, random, d2DFactory, bitmap, dwriteFactory)
 {
     RandomizeTextLayout();
     Point0 = RandomPoint();
 }
예제 #38
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(
                );
        }
예제 #39
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(
                );
        }