PageRenderTime 16ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/TTengine/util/TTutil.cs

http://github.com/trancetrance/TTengine
C# | 55 lines | 34 code | 4 blank | 17 comment | 3 complexity | 3b50fae0bb9eccfbcde9265f6366cb1f MD5 | raw file
 1using System;
 2using System.IO;
 3using System.Collections.Generic;
 4
 5using System.Text;
 6using Microsoft.Xna.Framework;
 7
 8namespace TTengine.Util
 9{
10    /**
11     * general utility methods that are handy in creating your games
12     */
13    public class TTUtil
14    {
15        /// <summary>
16        /// Rounds the components of a Vector2 in-place
17        /// </summary>
18        /// <param name="input">Vector2 to round</param>
19        public static void Round(ref Vector2 input)
20        {
21            input.X = (float)Math.Round(input.X);
22            input.Y = (float)Math.Round(input.Y);
23        }
24
25        /// <summary>
26        /// Count the number of lines in a string
27        /// </summary>
28        /// <param name="s">The string</param>
29        /// <returns>The linecount, or 0 if empty string</returns>
30        public static int LineCount(string s)
31        {
32            if (s.Length == 0)
33                return 0;
34            int result = 1;
35            foreach (char c in s)
36            {
37                if (c.Equals('\n'))
38                {
39                    result++;
40                }
41            }
42            return result;
43        }
44
45        /// <summary>
46        /// Invert color
47        /// </summary>
48        /// <param name="c">color to invert</param>
49        /// <returns>Inverted color, "1-c"</returns>
50        public static Color InvertColor(Color c)
51        {
52            return new Color(new Vector3(1f, 1f, 1f) - c.ToVector3());
53        }
54    }
55}