Pixel-Composer/scripts/mouse_input/mouse_input.gml

160 lines
5.4 KiB
Plaintext
Raw Normal View History

2022-12-23 04:45:52 +01:00
#region mouse global
2024-03-26 04:03:45 +01:00
globalvar CURSOR, CURSOR_LOCK, CURSOR_IS_LOCK, CURSOR_LOCK_X, CURSOR_LOCK_Y;
2024-01-16 11:00:39 +01:00
globalvar MOUSE_WRAP, MOUSE_WRAPPING, MOUSE_BLOCK, _MOUSE_BLOCK;
2024-09-12 05:08:48 +02:00
globalvar MOUSE_POOL;
2023-04-07 21:25:27 +02:00
2023-12-05 09:51:24 +01:00
MOUSE_WRAP = false;
2022-12-23 04:45:52 +01:00
MOUSE_WRAPPING = false;
2024-01-16 11:00:39 +01:00
MOUSE_BLOCK = false;
_MOUSE_BLOCK = false;
PEN_RELEASED = false;
2024-09-12 05:08:48 +02:00
MOUSE_POOL = {
lclick: false, lpress: false, lrelease: false,
rclick: false, rpress: false, rrelease: false,
mclick: false, mpress: false, mrelease: false,
}
2022-12-23 04:45:52 +01:00
2023-10-31 05:30:42 +01:00
#macro SCROLL_SPEED PREFERENCES.mouse_wheel_speed
#macro MOUSE_MOVED (window_mouse_get_delta_x() || window_mouse_get_delta_y())
2023-04-07 21:25:27 +02:00
#macro mouse_wheel_up mouse_wheel_up_override
#macro __mouse_wheel_up mouse_wheel_up
#macro mouse_wheel_down mouse_wheel_down_override
#macro __mouse_wheel_down mouse_wheel_down
2022-12-23 04:45:52 +01:00
function setMouseWrap() {
2023-12-05 09:51:24 +01:00
INLINE
2022-12-23 04:45:52 +01:00
MOUSE_WRAP = true;
}
2024-01-16 11:00:39 +01:00
#endregion
2024-09-12 05:08:48 +02:00
function global_mouse_pool_init() {
MOUSE_POOL.lclick = mouse_check_button(mb_left);
MOUSE_POOL.rclick = mouse_check_button(mb_right);
MOUSE_POOL.mclick = mouse_check_button(mb_middle);
MOUSE_POOL.lpress = mouse_check_button_pressed(mb_left);
MOUSE_POOL.rpress = mouse_check_button_pressed(mb_right);
MOUSE_POOL.mpress = mouse_check_button_pressed(mb_middle);
MOUSE_POOL.lrelease = mouse_check_button_released(mb_left);
MOUSE_POOL.rrelease = mouse_check_button_released(mb_right);
MOUSE_POOL.mrelease = mouse_check_button_released(mb_middle);
for( var i = 0, n = array_length(global.winwin_all); i < n; i++ ) {
var ww = global.winwin_all[i];
if(!__ww_valid) continue;
MOUSE_POOL.lclick |= winwin_mouse_check_button(ww, mb_left);
MOUSE_POOL.rclick |= winwin_mouse_check_button(ww, mb_right);
MOUSE_POOL.mclick |= winwin_mouse_check_button(ww, mb_middle);
MOUSE_POOL.lpress |= winwin_mouse_check_button_pressed(ww, mb_left);
MOUSE_POOL.rpress |= winwin_mouse_check_button_pressed(ww, mb_right);
MOUSE_POOL.mpress |= winwin_mouse_check_button_pressed(ww, mb_middle);
MOUSE_POOL.lrelease |= winwin_mouse_check_button_released(ww, mb_left);
MOUSE_POOL.rrelease |= winwin_mouse_check_button_released(ww, mb_right);
MOUSE_POOL.mrelease |= winwin_mouse_check_button_released(ww, mb_middle);
}
}
function mouse_click(mouse, focus = true) {
2024-01-16 11:00:39 +01:00
INLINE
2024-03-02 10:08:44 +01:00
if(MOUSE_BLOCK) return false;
if(!focus) return false;
if(PEN_RIGHT_CLICK) return mouse == mb_right;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button(mouse) : winwin_mouse_check_button_safe(WINDOW_ACTIVE, mouse);
}
2024-03-02 10:08:44 +01:00
2024-09-13 08:25:00 +02:00
function mouse_press(mouse, focus = true, pass = false) {
2024-03-02 10:08:44 +01:00
INLINE
2024-09-13 08:25:00 +02:00
if(!pass && MOUSE_BLOCK) return false;
if(!focus) return false;
2024-03-02 10:08:44 +01:00
2024-09-13 08:25:00 +02:00
if(PEN_RIGHT_PRESS) return mouse == mb_right;
2024-09-16 09:29:37 +02:00
if(mouse == mb_any) return winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mb_left) ||
winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mb_right) ||
winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mb_middle);
2024-09-13 08:25:00 +02:00
return winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mouse);
}
2024-03-02 10:08:44 +01:00
function mouse_release(mouse, focus = true) {
2024-03-02 10:08:44 +01:00
INLINE
if(!focus) return false;
if(PEN_RIGHT_RELEASE) return mouse == mb_right;
2024-09-11 11:56:41 +02:00
var rl = WINDOW_ACTIVE == noone? mouse_check_button_released(mouse) : winwin_mouse_check_button_released_safe(WINDOW_ACTIVE, mouse);
return rl || ((mouse == mb_left || mouse == mb_any) && PEN_RELEASED);
}
2024-03-02 10:08:44 +01:00
function mouse_lclick(focus = true) {
2024-03-02 10:08:44 +01:00
INLINE
if(MOUSE_BLOCK) return false;
if(!focus) return false;
if(PEN_RIGHT_CLICK || PEN_RIGHT_RELEASE) return false;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button(mb_left) : winwin_mouse_check_button_safe(WINDOW_ACTIVE, mb_left);
}
2024-03-02 10:08:44 +01:00
function mouse_lpress(focus = true) {
2024-03-02 10:08:44 +01:00
INLINE
if(MOUSE_BLOCK) return false;
if(!focus) return false;
if(PEN_RIGHT_PRESS) return false;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button_pressed(mb_left) : winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mb_left);
}
2024-03-02 10:08:44 +01:00
function mouse_lrelease(focus = true) {
2024-03-02 10:08:44 +01:00
INLINE
if(!focus) return false;
if(PEN_RIGHT_RELEASE) return false;
if(PEN_RELEASED) return true;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button_released(mb_left) : winwin_mouse_check_button_released_safe(WINDOW_ACTIVE, mb_left);
}
2024-03-02 10:08:44 +01:00
function mouse_rclick(focus = true) {
2024-03-02 10:08:44 +01:00
INLINE
if(MOUSE_BLOCK) return false;
if(!focus) return false;
if(PEN_RIGHT_CLICK) return true;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button(mb_right) : winwin_mouse_check_button_safe(WINDOW_ACTIVE, mb_right);
}
2024-01-16 11:00:39 +01:00
function mouse_rpress(focus = true) {
2024-01-16 11:00:39 +01:00
INLINE
2024-03-02 10:08:44 +01:00
if(MOUSE_BLOCK) return false;
if(!focus) return false;
if(PEN_RIGHT_PRESS) return true;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button_pressed(mb_right) : winwin_mouse_check_button_pressed_safe(WINDOW_ACTIVE, mb_right);
}
2024-01-16 11:00:39 +01:00
function mouse_rrelease(focus = true) {
2024-01-16 11:00:39 +01:00
INLINE
2024-03-02 10:08:44 +01:00
if(!focus) return false;
if(PEN_RIGHT_RELEASE) return true;
2024-09-11 11:56:41 +02:00
return WINDOW_ACTIVE == noone? mouse_check_button_released(mb_right) : winwin_mouse_check_button_released_safe(WINDOW_ACTIVE, mb_right);
}
2024-03-26 04:03:45 +01:00
function mouse_lock(mx = CURSOR_LOCK_X, my = CURSOR_LOCK_Y) {
2024-03-26 04:03:45 +01:00
INLINE
CURSOR_LOCK = true;
CURSOR_LOCK_X = mx;
CURSOR_LOCK_Y = my;
window_mouse_set(CURSOR_LOCK_X, CURSOR_LOCK_Y);
}
2024-09-11 11:56:41 +02:00
function mouse_wheel_up_override() { return (WINDOW_ACTIVE != noone && winwin_exists(WINDOW_ACTIVE))? winwin_mouse_wheel_up(WINDOW_ACTIVE) : __mouse_wheel_up(); }
function mouse_wheel_down_override() { return (WINDOW_ACTIVE != noone && winwin_exists(WINDOW_ACTIVE))? winwin_mouse_wheel_down(WINDOW_ACTIVE) : __mouse_wheel_down(); }