more SDL2-related backports from sauer
* use keyrepeat and textinput switch code from sauer (on windows, opening a console with "t" also produced a "t" as text otherwise) * screenw and screenh are now cubescript-variables that always reflect the actual resolution of the screen or the window DOCREF screenw screenh
This commit is contained in:
@@ -303,9 +303,10 @@ COMMAND(onrelease, "s");
|
||||
void saycommand(char *init) // turns input to the command line on or off
|
||||
{
|
||||
saycommandon = (init != NULL);
|
||||
textinput(saycommandon, TI_CONSOLE);
|
||||
keyrepeat(saycommandon, KR_CONSOLE);
|
||||
setscope(false);
|
||||
setburst(false);
|
||||
if(!editmode) keyrepeat = saycommandon;
|
||||
copystring(cmdline.buf, init ? escapestring(init, false, true) : "");
|
||||
DELETEA(cmdaction);
|
||||
DELETEA(cmdprompt);
|
||||
@@ -553,7 +554,7 @@ void consolekey(int code, bool isdown, SDL_Keymod mod)
|
||||
}
|
||||
}
|
||||
|
||||
void textinput(const char *text)
|
||||
void processtextinput(const char *text)
|
||||
{
|
||||
if(saycommandon)
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ void toggleedit(bool force)
|
||||
//put call to clear/restart gamemode
|
||||
player1->attacking = false;
|
||||
}
|
||||
keyrepeat = editmode;
|
||||
keyrepeat(editmode, KR_EDITMODE);
|
||||
editing = editmode ? 1 : 0;
|
||||
editing_sp = editmode && !multiplayer(NULL) ? 1 : 0;
|
||||
player1->state = editing ? CS_EDITING : (watchingdemo ? CS_SPECTATE : CS_ALIVE);
|
||||
|
||||
+34
-16
@@ -95,8 +95,9 @@ bool initwarning(const char *desc, int level, int type)
|
||||
|
||||
SDL_Window *screen = NULL;
|
||||
SDL_GLContext glcontext = 0;
|
||||
static int screenw = 0, screenh = 0; // actual current resolution of screen
|
||||
|
||||
VAR(screenw, 1, 0, 0); // actual current resolution of screen/window
|
||||
VAR(screenh, 1, 0, 0);
|
||||
#define SCR_MINW 320
|
||||
#define SCR_MINH 200
|
||||
#define SCR_MAXW 10000
|
||||
@@ -689,7 +690,32 @@ void fpsrange(int *low, int *high)
|
||||
|
||||
COMMAND(fpsrange, "ii");
|
||||
|
||||
bool keyrepeat = false;
|
||||
int keyrepeatmask = 0, textinputmask = 0; // bunches of flags for the same functions
|
||||
Uint32 textinputtime = 0;
|
||||
|
||||
void keyrepeat(bool on, int mask)
|
||||
{
|
||||
if(on) keyrepeatmask |= mask;
|
||||
else keyrepeatmask &= ~mask;
|
||||
}
|
||||
|
||||
void textinput(bool on, int mask)
|
||||
{
|
||||
if(on)
|
||||
{
|
||||
if(!textinputmask)
|
||||
{
|
||||
SDL_StartTextInput();
|
||||
textinputtime = SDL_GetTicks();
|
||||
}
|
||||
textinputmask |= mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
textinputmask &= ~mask;
|
||||
if(!textinputmask) SDL_StopTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
vector<SDL_Event> events;
|
||||
|
||||
@@ -793,12 +819,15 @@ void checkinput()
|
||||
entropy_add_byte(event.key.keysym.sym ^ totalmillis);
|
||||
EVENTDEBUG(concatformatstring(eb, " sym %d (%Xh), scancode %d (%Xh), state %d, repeat %d", event.key.keysym.sym, event.key.keysym.sym, event.key.keysym.scancode, event.key.keysym.scancode, event.key.state, event.key.repeat));
|
||||
if(event.key.keysym.sym == SDLK_SCANCODE_MASK) event.key.keysym.sym |= event.key.keysym.scancode; // workaround SDL 2.0.5 bug which returns sym == 40000000h for all dead keys
|
||||
if(!event.key.repeat || keyrepeat) keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, (SDL_Keymod)event.key.keysym.mod);
|
||||
if(!event.key.repeat || keyrepeatmask) keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, (SDL_Keymod)event.key.keysym.mod);
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
EVENTDEBUG(concatformatstring(eb, "(SDL_TEXTINPUT) %s", escapestring(event.text.text)));
|
||||
textinput(event.text.text);
|
||||
EVENTDEBUG(thres = 2; concatformatstring(eb, "(SDL_TEXTINPUT) %s %d %d", escapestring(event.text.text), textinputmask, int(event.text.timestamp - textinputtime)));
|
||||
if(textinputmask && int(event.text.timestamp - textinputtime) >= 5) // mute textinput for a few milliseconds, to avoid receiving the "t" that switched on the console
|
||||
{
|
||||
processtextinput(event.text.text);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
@@ -1075,15 +1104,6 @@ void initclientlog() // rotate old logfiles and create new one
|
||||
DELETEP(bootclientlog);
|
||||
}
|
||||
|
||||
/// SDL event filter that drops text input events unless some kind of
|
||||
/// text input is enabled (text field in menu item active, chat prompt...)
|
||||
int textinputfilter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
extern bool saycommandon, menutextinputon;
|
||||
if(event->type != SDL_TEXTINPUT) return 1;
|
||||
return (saycommandon || menutextinputon) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void sanitychecks()
|
||||
{
|
||||
@@ -1372,8 +1392,6 @@ int main(int argc, char **argv)
|
||||
|
||||
if(initscript) execute(initscript);
|
||||
|
||||
SDL_SetEventFilter(textinputfilter, NULL);
|
||||
|
||||
initlog("mainloop");
|
||||
|
||||
inputgrab(grabinput = true);
|
||||
|
||||
@@ -14,8 +14,7 @@ COMMANDF(curmenu, "", () {result(curmenu ? curmenu->name : "");} );
|
||||
inline gmenu *setcurmenu(gmenu *newcurmenu) // only change curmenu through here!
|
||||
{
|
||||
curmenu = newcurmenu;
|
||||
extern bool saycommandon;
|
||||
if(!editmode && !saycommandon) keyrepeat = curmenu && curmenu->allowinput && !curmenu->hotkeys;
|
||||
keyrepeat(curmenu && curmenu->allowinput && !curmenu->hotkeys, KR_MENU);
|
||||
return curmenu;
|
||||
}
|
||||
|
||||
@@ -380,8 +379,6 @@ struct mitemmapload : mitemmanual
|
||||
|
||||
// text input item
|
||||
|
||||
bool menutextinputon = false;
|
||||
|
||||
struct mitemtextinput : mitemtext
|
||||
{
|
||||
textinputbuffer input;
|
||||
@@ -440,7 +437,7 @@ struct mitemtextinput : mitemtext
|
||||
{
|
||||
if(on && hoveraction) execute(hoveraction);
|
||||
|
||||
menutextinputon = on;
|
||||
textinput(on, TI_MENU);
|
||||
if(action && !on && modified && parent->items.find(this) != parent->items.length() - 1)
|
||||
{
|
||||
modified = false;
|
||||
@@ -1100,7 +1097,7 @@ static bool iskeypressed(int key)
|
||||
|
||||
void menusay(const char *text)
|
||||
{
|
||||
if(menutextinputon && curmenu && curmenu->allowinput && curmenu->items.inrange(curmenu->menusel)) curmenu->items[curmenu->menusel]->say(text);
|
||||
if(curmenu && curmenu->allowinput && curmenu->items.inrange(curmenu->menusel)) curmenu->items[curmenu->menusel]->say(text);
|
||||
}
|
||||
|
||||
bool menukey(int code, bool isdown, SDL_Keymod mod)
|
||||
|
||||
+10
-14
@@ -131,7 +131,7 @@ extern char *getcurcommand(int *pos);
|
||||
extern char *addreleaseaction(const char *s);
|
||||
extern void savehistory();
|
||||
extern void loadhistory();
|
||||
extern void textinput(const char *text);
|
||||
extern void processtextinput(const char *text);
|
||||
extern void writebinds(stream *f);
|
||||
extern void clientlogf(const char *s, ...) PRINTFARGS(1, 2);
|
||||
|
||||
@@ -673,23 +673,19 @@ extern int isoccluded(float vx, float vy, float cx, float cy, float csize);
|
||||
// main
|
||||
extern char *lang;
|
||||
extern SDL_Window *screen;
|
||||
extern int depthbits, stencilbits;
|
||||
extern int stencilbits;
|
||||
|
||||
enum { KR_CONSOLE = 1<<0, KR_MENU = 1<<1, KR_EDITMODE = 1<<2 };
|
||||
extern void keyrepeat(bool on, int mask = ~0);
|
||||
|
||||
enum { TI_CONSOLE = 1<<0, TI_MENU = 1<<1 };
|
||||
extern void textinput(bool on, int mask = ~0);
|
||||
|
||||
extern bool keyrepeat;
|
||||
extern bool interceptkey(int sym);
|
||||
extern bool inmainloop;
|
||||
|
||||
enum
|
||||
{
|
||||
NOT_INITING = 0,
|
||||
INIT_LOAD,
|
||||
INIT_RESET
|
||||
};
|
||||
enum
|
||||
{
|
||||
CHANGE_GFX = 1<<0,
|
||||
CHANGE_SOUND = 1<<1
|
||||
};
|
||||
enum { NOT_INITING = 0, INIT_LOAD, INIT_RESET };
|
||||
enum { CHANGE_GFX = 1<<0, CHANGE_SOUND = 1<<1 };
|
||||
extern bool initwarning(const char *desc, int level = INIT_RESET, int type = CHANGE_GFX);
|
||||
|
||||
// rendertext
|
||||
|
||||
@@ -1058,12 +1058,9 @@ struct vertmodel : model
|
||||
shadows = new GLuint[numframes];
|
||||
glGenTextures(numframes, shadows);
|
||||
|
||||
extern SDL_Window *screen;
|
||||
extern int screenw, screenh;
|
||||
int aasize = 1<<(dynshadowsize + aadynshadow);
|
||||
|
||||
int ww, wh;
|
||||
SDL_GetWindowSize(screen, &ww, &wh);
|
||||
while(aasize > ww || aasize > wh) aasize /= 2;
|
||||
while(aasize > screenw || aasize > screenh) aasize /= 2;
|
||||
|
||||
stream *f = filename ? opengzfile(filename, "wb") : NULL;
|
||||
if(f)
|
||||
@@ -1098,7 +1095,7 @@ struct vertmodel : model
|
||||
endgenshadow();
|
||||
|
||||
glEnable(GL_FOG);
|
||||
glViewport(0, 0, ww, wh);
|
||||
glViewport(0, 0, screenw, screenh);
|
||||
|
||||
if(f) delete f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user