public static Trigger UserActionToTrigger(IMutableRegion mr, VGUserAction userAction) { Trigger trigger = null; Region r = mr.Rectangle; if (userAction is VGTextTrigger vgTextTrigger) { trigger = new TextTrigger(r, vgTextTrigger.Text); } else if (userAction is VGMouseTrigger vgMouseTrigger) { trigger = new MouseTrigger(vgMouseTrigger.Action, r, vgMouseTrigger.Cursor); } return(trigger); }
private static void CollectRegions_(ImageMatchSettings imageMatchSettings, IList <IRegion> regions, IList <VisualGridSelector[]> regionSelectors) { if (regions == null) { return; } int currentCounter = 0; int currentTypeIndex = 0; int currentTypeRegionCount = regionSelectors[0].Length; List <IMutableRegion>[] mutableRegions = new List <IMutableRegion>[] { new List <IMutableRegion>(), // Ignore Regions new List <IMutableRegion>(), // Layout Regions new List <IMutableRegion>(), // Strict Regions new List <IMutableRegion>(), // Content Regions new List <IMutableRegion>(), // Floating Regions new List <IMutableRegion>(), // Accessibility Regions new List <IMutableRegion>(), // Target Element Location }; foreach (IRegion r in regions) { bool canAddRegion = false; while (!canAddRegion) { currentCounter++; if (currentCounter > currentTypeRegionCount) { currentTypeIndex++; currentTypeRegionCount = regionSelectors[currentTypeIndex].Length; currentCounter = 0; } else { canAddRegion = true; } } MutableRegion mr = new MutableRegion(r); mutableRegions[currentTypeIndex].Add(mr); } Point location = Point.Empty; // If target element location available if (mutableRegions[6].Count > 0) { location = mutableRegions[6][0].Location; } imageMatchSettings.Ignore = FilterEmptyEntries_(mutableRegions[0], location); imageMatchSettings.Layout = FilterEmptyEntries_(mutableRegions[1], location); imageMatchSettings.Strict = FilterEmptyEntries_(mutableRegions[2], location); imageMatchSettings.Content = FilterEmptyEntries_(mutableRegions[3], location); List <FloatingMatchSettings> floatingMatchSettings = new List <FloatingMatchSettings>(); for (int i = 0; i < regionSelectors[4].Length; i++) { IMutableRegion mr = mutableRegions[4][i]; if (mr.Area == 0) { continue; } VisualGridSelector vgs = regionSelectors[4][i]; if (vgs.Category is IGetFloatingRegionOffsets gfr) { FloatingMatchSettings fms = new FloatingMatchSettings() { MaxLeftOffset = gfr.MaxLeftOffset, MaxUpOffset = gfr.MaxUpOffset, MaxRightOffset = gfr.MaxRightOffset, MaxDownOffset = gfr.MaxDownOffset, Top = mr.Top - location.Y, Left = mr.Left - location.X, Width = mr.Width, Height = mr.Height }; floatingMatchSettings.Add(fms); } } imageMatchSettings.Floating = floatingMatchSettings.ToArray(); List <AccessibilityRegionByRectangle> accessibilityRegions = new List <AccessibilityRegionByRectangle>(); for (int i = 0; i < regionSelectors[5].Length; i++) { IMutableRegion mr = mutableRegions[5][i]; if (mr.Area == 0) { continue; } VisualGridSelector vgs = regionSelectors[5][i]; if (vgs.Category is IGetAccessibilityRegionType gar) { AccessibilityRegionByRectangle accessibilityRegion = new AccessibilityRegionByRectangle( mr.Left - location.X, mr.Top - location.Y, mr.Width, mr.Height, gar.AccessibilityRegionType); accessibilityRegions.Add(accessibilityRegion); } } imageMatchSettings.Accessibility = accessibilityRegions.ToArray(); }
public SimpleRegionByRectangle(Rectangle region) { this.region = new MutableRegion(region); }