Display_mouse_get_x(y)

Petrik33

Member
Hello everybody, I have question: what does this function relate on? I mean when I resize my window(here is the code of the resize):
GML:
surface_resize(application_surface,VIEW_W,VIEW_H)
window_set_size(VIEW_W,VIEW_H);
view_wport[0]=VIEW_W;
view_hport[0]=VIEW_H;
camera_set_view_size(global.oCamera.cam,VIEW_W,VIEW_H);
alarm[0]=1;

//Alarm[0]
window_center();
display_set_gui_size(window_get_width(),window_get_height())
global.GUI_W=display_get_gui_width()
global.GUI_H=display_get_gui_height()
the mouse appears to be drawn in the wrong place using this function, some screenshots(sorry for the gui elements, they will be resized later)
And when I run it fullscreen it is drawn in apppropriate way.
 

Attachments

Petrik33

Member
You can use device_mouse_x_to_gui(0), and device_mouse_y_to_gui(0) to convert mouse coordinates to GUI coordinates
Yeah, thanks a lot, haven't known about this function, but still it is interesting to know what did the previous function depend on, to understand if I am doing it alright with screen resize
 
I haven't really toyed around with display_get_mouse_* functions, but reading the manual (here) it seems as though it would return the position of the mouse on the actual screen with whatever the actual screens resolution is. So if your computer's resolution is set to 1920x1080 and your game is 1280x720 (as random examples) the mouse is going to return the wrong coordinates for its position within your game (I assume). Also if your game window is not fullscreened it will return wrong coordinates. Display_get_mouse_* is not really useful outside of specific circumstances, so you should stick to either mouse_* functions or device_mouse_*_to_gui functions, as @Pat Ferguson has already pointed out. I've never had the need to touch display_get_mouse_* functions in many years of using GMS.
 

Petrik33

Member
I haven't really toyed around with display_get_mouse_* functions, but reading the manual (here) it seems as though it would return the position of the mouse on the actual screen with whatever the actual screens resolution is. So if your computer's resolution is set to 1920x1080 and your game is 1280x720 (as random examples) the mouse is going to return the wrong coordinates for its position within your game (I assume). Also if your game window is not fullscreened it will return wrong coordinates. Display_get_mouse_* is not really useful outside of specific circumstances, so you should stick to either mouse_* functions or device_mouse_*_to_gui functions, as @Pat Ferguson has already pointed out. I've never had the need to touch display_get_mouse_* functions in many years of using GMS.
Thanks a lot!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
display_mouse_ functions return a position related to the top-left corner of primary display. For multi-display setups with screens to the left of the primary one, these can also be negative.

They are not particularly handy unless you are trying to implement a custom window border (in which case you do want desktop coordinates for dragging/resizing) or do something else that specifically measures in desktop pixels (e.g. I once made an extension to capture arbitrary snips of desktop inside or outside the game window).
 
Top