[console] Provide control of cursor visibility

It's usually desirable to hide the cursor when playing quake, but when
using the console, or in various other states, being able to see the
cursor can be quite important.
This commit is contained in:
Bill Currie 2023-06-30 14:57:04 +09:00
parent 759e67bb7c
commit 0b0271ee76
9 changed files with 26 additions and 20 deletions

View file

@ -69,7 +69,7 @@ void Con_DrawConsole (void);
void Con_Printf (const char *fmt, ...) __attribute__((format(PRINTF, 1, 2)));
void Con_Print (const char *fmt, va_list args) __attribute__((format(PRINTF, 1, 0)));
void Con_SetState (con_state_t state);
void Con_SetState (con_state_t state, bool hide_mouse);
struct inputline_s;
// wrapper function to attempt to either complete the command line

View file

@ -39,7 +39,7 @@ typedef struct console_funcs_s {
void (*process_input) (void);
void (*draw_console) (void);
void (*new_map) (void);
void (*set_state) (con_state_t state);
void (*set_state) (con_state_t state, bool hide_mouse);
} console_funcs_t;
typedef struct console_data_s {

View file

@ -581,7 +581,7 @@ static int
cl_key_event (const IE_event_t *ie_event)
{
if (ie_event->key.code == QFK_ESCAPE) {
Con_SetState (con_menu);
Con_SetState (con_menu, true);
return 1;
}
return 0;

View file

@ -155,6 +155,7 @@ static uint32_t canvas_base;
static uint32_t view_base;
static con_state_t con_state;
static bool con_hide_mouse;
static int con_event_id;
static int con_saved_focos;
@ -332,15 +333,18 @@ ClearNotify (void)
}
static void
C_SetState (con_state_t state)
C_SetState (con_state_t state, bool hide_mouse)
{
con_state_t old_state = con_state;
con_state = state;
con_hide_mouse = hide_mouse;
if (con_state == con_inactive) {
IE_Set_Focus (con_saved_focos);
VID_SetCursor (!con_hide_mouse);
} else if (old_state == con_inactive) {
con_saved_focos = IE_Get_Focus ();
IE_Set_Focus (con_event_id);
VID_SetCursor (true);
}
if (state == con_message) {
@ -369,10 +373,10 @@ ToggleConsole_f (void)
case con_message:
return;
case con_inactive:
C_SetState (con_active);
C_SetState (con_active, con_hide_mouse);
break;
case con_active:
C_SetState (con_inactive);
C_SetState (con_inactive, con_hide_mouse);
break;
case con_fullscreen:
break;
@ -413,7 +417,7 @@ static void
con_end_message (inputline_t *line)
{
Con_ClearTyping (line, 1);
C_SetState (con_inactive);
C_SetState (con_inactive, con_hide_mouse);
}
static void
@ -979,7 +983,7 @@ MessageMode_f (void)
if (con_state != con_inactive)
return;
chat_team = false;
C_SetState (con_message);
C_SetState (con_message, con_hide_mouse);
}
static void
@ -988,7 +992,7 @@ MessageMode2_f (void)
if (con_state != con_inactive)
return;
chat_team = true;
C_SetState (con_message);
C_SetState (con_message, con_hide_mouse);
}
static void

View file

@ -175,10 +175,10 @@ Con_Print (const char *fmt, va_list args)
}
VISIBLE void
Con_SetState (con_state_t state)
Con_SetState (con_state_t state, bool hide_mouse)
{
if (con_module) {
con_module->functions->console->set_state (state);
con_module->functions->console->set_state (state, hide_mouse);
}
}

View file

@ -378,7 +378,7 @@ bi_Menu_SelectMenu (progs_t *pr, void *data)
if (name && *name)
menu = Hash_Find (menu_hash, name);
if (menu) {
Con_SetState (con_menu);
Con_SetState (con_menu, true);
if (menu->enter_hook) {
run_menu_pre ();
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
@ -387,7 +387,7 @@ bi_Menu_SelectMenu (progs_t *pr, void *data)
} else {
if (name && *name)
Sys_Printf ("no menu \"%s\"\n", name);
Con_SetState (con_inactive);
Con_SetState (con_inactive, true);
}
}
@ -472,7 +472,7 @@ bi_Menu_Leave (progs_t *pr, void *data)
}
menu = menu->parent;
if (!menu) {
Con_SetState (con_inactive);
Con_SetState (con_inactive, true);
}
}
}
@ -851,14 +851,14 @@ void
Menu_Enter ()
{
if (!top_menu) {
Con_SetState (con_active);
Con_SetState (con_active, true);
return;
}
if (!menu) {
menu = Hash_Find (menu_hash, top_menu);
}
if (menu) {
Con_SetState (con_menu);
Con_SetState (con_menu, true);
if (menu->enter_hook) {
run_menu_pre ();
PR_ExecuteProgram (&menu_pr_state, menu->enter_hook);
@ -878,7 +878,7 @@ Menu_Leave ()
}
menu = menu->parent;
if (!menu) {
Con_SetState (con_inactive);
Con_SetState (con_inactive, true);
}
}
}

View file

@ -591,7 +591,8 @@ CL_SetState (cactive_t state)
CL_UpdateScreen (&cl.viewstate);
}
host_in_game = 0;
Con_SetState (state == ca_active ? con_inactive : con_fullscreen);
Con_SetState (state == ca_active ? con_inactive : con_fullscreen,
state == ca_active && !cls.demoplayback);
if (state != old_state && state == ca_active) {
CL_Input_Activate (host_in_game = !cls.demoplayback);
}

View file

@ -1406,7 +1406,8 @@ CL_SetState (cactive_t state)
}
Sbar_SetActive (state == ca_active);
}
Con_SetState (state == ca_active ? con_inactive : con_fullscreen);
Con_SetState (state == ca_active ? con_inactive : con_fullscreen,
state == ca_active && !cls.demoplayback);
if (state != old_state && state == ca_active) {
CL_Input_Activate (!cls.demoplayback);
}

View file

@ -161,7 +161,7 @@ event_handler (const IE_event_t *ie_event, void *_pr)
{
// FIXME rethink event handling for qwaq
if (ie_event->type == ie_key && ie_event->key.code == QFK_ESCAPE) {
Con_SetState (con_active);
Con_SetState (con_active, false);
return 1;
}
return IN_Binding_HandleEvent (ie_event);