Beispiel #1
0
 public static void DrawColorCodedStringShadow(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color color, float rotation, Vector2 origin, Vector2 scale, float maxW = -1f, int offset = 1)
 {
     color = new Color((int)color.R, (int)color.G, (int)color.B, (int)((byte)(Math.Pow((double)(((float)color.A) / 255f), 2.0) * 255.0)));
     foreach (int[] t in ShadowOffset)
     {
         DrawColorCodedString(sb, font, text, new Vector2(pos.X + (t[0] * offset), pos.Y + (t[1] * offset)), color, rotation, origin, scale, maxW, true);
     }
 }
Beispiel #2
0
 public static void DrawStringShadow(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color color, float rotation, Vector2 origin, Vector2 scale, int offset = 1)
 {
     color = new Color((int)color.R, (int)color.G, (int)color.B, (int)((byte)(Math.Pow((double)(((float)color.A) / 255f), 2.0) * 255.0)));
     foreach (var t in ShadowOffset)
     {
         sb.DrawString(font, text, new Vector2(pos.X + (t[0] * offset), pos.Y + (t[1] * offset)), color, rotation, origin, scale, SpriteEffects.None, 0f);
     }
 }
Beispiel #3
0
 public static Vector2 DString(SpriteBatch sp, string se, Vector2 ve, Color ce, float fe = 1f, float rex = 0f, float rey = 0f, int font = 0)
 {
     ReLogic.Graphics.DynamicSpriteFont fontMouseText = Main.fontMouseText;
     if (font == 1)
     {
         fontMouseText = Main.fontDeathText;
     }
     for (int i = -1; i < 2; i++)
     {
         for (int j = -1; j < 2; j++)
         {
             sp.DrawString(fontMouseText, se, ve + ((Vector2)(new Vector2((float)i, (float)j) * 1f)), Color.Black, 0f, new Vector2(rex, rey) * fontMouseText.MeasureString(se), fe, SpriteEffects.None, 0f);
         }
     }
     sp.DrawString(fontMouseText, se, ve, ce, 0f, new Vector2(rex, rey) * fontMouseText.MeasureString(se), fe, SpriteEffects.None, 0f);
     return((Vector2)(fontMouseText.MeasureString(se) * fe));
 }
Beispiel #4
0
 public static void StringShadowed(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color c, float scale = 1f, Vector2 origin = new Vector2(), int offset = 2)
 {
     DrawStringShadow(sb, font, text, pos, new Color(0, 0, 0, c.A), 0f, origin, scale, offset);
     sb.DrawString(font, text, pos, c, 0f, origin, scale, SpriteEffects.None, 0f);
 }
Beispiel #5
0
 public static void StringShadowed(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, int offset = 2)
 {
     StringShadowed(sb, font, text, pos, Color.White, 1f, new Vector2(), offset);
 }
Beispiel #6
0
 public static Vector2 MeasureColorCodedString(ReLogic.Graphics.DynamicSpriteFont font, string text)
 {
     return(font.MeasureString(DropColorCodes(text)));
 }
Beispiel #7
0
 public static void DrawStringShadow(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color color, float rotation = 0f, Vector2 origin = new Vector2(), float scale = 1f, int offset = 1)
 {
     DrawStringShadow(sb, font, text, pos, color, rotation, origin, new Vector2(scale, scale), offset);
 }
Beispiel #8
0
 public static void DrawStringShadow(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, int offset = 1)
 {
     DrawStringShadow(sb, font, text, pos, new Color(0f, 0f, 0f, 0.5f), 0f, new Vector2(), (float)1f, offset);
 }
