Skip to content

Commit 1fb8ee9

Browse files
committed
[Toolkit.Samples] Improved mouse input sample to explain the changes in coordinates to be in range [0; 1]
1 parent 4e8171f commit 1fb8ee9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Samples/Toolkit/Common/MouseInput/MouseInputGame.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,21 @@ protected override void Draw(GameTime gameTime)
101101
sb.AppendFormat("Right button : {0}\n", mouseState.Right);
102102
sb.AppendFormat("XButton1 : {0}\n", mouseState.XButton1);
103103
sb.AppendFormat("XButton2 : {0}\n", mouseState.XButton2);
104+
105+
// the mouse coordinates are in range [0; 1] relative to window.
106+
// any coordinates outside of the game window or control are clamped to this range
107+
// on Windows 8 platform it may not get to the values exactly 0 or 1 because of "active corners" feature of the OS.
104108
sb.AppendFormat("X : {0}\n", mouseState.X);
105109
sb.AppendFormat("Y : {0}\n", mouseState.Y);
110+
111+
// compute mouse position in screen coordinates
112+
var backbuffer = GraphicsDevice.BackBuffer;
113+
var screenWidth = backbuffer.Width;
114+
var screenHeight = backbuffer.Height;
115+
116+
sb.AppendFormat("Screen X : {0}\n", mouseState.X * screenWidth);
117+
sb.AppendFormat("Screen Y : {0}\n", mouseState.Y * screenHeight);
118+
106119
sb.AppendFormat("Wheel : {0}\n", mouseState.WheelDelta);
107120

108121
// Render the text

0 commit comments

Comments
 (0)