public static WindowRectangle CheckWindow(int height, int width) { // Have to declare a delegate so that a thunk is created, so that win32 may call us back. EnumWindowsCallback callBackFn = new EnumWindowsCallback(ReportWindow); heightWindow = height; widthWindow = width; EnumWindows(callBackFn, 0); WindowRectangle w = new WindowRectangle(); w.Left = rectangleOfWindow.Left; w.Right = rectangleOfWindow.Right; w.Top = rectangleOfWindow.Top; w.Bottom = rectangleOfWindow.Bottom; return(w); }
public void timer_Tick(object sender, EventArgs e) { //get coordinates of textview if (wr.Equals(null) || wr.Left == 0) { wr = WindowEnumerator.CheckWindow((int)textView.ViewportHeight, (int)textView.ViewportWidth); return; } if (eyePoint.X < wr.Left || eyePoint.Y < wr.Top || eyePoint.Y > wr.Bottom || eyePoint.X > wr.Right) { //outside of textview, so return, no update. return; } else { int startPosition = textView.TextSnapshot.GetLineNumberFromPosition(textView.TextViewLines.FirstVisibleLine.Start); int endPosition = textView.TextSnapshot.GetLineNumberFromPosition(textView.TextViewLines.LastVisibleLine.Start); int noOfLines = endPosition - startPosition; double noOfPixels = noOfLines * textView.LineHeight; double lineNumberRelativeToView = (eyePoint.Y - wr.Top) / (textView.LineHeight * (textView.ZoomLevel / 100)); double lineNumberAbsoluteToView = lineNumberRelativeToView + (startPosition); lineNumber = Math.Ceiling(lineNumberAbsoluteToView); try { currentLineCounter[(int)lineNumber - 1]++; } catch (IndexOutOfRangeException) { currentLineCounter[currentLineCounter.Length - 1]++; } Debug.WriteLine("Gazing at line: " + lineNumber); } }