private MouseEventHandler HandleMouseMove(ISeleniumAdapter selenium) { return(delegate(object o, MouseEventArgs args) { this.HoverX = ((MouseEventArgs)args).X; this.HoverY = ((MouseEventArgs)args).Y; var windowRect = selenium.BrowserWindowScreenRectangle; var topLeft = new Point(windowRect.Left, windowRect.Top); var bottomRight = new Point(windowRect.Right, windowRect.Bottom); UserInteropAdapter.ScreenToGraphics(ref topLeft); UserInteropAdapter.ScreenToGraphics(ref bottomRight); float height = Math.Abs(bottomRight.Y - topLeft.Y); float width = Math.Abs(bottomRight.X - topLeft.X); var contentTopLeft = new Point(windowRect.Left, windowRect.Top); contentTopLeft.X += selenium.ContentOffsetX(); contentTopLeft.Y += selenium.ContentOffsetY(); // var point = new Point(this.HoverX, this.HoverY); selenium.ConvertFromScreenToWindow(ref point); selenium.ConvertFromWindowToPage(ref point); var elements = selenium.WebDriver.GetElementByCoordinates(point.X, point.Y); var element = elements.LastOrDefault(x => x.IsClickable()); //Console.Out.Wipe(); //Console.Out.BeginRewritableLine(); //Console.Out.WriteColored(ConsoleColor.Yellow, $"X {HoverX:D4} Y {HoverY:D4} "); //Console.Out.WriteColored(ConsoleColor.Green, $"{(element == null ? " " : $" -- Button {element.Text} --")}"); //Console.Out.WriteColored(ConsoleColor.Magenta, $"width {width} height {height} "); if (element != null) { var p = new Point(element.Location.X, element.Location.Y); selenium.ConvertFromPageToWindow(ref p); selenium.ConvertFromWindowToScreen(ref p); selenium.ConvertFromScreenToGraphics(ref p); ElementLocation = p; ElementSize = element.Size; } else { ElementLocation = default(Point); } }); }
private void DrawStuff(int number, int clientX, int clientY, Graphics overlayGraphics) { var point = new Point(clientX, clientY); var handle = Selenium.GetChromeHandle(); ClientToScreen(handle, ref point); UserInteropAdapter.ScreenToGraphics(ref point); overlayGraphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 255, 255)), point.X, point.Y, 20, 20); overlayGraphics.DrawString(number.ToString(), new Font(FontFamily.GenericSansSerif, 10), new SolidBrush(Color.DarkMagenta), point.X, point.Y); overlayGraphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 0, 255)), point.X, point.Y, 21, 21); }
private void Render(Graphics backBuffer, ISeleniumAdapter selenium) { var windowRect = selenium.BrowserWindowScreenRectangle; var topLeft = new Point(windowRect.Left, windowRect.Top); var bottomRight = new Point(windowRect.Right, windowRect.Bottom); UserInteropAdapter.ScreenToGraphics(ref topLeft); UserInteropAdapter.ScreenToGraphics(ref bottomRight); backBuffer.Clear(Color.Black); float height = Math.Abs(bottomRight.Y - topLeft.Y); float width = Math.Abs(bottomRight.X - topLeft.X); var contentTopLeft = new Point(windowRect.Left, windowRect.Top); contentTopLeft.X += selenium.ContentOffsetX(); contentTopLeft.Y += selenium.ContentOffsetY(); if (!ClickThrough) { backBuffer.FillRectangle(new SolidBrush(BackgroundColor), contentTopLeft.X + 8, contentTopLeft.Y, width - selenium.ContentOffsetX() - 16, height - selenium.ContentOffsetY() - 18); } backBuffer.FillRectangle(new SolidBrush(HeaderColor), topLeft.X + 8, topLeft.Y + 22, width - 16, 24); backBuffer.DrawRectangle(new Pen(HeaderColor, 10), topLeft.X + 8, topLeft.Y, width - 16, height - 8); backBuffer.DrawString(Title, new Font(FontFamily.GenericSansSerif, 14), new SolidBrush(Color.FromArgb(255, 10, 10, 10)), topLeft.X + 340, topLeft.Y + 22); if (ElementLocation != default(Point)) { backBuffer.DrawRectangle(new Pen(Color.FromArgb(255, 0, 50, 150), 4), ElementLocation.X - 2, ElementLocation.Y - 2, ElementSize.Width + 4, ElementSize.Height + 4); backBuffer.FillRectangle(new SolidBrush(Color.FromArgb(255, 100, 255, 255)), ElementLocation.X - 2, ElementLocation.Y - 2, ElementSize.Width + 4, ElementSize.Height + 4); } foreach (var artifact in Artifacts) { var rectangle = new Rectangle(artifact.Rectangle.X, artifact.Rectangle.Y, artifact.Rectangle.Width, artifact.Rectangle.Height); _seleniumAdapter.ConvertFromPageToWindow(ref rectangle); _seleniumAdapter.ConvertFromWindowToScreen(ref rectangle); _seleniumAdapter.ConvertFromScreenToGraphics(ref rectangle); backBuffer.DrawRectangle(new Pen(artifact.LineColor, 6), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); backBuffer.FillRectangle(new SolidBrush(artifact.BackgroundColor), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); backBuffer.DrawString(artifact.Text, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.FromArgb(255, 10, 10, 10)), rectangle.X, rectangle.Y); } }
public void DrawStuff(IntPtr handle, int number, int clientX, int clientY, Graphics overlayGraphics, int width, int height, Color innerColor, Color outerColor) { var point = new Point(clientX, clientY); UserBindings.ClientToScreen(handle, ref point); UserInteropAdapter.ScreenToGraphics(ref point); overlayGraphics.FillRectangle(new SolidBrush(innerColor), point.X, point.Y, width, height); if (number != -1) { overlayGraphics.DrawString(number.ToString(), new Font(FontFamily.GenericSansSerif, 10), new SolidBrush(Color.FromArgb(1, 1, 1)), point.X, point.Y); } overlayGraphics.DrawRectangle(new Pen(outerColor), point.X, point.Y, width + 1, height + 1); }
public void ConvertFromScreenToGraphics(ref Rectangle rectangle) { UserInteropAdapter.ScreenToGraphics(ref rectangle); }
public void ConvertFromScreenToGraphics(ref Point point) { UserInteropAdapter.ScreenToGraphics(ref point); }