mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +00:00
input: More text input restructuring.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1077 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
ebe223a689
commit
8d0cb0086a
5 changed files with 130 additions and 30 deletions
|
@ -1222,6 +1222,7 @@ Con_NotifyBox
|
|||
void Con_NotifyBox (const char *text)
|
||||
{
|
||||
double t1, t2;
|
||||
int lastkey, lastchar;
|
||||
|
||||
// during startup for sound / cd warnings
|
||||
Con_Printf ("\n\n%s", Con_Quakebar(40)); //johnfitz
|
||||
|
@ -1229,18 +1230,21 @@ void Con_NotifyBox (const char *text)
|
|||
Con_Printf ("Press a key.\n");
|
||||
Con_Printf ("%s", Con_Quakebar(40)); //johnfitz
|
||||
|
||||
key_count = -2; // wait for a key down and up
|
||||
IN_Deactivate(modestate == MS_WINDOWED);
|
||||
key_dest = key_console;
|
||||
|
||||
Key_BeginInputGrab ();
|
||||
do
|
||||
{
|
||||
t1 = Sys_DoubleTime ();
|
||||
SCR_UpdateScreen ();
|
||||
Sys_SendKeyEvents ();
|
||||
Key_GetGrabbedInput (&lastkey, &lastchar);
|
||||
Sys_Sleep (16);
|
||||
t2 = Sys_DoubleTime ();
|
||||
realtime += t2-t1; // make the cursor blink
|
||||
} while (key_count < 0);
|
||||
} while (lastkey == 0 && lastchar == 0);
|
||||
Key_EndInputGrab ();
|
||||
|
||||
Con_Printf ("\n");
|
||||
IN_Activate();
|
||||
|
|
|
@ -898,6 +898,7 @@ keypress.
|
|||
int SCR_ModalMessage (const char *text, float timeout) //johnfitz -- timeout
|
||||
{
|
||||
double time1, time2; //johnfitz -- timeout
|
||||
int lastkey, lastchar;
|
||||
|
||||
if (cls.state == ca_dedicated)
|
||||
return true;
|
||||
|
@ -914,20 +915,18 @@ int SCR_ModalMessage (const char *text, float timeout) //johnfitz -- timeout
|
|||
time1 = Sys_DoubleTime () + timeout; //johnfitz -- timeout
|
||||
time2 = 0.0f; //johnfitz -- timeout
|
||||
|
||||
Key_BeginInputGrab ();
|
||||
do
|
||||
{
|
||||
key_count = -1; // wait for a key down and up
|
||||
Sys_SendKeyEvents ();
|
||||
Sys_Sleep(16);
|
||||
Key_GetGrabbedInput (&lastkey, &lastchar);
|
||||
Sys_Sleep (16);
|
||||
if (timeout) time2 = Sys_DoubleTime (); //johnfitz -- zero timeout means wait forever.
|
||||
} while (key_lastpress != 'y' &&
|
||||
key_lastpress != 'n' &&
|
||||
key_lastpress != K_ESCAPE &&
|
||||
time2 <= time1);
|
||||
|
||||
// make sure we don't ignore the next keypress
|
||||
if (key_count < 0)
|
||||
key_count = 0;
|
||||
} while (lastchar != 'y' && lastchar != 'Y' &&
|
||||
lastchar != 'n' && lastchar != 'N' &&
|
||||
lastkey != K_ESCAPE &&
|
||||
time2 <= time1);
|
||||
Key_EndInputGrab ();
|
||||
|
||||
// SCR_UpdateScreen (); //johnfitz -- commented out
|
||||
|
||||
|
@ -936,7 +935,7 @@ int SCR_ModalMessage (const char *text, float timeout) //johnfitz -- timeout
|
|||
return false;
|
||||
//johnfitz
|
||||
|
||||
return key_lastpress == 'y';
|
||||
return (lastchar == 'y' || lastchar == 'Y');
|
||||
}
|
||||
|
||||
|
||||
|
|
100
Quake/keys.c
100
Quake/keys.c
|
@ -32,7 +32,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
char key_lines[CMDLINES][MAXCMDLINE];
|
||||
|
||||
int key_linepos;
|
||||
int key_lastpress;
|
||||
int key_insert; //johnfitz -- insert key toggle (for editing)
|
||||
double key_blinktime; //johnfitz -- fudge cursor blinking to make it easier to spot in certain cases
|
||||
|
||||
|
@ -41,8 +40,6 @@ int history_line = 0;
|
|||
|
||||
keydest_t key_dest;
|
||||
|
||||
int key_count; // incremented every key event
|
||||
|
||||
#define MAX_KEYS 256
|
||||
|
||||
char *keybindings[MAX_KEYS];
|
||||
|
@ -853,11 +850,8 @@ void Key_Init (void)
|
|||
ignoretext[K_DOWNARROW] = true;
|
||||
ignoretext[K_LEFTARROW] = true;
|
||||
ignoretext[K_RIGHTARROW] = true;
|
||||
ignoretext[K_ALT] = true;
|
||||
ignoretext[K_CTRL] = true;
|
||||
ignoretext[K_SHIFT] = true;
|
||||
for (i = 0; i < 12; i++)
|
||||
ignoretext[K_F1+i] = true;
|
||||
ignoretext[K_BACKSPACE] = true;
|
||||
ignoretext[K_INS] = true;
|
||||
ignoretext[K_DEL] = true;
|
||||
|
@ -865,7 +859,6 @@ void Key_Init (void)
|
|||
ignoretext[K_PGUP] = true;
|
||||
ignoretext[K_HOME] = true;
|
||||
ignoretext[K_END] = true;
|
||||
ignoretext[K_KP_NUMLOCK] = true;
|
||||
ignoretext[K_KP_HOME] = true;
|
||||
ignoretext[K_KP_UPARROW] = true;
|
||||
ignoretext[K_KP_PGUP] = true;
|
||||
|
@ -878,7 +871,6 @@ void Key_Init (void)
|
|||
ignoretext[K_KP_INS] = true;
|
||||
ignoretext[K_KP_DEL] = true;
|
||||
ignoretext[K_COMMAND] = true;
|
||||
ignoretext[K_PAUSE] = true;
|
||||
ignoretext[K_MWHEELUP] = true;
|
||||
ignoretext[K_MWHEELDOWN] = true;
|
||||
|
||||
|
@ -891,6 +883,51 @@ void Key_Init (void)
|
|||
Cmd_AddCommand ("unbindall",Key_Unbindall_f);
|
||||
}
|
||||
|
||||
static struct {
|
||||
qboolean active;
|
||||
int lastkey;
|
||||
int lastchar;
|
||||
} key_inputgrab;
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_BeginInputGrab
|
||||
===================
|
||||
*/
|
||||
void Key_BeginInputGrab (void)
|
||||
{
|
||||
key_inputgrab.active = true;
|
||||
key_inputgrab.lastkey = 0;
|
||||
key_inputgrab.lastchar = 0;
|
||||
|
||||
IN_UpdateInputMode ();
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_EndInputGrab
|
||||
===================
|
||||
*/
|
||||
void Key_EndInputGrab (void)
|
||||
{
|
||||
key_inputgrab.active = false;
|
||||
|
||||
IN_UpdateInputMode ();
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_GetGrabbedInput
|
||||
===================
|
||||
*/
|
||||
void Key_GetGrabbedInput (int *lastkey, int *lastchar)
|
||||
{
|
||||
if (lastkey)
|
||||
*lastkey = key_inputgrab.lastkey;
|
||||
if (lastchar)
|
||||
*lastchar = key_inputgrab.lastchar;
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_Event
|
||||
|
@ -910,12 +947,18 @@ void Key_Event (int key, qboolean down)
|
|||
keydown[key] = down;
|
||||
|
||||
if (!down)
|
||||
key_repeats[key] = 0;
|
||||
{
|
||||
if (key_repeats[key] == 0)
|
||||
return;
|
||||
else
|
||||
key_repeats[key] = 0;
|
||||
}
|
||||
|
||||
key_lastpress = key;
|
||||
key_count++;
|
||||
if (key_count <= 0)
|
||||
return; // just catching keys for Con_NotifyBox
|
||||
if (key_inputgrab.active)
|
||||
{
|
||||
key_inputgrab.lastkey = key;
|
||||
return;
|
||||
}
|
||||
|
||||
// update auto-repeat status
|
||||
if (down)
|
||||
|
@ -1031,6 +1074,12 @@ void Char_Event (int key)
|
|||
if (key < 32 || key > 126)
|
||||
return;
|
||||
|
||||
if (key_inputgrab.active)
|
||||
{
|
||||
key_inputgrab.lastchar = key;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (key_dest)
|
||||
{
|
||||
case key_message:
|
||||
|
@ -1054,8 +1103,24 @@ Key_InputtingText
|
|||
*/
|
||||
qboolean Key_InputtingText (void)
|
||||
{
|
||||
return (key_dest == key_console || (key_dest == key_game && con_forcedup) ||
|
||||
key_dest == key_message || (key_dest == key_menu && M_InputtingText()));
|
||||
if (key_inputgrab.active)
|
||||
return true;
|
||||
|
||||
switch (key_dest)
|
||||
{
|
||||
case key_message:
|
||||
return true;
|
||||
case key_menu:
|
||||
return M_InputtingText();
|
||||
case key_game:
|
||||
if (!con_forcedup)
|
||||
return false;
|
||||
/* fallthrough */
|
||||
case key_console:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1065,6 +1130,11 @@ Key_IgnoreTextInput
|
|||
*/
|
||||
qboolean Key_IgnoreTextInput (int key)
|
||||
{
|
||||
#if defined(PLATFORM_OSX) || defined(PLATFORM_MAC)
|
||||
if (keydown[K_COMMAND])
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if (keydown[K_CTRL])
|
||||
return true;
|
||||
|
||||
|
|
|
@ -165,6 +165,10 @@ void Key_Init (void);
|
|||
void Key_ClearStates (void);
|
||||
void Key_UpdateForDest (void);
|
||||
|
||||
void Key_BeginInputGrab (void);
|
||||
void Key_EndInputGrab (void);
|
||||
void Key_GetGrabbedInput (int *lastkey, int *lastchar);
|
||||
|
||||
void Key_Event (int key, qboolean down);
|
||||
void Char_Event (int key);
|
||||
qboolean Key_InputtingText (void);
|
||||
|
|
27
Quake/menu.c
27
Quake/menu.c
|
@ -1557,10 +1557,28 @@ void M_Menu_Quit_f (void)
|
|||
|
||||
|
||||
void M_Quit_Key (int key)
|
||||
{
|
||||
if (key == K_ESCAPE)
|
||||
{
|
||||
if (wasInMenus)
|
||||
{
|
||||
m_state = m_quit_prevstate;
|
||||
m_entersound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void M_Quit_Char (int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case K_ESCAPE:
|
||||
case 'n':
|
||||
case 'N':
|
||||
if (wasInMenus)
|
||||
|
@ -1576,8 +1594,8 @@ void M_Quit_Key (int key)
|
|||
}
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
case 'y':
|
||||
case 'Y':
|
||||
IN_Deactivate(modestate == MS_WINDOWED);
|
||||
key_dest = key_console;
|
||||
Host_Quit_f ();
|
||||
|
@ -2645,6 +2663,9 @@ void M_Charinput (int key)
|
|||
case m_setup:
|
||||
M_Setup_Char (key);
|
||||
return;
|
||||
case m_quit:
|
||||
M_Quit_Char (key);
|
||||
return;
|
||||
case m_lanconfig:
|
||||
M_LanConfig_Char (key);
|
||||
return;
|
||||
|
@ -2660,6 +2681,8 @@ qboolean M_InputtingText (void)
|
|||
{
|
||||
case m_setup:
|
||||
return M_Setup_InputtingText();
|
||||
case m_quit:
|
||||
return true;
|
||||
case m_lanconfig:
|
||||
return M_LanConfig_InputtingText();
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue