private static GuiControl FindControlAtPoint(GuiControlCollection controls, Point point)
        {
            var topMostControl = (GuiControl)null;

            for (var i = controls.Count - 1; i >= 0; i--)
            {
                var control = controls[i];

                if (control.IsVisible)
                {
                    if (topMostControl == null && control.BoundingRectangle.Contains(point))
                    {
                        topMostControl = control;
                    }

                    if (control.Controls.Any())
                    {
                        var child = FindControlAtPoint(control.Controls, point);

                        if (child != null)
                        {
                            topMostControl = child;
                        }
                    }
                }
            }

            return(topMostControl);
        }
Example #2
0
 private void DrawChildren(GuiControlCollection controls, float deltaSeconds)
 {
     foreach (var control in controls.Where(c => c.IsVisible))
     {
         control.Draw(this, _renderer, deltaSeconds);
         DrawChildren(control.Controls, deltaSeconds);
     }
 }
 public GuiScreen(GuiSkin skin)
 {
     Skin     = skin;
     Controls = new GuiControlCollection {
         ItemAdded = c => _isLayoutRequired = true
     };
     Windows = new GuiWindowCollection(this)
     {
         ItemAdded = w => _isLayoutRequired = true
     };
 }
        public void GuiControlCollection_Insert_SetsTheParent_Test()
        {
            var parent = Substitute.For <GuiControl>();
            var child  = Substitute.For <GuiControl>();

            var controls = new GuiControlCollection(parent);

            controls.Insert(0, child);
            Assert.IsTrue(controls.Contains(child));
            Assert.AreSame(parent, child.Parent);
        }
        private static T FindControl <T>(GuiControlCollection controls, string name)
            where T : GuiControl
        {
            foreach (var control in controls)
            {
                if (control.Name == name)
                {
                    return(control as T);
                }

                if (control.Controls.Any())
                {
                    var childControl = FindControl <T>(control.Controls, name);

                    if (childControl != null)
                    {
                        return(childControl);
                    }
                }
            }

            return(null);
        }
 public GuiScreen()
 {
     Controls = new GuiControlCollection();
 }