コード例 #1
0
        public void Render(DrawingContext context, Point offset, double scale, Rect viewRect)
        {
            if (m_position != m_orbitCenterPosition && !Name.StartsWith("Asteroid"))
            {
                var focus         = Focus * scale;
                var renderOrbitAt = new Point((OrbitCenterPosition.X * scale) - focus + offset.X, (OrbitCenterPosition.Y * scale) + offset.Y);
                var semiMajorAxis = SemiMajorAxis * scale;
                var semiMinorAxis = SemiMinorAxis * scale;
                var center        = new Point((OrbitCenterPosition.X * scale) - focus, OrbitCenterPosition.Y * scale)
                                    .RotateAround(new Point((OrbitCenterPosition.X * scale), OrbitCenterPosition.Y * scale), LongitudeOfPeriapsis)
                                    .WithOffset(offset);
                if (EllipseUtility.ShouldRenderEllipseInRectangle(viewRect, center, semiMajorAxis, semiMinorAxis))
                {
                    EllipseUtility.OrbitsRendered++;
                    var orbitPen = (Pen)ThemesUtility.CurrentThemeDictionary["PlanetOrbitPen"];
                    using (context.ScopedTransform(new TranslateTransform(renderOrbitAt.X, renderOrbitAt.Y)))
                        using (context.ScopedTransform(new RotateTransform(LongitudeOfPeriapsis, focus, 0.0)))
                        {
                            context.DrawEllipse(null, orbitPen, new Point(), semiMajorAxis, semiMinorAxis);
                        }
                }
                else
                {
                    EllipseUtility.OrbitsSkipped++;
                }
            }

            var minRadius = (double)ThemesUtility.CurrentThemeDictionary["PlanetMinRadius"];
            var radius    = Math.Max(minRadius, Radius * scale);
            var renderAt  = new Point((Position.X * scale) + offset.X, (Position.Y * scale) + offset.Y);
            var bodyBrush = (Brush)ThemesUtility.CurrentThemeDictionary["PlanetBodyBrush"];

            if (Position != new Point())
            {
                var vectorToCenter = renderAt.VectorTo(offset);
                vectorToCenter.Normalize();
                var gradientStart = renderAt + (vectorToCenter * 10.0);
                var lightColor    = ((SolidColorBrush)ThemesUtility.CurrentThemeDictionary["PlanetBodyLightBrush"]).Color;
                var darkColor     = ((SolidColorBrush)ThemesUtility.CurrentThemeDictionary["PlanetBodyDarkBrush"]).Color;
                var gradientBrush = new LinearGradientBrush(new GradientStopCollection
                {
                    new GradientStop(lightColor, 0.0),
                    new GradientStop(lightColor, 1.0),
                    new GradientStop(darkColor, 1.0),
                },
                                                            gradientStart,
                                                            renderAt
                                                            );
                gradientBrush.MappingMode  = BrushMappingMode.Absolute;
                gradientBrush.SpreadMethod = GradientSpreadMethod.Pad;
                bodyBrush = gradientBrush.Frozen();
            }

            var bodyPen = (Pen)ThemesUtility.CurrentThemeDictionary["PlanetBodyPen"];

            context.DrawEllipse(bodyBrush, bodyPen, renderAt, radius, radius);
        }
コード例 #2
0
        protected override void OnRender(DrawingContext context)
        {
            base.OnRender(context);

            var viewRect = new Rect(0, 0, ActualWidth, ActualHeight);

            using (context.ScopedClip(new RectangleGeometry(viewRect)))
            {
                context.DrawRectangle(s_backgroundBrush, null, viewRect);

                if (!double.TryParse(Left, out var left))
                {
                    return;
                }
                if (!double.TryParse(Top, out var top))
                {
                    return;
                }
                if (!double.TryParse(Right, out var right))
                {
                    return;
                }
                if (!double.TryParse(Bottom, out var bottom))
                {
                    return;
                }

                var centerPoint = new Point(viewRect.Width / 2.0, viewRect.Height / 2.0);
                var scale       = Scale * Math.Min(centerPoint.X, centerPoint.Y);
                var offset      = new Point(centerPoint.X - (Center.X * scale), centerPoint.Y - (Center.Y * scale));

                var adjustedLeft      = (left * scale) + offset.X;
                var adjustedTop       = (top * scale) + offset.Y;
                var adjustedRight     = (right * scale) + offset.X;
                var adjustedBottom    = (bottom * scale) + offset.Y;
                var adjustedRectangle = new Rect(adjustedLeft, adjustedTop, adjustedRight - adjustedLeft, adjustedBottom - adjustedTop);
                context.DrawRectangle(null, IsRectangleActive ? s_activePen : s_rectanglePen, adjustedRectangle);

                if (!double.TryParse(EllipseCenterX, out var ellipseCenterX))
                {
                    return;
                }
                if (!double.TryParse(EllipseCenterY, out var ellipseCenterY))
                {
                    return;
                }
                if (!double.TryParse(MajorRadius, out var majorRadius))
                {
                    return;
                }
                if (!double.TryParse(MinorRadius, out var minorRadius))
                {
                    return;
                }
                if (!double.TryParse(EllipseRotation, out var ellipseRotation))
                {
                    return;
                }

                var adjustedEllipseCenterX = (ellipseCenterX * scale) + offset.X;
                var adjustedEllipseCenterY = (ellipseCenterY * scale) + offset.Y;
                var adjustedMajorRadius    = majorRadius * scale;
                var adjustedMinorRadius    = minorRadius * scale;
                using (context.ScopedTransform(new TranslateTransform(adjustedEllipseCenterX, adjustedEllipseCenterY)))
                    using (context.ScopedTransform(new RotateTransform(ellipseRotation, 0.0, 0.0)))
                        context.DrawEllipse(null, IsEllipseActive ? s_activePen : s_orbitPen, new Point(), adjustedMajorRadius, adjustedMinorRadius);

                context.DrawEllipse(s_centerBrush, null, new Point(adjustedEllipseCenterX, adjustedEllipseCenterY), c_markerRadius, c_markerRadius);

                var rotationRadians = MathUtility.DegreesToRadians(-ellipseRotation);
                var ellipseCenter   = new Point(ellipseCenterX, ellipseCenterY);

                var leftPoints = NormalizeIntersectionPoints(EllipseUtility.FindIntersectionAndSlopeOfLineAndEllipse(new Point(left, bottom), new Point(left, top), true, ellipseCenter, majorRadius, minorRadius, rotationRadians), scale, offset);
                RenderIntersectionPoints(leftPoints, context);

                var topPoints = NormalizeIntersectionPoints(EllipseUtility.FindIntersectionAndSlopeOfLineAndEllipse(new Point(left, top), new Point(right, top), true, ellipseCenter, majorRadius, minorRadius, rotationRadians), scale, offset);
                RenderIntersectionPoints(topPoints, context);

                var rightPoints = NormalizeIntersectionPoints(EllipseUtility.FindIntersectionAndSlopeOfLineAndEllipse(new Point(right, top), new Point(right, bottom), true, ellipseCenter, majorRadius, minorRadius, rotationRadians), scale, offset);
                RenderIntersectionPoints(rightPoints, context);

                var bottomPoints = NormalizeIntersectionPoints(EllipseUtility.FindIntersectionAndSlopeOfLineAndEllipse(new Point(right, bottom), new Point(left, bottom), true, ellipseCenter, majorRadius, minorRadius, rotationRadians), scale, offset);
                RenderIntersectionPoints(bottomPoints, context);

                var normalizedEllipseCenter = new Point((ellipseCenter.X * scale) + offset.X, (ellipseCenter.Y * scale) + offset.Y);
                RenderEstimates(leftPoints, topPoints, rightPoints, bottomPoints, normalizedEllipseCenter, MathUtility.DegreesToRadians(ellipseRotation), adjustedMajorRadius, adjustedMinorRadius, adjustedRectangle, context);
            }
        }