internal void DrawSpriteGlyph(Texture2D texture, Vector4 dest, Vector4 source, Color color)
        {
            if (!m_DrawString_InProgress)
                Logging.Fatal("BeginDrawString() must be called before DrawSpriteGlyph()");

            Vector4 uv = new Vector4(
                (float)source.X / texture.Width,
                (float)source.Y / texture.Height,
                (float)(source.X + source.Z) / texture.Width,
                (float)(source.Y + source.W) / texture.Height);

            VertexPositionTextureHueExtra[] v = new VertexPositionTextureHueExtra[4]
            {
                new VertexPositionTextureHueExtra(new Vector3(dest.X, dest.Y, m_DrawString_Depth), new Vector2(uv.X, uv.Y), color, Vector4.Zero), // top left
                new VertexPositionTextureHueExtra(new Vector3(dest.X + dest.Z, dest.Y, m_DrawString_Depth), new Vector2(uv.Z, uv.Y), color, Vector4.Zero), // top right
                new VertexPositionTextureHueExtra(new Vector3(dest.X, dest.Y + dest.W, m_DrawString_Depth), new Vector2(uv.X, uv.W), color, Vector4.Zero), // bottom left
                new VertexPositionTextureHueExtra(new Vector3(dest.X + dest.Z, dest.Y + dest.W, m_DrawString_Depth), new Vector2(uv.Z, uv.W), color, Vector4.Zero) // bottom right
            };

            /*if (shadow != null)
            {
                Color shadow2 = new Color(
                    shadow.Value.R, shadow.Value.G,
                    shadow.Value.B, 128);
                for (int i = 0; i < 4; i++)
                {
                    VertexPositionTextureHueExtra v0 = v[i];
                    v0.Hue = shadow.Value;
                    v0.Position.Y += 1f;
                    m_DrawString_VertexList.Add(v0);
                }
            }*/
            for (int i = 0; i < 4; i++)
                m_DrawString_VertexList.Add(v[i]);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a circle shape with a designated border width. The circle begins and ends at border_origin_radians.
        /// </summary>
        public static Shape CreateBorderedCircle(Vector3 origin, float radius, float border_width, float border_origin_radians, Vector4 uv, BorderStyle style, Color? hue = null)
        {
            float inner_delta = 0f, outer_delta = 0f;
            switch (style)
            {
                case BorderStyle.Centered:
                    inner_delta = outer_delta = border_width / 2f;
                    break;
                case BorderStyle.Inside:
                    inner_delta = border_width;
                    break;
                case BorderStyle.Outside:
                    outer_delta = border_width;
                    break;
            }

            int numSegments = segmentsForSmoothCircle(radius);

            float radiansPerPoint = (Math.PI * 2) / numSegments;
            Vector3[] pointsOutside = new Vector3[numSegments + 1], pointsInside = new Vector3[numSegments + 1];

            // really, we only need to generate numPoints, but generating the final point (which is equal to the first point
            // saves us a mod operation in the next for loop.
            for (int i = 0; i < numSegments + 1; i++)
            {
                pointsOutside[i] = new Vector3(
                    origin.X + Math.Cos(radiansPerPoint * i + border_origin_radians) * (radius + outer_delta),
                    origin.Y + Math.Sin(radiansPerPoint * i + border_origin_radians) * (radius + outer_delta),
                    origin.Z);
                pointsInside[i] = new Vector3(
                    origin.X + Math.Cos(radiansPerPoint * i + border_origin_radians) * (radius - inner_delta),
                    origin.Y + Math.Sin(radiansPerPoint * i + border_origin_radians) * (radius - inner_delta),
                    origin.Z);
            }

            VertexPositionTextureHueExtra[] vertices = new VertexPositionTextureHueExtra[(numSegments) * 4];

            Color color = (hue.HasValue) ? hue.Value : Color.White;

            for (int i = 0; i < numSegments; i++)
            {
                int i4 = i * 4;
                int i6 = i * 6;

                vertices[i4 + 0] = new VertexPositionTextureHueExtra(pointsOutside[i + 0], new Vector2(uv.X, uv.Y), color, Vector4.Zero);
                vertices[i4 + 1] = new VertexPositionTextureHueExtra(pointsOutside[i + 1], new Vector2(uv.Z, uv.Y), color, Vector4.Zero);
                vertices[i4 + 2] = new VertexPositionTextureHueExtra(pointsInside[i + 0], new Vector2(uv.X, uv.W), color, Vector4.Zero);
                vertices[i4 + 3] = new VertexPositionTextureHueExtra(pointsInside[i + 1], new Vector2(uv.Z, uv.W), color, Vector4.Zero);
            }

            Shape shape = new Shape();
            shape.Vertices = vertices;

            return shape;
        }
Esempio n. 3
0
        public static Shape CreateFilledCircle(Vector3 origin, float border_radius, float border_width, float border_origin_radians, Vector4 uv)
        {
            int numSegments = segmentsForSmoothCircle(border_radius);

            float radiansPerPoint = (Math.PI * 2) / numSegments;
            Vector3[] pointsOutside = new Vector3[numSegments + 1], pointsInside = new Vector3[numSegments + 1];

            // really, we only need to generate numPoints, but generating the final point (which is equal to the first point
            // saves us a mod operation in the next for loop.
            for (int i = 0; i < numSegments + 1; i++)
            {
                pointsOutside[i] = new Vector3(
                    origin.X + Math.Cos(radiansPerPoint * i + border_origin_radians) * (border_radius),
                    origin.Y + Math.Sin(radiansPerPoint * i + border_origin_radians) * (border_radius),
                    origin.Z);
                pointsInside[i] = new Vector3(
                    origin.X + Math.Cos(radiansPerPoint * i + border_origin_radians) * (border_radius - border_width),
                    origin.Y + Math.Sin(radiansPerPoint * i + border_origin_radians) * (border_radius - border_width),
                    origin.Z);
            }

            VertexPositionTextureHueExtra[] vertices = new VertexPositionTextureHueExtra[(numSegments) * 4];

            for (int i = 0; i < numSegments; i++)
            {
                int i4 = i * 4;
                int i6 = i * 6;

                vertices[i4 + 0] = new VertexPositionTextureHueExtra(pointsOutside[i + 0], new Vector2(uv.X, uv.Y));
                vertices[i4 + 1] = new VertexPositionTextureHueExtra(pointsOutside[i + 1], new Vector2(uv.Z, uv.Y));
                vertices[i4 + 2] = new VertexPositionTextureHueExtra(pointsInside[i + 0], new Vector2(uv.X, uv.W));
                vertices[i4 + 3] = new VertexPositionTextureHueExtra(pointsInside[i + 1], new Vector2(uv.Z, uv.W));
            }

            Shape shape = new Shape();
            shape.Vertices = vertices;

            return shape;
        }
        internal void DrawSpriteGlyphDF(Texture2D texture, Vector4 dest, Vector4 source, Color color, float font_scale)
        {
            if (!m_DrawString_InProgress)
                Logging.Fatal("BeginDrawString() must be called before DrawSpriteGlyph()");

            Vector4 uv = new Vector4(
                (float)source.X / texture.Width,
                (float)source.Y / texture.Height,
                (float)(source.X + source.Z) / texture.Width,
                (float)(source.Y + source.W) / texture.Height);

            float smoothing = 0.4f * Math.Pow(0.333f, font_scale * 2f) + 0.05f;
            Vector4 extra = new Vector4(0, 0, smoothing, 2);

            VertexPositionTextureHueExtra[] v = new VertexPositionTextureHueExtra[4]
            {
                new VertexPositionTextureHueExtra(new Vector3(dest.X, dest.Y, m_DrawString_Depth), new Vector2(uv.X, uv.Y), color, extra), // top left
                new VertexPositionTextureHueExtra(new Vector3(dest.X + dest.Z, dest.Y, m_DrawString_Depth), new Vector2(uv.Z, uv.Y), color, extra), // top right
                new VertexPositionTextureHueExtra(new Vector3(dest.X, dest.Y + dest.W, m_DrawString_Depth), new Vector2(uv.X, uv.W), color, extra), // bottom left
                new VertexPositionTextureHueExtra(new Vector3(dest.X + dest.Z, dest.Y + dest.W, m_DrawString_Depth), new Vector2(uv.Z, uv.W), color, extra) // bottom right
            };

            for (int i = 0; i < 4; i++)
                m_DrawString_VertexList.Add(v[i]);
        }