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(); }
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)); }
public void ToStretched() { // 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.ToStretched(null)); Assert.Catch<NullReferenceException>(() => c2.ToStretched(null)); StretchedPoint s = c3.ToStretched(null); Assert.AreEqual(s.X, sp.X); Assert.AreEqual(s.Y, sp.Y); // Normal calls StretchedPoint a = c1.ToStretched(w); Assert.AreEqual(a.X, -0.78125); Assert.AreEqual(a.Y, -0.625); StretchedPoint r = c2.ToStretched(w); Assert.AreEqual(r.X, 0.15625); Assert.AreEqual(r.Y, 0.41666666666666666); StretchedPoint s1 = c3.ToStretched(w); Assert.AreEqual(s1.X, sp.X); Assert.AreEqual(s1.Y, sp.Y); }
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)); }