Torque2D and Windows 7 mouse cordinate bug.
by Christopher Wesley Joyner · in Technical Issues · 07/21/2011 (6:13 pm) · 2 replies
I have seen this bug with my own application and know what a solution is to this problem.
After studying the bug in Torque2D on my Windows7 operating system, I relized what the problem is.
Windows7 allows reshaping of windows using click and drag teqhniques. All Windows does this, but what is different in Windows7
from most Windows before Windows7, is the fact that rather than give the window or application more space, the space is still confined
to the size that the applications windows was created in. So a 800x600 Window will always be 800x600 no matter how the user changes it.
So basically your windows is becoming distorted because it is being stretched or shrinked. I had this exzact same problem
and have already come to a solution for it. (Even though windows is not proportional, the mouse never is changed)
This is only to solve the situation where Windows7 distorts the window size that Torque2D uses.
This was only tested on Windows 7, (Windows Vista might ahve a different problem?)
This was not tested with Torque2D's game building, although from examining the bug when using the application, I determined this was the problem.
Another solution could be to force Torqu2D game building to never allow resizing of the window. Tests would have to be done to make sure
that Windows doesn't create a distortion of size on window creation.
To confirm/proove that windows 7 is distorting the window size, you can check to see how far the mouse is off when selecting icons in the application,
resize the window and then check how far it is off then. by resizing the window it should be possible to get the mouse in the correct place without putting in a modd like the above code. That is an idea for a temporary fix
I delcare the souce code contained in this email to be free without any restrictions or obligations.
After studying the bug in Torque2D on my Windows7 operating system, I relized what the problem is.
Windows7 allows reshaping of windows using click and drag teqhniques. All Windows does this, but what is different in Windows7
from most Windows before Windows7, is the fact that rather than give the window or application more space, the space is still confined
to the size that the applications windows was created in. So a 800x600 Window will always be 800x600 no matter how the user changes it.
So basically your windows is becoming distorted because it is being stretched or shrinked. I had this exzact same problem
and have already come to a solution for it. (Even though windows is not proportional, the mouse never is changed)
//here is a C/C++ code example defining how I solved this problem on my machine for my own application that handled mouse clicks. float tempfloat; //a temorary floating point storage int real_mousex; //will contain the real location in the window the mouse is hovering over. int real_mousey; //companioin to real_mousex. int temp_mousex= LOWORD(lParam); //The scenerio is when the main proc function is called by windows. int temp_mousey= HIWORD(lParam); //The WM could be a mouse move event. RECT temprect; //Used to give information by current size of window. GetClientRect(globhwnd,&temprect); //Find the size of the window the mouse is over. //The below line is a percent calculation, it calculates a percentage. tempfloat= (float)((800*100)/temprect.right)/100; //This calculation takes the real size before stretch which is 800 from the 800x600 mode // given to windows when creating the window. temprect.right holds the current size of the window, and not truthfuly the right placement. // after the line is done tempfloat will hold the percentage of of the size difference from the window after initalization, and it's current // condition. (it is in decimal format) global_mousex=(int) global_mousex*tempfloat; //After getting the percent different, adjust the detected mousex location to find real position. tempfloat= (float)((600*100)/temprect.bottom)/100; //Now find the Y percentage to adjust the location of the detected mousey. global_mousey=(int) global_mousey*tempfloat; //adjust to find real pointer location of distorted window mouse location.
This is only to solve the situation where Windows7 distorts the window size that Torque2D uses.
This was only tested on Windows 7, (Windows Vista might ahve a different problem?)
This was not tested with Torque2D's game building, although from examining the bug when using the application, I determined this was the problem.
Another solution could be to force Torqu2D game building to never allow resizing of the window. Tests would have to be done to make sure
that Windows doesn't create a distortion of size on window creation.
To confirm/proove that windows 7 is distorting the window size, you can check to see how far the mouse is off when selecting icons in the application,
resize the window and then check how far it is off then. by resizing the window it should be possible to get the mouse in the correct place without putting in a modd like the above code. That is an idea for a temporary fix
I delcare the souce code contained in this email to be free without any restrictions or obligations.
#2
Well here is another bug fixed version of the code in the first post, incase someone can't understand what I ment.
07/21/2011 (6:18 pm)
Well here is another bug fixed version of the code in the first post, incase someone can't understand what I ment.
After studying the bug in Torque2D on my Windows 7 operating system, I relized what the problem is. Windows7 allows reshaping of windows using click and drag teqhniques. All Windows does this, but what is different in Windows7 from most Windows before Windows7, is the fact that rather than give the window or application more space, the space is still confined to the size that the applications windows was created in. So a 800x600 Window will always be 800x600 no matter how the user changes it. So basically your windows is becoming distorted because it is being stretched or shrinked. I had this exzact same problem and have already come to a solution for it. (Even though windows is not proportional, the mouse never is changed) //here is a C/C++ code example defining how I solved this problem on my machine for my own application that handled mouse clicks. float tempfloat; //a temorary floating point storage int real_mousex; //will contain the real location in the window the mouse is hovering over. int real_mousey; //companioin to real_mousex. int temp_mousex= LOWORD(lParam); //The scenerio is when the main proc function is called by windows. int temp_mousey= HIWORD(lParam); //The WM could be a mouse move event. RECT temprect; //Used to give information by current size of window. GetClientRect(globhwnd,&temprect); //Find the size of the window the mouse is over. //The below line is a percent calculation, it calculates a percentage. tempfloat= (float)((800*100)/temprect.right)/100; //This calculation takes the real size before stretch which is 800 from the 800x600 mode // given to windows when creating the window. temprect.right holds the current size of the window, and not truthfuly the right placement. // after the line is done tempfloat will hold the percentage of of the size difference from the window after initalization, and it's current // condition. (it is in decimal format) real_mousex=(int) temp_mousex*tempfloat; //After getting the percent different, adjust the detected mousex location to find real position. tempfloat= (float)((600*100)/temprect.bottom)/100; //Now find the Y percentage to adjust the location of the detected mousey. real_mousey=(int) temp_mousey*tempfloat; //adjust to find real pointer location of distorted window mouse location. //This is only to solve the situation where Windows7 distorts the window size that Torque2D uses. //This was only tested on Windows 7, (Windows Vista might ahve a different problem?) //This was not tested with Torque2D's game building, although from examining the bug when using the application, I determined this was the problem. //Another solution could be to force Torqu2D game building to never allow resizing of the window. Tests would have to be done to make sure //that Windows doesn't create a distortion of size on window creation. //To confirm/proove that windows7 is distorting the window size, you can check to see how far the mouse is off when selecting icons in the application, //resize the window and then check how far it is off then. by resizing the window it should be possible to get the mouse in the correct //place without putting in a modd like the above code. That is an idea for a temporary fix for your users and me. //I delcare the souce code contained in this email to be free without any restrictions or obligations.
Torque 3D Owner Christopher Wesley Joyner