git-svn-id: https://svn.eduke32.com/eduke32@838 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-07-04 02:13:48 +00:00
parent 275fdc8552
commit 9a29dae7b3
4 changed files with 188 additions and 193 deletions

View file

@ -67,7 +67,7 @@ void OSD_CaptureKey(int sc);
// handles keyboard input when capturing input. returns 0 if key was handled // handles keyboard input when capturing input. returns 0 if key was handled
// or the scancode if it should be handled by the game. // or the scancode if it should be handled by the game.
int OSD_HandleScanCode(int sc, int press); int OSD_HandleScanCode(int sc, int press);
int OSD_HandleChars(void); int OSD_HandleChars(char ch);
// handles the readjustment when screen resolution changes // handles the readjustment when screen resolution changes
void OSD_ResizeDisplay(int w,int h); void OSD_ResizeDisplay(int w,int h);

View file

@ -641,227 +641,220 @@ static int OSD_FindDiffPoint(const char *str1, const char *str2)
// be passed on to the game. // be passed on to the game.
// //
int OSD_HandleChars(void) int OSD_HandleChar(char ch)
{ {
int i,j; int i,j;
symbol_t *tabc = NULL; symbol_t *tabc = NULL;
static symbol_t *lastmatch = NULL; static symbol_t *lastmatch = NULL;
char ch;
if (!osdinited) return 1; if (!osdinited || !osdinput) return ch;
if (!osdinput) if (ch != 9) lastmatch = NULL; // tab
return 1; if (ch == 1) // control a. jump to beginning of line
while ((ch = bgetchar()))
{ {
if (ch != 9) lastmatch = NULL; // tab }
if (ch == 1) // control a. jump to beginning of line else if (ch == 2) // control b, move one character left
{
}
else if (ch == 5) // control e, jump to end of line
{
}
else if (ch == 6) // control f, move one character right
{
}
else if (ch == 8 || ch == 127) // control h, backspace
{
if (!osdeditcursor || !osdeditlen) return 0;
if (!osdovertype)
{ {
if (osdeditcursor < osdeditlen)
Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen--;
} }
else if (ch == 2) // control b, move one character left osdeditcursor--;
{ if (osdeditcursor<osdeditwinstart) osdeditwinstart--,osdeditwinend--;
} }
else if (ch == 5) // control e, jump to end of line else if (ch == 9) // tab
{ {
} int commonsize = 512;
else if (ch == 6) // control f, move one character right
{
}
else if (ch == 8 || ch == 127) // control h, backspace
{
if (!osdeditcursor || !osdeditlen) continue;
if (!osdovertype)
{
if (osdeditcursor < osdeditlen)
Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen--;
}
osdeditcursor--;
if (osdeditcursor<osdeditwinstart) osdeditwinstart--,osdeditwinend--;
}
else if (ch == 9) // tab
{
int commonsize = 512;
if (!lastmatch) if (!lastmatch)
{ {
for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break; for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break;
for (j=0;osdeditbuf[i] != ' ' && i < osdeditlen;j++,i++) for (j=0;osdeditbuf[i] != ' ' && i < osdeditlen;j++,i++)
osdedittmp[j] = osdeditbuf[i]; osdedittmp[j] = osdeditbuf[i];
osdedittmp[j] = 0; osdedittmp[j] = 0;
if (j > 0) if (j > 0)
{
tabc = findsymbol(osdedittmp, NULL);
if (tabc)
{ {
tabc = findsymbol(osdedittmp, NULL); if (tabc->next)
if (tabc)
{ {
if (tabc->next) if (findsymbol(osdedittmp, tabc->next))
{ {
if (findsymbol(osdedittmp, tabc->next)) symbol_t *symb=tabc;
int maxwidth = 0, x = 0, num = 0;
while (symb && symb != lastmatch)
{ {
symbol_t *symb=tabc; int diffpt;
int maxwidth = 0, x = 0, num = 0;
while (symb && symb != lastmatch) num++;
if (lastmatch)
{ {
int diffpt; diffpt = OSD_FindDiffPoint(symb->name,lastmatch->name);
if (diffpt < commonsize)
num++;
if (lastmatch)
{ {
diffpt = OSD_FindDiffPoint(symb->name,lastmatch->name); commonsize = diffpt;
if (diffpt < commonsize)
{
commonsize = diffpt;
// OSD_Printf("commonsize %d\n",commonsize); // OSD_Printf("commonsize %d\n",commonsize);
}
} }
}
maxwidth = max((unsigned)maxwidth,Bstrlen(symb->name)); maxwidth = max((unsigned)maxwidth,Bstrlen(symb->name));
lastmatch = symb; lastmatch = symb;
symb=findsymbol(osdedittmp, lastmatch->next); symb=findsymbol(osdedittmp, lastmatch->next);
}
OSD_Printf("Found %d completions for '%s':\n",num,osdedittmp);
maxwidth += 3;
symb = tabc;
OSD_Printf(" ");
while (symb && symb != lastmatch)
{
tabc = symb;
OSD_Printf("%-*s",maxwidth,symb->name);
x += maxwidth;
lastmatch = symb;
symb=findsymbol(osdedittmp, lastmatch->next);
if (x > osdcols - maxwidth)
{
x = 0;
OSD_Printf("\n");
if (symb && symb != lastmatch)
OSD_Printf(" ");
}
}
if (x)
OSD_Printf("\n");
} }
OSD_Printf("Found %d completions for '%s':\n",num,osdedittmp);
maxwidth += 3;
symb = tabc;
OSD_Printf(" ");
while (symb && symb != lastmatch)
{
tabc = symb;
OSD_Printf("%-*s",maxwidth,symb->name);
x += maxwidth;
lastmatch = symb;
symb=findsymbol(osdedittmp, lastmatch->next);
if (x > osdcols - maxwidth)
{
x = 0;
OSD_Printf("\n");
if (symb && symb != lastmatch)
OSD_Printf(" ");
}
}
if (x)
OSD_Printf("\n");
} }
} }
} }
} }
else }
{ else
tabc = findsymbol(osdedittmp, lastmatch->next); {
if (!tabc && lastmatch) tabc = findsymbol(osdedittmp, lastmatch->next);
tabc = findsymbol(osdedittmp, NULL); // wrap */ if (!tabc && lastmatch)
} tabc = findsymbol(osdedittmp, NULL); // wrap */
}
if (tabc) if (tabc)
{
for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break;
osdeditlen = i;
for (j=0;tabc->name[j] && osdeditlen <= EDITLENGTH
&& (osdeditlen < commonsize);i++,j++,osdeditlen++)
osdeditbuf[i] = tabc->name[j];
osdeditcursor = osdeditlen;
osdeditwinend = osdeditcursor;
osdeditwinstart = osdeditwinend-editlinewidth;
if (osdeditwinstart<0)
{ {
for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break; osdeditwinstart=0;
osdeditlen = i;
for (j=0;tabc->name[j] && osdeditlen <= EDITLENGTH
&& (osdeditlen < commonsize);i++,j++,osdeditlen++)
osdeditbuf[i] = tabc->name[j];
osdeditcursor = osdeditlen;
osdeditwinend = osdeditcursor;
osdeditwinstart = osdeditwinend-editlinewidth;
if (osdeditwinstart<0)
{
osdeditwinstart=0;
osdeditwinend = editlinewidth;
}
lastmatch = tabc;
}
}
else if (ch == 11) // control k, delete all to end of line
{
}
else if (ch == 12) // control l, clear screen
{
Bmemset(osdtext,0,sizeof(osdtext));
osdlines = 1;
}
else if (ch == 13) // control m, enter
{
if (osdeditlen>0)
{
osdeditbuf[osdeditlen] = 0;
Bmemmove(osdhistorybuf[1], osdhistorybuf[0], HISTORYDEPTH*(EDITLENGTH+1));
Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1);
if (osdhistorysize < HISTORYDEPTH) osdhistorysize++;
if (osdexeccount == HISTORYDEPTH)
OSD_Printf("Command Buffer Warning: Failed queueing command "
"for execution. Buffer full.\n");
else
osdexeccount++;
osdhistorypos=-1;
}
osdeditlen=0;
osdeditcursor=0;
osdeditwinstart=0;
osdeditwinend=editlinewidth;
}
else if (ch == 16) // control p, previous (ie. up arrow)
{
}
else if (ch == 20) // control t, swap previous two chars
{
}
else if (ch == 21) // control u, delete all to beginning
{
if (osdeditcursor>0 && osdeditlen)
{
if (osdeditcursor<osdeditlen)
Bmemmove(osdeditbuf, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen-=osdeditcursor;
osdeditcursor = 0;
osdeditwinstart = 0;
osdeditwinend = editlinewidth; osdeditwinend = editlinewidth;
} }
}
else if (ch == 23) // control w, delete one word back
{
if (osdeditcursor>0 && osdeditlen>0)
{
i=osdeditcursor;
while (i>0 && osdeditbuf[i-1]==32) i--;
while (i>0 && osdeditbuf[i-1]!=32) i--;
if (osdeditcursor<osdeditlen)
Bmemmove(osdeditbuf+i, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen -= (osdeditcursor-i);
osdeditcursor = i;
if (osdeditcursor < osdeditwinstart)
{
osdeditwinstart=osdeditcursor;
osdeditwinend=osdeditwinstart+editlinewidth;
}
}
}
else if (ch >= 32) // text char
{
if (!osdovertype && osdeditlen == EDITLENGTH) // buffer full, can't insert another char
continue;
if (!osdovertype) lastmatch = tabc;
{
if (osdeditcursor < osdeditlen)
Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen++;
}
else
{
if (osdeditcursor == osdeditlen)
osdeditlen++;
}
osdeditbuf[osdeditcursor] = ch;
osdeditcursor++;
if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++;
} }
} }
else if (ch == 11) // control k, delete all to end of line
{
}
else if (ch == 12) // control l, clear screen
{
Bmemset(osdtext,0,sizeof(osdtext));
osdlines = 1;
}
else if (ch == 13) // control m, enter
{
if (osdeditlen>0)
{
osdeditbuf[osdeditlen] = 0;
Bmemmove(osdhistorybuf[1], osdhistorybuf[0], HISTORYDEPTH*(EDITLENGTH+1));
Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1);
if (osdhistorysize < HISTORYDEPTH) osdhistorysize++;
if (osdexeccount == HISTORYDEPTH)
OSD_Printf("Command Buffer Warning: Failed queueing command "
"for execution. Buffer full.\n");
else
osdexeccount++;
osdhistorypos=-1;
}
osdeditlen=0;
osdeditcursor=0;
osdeditwinstart=0;
osdeditwinend=editlinewidth;
}
else if (ch == 16) // control p, previous (ie. up arrow)
{
}
else if (ch == 20) // control t, swap previous two chars
{
}
else if (ch == 21) // control u, delete all to beginning
{
if (osdeditcursor>0 && osdeditlen)
{
if (osdeditcursor<osdeditlen)
Bmemmove(osdeditbuf, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen-=osdeditcursor;
osdeditcursor = 0;
osdeditwinstart = 0;
osdeditwinend = editlinewidth;
}
}
else if (ch == 23) // control w, delete one word back
{
if (osdeditcursor>0 && osdeditlen>0)
{
i=osdeditcursor;
while (i>0 && osdeditbuf[i-1]==32) i--;
while (i>0 && osdeditbuf[i-1]!=32) i--;
if (osdeditcursor<osdeditlen)
Bmemmove(osdeditbuf+i, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen -= (osdeditcursor-i);
osdeditcursor = i;
if (osdeditcursor < osdeditwinstart)
{
osdeditwinstart=osdeditcursor;
osdeditwinend=osdeditwinstart+editlinewidth;
}
}
}
else if (ch >= 32) // text char
{
if (!osdovertype && osdeditlen == EDITLENGTH) // buffer full, can't insert another char
return 0;
if (!osdovertype)
{
if (osdeditcursor < osdeditlen)
Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
osdeditlen++;
}
else
{
if (osdeditcursor == osdeditlen)
osdeditlen++;
}
osdeditbuf[osdeditcursor] = ch;
osdeditcursor++;
if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++;
}
return 0; return 0;
} }

View file

@ -1420,9 +1420,11 @@ int handleevents(void)
(ev.key.keysym.unicode & 0xff80) == 0 && (ev.key.keysym.unicode & 0xff80) == 0 &&
((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc)
{ {
keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; if (OSD_HandleChars(ev.key.keysym.unicode & 0x7f))
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); {
OSD_HandleChars(); keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
}
} }
// hook in the osd // hook in the osd

View file

@ -4125,9 +4125,9 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
if (((keyasciififoend+1)&(KEYFIFOSIZ-1)) == keyasciififoplc) return 0; if (((keyasciififoend+1)&(KEYFIFOSIZ-1)) == keyasciififoplc) return 0;
if ((keyasciififoend - keyasciififoplc) > 0) return 0; if ((keyasciififoend - keyasciififoplc) > 0) return 0;
if (Btolower(scantoasc[osdkey]) == Btolower((unsigned char)wParam)) return 0; if (Btolower(scantoasc[osdkey]) == Btolower((unsigned char)wParam)) return 0;
if (!OSD_HandleChar((unsigned char)wParam)) return 0;
keyasciififo[keyasciififoend] = (unsigned char)wParam; keyasciififo[keyasciififoend] = (unsigned char)wParam;
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
OSD_HandleChars();
//OSD_Printf("WM_CHAR %d, %d-%d\n",wParam,keyasciififoplc,keyasciififoend); //OSD_Printf("WM_CHAR %d, %d-%d\n",wParam,keyasciififoplc,keyasciififoend);
return 0; return 0;