コード例 #1
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));
        }
コード例 #2
0
ファイル: Chart_Bar.cs プロジェクト: hljlishen/Utilities
        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();
        }
コード例 #3
0
 public static TextFormat MakeFormat(this string fontName, float size)
 {
     using (var dw = DWriteFactory.CreateFactory())
     {
         return(dw.CreateTextFormat(fontName, size));
     }
 }
コード例 #4
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();
        }
コード例 #5
0
ファイル: CameraSence.cs プロジェクト: wwkkww1983/Nutshell
        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);
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: Window1.xaml.cs プロジェクト: kagada/Arianrhod
        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();
        }
コード例 #8
0
ファイル: FontEnumComboBox.cs プロジェクト: kagada/Arianrhod
 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;
 }
コード例 #9
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;
        }
コード例 #10
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
     });
 }
コード例 #11
0
ファイル: D2DShapesControl.cs プロジェクト: kagada/Arianrhod
        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);
            }
        }
コード例 #12
0
        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();
        }
コード例 #13
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);
            }
        }
コード例 #14
0
ファイル: Paint2DForm.cs プロジェクト: kagada/Arianrhod
        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);
        }
コード例 #15
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);
        }
コード例 #16
0
ファイル: Situation.cs プロジェクト: yadac/WinFormsApp_D2D
        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();
        }
コード例 #17
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(
                );
        }
コード例 #18
0
 public MySence()
     : base(100)             // Will probably only be about 67 fps due to the limitations of the timer
 {
     writeFactory = DWriteFactory.CreateFactory();
 }