Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Incorrect cursor position when fullscreen. #279

Closed
xanather opened this issue Feb 13, 2014 · 6 comments
Closed

Incorrect cursor position when fullscreen. #279

xanather opened this issue Feb 13, 2014 · 6 comments

Comments

@xanather
Copy link
Contributor

Looks like internal cursor positions are getting obtained from

var p = control.PointToClient(Cursor.Position);

which does not seem to work correctly when a Windows Desktop toolkit game is in fullscreen (the mouse cannot cover the whole screen).

What would be the best solution? Checking whether the game is in fullscreen or not (if true then just use Cursor.Position instead?), or are there any other methods? I'm not sure what happens to the underlying form when the game goes fullscreen.

This is the last "bug" I have encounted for the toolkit.

@CoderBob
Copy link

Not sure about the coordinates being wrong, but in any case, PointToClient() creates garbage. And you will be calling this once every update.
http://stackoverflow.com/questions/13750394/garbage-free-client-coordinates

So in the end, I used interop:

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;

public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}

[DllImport("user32.dll")]
static extern bool GetCursorPos(out POINT lpPoint);

[DllImport("user32.dll", SetLastError = true)]
public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref POINT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);

@xoofx
Copy link
Member

xoofx commented Feb 15, 2014

Thanks for the report, indeed, the code behind PointToClient is bad. Will try to see if I can fix the coordinates problem

@xanather
Copy link
Contributor Author

Related question: Is there a reason why the toolkit Mouse position returns floats between 0 and 1? Wouldn't it be easier to just return the cursor position as is? That way the user wont need to multiply the floats back to correct x/y values?

@TheWhiteAmbit
Copy link
Contributor

I think this is a relative layout, and will help you when f.e. the elements size changes. 0.5 will still be center.

@xanather
Copy link
Contributor Author

I realize that, but many other high-level libraries do it in this way. I assume for the majority it would be used as just getting straight x/y positions.

xoofx added a commit that referenced this issue Feb 15, 2014
…tching to fullscreen. Remove call to PointToClient to avoid GC
@xoofx
Copy link
Member

xoofx commented Feb 15, 2014

This should be fixed by latest commit. Concerning position in the range [0, 1], well, it is a convention. I found more practical to use [0, 1] as it directly maps to a texcoord and can be more friendly to different screen ratio.

@xoofx xoofx closed this as completed Feb 15, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants