コード例 #1
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();
        }
コード例 #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
ファイル: TextShape.cs プロジェクト: kagada/Arianrhod
        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
ファイル: TextShape.cs プロジェクト: QuocHuy7a10/Arianrhod
        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;
            }
        }
コード例 #5
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();
        }
コード例 #6
0
ファイル: FontEnumComboBox.cs プロジェクト: kagada/Arianrhod
        private void AddFontFamily(FontFamily family)
        {
            string      familyName;
            CultureInfo familyCulture;

            // First try getting a name in the user's language.
            familyCulture = CultureInfo.CurrentUICulture;
            family.FamilyNames.TryGetValue(familyCulture, out familyName);

            if (familyName == null)
            {
                // Fall back to en-US culture. This is somewhat arbitrary, but most fonts have English
                // strings so this at least yields predictable fallback behavior in most cases.
                familyCulture = enUSCulture;
                family.FamilyNames.TryGetValue(familyCulture, out familyName);
            }

            if (familyName == null)
            {
                // As a last resort, use the first name we find. This will just be the name associated
                // with whatever locale name sorts first alphabetically.
                foreach (KeyValuePair <CultureInfo, string> entry in family.FamilyNames)
                {
                    familyCulture = entry.Key;
                    familyName    = entry.Value;
                }
            }

            if (familyName == null)
            {
                return;
            }

            //add info to list of structs used as a cache of text layouts
            var displayFormats = new List <TextLayout>();
            var format         = dwriteFactory.CreateTextFormat(
                family.Fonts[0].IsSymbolFont ? Font.FontFamily.Name : familyName,
                DropDownFontSize,
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                familyCulture);

            format.WordWrapping = WordWrapping.NoWrap;
            var layout = dwriteFactory.CreateTextLayout(
                familyName,
                format,
                10000,
                10000);

            DropDownWidth = Math.Max(DropDownWidth, (int)layout.Metrics.Width);
            maxHeight     = Math.Max(maxHeight, layout.Metrics.Height);
            displayFormats.Add(layout);
            //add name to list
            primaryNames.Add(familyName);
            layouts.Add(familyName, layout);
        }
コード例 #7
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();
        }
コード例 #8
0
        protected override void OnCreateResources(RenderTarget target)
        {
            // We don't need to free any resources because the base class will
            // call OnFreeResources if necessary before calling this method.
            redBrush   = target.CreateSolidColorBrush(new ColorF(1, 0, 0));
            whiteBrush = target.CreateSolidColorBrush(new ColorF(1, 1, 1));

            textFormat = writeFactory.CreateTextFormat("Arial", 12);

            base.OnCreateResources(target);             // Call this last to start the animation
        }
コード例 #9
0
ファイル: Situation.cs プロジェクト: yadac/WinFormsApp_D2D
        /// <summary>
        /// Draw
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            rand = new Random(Environment.TickCount);
            try
            {
                // 描画開始
                renderTarget.BeginDraw();

                // 背景塗りつぶし
                renderTarget.Clear(new ColorF(0.9f, 0.9f, 0.9f));

                // テキスト描画
                // define font style
                const string fontFamily = "Wingdings"; // you can edit this of course, ex) "Wingdings", "Arial"
                const float  fontSize   = 20.0f;
                TextFormat   tf         = dwriteFactory.CreateTextFormat(
                    fontFamily,
                    fontSize,
                    FontWeight.Normal,
                    FontStyle.Normal,
                    FontStretch.Normal);

                // 16進数 -> 数値 -> 文字 -> 文字列
                string charCode   = "51";
                int    charCode16 = Convert.ToInt32(charCode, 16); // 16進数文字列 -> 数値
                char   c          = Convert.ToChar(charCode16);    // 数値(文字コード) -> 文字
                string str        = c.ToString();                  // 文字 -> 「文字列」
                for (int i = 0; i < 10; i++)
                {
                    float left = rand.Next(0, (int)renderTarget.Size.Width);
                    float top  = rand.Next(0, (int)renderTarget.Size.Height);
                    renderTarget.DrawText(str, tf, new RectF(left, top, left + fontSize, top + fontSize), renderTarget.CreateSolidColorBrush(new ColorF(0.0f, 0.0f, 1.0f)));
                }

                // 描画終了 flush buffered data
                renderTarget.EndDraw();
            }
            catch (Exception ex)
            {
                // handle if draw failed.
                Console.WriteLine("[error][{0}]{1}", DateTime.Now.Millisecond, ex.Message);
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            finally
            {
            }
            // 描画領域の背面に隠れるのを防ぐ
            foreach (var form in forms)
            {
                form?.BringToFront();
            }
        }
コード例 #10
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);
        }
コード例 #11
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;
        }
コード例 #12
0
ファイル: CameraSence.cs プロジェクト: wwkkww1983/Nutshell
        protected override void OnCreateResources(RenderTarget target)
        {
            // We don't need to free any resources because the base class will
            // call OnFreeResources if necessary before calling this method.

            RedBrush = target.CreateSolidColorBrush(new ColorF(1, 0, 0));

            //whiteBrush = RenderTarget.CreateSolidColorBrush(new ColorF(1, 1, 1));
            _d2DBitmap = target.CreateBitmap(target.PixelSize,
                                             new BitmapProperties(new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.PixelFormat(Format.B8G8R8A8UNorm, AlphaMode.Premultiplied), 96, 96));

            textFormat = writeFactory.CreateTextFormat("Arial", 12);

            base.OnCreateResources(target);             // Call this last to start the animation
        }
コード例 #13
0
ファイル: Window1.xaml.cs プロジェクト: kagada/Arianrhod
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties     props     = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops =
                {
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection        pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
コード例 #14
0
ファイル: Window1.xaml.cs プロジェクト: Prashant-Jonny/phever
        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);
        }
コード例 #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
ファイル: Window1.xaml.cs プロジェクト: Prashant-Jonny/phever
        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;
        }
コード例 #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
ファイル: Window1.xaml.cs プロジェクト: QuocHuy7a10/Arianrhod
        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(
                );
        }