GMS 2 gui mouse position ;_;

Azenris

Member
Having gui mouse position problems :(
Not sure what's wrong :(
Any help please :(

I attached 2 screenshots in this link
https://imgur.com/a/OFXwfVH
It basically just shows some variables

Code:
window size = 1920, 1080
game/res size = 960, 540
gui size = 960, 540
view size = 960, 540
viewport = 0, 0, 1920, 1080
ignore display size its not used in any calcs ( unless it is behind my back )
display size is not the display size, it seems to be the display size of my other monitor
not sure how you get display size of the current monitor.
window size is sufficient at fullscreen anyway?


ANYWAY, basically my issue is with the GUI_MOUSE Y coord.
At the top of the screen, its 0, as expected.
At the bottom of the screen it reaches only 485. Despite the GUI SIZE shown to be 540.

my GUI_MOUSE positions are gained through
Code:
device_mouse_x_to_gui( 0 )
device_mouse_y_to_gui( 0 )
there is a gui resize where my game surface and gui are set the same. there calcs can be seen above
Code:
surface_resize( application_surface, _res_w, _res_h );
display_set_gui_size( _res_w, _res_h );
Any ideas whats causing this?
my only CRAYCRAY idea is that device_mouse_x_to_gui & device_mouse_y_to_gui do their conversions using the display size which is inaccurate and as far as I know read only.

Im hoping its just some small overlooked thing you can easyly help with me :(
Ask for more information if needed. Not really sure what to show :(
 

CloseRange

Member
I could be wrong but the gui layer should be stretched to the window size, not the application surface size.
There is a chance your gui then is bigger than your window you could test to see if this works:
Code:
var mx = (window_mouse_get_x()/window_get_width()) * display_get_gui_width();
var my = (window_mouse_get_y()/window_get_height()) * display_get_gui_height();
at this point mx and my should be what you expect but this is just a test not a solution. The soulution would be to properly scale your gui layer
 

Ido-f

Member
display_get_gui_width/height are bugged.
They show the display dimensions instead of the gui dimensions, which aren't always the same.
After using display_set_gui_size for the first time it gets sorted, out for some reason, and display_get_gui_width/height work as they should again.
I don't know if that makes device_mouse_x/y_to_gui bugged as well, but I wouldn't be surprised.

But reading your post again it's unlikely that's the issue.
Do you have black bars drawn manually? That could offset the gui layer and its mouse coordinates.
 
Last edited:

Azenris

Member
I could be wrong but the gui layer should be stretched to the window size, not the application surface size.
There is a chance your gui then is bigger than your window you could test to see if this works:
Code:
var mx = (window_mouse_get_x()/window_get_width()) * display_get_gui_width();
var my = (window_mouse_get_y()/window_get_height()) * display_get_gui_height();
at this point mx and my should be what you expect but this is just a test not a solution. The soulution would be to properly scale your gui layer
This is giving me the correct results. 0,0 top-left and 960,540 bottom-right as I was ecpecting from device_mouse_x_to_gui, device_mouse_x_to_guy

However, I dont understand why :] Why shouldn't my GUI be the same resolution as my game. Im not really understanding, trying to visualise it in my head :D
Wouldn't differnt resolutions give me MIXELS, i want it to be all the same.
 

CloseRange

Member
application surface relates to the draw events and "real world" events such as drawing players and enemies and what not. Size and scale doesn't need to be and usually isn't the same as the gui layer. It can be but doesn't need to be.
What's more important is that your gui is scaled to the window instead.
This happens by default actually and it is not a bug.... you can just set it yourself to override it...
The more important thing to do is just call this:
Code:
display_set_gui_maximize();
Generally you only need to do this not deal with resizing your gui layer as this seems to do the job, for me at least.
 

Azenris

Member
Ty for the suggestions CloseRange.
I want to keep the GUI resolution and game resolution the same for now. I dont want to maximise it to the window.

Still relating to the GUI stuff,
I have been doing some experimenting and I'm either misunderstanding more, or something is fishy going on.
I'll explain what I did and what I think and you tell me where I want wrong :D

So in my previous pictures I already linked https://imgur.com/a/OFXwfVH I didn't even notice the distortion on my GUI text pixels ( at the bottom ).

I really didn't understand them. The monitor is resolution 1920x1080. the game and GUI is 960x540. so exactly half. So everything should just look x2 bigger, pixel perfect.

I did a surface_save on the surface I create for the ACTION_BAR at the bottom. The save png was pixel perfect. So it wasnt being introduced while I was creating the that surface.

So I tried to save the application_surface in draw GUI end event so I could see the screen after that action bar surface was drawn. That didn't work though as I guess GMS does GUI stuff later/differently?

So Then I tried to save the screen with screen_save, but this had a weird result in that the saved image was 1920x1200 and not 1920x1080. basically it was saving the screen with the dimensions of my other monitor.

So then I added some code to intercept the draw GUI calls. Basically in draw GUI begin I create a surface with the same resolution as my gui ( display_get_gui_width(), display_get_gui_height() ), and set it as the target. then in draw GUI end I reset and draw that surface.

Now I have a surface with my GUI. I used surface_save again. My GUI in this surface was also pixel perfect !!

I disconnected my 1920x1200 monitor and the distortion ( from the first two pics ) was fixed... I did a screen_save of that and this time it made an image 1920x1080.

So what exactly is going on :D are there some internal values/scaling etc not working when moving the window from one monitor to another? I will keep checking my code, but I've spent 2 days trying to figure this all out and I can't seem to just quite grasp it.

As show in the 2 images, the display_get_width and display_get_height are shown incorrectly ( or as far as I would expect ). Are they used in some internal calculations too ?
 
Top