public virtual void UpdateMaginifier() { if ((!initialized) || (hwndMag == IntPtr.Zero)) { return; } //*************************Take Eye Gaze From Both Eye and Head**********************************************// Point gazePointEyes = combineEyeGaze.GetGazePoint(); gazePointEyes = combineEyeGaze.GetWarpPoint(); Point warpPointEyes = combineEyeGaze.GetNextPoint(gazePointEyes); //overlayEyeNewForm.mTargetPoint = warpPoint; //show where am I Point //overlayEyeNewForm.wWhereAmIPoint = warpPoint; Point targetEyes = calculateTargetPoint(warpPointEyes); Vector3 headPoint = headPoints.GetHeadPoint(); Point warpPoint = headPoints.GetNextPoint(targetEyes); //show where am I Point //overlayEyeNewForm.wWhereAmIPoint = warpPoint; Point target = calculateTargetPoint(warpPoint); overlayEyeNewForm.mTargetPoint = target; //***********************************************************************************************// RECT hostWindowRect = new RECT(); NativeMethods.GetWindowRect(hwndMag, out hostWindowRect); int width = (int)((magWindowRect.right - magWindowRect.left) / m_MAGFACTOR); int height = (int)((magWindowRect.bottom - magWindowRect.top) / m_MAGFACTOR); RECT sourceRect = getInScreenRectFromTargetPoint(target, width, height); // Set the magnification factor. NativeMethods.MagTransform matrix = new NativeMethods.MagTransform(mConfiguration.ZoomFactor); NativeMethods.MagSetWindowTransform(hwndMag, ref matrix); if (mConfiguration.HideMouseCursor == true) { NativeMethods.MagShowSystemCursor(false); } else if (mConfiguration.HideMouseCursor == false) { NativeMethods.MagShowSystemCursor(true); } setColor(); // Set the source rectangle for the magnifier control. bool ret = NativeMethods.MagSetWindowSource(hwndMag, sourceRect); POINT cursor = new POINT(); NativeMethods.GetCursorPos(ref cursor); // The reason why "right" and "bottom" minus the 10 is, normally the image // of the cursor is shown at the bottom right of the cursor position, // if they don't minus some pixel, the cursor will stay outside of the magnifier. if (cursor.x <= sourceRect.left) { cursor.x = sourceRect.left; } if (cursor.x >= sourceRect.right) { cursor.x = sourceRect.right - 10; } if (cursor.y <= sourceRect.top) { cursor.y = sourceRect.top; } if (cursor.y >= sourceRect.bottom) { cursor.y = sourceRect.bottom - 10; } NativeMethods.SetCursorPos(cursor.x, cursor.y); // NativeMethods.ShowCursor(true); // if (!mConfiguration.HideMouseCursor) NativeMethods.ShowCursor(true); // else // NativeMethods.ShowCursor(false); //NativeMethods.MagShowSystemCursor(FALSE); if (this.form == null) { timer.Enabled = false; return; } if (this.form.IsDisposed) { timer.Enabled = false; return; } // Set the source rectangle for the magnifier control. //NativeMethods.MagSetWindowSource(hwndMag, sourceRect); // setWindowsPosition(); //Reclaim topmost status, to prevent unmagnified menus from remaining in view. NativeMethods.SetWindowPos(hwndMag, NativeMethods.HWND_TOPMOST, 0, 0, 0, 0, (int)SetWindowPosFlags.SWP_NOACTIVATE | (int)SetWindowPosFlags.SWP_NOMOVE | (int)SetWindowPosFlags.SWP_NOSIZE); //setWindowsPosition(); // Force redraw. NativeMethods.InvalidateRect(hwndMag, IntPtr.Zero, true); }
/* * if the users result by calibration is more than 80% in each of eyes, we can use followEyes option, in other * cases just mouse position. */ private void onPaint(object sender, PaintEventArgs e) { //mConfiguration.ZoomFactor = 1; SolidBrush newBrush; if (mConfiguration.whereIAmColor != "0") { newBrush = new SolidBrush(Color.FromName(mConfiguration.whereIAmColor)); } else { newBrush = new SolidBrush(Color.Red); } Rectangle rec; Rectangle rec2; if (!mfollowEyes) { int x = Cursor.Position.X; int y = Cursor.Position.Y; //stay in screen if (x - 100 <= 0) { x = 100; } if (x - 100 >= Screen.PrimaryScreen.Bounds.Width) { x = Screen.PrimaryScreen.Bounds.Width - 100; } if (y - 100 <= 0) { y = 100; } if (y - 100 >= Screen.PrimaryScreen.Bounds.Height) { y = Screen.PrimaryScreen.Bounds.Height - 100; } rec = new Rectangle(x - 100, y - 100, 200, 200); e.Graphics.FillEllipse(newBrush, rec); e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; rec = new Rectangle(x - 25, y - 25, 50, 50); e.Graphics.FillEllipse(new SolidBrush(Color.Yellow), rec); e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; this.Invalidate(); } else if (mfollowEyes) { Point gazePoint = combineEyes.GetWarpPoint(); Point warpPoint = combineEyes.GetNextPoint(gazePoint); //stay in primary screen if (warpPoint.X - 100 <= 0) { warpPoint.X = 100; } if (warpPoint.X - 100 >= Screen.PrimaryScreen.Bounds.Width) { warpPoint.X = Screen.PrimaryScreen.Bounds.Width - 100; } if (warpPoint.Y - 100 <= 0) { warpPoint.Y = 100; } if (warpPoint.Y - 100 >= Screen.PrimaryScreen.Bounds.Height) { warpPoint.Y = Screen.PrimaryScreen.Bounds.Height - 100; } //center of the circel int x = warpPoint.X; int y = warpPoint.Y; rec = new Rectangle(x - 100, y - 100, 200, 200); e.Graphics.FillEllipse(newBrush, rec); e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; rec = new Rectangle(x - 25, y - 25, 50, 50); e.Graphics.FillEllipse(new SolidBrush(Color.Yellow), rec); e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; this.Invalidate(); } }