Beispiel #1
0
        public Geometry CreateGeometry(Direct2DFactory factory)
        {
            PathGeometry geometry = factory.CreatePathGeometry();

            //using (GeometrySink sink = geometry.Open())
            //{
            //    sink.BeginFigure(Project(this._points[0]), FigureBegin.Hollow);
            //    for (int index = 1; index < this._points.Length; ++index)
            //    {
            //        sink.AddLine(Project(this._points[index]));
            //    }
            //    sink.EndFigure(FigureEnd.Open);
            //    sink.Close();
            //}
            List <Geometry> list = new List <Geometry>();

            //list.Add(geometry);

            for (int index = 0; index < _points.Length; ++index)
            {
                EllipseGeometry ellipse = factory.CreateEllipseGeometry(new Ellipse(Project(_points[index]), 5, 5));
                list.Add(ellipse);
            }

            GeometryGroup group = factory.CreateGeometryGroup(FillMode.Winding, list.ToArray());

            return(group);
        }
Beispiel #2
0
        private void MainWindow_Paint(object sender, PaintEventArgs e)
        {
            _renderTarget.BeginDraw();
            _renderTarget.Clear(Color.FromKnown(Colors.Blue, 1));

            PointF center = new PointF(ClientSize.Width / 2, ClientSize.Height / 2);

            _renderTarget.Transform = Matrix3x2.Rotation(_angle, center);

            RoundedRect rr = new RoundedRect(new RectF(30, 30, ClientSize.Width - 60, ClientSize.Height - 60), ClientSize.Width / 2.5f, ClientSize.Height / 2.5f);

            _renderTarget.FillRoundedRect(RectBrush, rr);
            _renderTarget.DrawRoundedRect(_strokeBrush, 5, _strokeStyle, rr);

            Ellipse ellipse = new Ellipse(ClientSize.Width / 2, ClientSize.Height / 2, ClientSize.Width / 4, ClientSize.Height / 4);

            using (EllipseGeometry eg = _factory.CreateEllipseGeometry(ellipse))
            {
                using (Brush b = CreateEllipseBrush(ellipse))
                {
                    _renderTarget.FillGeometry(b, eg);
                    _renderTarget.DrawGeometry(_strokeBrush, 5, _strokeStyle, eg);
                }
            }
            RectF textBounds = new RectF(0, 0, ClientSize.Width, ClientSize.Height);

            _renderTarget.DrawText("Hello, world!", _textFormat, textBounds, _strokeBrush, DrawTextOptions.None, MeasuringMode.Natural);

            _renderTarget.DrawLine(_strokeBrush, 5, _strokeStyle, new PointF(0, 0), new PointF(ClientSize.Width, ClientSize.Height));

            _renderTarget.EndDraw();
        }
