Example #1
0
        /// <summary>
        /// transfers the data from our segments to the vertices for display
        /// </summary>
        void CalculateVertices()
        {
            if (!_areVertsDirty)
            {
                return;
            }

            var center = new Vector3(Entity.Transform.Position, 0f);
            var radVec = new Vector3(0, -RibbonRadius, 0);

            // starting triangle, the head
            _vertices[0].Position = center + radVec;
            _vertices[0].Color    = Color.Red;
            _vertices[1].Position = center + radVec;
            _vertices[1].Color    = Color.Yellow;
            _vertices[2].Position = center + radVec;
            _vertices[2].Color    = Color.Green;

            var maxX = float.MinValue;
            var minX = float.MaxValue;
            var maxY = float.MinValue;
            var minY = float.MaxValue;

            var index    = 3;
            var segCount = 1;

            foreach (var seg in _segments)
            {
                var ratio = 1 - (1 / (float)_ribbonLength * segCount);
                seg.Radius = ratio * RibbonRadius;

                ColorExt.Lerp(ref StartColor, ref EndColor, out _vertices[index].Color, 1 - ratio);
                _vertices[index].Position     = seg.TopPoint;
                _vertices[index + 1].Position = seg.BottomPoint;
                _vertices[index + 1].Color    = _vertices[index].Color;

                // update min/max for any visible verts
                maxX = Mathf.MaxOf(maxX, _vertices[index].Position.X, _vertices[index + 1].Position.X);
                minX = Mathf.MinOf(minX, _vertices[index].Position.X, _vertices[index + 1].Position.X);
                maxY = Mathf.MaxOf(maxY, _vertices[index].Position.Y, _vertices[index + 1].Position.Y);
                minY = Mathf.MinOf(minY, _vertices[index].Position.Y, _vertices[index + 1].Position.Y);

                // increment counters
                index += 2;
                segCount++;
            }

            _bounds.X      = minX;
            _bounds.Y      = minY;
            _bounds.Width  = maxX - minX;
            _bounds.Height = maxY - minY;

            _areVertsDirty = false;
        }
Example #2
0
 // Default theme
 static Theme()
 {
     DeveloperFont        = Graphics.Instance.DevFont;
     DefaultFont          = Graphics.Instance.DevFontNarrow;
     ApplicationNullColor = Color.Black;
     PanelBackground      = ColorExt.HexToColor("#14101d");
     BackgroundColor      = ColorExt.HexToColor("#07090F");
     FaintBackgroundColor = Color.FromNonPremultiplied(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, 140);
     ForegroundColor      = ColorExt.HexToColor("#D8DBE2");
     HighlightColor       = ColorExt.HexToColor("#2176AE");
     PrimaryThemeColor    = ColorExt.HexToColor("#04F06A");
     SecondaryThemeColor  = ColorExt.HexToColor("#E56399");
     ErrorThemeColor      = ColorExt.HexToColor("#D8DBE2");
 }
