public override Point ConvertLocation(Point location, CoordinatesTypeEnum from, CoordinatesTypeEnum to) { if (from == to) { return(location); } Point updatedLocation = new Point(location.X - workingArea_.Left, location.Y - workingArea_.Top); return(updatedLocation); }
/// <summary> /// Create a new <see cref="Region"/> instance. /// </summary> /// <param name="left"></param> /// <param name="top"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="coordinateType"></param> public Region(int left, int top, int width, int height, CoordinatesTypeEnum coordinateType = CoordinatesTypeEnum.SCREENSHOT_AS_IS) { ArgumentGuard.GreaterOrEqual(width, 0, nameof(width)); ArgumentGuard.GreaterOrEqual(height, 0, nameof(height)); Left = left; Top = top; Width = width; Height = height; CoordinatesType = coordinateType; }
public override Point GetLocationInScreenshot(Point location, CoordinatesTypeEnum coordinatesType) { location = ConvertLocation(location, coordinatesType, CoordinatesTypeEnum.SCREENSHOT_AS_IS); // Making sure it's within the screenshot bounds if (!frameWindow_.Contains(location)) { throw new OutOfBoundsException($"Location {location} ('{coordinatesType}') is not visible in screenshot!"); } return(location); }
/// <summary> /// Converts a region's location coordinates with the <paramref name="from"/> coordinates type to the <paramref name="to"/> coordinates type. /// </summary> /// <param name="region">The region which location's coordinates needs to be converted.</param> /// <param name="from">The current coordinates type for <paramref name="region"/>.</param> /// <param name="to"> The target coordinates type for <paramref name="region"/>.</param> /// <returns>A new region which is the transformation of <paramref name="region"/> to the <paramref name="to"/> coordinates type.</returns> public Region ConvertRegionLocation(Region region, CoordinatesTypeEnum from, CoordinatesTypeEnum to) { ArgumentGuard.NotNull(region, nameof(region)); if (region.IsSizeEmpty) { return(region); } ArgumentGuard.NotNull(from, nameof(from)); ArgumentGuard.NotNull(to, nameof(to)); Point updatedLocation = ConvertLocation(region.Location, from, to); return(new Region(updatedLocation, region.Size)); }
public override Region GetIntersectedRegion(Region region, CoordinatesTypeEnum originalCoordinatesType, CoordinatesTypeEnum resultCoordinatesType) { if (region.IsSizeEmpty) { return(region); } Region intersectedRegion = ConvertRegionLocation(region, originalCoordinatesType, CoordinatesTypeEnum.SCREENSHOT_AS_IS); switch (originalCoordinatesType) { // If the request was context based, we intersect with the frame window. case CoordinatesTypeEnum.CONTEXT_AS_IS: case CoordinatesTypeEnum.CONTEXT_RELATIVE: intersectedRegion.Intersect(frameWindow_); break; // If the request is screenshot based, we intersect with the image case CoordinatesTypeEnum.SCREENSHOT_AS_IS: intersectedRegion.Intersect(new Region(0, 0, Image.Width, Image.Height)); break; default: throw new CoordinatesTypeConversionException(string.Format("Unknown coordinates type: '{0}'", originalCoordinatesType)); } // If the intersection is empty we don't want to convert the coordinates. if (intersectedRegion.IsSizeEmpty) { return(intersectedRegion); } // Converting the result to the required coordinates type. intersectedRegion = ConvertRegionLocation(intersectedRegion, CoordinatesTypeEnum.SCREENSHOT_AS_IS, resultCoordinatesType); return(intersectedRegion); }
public override Point ConvertLocation(Point location, CoordinatesTypeEnum from, CoordinatesTypeEnum to) { return(location); }
public override Utils.Geometry.Region GetIntersectedRegion(Utils.Geometry.Region region, CoordinatesTypeEnum originalCoordinatesType, CoordinatesTypeEnum resultCoordinatesType) { return(region); }
public override Point ConvertLocation(Point location, CoordinatesTypeEnum from, CoordinatesTypeEnum to) { ArgumentGuard.NotNull(location, nameof(location)); ArgumentGuard.NotNull(from, nameof(from)); ArgumentGuard.NotNull(to, nameof(to)); if (from == to) { return(location); } Point result = location; // If we're not inside a frame, and the screenshot is the entire // page, then the context as-is/relative are the same (notice // screenshot as-is might be different, e.g., // if it is actually a sub-screenshot of a region). if (frameChain_.Count == 0 && screenshotType_ == ScreenshotTypeEnum.ENTIRE_FRAME) { if ((from == CoordinatesTypeEnum.CONTEXT_RELATIVE || from == CoordinatesTypeEnum.CONTEXT_AS_IS) && to == CoordinatesTypeEnum.SCREENSHOT_AS_IS) { // If this is not a sub-screenshot, this will have no effect. result.Offset(frameLocationInScreenshot_); } else if (from == CoordinatesTypeEnum.SCREENSHOT_AS_IS && (to == CoordinatesTypeEnum.CONTEXT_RELATIVE || to == CoordinatesTypeEnum.CONTEXT_AS_IS)) { result.Offset(-frameLocationInScreenshot_.X, -frameLocationInScreenshot_.Y); } return(result); } switch (from) { case CoordinatesTypeEnum.CONTEXT_AS_IS: switch (to) { case CoordinatesTypeEnum.CONTEXT_RELATIVE: result.Offset(currentFrameScrollPosition_); break; case CoordinatesTypeEnum.SCREENSHOT_AS_IS: result.Offset(frameLocationInScreenshot_); break; default: throw new CoordinatesTypeConversionException(from, to); } break; case CoordinatesTypeEnum.CONTEXT_RELATIVE: switch (to) { case CoordinatesTypeEnum.SCREENSHOT_AS_IS: // First, convert context-relative to context-as-is. result.Offset(-currentFrameScrollPosition_.X, -currentFrameScrollPosition_.Y); // Now convert context-as-is to screenshot-as-is. result.Offset(frameLocationInScreenshot_); break; case CoordinatesTypeEnum.CONTEXT_AS_IS: result.Offset(-currentFrameScrollPosition_.X, -currentFrameScrollPosition_.Y); break; default: throw new CoordinatesTypeConversionException(from, to); } break; case CoordinatesTypeEnum.SCREENSHOT_AS_IS: switch (to) { case CoordinatesTypeEnum.CONTEXT_RELATIVE: // First convert to context-as-is. result.Offset(-frameLocationInScreenshot_.X, -frameLocationInScreenshot_.Y); // Now convert to context-relative. result.Offset(currentFrameScrollPosition_); break; case CoordinatesTypeEnum.CONTEXT_AS_IS: result.Offset(-frameLocationInScreenshot_.X, -frameLocationInScreenshot_.Y); break; default: throw new CoordinatesTypeConversionException(from, to); } break; default: throw new CoordinatesTypeConversionException(from, to); } return(result); }
/// <summary> /// Converts a location's coordinates with the <paramref name="from"/> coordinates type /// to the <paramref name="to"/> coordinates type. /// </summary> /// <param name="location">The location which coordinates needs to be converted.</param> /// <param name="from">The current coordinates type for <paramref name="location"/></param> /// <param name="to">The target coordinates type for <paramref name="location"/></param> /// <returns>A new location which is the transformation of <paramref name="location"/> to the <paramref name="to"/> coordinates type.</returns> public abstract Point ConvertLocation(Point location, CoordinatesTypeEnum from, CoordinatesTypeEnum to);
/// <summary> /// Create a new <see cref="Region"/> instance. /// </summary> /// <param name="position"></param> /// <param name="size"></param> /// <param name="coordinateType"></param> public Region(Point position, Size size, CoordinatesTypeEnum coordinateType = CoordinatesTypeEnum.SCREENSHOT_AS_IS) : this(position.X, position.Y, size.Width, size.Height, coordinateType) { }
/// <summary> /// Get the intersection of the given region with the screenshot. /// </summary> /// <param name="region">region The region to intersect.</param> /// <param name="coordinatesType">The coordinates type of <paramref name="region"/>.</param> /// <returns>The intersected region, in <paramref name="coordinatesType"/> coordinates.</returns> public Region GetIntersectedRegion(Region region, CoordinatesTypeEnum coordinatesType) { return(GetIntersectedRegion(region, region.CoordinatesType, coordinatesType)); }
/// <summary> /// Get the intersection of the given region with the screenshot. /// </summary> /// <param name="region">region The region to intersect.</param> /// <param name="originalCoordinatesType">The coordinates type of <paramref name="region"/>.</param> /// <param name="resultCoordinatesType">The coordinates type of the resulting region.</param> /// <returns>The intersected region, in <paramref name="resultCoordinatesType"/> coordinates.</returns> public abstract Region GetIntersectedRegion(Region region, CoordinatesTypeEnum originalCoordinatesType, CoordinatesTypeEnum resultCoordinatesType);
/// <summary> /// Calculates the location in the screenshot of the location given as parameter. /// </summary> /// <param name="location">The location as coordinates inside the current frame.</param> /// <param name="coordinatesType">The coordinates type of <paramref name="location"/></param> /// <returns>The corresponding location inside the screenshot, in screenshot as-is coordinates type.</returns> /// <exception cref="OutOfBoundsException">If the location is not inside the frame's region in the screenshot.</exception> public abstract Point GetLocationInScreenshot(Point location, CoordinatesTypeEnum coordinatesType);
public override Region GetIntersectedRegion(Region region, CoordinatesTypeEnum originalCoordinatesType, CoordinatesTypeEnum resultCoordinatesType) { return(region); }
/// <summary> /// Create a new <see cref="Region"/> instance. /// </summary> /// <param name="rectangle"></param> /// <param name="coordinateType"></param> public Region(Rectangle rectangle, CoordinatesTypeEnum coordinateType = CoordinatesTypeEnum.SCREENSHOT_AS_IS) : this(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, coordinateType) { }
public override Point GetLocationInScreenshot(Point location, CoordinatesTypeEnum coordinatesType) { return(location); }
public CoordinatesTypeConversionException(CoordinatesTypeEnum from, CoordinatesTypeEnum to) { this.from = from; this.to = to; }