예제 #1
0
 public void ToRelative()
 {
     // Init
     Point p = CreateStdPoint();
     StretchedPoint sp = CreateStdStretchedPoint();
     Window w = CreateStdWindow();
     Coordinate c1 = new Coordinate(CoordinateType.Absolute, p);
     Coordinate c2 = new Coordinate(CoordinateType.Relative, p);
     Coordinate c3 = new Coordinate(sp);
     // Null argument
     Assert.Catch<NullReferenceException>(() => c1.ToRelative(null));
     Point r = c2.ToRelative(null);
     Assert.AreEqual(r.X, p.X);
     Assert.AreEqual(r.Y, p.Y);
     Assert.Catch<NullReferenceException>(() => c3.ToRelative(null));
     // Normal calls
     Point a = c1.ToRelative(w);
     Assert.AreEqual(a.X, -500);
     Assert.AreEqual(a.Y, -300);
     Point r1 = c2.ToRelative(w);
     Assert.AreEqual(r1.X, p.X);
     Assert.AreEqual(r1.Y, p.Y);
     Point s = c3.ToRelative(w);
     Assert.AreEqual(s.X, 96);
     Assert.AreEqual(s.Y, 120);
 }
예제 #2
0
파일: HtmlRecorder.cs 프로젝트: antgraf/BA
 private static string PointInformation()
 {
     StringBuilder text = new StringBuilder();
     Window window = Window.GetWindowAtCursor();
     Coordinate pt = new Coordinate(CoordinateType.Absolute, new WindowEntity.Point() { X = Cursor.Position.X, Y = Cursor.Position.Y });
     Color color = Desktop.Primary.GetPixelColor(pt);
     if(window != null)
     {
         WindowEntity.Point rel = pt.ToRelative(window);
         StretchedPoint st = pt.ToStretched(window);
         text.Append("<b>Window</b>: ");
         text.AppendFormat("[{0}, {1}] ", window.Width, window.Height);
         text.AppendFormat("\"{0}\"", window.Title);
         text.AppendLine();
         text.Append("<br><b>Color</b>: ");
         text.AppendLine(color.ToString());
         text.Append("<br><b>Coordinate</b>: Absolute: ");
         text.AppendFormat("X = {0}, Y = {1}", pt.X, pt.Y);
         text.Append("; Relative: ");
         text.AppendFormat("X = {0}, Y = {1}", rel.X, rel.Y);
         text.Append("; Stretched: ");
         text.AppendFormat(CultureInfo.InvariantCulture, "X = {0}, Y = {1}", st.X, st.Y);
     }
     else
     {
         text.Append("<b>Color</b>: ");
         text.AppendLine(color.ToString());
         text.Append("<br><b>Coordinate</b>: Absolute: ");
         text.AppendFormat("{0}, {1}", pt.X, pt.Y);
     }
     return text.ToString();
 }
예제 #3
0
 public void WrongCalls()
 {
     Window w = CreateStdWindow();
     Coordinate c0 = new Coordinate();
     Assert.Catch<InitializationException>(() => c0.ToAbsolute(null));
     Assert.Catch<InitializationException>(() => c0.ToAbsolute(w));
     Assert.Catch<InitializationException>(() => c0.ToRelative(null));
     Assert.Catch<InitializationException>(() => c0.ToRelative(w));
     Assert.Catch<InitializationException>(() => c0.ToStretched(null));
     Assert.Catch<InitializationException>(() => c0.ToStretched(w));
 }
예제 #4
0
 public void WrongPoint()
 {
     StretchedPoint wrongP1 = new StretchedPoint {X = 100.0, Y = 0.0};
     StretchedPoint wrongP2 = new StretchedPoint {X = 0.0, Y = 100.0};
     StretchedPoint wrongP3 = new StretchedPoint {X = 100.0, Y = 200.0};
     Coordinate c1 = new Coordinate(wrongP1);
     Coordinate c2 = new Coordinate(wrongP2);
     Coordinate c3 = new Coordinate(wrongP3);
     Window w = CreateStdWindow();
     Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToAbsolute(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToAbsolute(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToAbsolute(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToRelative(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToRelative(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToRelative(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c1.ToStretched(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c2.ToStretched(w));
     Assert.Catch<CoordinatesOutOfRangeException>(() => c3.ToStretched(w));
 }
예제 #5
0
 private Coordinate FindImageCoordinate(Coordinate topLeft, Coordinate bottomRight, string imageName)
 {
     Bitmap screen = pEveWindow.Screenshot(topLeft, bottomRight);
     SaveDebugImage(screen);
     Bitmap fragment = new Bitmap(Relative2AbsolutePath(imageName));
     pEveWindow.AllowedColorDeviation = pStandardColorDeviation;
     Coordinate found = pEveWindow.FindImageWithColorDeviation(screen, fragment);
     if(found == null)
     {
         return null;
     }
     WindowEntity.Point rel1 = topLeft.ToRelative(pEveWindow);
     WindowEntity.Point rel2 = found.ToRelative(pEveWindow);
     return new Coordinate(CoordinateType.Relative, new WindowEntity.Point() { X = rel1.X + rel2.X, Y = rel1.Y + rel2.Y });
 }