add mouse cursor locking
This commit is contained in:
parent
9911229282
commit
73cc16f1d4
@ -4,6 +4,28 @@
|
||||
|
||||
#load "sokol.jai";
|
||||
|
||||
#scope_file
|
||||
shouldLockMouseCursor : bool = false;
|
||||
#scope_export;
|
||||
|
||||
set_should_lock_cursor :: (shouldLock: bool) {
|
||||
shouldLockMouseCursor = shouldLock;
|
||||
}
|
||||
|
||||
is_cursor_locked :: () -> bool {
|
||||
return shouldLockMouseCursor;
|
||||
}
|
||||
|
||||
unlock_cursor :: () {
|
||||
plat_set_cursor_lock(false);
|
||||
}
|
||||
|
||||
// We use this so menu and editor is unlocked and game is locked if the game sets the should lock.
|
||||
lock_cursor_if_should :: () {
|
||||
if shouldLockMouseCursor then plat_set_cursor_lock(true);
|
||||
}
|
||||
|
||||
|
||||
Event_Type :: enum u32 { // If we set this to u8, our packing will stop matching C's.
|
||||
UNINITIALIZED :: 0;
|
||||
KEYBOARD :: 1;
|
||||
|
||||
@ -7,6 +7,10 @@ input_mouse_y : float;
|
||||
set_custom_cursor_handling :: (is_custom: bool) {
|
||||
}
|
||||
|
||||
plat_set_cursor_lock :: (locked: bool) {
|
||||
sapp_lock_mouse(locked);
|
||||
}
|
||||
|
||||
get_key_code :: (key: sapp_keycode) -> Key_Code {
|
||||
using Key_Code;
|
||||
// non-ascii ordered as in ./module.jai/Key_Code
|
||||
|
||||
@ -109,6 +109,11 @@ tick_editor_ui :: () {
|
||||
in_editor_view = !in_editor_view;
|
||||
g_mixer.paused = in_editor_view;
|
||||
clear_particles();
|
||||
if in_editor_view {
|
||||
unlock_cursor();
|
||||
} else {
|
||||
lock_cursor_if_should();
|
||||
}
|
||||
}
|
||||
|
||||
#if !FLAG_RELEASE_BUILD && OS != .WASM {
|
||||
|
||||
@ -167,7 +167,7 @@ init_after_core :: () {
|
||||
// We want to do this last.
|
||||
game_init();
|
||||
|
||||
// #if UNCAPPED_FRAMES then sapp_glx_swapinterval(0);
|
||||
lock_cursor_if_should();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -220,10 +220,15 @@ navigate_to :: (page: Settings_Page) {
|
||||
g_settings.cursor = 0;
|
||||
}
|
||||
|
||||
close_settings_menu :: () {
|
||||
save_settings();
|
||||
lock_cursor_if_should();
|
||||
g_settings.open = false;
|
||||
}
|
||||
|
||||
go_back :: () {
|
||||
if g_settings.page == .MAIN {
|
||||
save_settings();
|
||||
g_settings.open = false;
|
||||
close_settings_menu();
|
||||
} else {
|
||||
navigate_to(page_parent());
|
||||
}
|
||||
@ -234,10 +239,9 @@ handle_enter :: (index: s32 = -1) {
|
||||
if g_settings.page == {
|
||||
case .MAIN;
|
||||
game_items := cast(s32) g_settings_config.main_items.count;
|
||||
if i == 0 { save_settings(); g_settings.open = false; }
|
||||
if i == 0 then close_settings_menu();
|
||||
else if i <= game_items {
|
||||
save_settings();
|
||||
g_settings.open = false;
|
||||
close_settings_menu();
|
||||
g_settings_config.main_items[i - 1].on_select();
|
||||
} else {
|
||||
i -= game_items;
|
||||
@ -306,6 +310,7 @@ tick_settings_menu :: () {
|
||||
if is_action_start(Editor_Action.TOGGLE_SETTINGS) {
|
||||
if !g_settings.open {
|
||||
g_settings.open = true;
|
||||
unlock_cursor();
|
||||
navigate_to(.MAIN);
|
||||
generate_blobs();
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user