Example #1
0
 protected override bool IntegrateChild(AssetManager assets, LayoutTreeNode childNode)
 {
     bool orderError = false;
     switch (childNode.Key)
     {
         case "Font":
             font = assets.GetFont(childNode.Value);
             if (text != null)
                 sprite = new TextSprite(font, text);
             return true;
         case "Text":
             text = childNode.Value;
             if (font != null)
                 sprite = new TextSprite(font, text);
             return true;
         case "Position":
             if (sprite != null)
             {
                 sprite.Position = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Rotation":
             if (sprite != null)
             {
                 sprite.Rotation = Convert.ToSingle(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Scale":
             if (sprite != null)
             {
                 sprite.Scale = ExtendedConvert.ToVector2(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Color":
             if (sprite != null)
             {
                 sprite.Color = ExtendedConvert.ToColor(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
         case "Anchor":
             if (sprite != null)
             {
                 sprite.Anchor = ExtendedConvert.ToEnum<Anchor>(childNode.Value);
                 return true;
             }
             else
                 orderError = true;
             break;
     }
     if (orderError)
     {
     #if DEBUG
         Console.WriteLine("ContextElement WARNING: Tried to set {0}'s {1} field before the Text and Font were specified.", LayoutName, childNode.Key);
     #endif
         return true;
     }
     return false;
 }
Example #2
0
 public void DrawTextSprite(TextSprite textSprite)
 {
     Vector2 position = textSprite.Position;
     float rotation = textSprite.Rotation;
     Vector2 scale = textSprite.Scale;
     for (int i = 0; i < transformationStack.Count; i++)
         transformationStack[i].Transform(ref position, ref rotation, ref scale);
     Vector2 origin = AnchorHelper.ComputeAnchorOrigin(textSprite.Anchor, textSprite.Dimensions);
     spriteBatch.DrawString(textSprite.SpriteFont,
                            textSprite.Text,
                            position,
                            textSprite.Color,
                            rotation,
                            origin,
                            scale,
                            SpriteEffects.None,
                            0);
     #if DEBUG
     if (displayDebugInformation)
         Console.WriteLine("CANVAS DEBUG: Drawing String\n" +
                           "               Text: {0} ({1}x{2})\n" +
                           "           Position: {3}\n" +
                           "              Color: {4}\n" +
                           "           Rotation: {5}\n" +
                           "             Origin: {6} ({7})\n" +
                           "              Scale: {8}",
                           textSprite.Text,
                           textSprite.Dimensions.X,
                           textSprite.Dimensions.Y,
                           position,
                           textSprite.Color,
                           rotation,
                           origin,
                           textSprite.Anchor,
                           scale);
     #endif
 }