/// <summary>
 /// Grabs the root parent of this control.
 /// </summary>
 /// <param name="control">Control to start with.</param>
 /// <returns>The root of the hierarchy.</returns>
 private Control RootControl(Control control)
 {
     if (control.parent != null)
         return RootControl(control.parent);
     return control;
 }
        public void Add(Control control)
        {
            // Prevents infinite looping. If for some reason this does occur, throw exception because itll crash the game anyway
            if (control == this)
                throw new InvalidOperationException();

            // set parent to this.

            // get other loaded stuff from root control
            control.parent = this;

            /*
            if(control.graphics == null)
                control.graphics = RootControl(control).graphics;

            if(control.contentManager == null)
                control.contentManager = RootControl(control).contentManager;

            // get loaded font from root.
            if(control.font == null)
                control.font = RootControl(this).font;
            */

            // see if controls need to have textures loaded.
            if (RootControl(this).graphics != null && RootControl(this).contentManager != null)
                control.LoadVisuals();

            controls.Add(control);

            if (RootControl(control).gameTime != null)
                control.Update(RootControl(control).gameTime);

            /*
            if(RootControl(this).graphics != null && RootControl(this).contentManager != null)
                control.LoadVisuals();

            if(RootControl(this).gameTime != null)
                control.Update(RootControl(this).gameTime);
             */
            //controls.Add(control.parent = this);
        }
        private Vector2 GlobalLocation(Vector2 location, Control parent)
        {
            if (parent == null)
                return location;

            return GlobalLocation(location + parent.Location, parent.parent);
        }
 public Control(string fontFile = "TimesNewRoman12")
 {
     locAndSize = new Rectangle(0, 0, 0, 0);
     controls = new List<Control>();
     firstClickLoc = Vector2.Zero;
     alignment = ControlAlignment.Left;
     isVisible = true;
     isActive = true;
     isDrawn = true;
     alignApplied = false;
     parent = null;
     this.fontFile = fontFile;
     borderInfo = new BorderInfo(1, Color.Black);
     fillInfo = new FillInfo(Color.Gray);
 }