Example #1
0
        /// <summary>
        /// Fills the given ellipse with the given brush.
        /// </summary>
        public void FillEllipse(Vector2 center, float radiusX, float radiusY, BrushResource brush)
        {
            var ellipse = new D2D.Ellipse(MathConverter.RawFromVector2(center), radiusX, radiusY);

            _renderTarget.FillEllipse(
                ellipse,
                brush.GetBrush(this.Device));
        }
Example #2
0
        /// <summary>
        /// Draws the given ellipse with the given brush.
        /// </summary>
        public void DrawEllipse(Vector2 center, float radiusX, float radiusY, BrushResource brush, float strokeWidth = 1f)
        {
            var ellipse = new D2D.Ellipse(MathConverter.RawFromVector2(center), radiusX, radiusY);

            _renderTarget.DrawEllipse(
                ellipse,
                brush.GetBrush(this.Device),
                strokeWidth);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Direct2DSingleRenderTextureResource"/> class.
        /// </summary>
        /// <param name="fillBrush">The brush which gets used when painting the texture on load time.</param>
        /// <param name="height">The width of the generated texture.</param>
        /// <param name="width">The height of the generated texture.</param>
        public Direct2DSingleRenderTextureResource(BrushResource fillBrush, int width, int height)
        {
            fillBrush.EnsureNotNull(nameof(fillBrush));
            width.EnsurePositive(nameof(width));
            height.EnsurePositive(nameof(height));

            m_fillBrush = fillBrush;
            m_width     = width;
            m_height    = height;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Direct2DOneTimeRenderTextureResource"/> class.
        /// </summary>
        /// <param name="fillBrush">The brush which gets used when painting the texture on load time.</param>
        /// <param name="height">The width of the generated texture.</param>
        /// <param name="width">The height of the generated texture.</param>
        public Direct2DOneTimeRenderTextureResource(BrushResource fillBrush, int width, int height)
        {
            fillBrush.EnsureNotNull(nameof(fillBrush));
            width.EnsurePositiveOrZero(nameof(width));
            height.EnsurePositiveOrZero(nameof(height));

            _fillBrush = fillBrush;
            _width     = width;
            _height    = height;
        }
Example #5
0
        /// <summary>
        /// Fills the given ellipse with the given brush.
        /// </summary>
        public void FillEllipse(RectangleF rectangle, BrushResource brush)
        {
            var radiusX = rectangle.Width / 2f;
            var radiusY = rectangle.Height / 2f;
            var center  = new Vector2(
                rectangle.X + radiusX,
                rectangle.Y + radiusY);
            var ellipse = new D2D.Ellipse(MathConverter.RawFromVector2(center), radiusX, radiusY);

            _renderTarget.FillEllipse(
                ellipse,
                brush.GetBrush(this.Device));
        }
Example #6
0
        /// <summary>
        /// Fills the given geometry.
        /// </summary>
        public void FillGeometry(Geometry2DResourceBase geometry, BrushResource brush)
        {
            if (_renderTarget == null)
            {
                return;
            }

            geometry.EnsureNotNullOrDisposed(nameof(geometry));
            brush.EnsureNotNull(nameof(brush));

            _renderTarget.FillGeometry(
                geometry.GetGeometry(),
                brush.GetBrush(this.Device));
        }
Example #7
0
        /// <summary>
        /// Fills the given rectangle with the given brush object.
        /// </summary>
        /// <param name="rectangle">The rectangle to be filled.</param>
        /// <param name="brush">The brush to be used.</param>
        public void FillRectangle(RectangleF rectangle, BrushResource brush)
        {
            if (_renderTarget == null)
            {
                return;
            }

            rectangle.EnsureNotEmpty(nameof(rectangle));
            brush.EnsureNotNull(nameof(brush));

            _renderTarget.FillRectangle(
                rectangle,
                brush.GetBrush(this.Device));
        }
Example #8
0
        /// <summary>
        /// Draws the given line with the given brush.
        /// </summary>
        public void DrawLine(Vector2 start, Vector2 end, BrushResource brush, float strokeWidth = 1f)
        {
            if (_renderTarget == null)
            {
                return;
            }

            brush.EnsureNotNull(nameof(brush));
            strokeWidth.EnsurePositiveAndNotZero(nameof(strokeWidth));

            _renderTarget.DrawLine(
                MathConverter.RawFromVector2(start), MathConverter.RawFromVector2(end),
                brush.GetBrush(this.Device),
                strokeWidth);
        }
Example #9
0
        /// <summary>
        /// Draws the given rectangle with the given brush.
        /// </summary>
        public void DrawRectangle(RectangleF rectangle, BrushResource brush, float strokeWidth = 1f)
        {
            if (_renderTarget == null)
            {
                return;
            }

            brush.EnsureNotNull(nameof(brush));
            rectangle.EnsureNotEmpty(nameof(rectangle));
            strokeWidth.EnsurePositiveOrZero(nameof(strokeWidth));

            _renderTarget.DrawRectangle(
                rectangle,
                brush.GetBrush(this.Device),
                strokeWidth);
        }
Example #10
0
        /// <summary>
        /// Draws the given geometry.
        /// </summary>
        public void DrawGeometry(Geometry2DResourceBase geometry, BrushResource brush, float strokeWidth = 1f)
        {
            if (_renderTarget == null)
            {
                return;
            }

            geometry.EnsureNotNullOrDisposed(nameof(geometry));
            brush.EnsureNotNull(nameof(brush));
            strokeWidth.EnsurePositiveOrZero(nameof(strokeWidth));

            _renderTarget.DrawGeometry(
                geometry.GetGeometry(),
                brush.GetBrush(this.Device),
                strokeWidth);
        }
        public void UpdateCommands(TestContext context)
        {
            if (!Enabled)
            {
                return;
            }
            List <Action <Graphics2D> > newList = new List <Action <Graphics2D> >();

            context.Persons.ForAllWtihReference(context.SIRInfo, (ref PositionItem p, ref SIRData infection) =>
            {
                if (infection.Status == SIRData.Susceptible || infection.Status == SIRData.Infective) //can infect others or can be infected
                {
                    BrushResource c = null;
                    if (infection.Status == SIRData.Susceptible)
                    {
                        c = greeBrush;
                    }
                    else
                    {
                        if (infection.GroundCountdown == TimeSpan.Zero)
                        {
                            c = redBrush;
                        }
                        else
                        {
                            c = yellowBrush;
                        }
                    }
                    var pos = p.Position;
                    newList.Add((graph) =>
                    {
                        graph.FillRectangle(new RectangleF(pos.X, pos.Y, 4, 4), c);
                    });
                }
            });

            lock (drawSync)
            {
                drawCommands = newList;
            }
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorResources"/> class.
        /// </summary>
        /// <param name="properties">The <see cref="EditorProperties"/> to wrap.</param>
        public EditorResources(EditorProperties properties)
        {
            _properties = properties;
            _properties.CustomColorChanged += properties_CustomColorChanged;

            Background = new BrushResource(properties, EditorProperties.BackgroundProperty);
            Foreground = new BrushResource(properties, EditorProperties.ForegroundProperty);
            Selection  = new BrushResource(properties, EditorProperties.SelectionProperty);
            LineNumber = new BrushResource(properties, EditorProperties.LineNumberProperty);

            FontName = properties.FontName;
            FontSize = properties.FontSize;

            _customBrushes = new TinyDictionary <int, Brush>();

            var formattedText = new FormattedText("0", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(FontName),
                                                  FontSize, Brushes.Black, VisualTreeHelper.GetDpi(new Button()).PixelsPerDip);

            CharacterWidth  = formattedText.Width;
            CharacterHeight = (int)(formattedText.Height + 0.75);
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="ImageDataFlowHelper"/> class.
            /// </summary>
            /// <param name="width">The width of the image.</param>
            /// <param name="height">The height of the image.</param>
            public ImageDataFlowHelper(string streamName)
            {
                this.StreamName = streamName;
                this.TextFormat = new TextFormatResource("Arial", 18f, FontWeight.Bold);
                this.TextFormat.TextAlignment = TextAlignment.Center;
                this.TextFormat.ParagraphAlignment = ParagraphAlignment.Center;
                this.TextBackground = new SolidBrushResource(Color4.LightGray.ChangeAlphaTo(0.7f));
                this.TextForeground = new SolidBrushResource(Color4.DarkBlue);

                // Initialize scene(s)
                this.Scene = new Scene();
                this.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    manipulator.AddDrawingLayer(OnDraw);
                }).FireAndForget();

                // Initialize members for Direct2D rendering
                this.Bitmap = null;
                this.BitmapSize = new Size2(0, 0);

                // Initialize members for synchronization
                this.SyncBufferSize = new Size2(0, 0);
                this.SyncBuffer = null;
                this.SyncBufferLock = new object();
                this.SyncBufferChanged = false;
            }
Example #14
0
        /// <summary>
        /// Draws the given text on the screen.
        /// </summary>
        /// <param name="textToDraw">The text to draw.</param>
        /// <param name="textFormat">The TextFormat to be used.</param>
        /// <param name="targetRectangle">The target rectangle.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="drawOptions">Some draw options to be passed to Direct2D.</param>
        /// <param name="measuringMode">Sets the measuring mode to be passed to Direct2D.</param>
        public void DrawText(
            string textToDraw, TextFormatResource textFormat, RectangleF targetRectangle, BrushResource brush,
            DrawTextOptions drawOptions = DrawTextOptions.None,
            MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            if (_renderTarget == null)
            {
                return;
            }

            textToDraw.EnsureNotNull(nameof(textToDraw));
            targetRectangle.EnsureNotEmpty(nameof(targetRectangle));
            brush.EnsureNotNull(nameof(brush));

            _renderTarget.DrawText(
                textToDraw,
                textFormat.GetTextFormat(this.Device),
                targetRectangle,
                brush.GetBrush(this.Device),
                (D2D.DrawTextOptions)drawOptions, (Vortice.DCommon.MeasuringMode)measuringMode);
        }
Example #15
0
        /// <summary>
        /// Fills the given rectangle with the given brush object.
        /// </summary>
        /// <param name="radiusX">The x radius of the rectangle's corners.</param>
        /// <param name="radiusY">The y radius of the rectangle's corners.</param>
        /// <param name="rectangle">The rectangle to be filled.</param>
        /// <param name="brush">The brush to be used.</param>
        public void FillRoundedRectangle(RectangleF rectangle, float radiusX, float radiusY, BrushResource brush)
        {
            if (_renderTarget == null)
            {
                return;
            }

            rectangle.EnsureNotEmpty(nameof(rectangle));
            brush.EnsureNotNull(nameof(brush));
            radiusX.EnsurePositiveOrZero(nameof(radiusX));
            radiusY.EnsurePositiveOrZero(nameof(radiusY));

            var roundedRect = new D2D.RoundedRectangle
            {
                Rect    = rectangle,
                RadiusX = radiusX,
                RadiusY = radiusY
            };

            _renderTarget.FillRoundedRectangle(
                roundedRect,
                brush.GetBrush(this.Device));
        }
Example #16
0
 /// <summary>
 /// Draws a point at the given location.
 /// </summary>
 public void DrawPoint(Vector2 point, BrushResource brush)
 {
     this.DrawLine(
         point, new Vector2(point.X + 1f, point.Y),
         brush);
 }