Beispiel #9
0
        public static Vector2 DrawColorCodedString(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color baseColor, float rotation, Vector2 origin, Vector2 baseScale, float maxW = -1f, bool ignoreColors = false)
        {
            var position = new Vector2(pos.X, pos.Y);
            var vector2  = position;
            var strArray = text.Split('\n');
            var x        = font.MeasureString(" ").X;
            var white    = baseColor;
            var num2     = 1f;
            var num3     = 0f;

            foreach (var str in strArray)
            {
                foreach (var str2 in Regex.Split(str, BuiltRegex))
                {
                    if (Regex.Match(str2, BuiltRegex).Success)
                    {
                        if (Regex.Match(str2, "#;").Success)
                        {
                            num2 = 1f;
                            if (!ignoreColors)
                            {
                                white = Color.White;
                            }
                        }
                        else
                        {
                            var match = Regex.Match(str2, "#([0-9a-f]);");
                            if (match.Success)
                            {
                                if (!ignoreColors)
                                {
                                    var r = ((float)int.Parse(match.Groups[1].Value, NumberStyles.HexNumber)) / 15f;
                                    white = new Color(r, r, r, ((float)white.A) / 255f);
                                }
                            }
                            else
                            {
                                match = Regex.Match(str2, "#([0-9a-f]{3});");
                                if (match.Success)
                                {
                                    if (!ignoreColors)
                                    {
                                        var source = match.Groups[1].Value;
                                        var num5   = (int.Parse(source.ElementAt(0).ToString(), NumberStyles.HexNumber)) / 15f;
                                        var g      = (int.Parse(source.ElementAt(1).ToString(), NumberStyles.HexNumber)) / 15f;
                                        var b      = (int.Parse(source.ElementAt(2).ToString(), NumberStyles.HexNumber)) / 15f;
                                        white = new Color(num5, g, b, ((float)white.A) / 255f);
                                    }
                                }
                                else
                                {
                                    match = Regex.Match(str2, "#([0-9a-f]{6});");
                                    if (match.Success)
                                    {
                                        if (!ignoreColors)
                                        {
                                            var str4  = match.Groups[1].Value;
                                            var num8  = ((float)int.Parse(str4.Substring(0, 2), NumberStyles.HexNumber)) / 255f;
                                            var num9  = ((float)int.Parse(str4.Substring(2, 2), NumberStyles.HexNumber)) / 255f;
                                            var num10 = ((float)int.Parse(str4.Substring(4, 2), NumberStyles.HexNumber)) / 255f;
                                            white = new Color(num8, num9, num10, ((float)white.A) / 255f);
                                        }
                                    }
                                    else
                                    {
                                        match = Regex.Match(str2, "#>([0-9]{1,3});");
                                        if (match.Success)
                                        {
                                            if (!ignoreColors)
                                            {
                                                var num11 = int.Parse(match.Groups[1].Value);
                                                white = new Color((((float)white.R) / 255f) * (1f + (num11 * 0.01f)), (((float)white.G) / 255f) * (1f + (num11 * 0.01f)), (((float)white.B) / 255f) * (1f + (num11 * 0.01f)), ((float)white.A) / 255f);
                                            }
                                        }
                                        else
                                        {
                                            match = Regex.Match(str2, "#<([0-9]{1,3});");
                                            if (match.Success)
                                            {
                                                if (!ignoreColors)
                                                {
                                                    var num12 = int.Parse(match.Groups[1].Value);
                                                    white = new Color((((float)white.R) / 255f) * (1f - (num12 * 0.01f)), (((float)white.G) / 255f) * (1f - (num12 * 0.01f)), (((float)white.B) / 255f) * (1f - (num12 * 0.01f)), ((float)white.A) / 255f);
                                                }
                                            }
                                            else
                                            {
                                                match = Regex.Match(str2, @"#\+([0-9a-f]{1,2});");
                                                if (match.Success)
                                                {
                                                    if (!ignoreColors)
                                                    {
                                                        var num13 = int.Parse(match.Groups[1].Value, NumberStyles.HexNumber);
                                                        white = new Color((byte)Math.Min(white.R + num13, 0xff), (byte)Math.Min(white.G + num13, 0xff), (byte)Math.Min(white.B + num13, 0xff), white.A);
                                                    }
                                                }
                                                else
                                                {
                                                    match = Regex.Match(str2, @"#\-([0-9a-f]{1,2});");
                                                    if (match.Success)
                                                    {
                                                        if (!ignoreColors)
                                                        {
                                                            var num14 = int.Parse(match.Groups[1].Value, NumberStyles.HexNumber);
                                                            white = new Color((byte)Math.Max(white.R - num14, 0), (byte)Math.Max(white.G - num14, 0), (byte)Math.Max(white.B - num14, 0), white.A);
                                                        }
                                                    }
                                                    else if (Regex.Match(str2, @"#\^;").Success)
                                                    {
                                                        if (!ignoreColors)
                                                        {
                                                            white = new Color((byte)(0xff - white.R), (byte)(0xff - white.G), (byte)(0xff - white.B), white.A);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        match = Regex.Match(str2, "#([RGB]{3});");
                                                        if (match.Success)
                                                        {
                                                            if (!ignoreColors)
                                                            {
                                                                var str5  = match.Groups[1].Value;
                                                                int num15 = (str5.ElementAt(0) == 'R') ? white.R : ((str5.ElementAt(0) == 'G') ? white.G : white.B);
                                                                int num16 = (str5.ElementAt(1) == 'R') ? white.R : ((str5.ElementAt(1) == 'G') ? white.G : white.B);
                                                                int num17 = (str5.ElementAt(2) == 'R') ? white.R : ((str5.ElementAt(2) == 'G') ? white.G : white.B);
                                                                white = new Color(num15, num16, num17, white.A);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            match = Regex.Match(str2, "#%([0-9]{1,3});");
                                                            if (match.Success)
                                                            {
                                                                num2 = int.Parse(match.Groups[1].Value) * 0.01f;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var strArray3 = str2.Split(' ');
                        for (var i = 0; i < strArray3.Length; i++)
                        {
                            if (i != 0)
                            {
                                position.X += (x * baseScale.X) * num2;
                            }
                            if (maxW > 0f)
                            {
                                var num19 = (font.MeasureString(strArray3[i]).X *baseScale.X) * num2;
                                if (((position.X - pos.X) + num19) > maxW)
                                {
                                    position.X  = pos.X;
                                    position.Y += (font.LineSpacing * num3) * baseScale.Y;
                                    vector2.Y   = Math.Max(vector2.Y, position.Y);
                                    num3        = 0f;
                                }
                            }
                            if (num3 < num2)
                            {
                                num3 = num2;
                            }
                            sb.DrawString(font, strArray3[i], position, white, rotation, origin, (Vector2)(baseScale * num2), SpriteEffects.None, 0f);
                            position.X += (font.MeasureString(strArray3[i]).X *baseScale.X) * num2;
                            vector2.X   = Math.Max(vector2.X, position.X);
                        }
                    }
                }
                position.X  = pos.X;
                position.Y += (font.LineSpacing * num3) * baseScale.Y;
                vector2.Y   = Math.Max(vector2.Y, position.Y);
                num3        = 0f;
            }
            return(vector2);
        }
Beispiel #10
0
 public static Vector2 DrawColorCodedString(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, Color baseColor, float rotation = 0f, Vector2 origin = new Vector2(), float scale = 1f, float maxW = -1f)
 {
     return(DrawColorCodedString(sb, font, text, pos, baseColor, rotation, origin, new Vector2(scale, scale), maxW, false));
 }
Beispiel #11
0
 public static Vector2 DrawColorCodedString(SpriteBatch sb, ReLogic.Graphics.DynamicSpriteFont font, string text, Vector2 pos, float maxW = -1f)
 {
     return(DrawColorCodedString(sb, font, text, pos, Color.White, 0f, new Vector2(), 1f, maxW));
 }