示例#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);
        }
        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);
        }
示例#3
0
        private static RectangleDouble ScreenToSystemWindow(ScreenRectangle rectOnScreen, SystemWindow containingWindow)
        {
            ScreenRectangle screenPosition = new ScreenRectangle()
            {
                Left   = (int)rectOnScreen.Left,
                Top    = (int)rectOnScreen.Top,
                Right  = (int)rectOnScreen.Right,
                Bottom = (int)rectOnScreen.Bottom,
            };

            AbstractOsMappingWidget mappingWidget = containingWindow.Parent as AbstractOsMappingWidget;

            screenPosition.Left   -= mappingWidget.DesktopPosition.x;
            screenPosition.Top    -= (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);
            screenPosition.Left   -= mappingWidget.DesktopPosition.x;
            screenPosition.Bottom -= (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);

            screenPosition.Top    = (int)containingWindow.Height - screenPosition.Top;
            screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

            return(new RectangleDouble()
            {
                Left = screenPosition.Left,
                Bottom = screenPosition.Bottom,
                Right = screenPosition.Right,
                Top = screenPosition.Top,
            });
        }
示例#4
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);
        }
示例#5
0
        public static bool Intersection(ScreenRectangle rectA, ScreenRectangle rectB, out ScreenRectangle result)
        {
            result = rectA;
            if (result.Left < rectB.Left)
            {
                result.Left = rectB.Left;
            }
            if (result.Top < rectB.Top)
            {
                result.Top = rectB.Top;
            }
            if (result.Right > rectB.Right)
            {
                result.Right = rectB.Right;
            }
            if (result.Bottom > rectB.Bottom)
            {
                result.Bottom = rectB.Bottom;
            }

            if (result.Left < result.Right && result.Top < result.Bottom)
            {
                return(true);
            }

            return(false);
        }
        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);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
		public static bool Intersection(ScreenRectangle rectA, ScreenRectangle rectB, out ScreenRectangle result)
		{
			result = rectA;
			if (result.Left < rectB.Left) result.Left = rectB.Left;
			if (result.Top < rectB.Top) result.Top = rectB.Top;
			if (result.Right > rectB.Right) result.Right = rectB.Right;
			if (result.Bottom > rectB.Bottom) result.Bottom = rectB.Bottom;

			if (result.Left < result.Right && result.Top < result.Bottom)
			{
				return true;
			}

			return false;
		}
示例#10
0
        public SearchRegion GetRegionByName(string widgetName, double secondsToWait = 0, SearchRegion searchRegion = null)
        {
            SystemWindow containingWindow;
            GuiWidget    namedWidget = GetWidgetByName(widgetName, out containingWindow, secondsToWait, searchRegion);

            if (namedWidget != null)
            {
                RectangleDouble childBounds = namedWidget.TransformToParentSpace(containingWindow, namedWidget.LocalBounds);

                ScreenRectangle screenPosition = SystemWindowToScreen(childBounds, containingWindow);

                return(new SearchRegion(this)
                {
                    ScreenRect = screenPosition,
                });
            }

            return(null);
        }
示例#11
0
        public static ScreenRectangle SystemWindowToScreen(RectangleDouble rectOnScreen, SystemWindow containingWindow)
        {
            ScreenRectangle screenPosition = new ScreenRectangle()
            {
                Left   = (int)rectOnScreen.Left,
                Top    = (int)rectOnScreen.Top,
                Right  = (int)rectOnScreen.Right,
                Bottom = (int)rectOnScreen.Bottom,
            };

            screenPosition.Top    = (int)containingWindow.Height - screenPosition.Top;
            screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

            AbstractOsMappingWidget mappingWidget = containingWindow.Parent as AbstractOsMappingWidget;

            screenPosition.Left   += mappingWidget.DesktopPosition.x;
            screenPosition.Top    += (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);
            screenPosition.Right  += mappingWidget.DesktopPosition.x;
            screenPosition.Bottom += (mappingWidget.DesktopPosition.y + mappingWidget.TitleBarHeight);

            return(screenPosition);
        }
示例#12
0
        private static ScreenRectangle SystemWindowToScreen(RectangleDouble rectOnScreen, SystemWindow containingWindow)
        {
            ScreenRectangle screenPosition = new ScreenRectangle()
            {
                Left   = (int)rectOnScreen.Left,
                Top    = (int)rectOnScreen.Top,
                Right  = (int)rectOnScreen.Right,
                Bottom = (int)rectOnScreen.Bottom,
            };

            screenPosition.Top    = (int)containingWindow.Height - screenPosition.Top;
            screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

            WidgetForWindowsFormsAbstract mappingWidget = containingWindow.Parent as WidgetForWindowsFormsAbstract;

            screenPosition.Left   += mappingWidget.WindowsFormsWindow.Location.X;
            screenPosition.Top    += (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);
            screenPosition.Right  += mappingWidget.WindowsFormsWindow.Location.X;
            screenPosition.Bottom += (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);

            return(screenPosition);
        }
示例#13
0
 public SearchRegion(ImageBuffer imageContents, ScreenRectangle screenBounds)
 {
     this.ScreenRect    = screenBounds;
     this.imageContents = imageContents;
 }
示例#14
0
		private static RectangleDouble ScreenToSystemWindow(ScreenRectangle rectOnScreen, SystemWindow containingWindow)
		{
			ScreenRectangle screenPosition = new ScreenRectangle()
			{
				Left = (int)rectOnScreen.Left,
				Top = (int)rectOnScreen.Top,
				Right = (int)rectOnScreen.Right,
				Bottom = (int)rectOnScreen.Bottom,
			};
			WidgetForWindowsFormsAbstract mappingWidget = containingWindow.Parent as WidgetForWindowsFormsAbstract;
			screenPosition.Left -= mappingWidget.WindowsFormsWindow.Location.X;
			screenPosition.Top -= (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);
			screenPosition.Left -= mappingWidget.WindowsFormsWindow.Location.X;
			screenPosition.Bottom -= (mappingWidget.WindowsFormsWindow.Location.Y + mappingWidget.WindowsFormsWindow.TitleBarHeight);

			screenPosition.Top = (int)containingWindow.Height - screenPosition.Top;
			screenPosition.Bottom = (int)containingWindow.Height - screenPosition.Bottom;

			return new RectangleDouble()
			{
				Left = screenPosition.Left,
				Bottom = screenPosition.Bottom,
				Right = screenPosition.Right,
				Top = screenPosition.Top,
			};
		}
示例#15
0
 public SearchRegion(ImageBuffer imageContents, ScreenRectangle screenBounds, AutomationRunner automationRunner)
     : this(automationRunner)
 {
     this.ScreenRect    = screenBounds;
     this.imageContents = imageContents;
 }
示例#16
0
		public SearchRegion(ImageBuffer imageContents, ScreenRectangle screenBounds)
		{
			this.ScreenRect = screenBounds;
			this.imageContents = imageContents;
		}