Example #3
0
        void CalculateVertices()
        {
            if (!_areVertsDirty || _points.Length < 2)
            {
                return;
            }

            _areVertsDirty = false;
            _indices.Reset();
            _vertices.Reset();

            var maxX = float.MinValue;
            var minX = float.MaxValue;
            var maxY = float.MinValue;
            var minY = float.MaxValue;

            if (_useStartEndWidths)
            {
                _maxWidth = System.Math.Max(_startWidth, _endWidth);
            }

            // calculate line length first and simulataneously get our min/max points for the bounds
            var lineLength   = 0f;
            var halfMaxWidth = _maxWidth * 0.5f;

            _points.Buffer[0].LengthFromPreviousPoint = 0;
            for (var i = 0; i < _points.Length - 1; i++)
            {
                var distance = Vector2.Distance(_points.Buffer[i].Position, _points.Buffer[i + 1].Position);
                _points.Buffer[i + 1].LengthFromPreviousPoint = distance;
                lineLength += distance;

                maxX = Mathf.MaxOf(maxX, _points.Buffer[i].Position.X + halfMaxWidth,
                                   _points.Buffer[i + 1].Position.X + halfMaxWidth);
                minX = Mathf.MinOf(minX, _points.Buffer[i].Position.X - halfMaxWidth,
                                   _points.Buffer[i + 1].Position.X - halfMaxWidth);
                maxY = Mathf.MaxOf(maxY, _points.Buffer[i].Position.Y + halfMaxWidth,
                                   _points.Buffer[i + 1].Position.Y + halfMaxWidth);
                minY = Mathf.MinOf(minY, _points.Buffer[i].Position.Y - halfMaxWidth,
                                   _points.Buffer[i + 1].Position.Y - halfMaxWidth);
            }

            _bounds.X      = minX;
            _bounds.Y      = minY;
            _bounds.Width  = maxX - minX;
            _bounds.Height = maxY - minY;

            // special case: single segment
            if (_points.Length == 2)
            {
                if (_useStartEndWidths)
                {
                    _points.Buffer[0].Width = _startWidth;
                    _points.Buffer[1].Width = _endWidth;
                }

                if (_useStartEndColors)
                {
                    _points.Buffer[0].Color = _startColor;
                    _points.Buffer[1].Color = _endColor;
                }

                _firstSegment.SetPoints(ref _points.Buffer[0], ref _points.Buffer[1]);
                AddSingleSegmentLine(ref _firstSegment, _points.Buffer[1].Color);
                return;
            }

            var distanceSoFar = 0f;
            var fusedPoint    = Vector2.Zero;
            var vertIndex     = 0;
            var thirdPoint    = new SegmentPoint();

            for (var i = 0; i < _points.Length - 1; i++)
            {
                var firstPoint  = _points.Buffer[i];
                var secondPoint = _points.Buffer[i + 1];

                var hasThirdPoint = _points.Length > i + 2;
                if (hasThirdPoint)
                {
                    thirdPoint = _points.Buffer[i + 2];
                }

                // we need the distance along the line of both the first and second points. distanceSoFar will always be for the furthest point
                // which is the previous point before adding the current segment distance.
                var firstPointDistance = distanceSoFar;
                distanceSoFar += secondPoint.LengthFromPreviousPoint;

                var firstPointRatio  = firstPointDistance / lineLength;
                var secondPointRatio = distanceSoFar / lineLength;
                var thirdPointRatio  = 0f;
                if (hasThirdPoint)
                {
                    thirdPointRatio = (distanceSoFar + thirdPoint.LengthFromPreviousPoint) / lineLength;
                }

                if (_useStartEndColors)
                {
                    ColorExt.Lerp(ref _startColor, ref _endColor, out firstPoint.Color, firstPointRatio);
                    ColorExt.Lerp(ref _startColor, ref _endColor, out secondPoint.Color, secondPointRatio);

                    if (hasThirdPoint)
                    {
                        ColorExt.Lerp(ref _startColor, ref _endColor, out thirdPoint.Color, thirdPointRatio);
                    }
                }

                if (_useStartEndWidths)
                {
                    firstPoint.Width  = Mathf.Lerp(_startWidth, _endWidth, firstPointRatio);
                    secondPoint.Width = Mathf.Lerp(_startWidth, _endWidth, secondPointRatio);

                    if (hasThirdPoint)
                    {
                        thirdPoint.Width = Mathf.Lerp(_startWidth, _endWidth, thirdPointRatio);
                    }
                }


                if (i == 0)
                {
                    _firstSegment.SetPoints(ref firstPoint, ref secondPoint);
                    _secondSegment.SetPoints(ref secondPoint, ref thirdPoint);
                }
                else
                {
                    Utils.Swap(ref _firstSegment, ref _secondSegment);
                    if (hasThirdPoint)
                    {
                        _secondSegment.SetPoints(ref secondPoint, ref thirdPoint);
                    }
                }

                // dont recalculate the fusedPoint for the last segment since there will be no third point to work with
                if (hasThirdPoint)
                {
                    var shouldFuseBottom =
                        Vector2Ext.IsTriangleCCW(firstPoint.Position, secondPoint.Position, thirdPoint.Position);
                    _secondSegment.SetFusedData(shouldFuseBottom, ref _firstSegment);
                }

                // special care needs to be take with the first segment since it has a different vert count
                if (i == 0)
                {
                    AddFirstSegment(ref _firstSegment, ref _secondSegment, ref vertIndex);
                }
                else
                {
                    AddSegment(ref _firstSegment, ref vertIndex);
                }

                _lastSegment.CloneFrom(ref _firstSegment);
            }
        }