Ported AC to SDL2

This commit is contained in:
Jani-Markus Maunus
2018-02-10 11:28:48 +01:00
committed by aurhat
parent 9f537b0876
commit f86579533a
119 changed files with 33154 additions and 10826 deletions
+44 -8
View File
@@ -302,7 +302,7 @@ COMMAND(onrelease, "s");
void saycommand(char *init) // turns input to the command line on or off
{
SDL_EnableUNICODE(saycommandon = (init!=NULL));
saycommandon = (init!=NULL);
setscope(false);
setburst(false);
if(!editmode) keyrepeat(saycommandon);
@@ -356,7 +356,8 @@ void pasteconsole(char *dst)
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
wminfo.subsystem = SDL_SYSWM_X11;
if(!SDL_GetWMInfo(&wminfo)) return;
extern SDL_Window *screen;
if(!SDL_GetWindowWMInfo(screen, &wminfo)) return;
int cbsize;
char *cb = XFetchBytes(wminfo.info.x11.display, &cbsize);
if(!cb || !cbsize) return;
@@ -497,10 +498,14 @@ void execbind(keym &k, bool isdown)
keypressed = NULL;
if(keyaction!=action) delete[] keyaction;
}
k.pressed = isdown;
}
void consolekey(int code, bool isdown, int cooked, SDLMod mod)
void consoletext(const char *text)
{
cmdline.say(text);
}
void consolekey(int code, bool isdown, SDL_Keymod mod)
{
static char *beforecomplete = NULL;
static bool ignoreescup = false;
@@ -552,8 +557,9 @@ void consolekey(int code, bool isdown, int cooked, SDLMod mod)
default:
resetcomplete();
DELETEA(beforecomplete);
case SDLK_LSHIFT:
cmdline.key(code, isdown, cooked);
cmdline.key(code);
break;
}
}
@@ -594,13 +600,24 @@ void consolekey(int code, bool isdown, int cooked, SDLMod mod)
}
}
void keypress(int code, bool isdown, int cooked, SDLMod mod)
extern bool menusay(const char *);
void textinput(const char *text)
{
if(saycommandon) {
cmdline.say(text);
} else {
menusay(text);
}
}
void keypress(int code, bool isdown, SDL_Keymod mod)
{
keym *haskey = NULL;
loopv(keyms) if(keyms[i].code==code) { haskey = &keyms[i]; break; }
if(haskey && haskey->pressed) execbind(*haskey, isdown); // allow pressed keys to release
else if(saycommandon) consolekey(code, isdown, cooked, mod); // keystrokes go to commandline
else if(!menukey(code, isdown, cooked, mod)) // keystrokes go to menu
else if(saycommandon) consolekey(code, isdown, mod); // keystrokes go to commandline
else if(!menukey(code, isdown)) // keystrokes go to menu
{
if(haskey) execbind(*haskey, isdown);
}
@@ -626,3 +643,22 @@ void writebinds(stream *f)
}
}
bool textinputbuffer::say(const char *c)
{
int buflen = strlen(buf);
if(buflen >= maxlen()) return false;
int clen = strlen(c);
if(buflen+clen < sizeof(buf))
{
if(pos < 0) strncpy(buf + buflen, c, clen);
else
{
memmove(&buf[pos+clen], &buf[pos], buflen - pos);
memcpy(&buf[pos], c, clen);
pos += clen;
}
buf[buflen+clen] = '\0';
return true;
}
return false;
}