public void CreateHUDItems(ICollection <IHUDItem> container, AutomationElement rootElement)
        {
            var element = rootElement;

            _taskList.Enqueue(rootElement);

            ControlType ct;

            System.Windows.Rect rect;
            AutomationElement.AutomationElementInformation aeInfo;
            IEnumerable <AutomationElement> children;

            while (_taskList.Count > 0)
            {
                element  = _taskList.Dequeue();
                children = element.FindAll(TreeScope.Children, Condition)?.Cast <AutomationElement>();

                if (children == null)
                {
                    continue;
                }

                foreach (AutomationElement elementNode in children)
                {
                    // call .Current once, because of high cost
                    aeInfo = elementNode.Current;
                    ct     = aeInfo.ControlType;

                    if (!IgnoreElements.Contains(ct))
                    {
                        rect = aeInfo.BoundingRectangle;
                        if (rect.Width != 0 && rect.Height != 0)
                        {
                            rect.X -= DesktopBounds.Left;
                            rect.Y -= DesktopBounds.Top;
                            AddHUDItem(container, rect);
                        }
                    }

                    if (CollectionElements.Contains(ct))
                    {
                        CreateHUDItemsForCollection(container, elementNode);
                        continue;
                    }

                    if (!EndElements.Contains(ct))
                    {
                        _taskList.Enqueue(elementNode);
                    }
                }
            }
        }
        // for List (except Tree)
        private void CreateHUDItemsForCollection(ICollection <IHUDItem> container, AutomationElement collection)
        {
            var bounds = collection.Current.BoundingRectangle;

            var treeWalker = new TreeWalker(Condition);
            var item       = treeWalker.GetFirstChild(collection);

            var beginOnScreen = false;

            while (item != null)
            {
                var aeInfo = item.Current;
                var rect   = aeInfo.BoundingRectangle;

                if (!IgnoreElements.Contains(aeInfo.ControlType) && bounds.Contains(rect))
                {
                    if (!beginOnScreen && ItemElements.Contains(aeInfo.ControlType))
                    {
                        beginOnScreen = true;
                    }
                    var ct = aeInfo.ControlType;
                    rect.X -= DesktopBounds.Left;
                    rect.Y -= DesktopBounds.Top;
                    AddHUDItem(container, rect);
                    if (!EndElements.Contains(ct))
                    {
                        _taskList.Enqueue(item);
                    }
                }
                else if (beginOnScreen)
                {
                    break;
                }

                item = treeWalker.GetNextSibling(item);
            }
        }
 public void AddIgnore(params ControlType[] types)
 {
     types.ForEach(item => IgnoreElements.Add(item));
 }