Beispiel #3
0
        public void Render(RenderTarget target)
        {
            Direct2DFactory factory = target.GetFactory();
            Color           red     = Color.FromRGB(128, 64, 64);
            Color           white   = Color.FromRGB(255, 255, 255);

            foreach (var star in _stars)
            {
                Vector4           location = star.Location;
                Nullable <PointF> locN     = Project(location);
                if (locN != null)
                {
                    location = location * Transform;
                    PointF locV = locN.Value;
                    double r    = Math.Sqrt(location.X * location.X + location.Y * location.Y + (location.Z - PointOfView) * (location.Z - PointOfView));
                    double rv   = Math.Sqrt(locV.X * locV.X + locV.Y * locV.Y + PointOfView * PointOfView);
                    double k    = (rv / r);
                    k = k > 1 ? 1 : (k < 0 ? 0 : k);
                    float radius = (float)(star.Radius * rv / r);
                    if (radius > 0.5f)
                    {
                        if (locV.X > 0 && locV.X < ViewPortSize.Width && locV.Y > 0 && locV.Y < ViewPortSize.Height)
                        {
                            using (EllipseGeometry ellipse = factory.CreateEllipseGeometry(new Ellipse(locV, radius, radius)))
                            {
                                float   hue   = (float)k;
                                Vector4 color = new Vector4((hue + 0.45f) % 1, 1f, 0.5f, 1);
                                Color   rgb   = XMath.ColorHslToRgb(color);
                                Color   w     = white.AdjustBrightness((float)Math.Sqrt(k));
                                rgb = Color.Lerp(w, rgb, (float)k);
                                if (radius > 3)
                                {
                                    Color rgb2 = rgb.AdjustBrightness(0.2f);
                                    using (GradientStopCollection coll = target.CreateGradientStopCollection(new GradientStop[] { new GradientStop(0, rgb), new GradientStop(1, rgb2) }))
                                    {
                                        using (Brush brush = target.CreateRadialGradientBrush(new RadialGradientBrushProperties(locV, new PointF(radius / 22f, -radius / 2f), radius, radius),
                                                                                              new BrushProperties(1, Matrix3x2.Identity), coll))
                                        {
                                            target.FillGeometry(brush, ellipse);
                                        }
                                    }
                                }
                                else
                                {
                                    using (SolidColorBrush brush = target.CreateSolidColorBrush(rgb))
                                    {
                                        target.FillGeometry(brush, ellipse);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     renderTarget.Clear(Color.FromKnown(Colors.Black, 1));
     using (EllipseGeometry geometry = Direct2DFactory.CreateEllipseGeometry(new Graphics.Direct2D.Ellipse(ClientSize.Width / 2, ClientSize.Height / 2, ClientSize.Width / 2 - 25, ClientSize.Height / 2 - 25)))
     {
         using (SolidColorBrush brush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Red, 1)))
         {
             renderTarget.DrawGeometry(brush, 50, geometry);
         }
     }
 }
Beispiel #5
0
        private void CreateGeometries(Direct2DFactory factory)
        {
            Ellipse circle1 = new Ellipse(75, 75, 50, 50);

            this._circleGeometry1 = factory.CreateEllipseGeometry(circle1);

            Ellipse circle2 = new Ellipse(125, 75, 50, 50);

            this._circleGeometry2 = factory.CreateEllipseGeometry(circle2);
            // Union
            this._geometryUnion = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryUnion.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Union, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Intersect
            this._geometryIntersect = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryIntersect.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Intersect, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Xor
            this._geometryXor = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryXor.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Xor, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Exclude
            this._geometryExclude = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryExclude.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Exclude, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
        }
        public Geometry CreateGeometry(Direct2DFactory factory)
        {
            PathGeometry geometry = factory.CreatePathGeometry();

            using (GeometrySink sink = geometry.Open())
            {
                sink.BeginFigure(_points[0], FigureBegin.Hollow);
                sink.AddLines(_points);
                sink.EndFigure(FigureEnd.Open);
                sink.Close();
            }
            Geometry[] list = new Geometry[_points.Length + 1];
            list[0] = geometry;

            for (int index = 0; index < _points.Length; ++index)
            {
                list[index + 1] = factory.CreateEllipseGeometry(new Ellipse(_points[index], 5, 5));
            }
            GeometryGroup group = factory.CreateGeometryGroup(FillMode.Winding, list);

            return(group);
        }
Beispiel #7
0
        private void CreateGeometries(Direct2DFactory factory)
        {
            Ellipse circle1 = new Ellipse(75, 75, 50, 50);
            this._circleGeometry1 = factory.CreateEllipseGeometry(circle1);

            Ellipse circle2 = new Ellipse(125, 75, 50, 50);
            this._circleGeometry2 = factory.CreateEllipseGeometry(circle2);
            // Union
            this._geometryUnion = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryUnion.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Union, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Intersect
            this._geometryIntersect = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryIntersect.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Intersect, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Xor
            this._geometryXor = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryXor.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Xor, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
            // Exclude
            this._geometryExclude = factory.CreatePathGeometry();
            using (GeometrySink sink = this._geometryExclude.Open())
            {
                this._circleGeometry1.CombineWithGeometry(this._circleGeometry2, CombineMode.Exclude, Matrix3x2.Identity, 0.25f, sink);
                sink.Close();
            }
        }