Пример #1
0
        private void DrawText(FontLocation[] font, Texture fontTexture, Vector2 startPos, float spacing, float scaling, bool centred, string text)
        {
            char[] charArray = text.ToCharArray();
            int    length    = charArray.Length;

            FontLocation[] cache = null;
            if (centred)
            {
                cache = new FontLocation[length];
                float textLength = 0;
                for (int i = 0; i < length; i++)
                {
                    cache[i]    = FontLookup.FindLetterLocation(font, charArray[i]);
                    textLength += cache[i].width;
                }
                startPos.X -= (textLength + spacing * (length - 1)) * speedoScale * scaling / 2f;
            }

            for (int i = 0; i < length; i++)
            {
                FontLocation letterLocation;
                if (cache != null)
                {
                    letterLocation = cache[i];
                }
                else
                {
                    letterLocation = FontLookup.FindLetterLocation(font, charArray[i]);
                }
                dial.Transform = Matrix.Transformation2D(Vector2.Zero, 0f, new Vector2(speedoScale, speedoScale) * scaling, Vector2.Zero, 0f, startPos);
                Rectangle?rectangle = new Rectangle(letterLocation.x, letterLocation.y, letterLocation.width, letterLocation.height);
                dial.Draw(fontTexture, baseColour, rectangle, new Vector3?(), new Vector3?());
                startPos.X += (letterLocation.width + spacing) * speedoScale * scaling;
            }
        }
Пример #2
0
        public static FontLocation[] ReadXML(string xmlPath)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(xmlPath);
            XmlNodeList charElements = xmlDocument.SelectNodes("/root/char");

            int length = charElements.Count;
            FontLocation[] fontLocations = new FontLocation[length];
            XmlNode element;
            for (int i = 0; i < length; i++)
            {
                element = charElements[i];
                fontLocations[i] = new FontLocation()
                {
                    letter = element.Attributes["id"].Value[0],
                    x = Convert.ToInt32(element.SelectSingleNode("x").InnerText),
                    y = Convert.ToInt32(element.SelectSingleNode("y").InnerText),
                    width = Convert.ToInt32(element.SelectSingleNode("width").InnerText),
                    height = Convert.ToInt32(element.SelectSingleNode("height").InnerText)
                };
            }

            return fontLocations;
        }