Exemplo n.º 1
0
        public bool NameExists(string widgetName, SearchRegion searchRegion = null)
        {
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows)
            {
                List <GuiWidget> foundChildren = new List <GuiWidget>();
                window.FindNamedChildrenRecursive(widgetName, foundChildren);
                if (foundChildren.Count > 0)
                {
                    foreach (GuiWidget foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool WidgetExists <T>(SearchRegion searchRegion = null) where T : GuiWidget
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                IEnumerable <T> foundChildren = window.Children <T>();
                if (foundChildren.Count() > 0)
                {
                    foreach (var foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool NamedWidgetExists(string widgetName, SearchRegion searchRegion = null, bool onlyVisible = true)
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (SystemWindow window in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                var foundChildren = window.FindDescendants(widgetName);
                if (foundChildren.Count > 0)
                {
                    foreach (GuiWidget.WidgetAndPosition foundChild in foundChildren)
                    {
                        if (onlyVisible)
                        {
                            RectangleDouble childBounds = foundChild.widget.TransformToParentSpace(window, foundChild.widget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                            ScreenRectangle result;
                            if (searchRegion == null ||
                                ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                if (foundChild.widget.ActuallyVisibleOnScreen())
                                {
                                    return(true);
                                }
                            }
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool ChildExists <T>(SearchRegion searchRegion = null) where T : GuiWidget
        {
            // Ignore SystemWindows with null PlatformWindow members - SystemWindow constructed but not yet shown
            foreach (var systemWindow in SystemWindow.AllOpenSystemWindows.ToArray())
            {
                // Get either the topmost or active SystemWindow
                var window = systemWindow.Parents <GuiWidget>().LastOrDefault() as SystemWindow ?? systemWindow;

                // Single window implementation requires both windows to be checked
                var foundChildren = window.Children <T>().Concat(systemWindow.Children <T>());
                if (foundChildren.Count() > 0)
                {
                    foreach (var foundChild in foundChildren)
                    {
                        RectangleDouble childBounds = foundChild.TransformToParentSpace(window, foundChild.LocalBounds);

                        ScreenRectangle screenRect = SystemWindowToScreen(childBounds, window);
                        ScreenRectangle result;
                        if (searchRegion == null || ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                        {
                            if (foundChild.ActuallyVisibleOnScreen())
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public List <GetResults> GetWidgetsByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            if (secondsToWait > 0)
            {
                bool foundWidget = WaitForName(widgetName, secondsToWait);
                if (!foundWidget)
                {
                    return(null);
                }
            }

            List <GetResults> namedWidgetsInRegion = new List <GetResults>();

            for (int i = SystemWindow.AllOpenSystemWindows.Count - 1; i >= 0; i--)
            {
                SystemWindow systemWindow = SystemWindow.AllOpenSystemWindows[i];
                if (searchRegion != null)                 // only add the widgets that are in the screen region
                {
                    List <GuiWidget> namedWidgets = new List <GuiWidget>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget namedWidget in namedWidgets)
                    {
                        if (namedWidget.ActuallyVisibleOnScreen())
                        {
                            RectangleDouble childBounds = namedWidget.TransformToParentSpace(systemWindow, namedWidget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, systemWindow);
                            ScreenRectangle result;
                            if (ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                namedWidgetsInRegion.Add(new GetResults()
                                {
                                    widget = namedWidget,
                                    containingSystemWindow = systemWindow,
                                });
                            }
                        }
                    }
                }
                else                 // add every named widget found
                {
                    List <GuiWidget> namedWidgets = new List <GuiWidget>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget namedWidget in namedWidgets)
                    {
                        if (namedWidget.ActuallyVisibleOnScreen())
                        {
                            namedWidgetsInRegion.Add(new GetResults()
                            {
                                widget = namedWidget,
                                containingSystemWindow = systemWindow,
                            });
                        }
                    }
                }
            }

            return(namedWidgetsInRegion);
        }
Exemplo n.º 6
0
        public List <GetByNameResults> GetWidgetsByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null, bool onlyVisible = true)
        {
            if (secondsToWait > 0)
            {
                bool foundWidget = WaitForName(widgetName, secondsToWait, onlyVisible);
                if (!foundWidget)
                {
                    return(null);
                }
            }

            List <GetByNameResults> namedWidgetsInRegion = new List <GetByNameResults>();

            foreach (var systemWindow in SystemWindow.AllOpenSystemWindows.Reverse())
            {
                if (searchRegion != null)                 // only add the widgets that are in the screen region
                {
                    List <GuiWidget.WidgetAndPosition> namedWidgets = new List <GuiWidget.WidgetAndPosition>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget.WidgetAndPosition widgetAndPosition in namedWidgets)
                    {
                        if (!onlyVisible ||
                            widgetAndPosition.widget.ActuallyVisibleOnScreen())
                        {
                            RectangleDouble childBounds = widgetAndPosition.widget.TransformToParentSpace(systemWindow, widgetAndPosition.widget.LocalBounds);

                            ScreenRectangle screenRect = SystemWindowToScreen(childBounds, systemWindow);
                            ScreenRectangle result;
                            if (ScreenRectangle.Intersection(searchRegion.ScreenRect, screenRect, out result))
                            {
                                namedWidgetsInRegion.Add(new GetByNameResults(widgetAndPosition.widget, widgetAndPosition.position, systemWindow, widgetAndPosition.NamedObject));
                            }
                        }
                    }
                }
                else                 // add every named widget found
                {
                    List <GuiWidget.WidgetAndPosition> namedWidgets = new List <GuiWidget.WidgetAndPosition>();
                    systemWindow.FindNamedChildrenRecursive(widgetName, namedWidgets);
                    foreach (GuiWidget.WidgetAndPosition namedWidget in namedWidgets)
                    {
                        if (!onlyVisible ||
                            namedWidget.widget.ActuallyVisibleOnScreen())
                        {
                            namedWidgetsInRegion.Add(new GetByNameResults(namedWidget.widget, namedWidget.position, systemWindow, namedWidget.NamedObject));
                        }
                    }
                }
            }

            return(namedWidgetsInRegion);
        }