Sign in to follow this  
Sixten

Wrong x, y ???

Recommended Posts

Hiya all.. didnt really know what to put in the subject.. Well im developing a UI System that i will implement in my 3DEngine.. with buttons, textboxes and so on.. i got the rendering working smoothly and i got it working with transparent textures and so on.. But i got a problem with the Mouse handling.. The mouse X, Y from the MSGPROC dosent correspond with the X, Y on the screen.. If i have made a button and placed it at x:200, Y:200 and i move the mouse down to that X, Y pos.. the button is missplaced.. and the missplacement gets larger the bigger the x, y value is.. I have check that the X, Y pos is correct when the object is drawn.... What could cause this ?? I am drawing it at RHW (0.0f) and Z (0.0).. Its probobly something simple.. but i just cant find it ??.. And u one got any ideas..?? Thx for the help :D

Share this post


Link to post
Share on other sites
I forget the exact details, but you might want to check the ScreenToClient() Win32 function. IIRC, the coordinates you're getting via Win32 aren't compensating for the border/title for your window, thus they appear incorrect...

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
I forget the exact details, but you might want to check the ScreenToClient() Win32 function. IIRC, the coordinates you're getting via Win32 aren't compensating for the border/title for your window, thus they appear incorrect...

hth
Jack

I don't think this will solve the OP's problem as he says the misplacement gets larger if the x and y values of a control are greater.

@ OP: are your sure your viewport/projection matrix matches the client-rect of the window?

Share this post


Link to post
Share on other sites
In screen coordinates, (0,0) is at the top left and X increases to the right and Y increases towards the bottom. In a normal 3D situation, (0,0) is in the center and X increases to the right and Y increases toward the top. Does this explain your behavior?

Share this post


Link to post
Share on other sites
I believe that I had this happen to me a while back...
Try and see if it still does it when your in fullscreen mode, (i'm assuming your windowed right now :)). If it does work correctly, then your problem is when windows creates a window to your specifications, it shrinks the client area to put in the outline, and the window title bar. So, what 20,20 to direct x, is not really 20,20 pixels from the corner of the winow.

Share this post


Link to post
Share on other sites
Well i have checked around alittle more.. and i noticed that the window created is only 791 wide and 564 high.. this is because of borders, and the top caption bar..

And i checked some sites and i found this function

AdjustWindowRect

All i had to do was to put my window size in a RECT and call this function like this and it resized the window :D

RECT rc;
SetRect( &rc, 0, 0, 800, 600 );
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );

So now its pixel accurat :D

Thx anyways guys..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this