コード例 #1
0
        /// <summary>
        /// Checks if the render target needs to be initialized and does it.
        /// Returns true if a new render target was created. False othewise.
        /// </summary>
        /// <param name="display"></param>
        /// <returns></returns>
        public bool InitializeRenderTarget(WidgetDisplay display, GraphicsDevice graphicsDevice)
        {
            var animation = display.Animation;


            if (animation.RenderTarget == null ||
                animation.RenderTarget.Width != display.Region.MarginRect.Width ||
                animation.RenderTarget.Height != display.Region.MarginRect.Height)
            {
                animation.RenderTarget?.Dispose();

                var size = display.Region.MarginRect;

                if (size.Width < 1)
                {
                    size.Width = 1;
                }
                if (size.Height < 1)
                {
                    size.Height = 1;
                }

                animation.RenderTarget = new RenderTarget2D(
                    graphicsDevice,
                    size.Width,
                    size.Height);

                return(true);
            }

            return(false);
        }
コード例 #2
0
    void Update()
    {
        float realSize = CameraFollow.scaleMultMatchScreen * iconSize;

        if (realSize > transform.lossyScale.x || targeted)
        {
            WidgetDisplay.getWidgetDisplay().DisplayWidget(planetIcon, transform.position, new Vector2(iconSize, iconSize), col);
        }
    }
コード例 #3
0
 public void DrawFrame(IWidgetRenderContext renderContext, WidgetDisplay display, Point dest)
 {
     styleRenderer.DrawFrame(
         renderContext.SpriteBatch,
         display.Style.Border,
         new Rectangle(
             new Point(dest.X - display.Region.BorderToContentOffset.Left,
                       dest.Y - display.Region.BorderToContentOffset.Top),
             display.Region.BorderRect.Size));
 }
コード例 #4
0
        private Mock <IWidget> CreateWidget()
        {
            var result  = new Mock <IWidget>();
            var display = new WidgetDisplay();

            result.Setup(x => x.Display).Returns(display);
            result.Setup(
                x => x.ComputeIdealSize(It.IsAny <IWidgetRenderContext>(), It.IsAny <Size>()))
            .Returns <IWidgetRenderContext, Size>((_, size) => new Size(100, 20));

            return(result);
        }
コード例 #5
0
    public static WidgetDisplay getWidgetDisplay()
    {
        if (display == null)
        {
            GameObject obj = new GameObject("WidgetDisplay");

            obj.transform.position   = Vector3.zero;
            obj.transform.localScale = Vector3.one;

            display = obj.AddComponent <WidgetDisplay>();
        }
        return(display);
    }
コード例 #6
0
        public void DrawBackground(IWidgetRenderContext renderContext, WidgetDisplay display, Point dest)
        {
            // This draws the background behind the border - a problem for borders which have transparency on their outer edges
            // but important for borders which have transparency on their inner edges. Oh what to do...
            //Rectangle backgroundRect = new Rectangle(
            //                                new Point(dest.X - display.Region.BorderToContentOffset.Left,
            //                                    dest.Y - display.Region.BorderToContentOffset.Top),
            //                                display.Region.BorderRect.Size);

            // Here we make a compromise and set the background rectangle to be slightly smaller than
            // the border rectangle
            Rectangle backgroundRect = new Rectangle(
                dest.X - display.Region.BorderToContentOffset.Left + display.Region.Style.Border.Left.Width / 2,
                dest.Y - display.Region.BorderToContentOffset.Top + display.Region.Style.Border.Top.Width / 2,
                display.Region.BorderRect.Width - display.Region.Style.Border.Width / 2,
                display.Region.BorderRect.Height - display.Region.Style.Border.Height / 2);

            styleRenderer.DrawBackground(
                renderContext.SpriteBatch,
                display.Style.Background,
                backgroundRect);
        }
コード例 #7
0
    void Update()
    {
        //make sure the prediction is up to date
        att.CalculatePrediction();

        //make sure we have the correct number of lines
        //set the lines verticies
        List <Vector3> positions = new List <Vector3>();

        Attractor currentSOI = null;
        int       lineIndex  = -1;

        //TODO: count rotation around each body and stop drawing the line if it passes a set threshold

        float lastAngle  = calcAngle(0, att.getOrbitingBody());
        float totalAngle = 0;
        bool  stop       = false;

        for (int i = 0; i < att.prediction.Count; i += linePointInc)
        {
            if (currentSOI != att.prediction[i].strongestAttractor || i == att.prediction.Count - 1 || stop)
            {
                setLineVerts(lineIndex, positions);
                ++lineIndex;
                validateLineIndex(lineIndex);

                if (positions.Count != 0)
                {
                    if (currentSOI != att.prediction[i].strongestAttractor)
                    {
                        WidgetDisplay.getWidgetDisplay().DisplayWidget(TransferNodeWidget, positions[positions.Count - 1], new Vector2(widgetSize, widgetSize), lineColors[lineIndex % lineColors.Length].startColor);
                    }

                    //draw apoapsis and periapsis
                    OrbitProperties properties = att.getOrbitProperties(currentSOI, i - positions.Count);
                    if (properties != null)
                    {
                        Vector2 apoapsisPos  = att.prediction[Attracted.getPredictionIndexFromFutureSteps(properties.stepsToApoapsis)];
                        Vector2 periapsisPos = att.prediction[Attracted.getPredictionIndexFromFutureSteps(properties.stepsToPeriapsis)];

                        apoapsisPos  = currentSOI.transformPositionReletiveSteps(apoapsisPos, Attracted.getFutureStepsFromPredictionIndex(properties.stepsToApoapsis));
                        periapsisPos = currentSOI.transformPositionReletiveSteps(periapsisPos, Attracted.getFutureStepsFromPredictionIndex(properties.stepsToPeriapsis));

                        if (properties.stepsToApoapsis != 0)
                        {
                            WidgetDisplay.getWidgetDisplay().DisplayWidget(ApoapsisWidget, apoapsisPos,
                                                                           new Vector2(widgetSize, widgetSize), lineColors[(lineIndex - 1) % lineColors.Length].startColor);
                        }

                        if (properties.stepsToPeriapsis != 0)
                        {
                            WidgetDisplay.getWidgetDisplay().DisplayWidget(PeriapsisWidget, periapsisPos,
                                                                           new Vector2(widgetSize, widgetSize), lineColors[(lineIndex - 1) % lineColors.Length].startColor);
                        }
                    }
                }

                currentSOI = att.prediction[i].strongestAttractor;
                positions.Clear();

                lastAngle  = calcAngle(i, currentSOI);
                totalAngle = 0;

                if (stop)
                {
                    break;
                }
            }

            Vector2 pos = currentSOI.transformPositionReletiveSteps(att.prediction[i], Attracted.getFutureStepsFromPredictionIndex(i));

            if (i == att.prediction.Count - 1 && att.IntersectionDetected)
            {
                WidgetDisplay.getWidgetDisplay().DisplayWidget(CollisionWidget, pos, new Vector2(widgetSize, widgetSize), Color.red);
            }

            float angle = calcAngle(i, currentSOI);

            if (Mathf.Abs(angle - lastAngle) < Mathf.PI)
            {
                totalAngle += Mathf.Abs(angle - lastAngle);
            }


            lastAngle = angle;

            if (totalAngle >= (Mathf.PI * 2) * (maxRotationsPerPlanet))
            {
                stop = true;
            }

            positions.Add(pos);
        }

        //setLineVerts(lineIndex, positions);

        clearAllLinesAfterIndex(lineIndex - 1);
    }