when closing an input config dialog, remove SDL timer if needed

fixes #429
This commit is contained in:
Arisotura
2019-06-04 16:17:30 +02:00
parent c8472a67c1
commit 86b4cbcb03

View File

@ -49,6 +49,7 @@ typedef struct
int pollid; int pollid;
uiButton* pollbtn; uiButton* pollbtn;
SDL_TimerID timer;
} InputDlgData; } InputDlgData;
@ -204,14 +205,27 @@ Uint32 JoyPoll(Uint32 interval, void* param)
{ {
InputDlgData* dlg = (InputDlgData*)param; InputDlgData* dlg = (InputDlgData*)param;
if (dlg->pollid < 0x100) return 0; if (dlg->pollid < 0x100)
{
dlg->timer = 0;
return 0;
}
int id = dlg->pollid & 0xFF; int id = dlg->pollid & 0xFF;
if (id > 12) return 0; if (id > 12)
{
dlg->timer = 0;
return 0;
}
SDL_JoystickUpdate(); SDL_JoystickUpdate();
SDL_Joystick* joy = Joystick; SDL_Joystick* joy = Joystick;
if (!joy) return 0; if (!joy)
{
dlg->timer = 0;
return 0;
}
int nbuttons = SDL_JoystickNumButtons(joy); int nbuttons = SDL_JoystickNumButtons(joy);
for (int i = 0; i < nbuttons; i++) for (int i = 0; i < nbuttons; i++)
@ -220,6 +234,7 @@ Uint32 JoyPoll(Uint32 interval, void* param)
{ {
dlg->joymap[id] = i; dlg->joymap[id] = i;
uiQueueMain(FinishJoyMapping, dlg); uiQueueMain(FinishJoyMapping, dlg);
dlg->timer = 0;
return 0; return 0;
} }
} }
@ -234,6 +249,7 @@ Uint32 JoyPoll(Uint32 interval, void* param)
dlg->joymap[id] = 0x100 | blackhat; dlg->joymap[id] = 0x100 | blackhat;
uiQueueMain(FinishJoyMapping, dlg); uiQueueMain(FinishJoyMapping, dlg);
dlg->timer = 0;
return 0; return 0;
} }
@ -282,7 +298,7 @@ void OnJoyStartConfig(uiButton* btn, void* data)
uiButtonSetText(btn, "[press button]"); uiButtonSetText(btn, "[press button]");
uiControlDisable(uiControl(btn)); uiControlDisable(uiControl(btn));
SDL_AddTimer(100, JoyPoll, dlg); dlg->timer = SDL_AddTimer(100, JoyPoll, dlg);
uiControlSetFocus(uiControl(dlg->keypresscatcher)); uiControlSetFocus(uiControl(dlg->keypresscatcher));
} }
@ -291,6 +307,7 @@ int OnCloseWindow(uiWindow* window, void* blarg)
{ {
InputDlgData* dlg = (InputDlgData*)(uiControl(window)->UserData); InputDlgData* dlg = (InputDlgData*)(uiControl(window)->UserData);
openedmask &= ~(1 << dlg->type); openedmask &= ~(1 << dlg->type);
if (dlg->timer) SDL_RemoveTimer(dlg->timer);
return 1; return 1;
} }
@ -312,6 +329,7 @@ void OnCancel(uiButton* btn, void* data)
uiControlDestroy(uiControl(dlg->win)); uiControlDestroy(uiControl(dlg->win));
openedmask &= ~(1 << dlg->type); openedmask &= ~(1 << dlg->type);
if (dlg->timer) SDL_RemoveTimer(dlg->timer);
} }
void OnOk(uiButton* btn, void* data) void OnOk(uiButton* btn, void* data)
@ -333,6 +351,7 @@ void OnOk(uiButton* btn, void* data)
uiControlDestroy(uiControl(dlg->win)); uiControlDestroy(uiControl(dlg->win));
openedmask &= ~(1 << dlg->type); openedmask &= ~(1 << dlg->type);
if (dlg->timer) SDL_RemoveTimer(dlg->timer);
} }
void Open(int type) void Open(int type)
@ -350,6 +369,7 @@ void Open(int type)
dlg->type = type; dlg->type = type;
dlg->pollid = -1; dlg->pollid = -1;
dlg->timer = 0;
if (type == 0) if (type == 0)
{ {
@ -475,6 +495,7 @@ void Close(int type)
uiControlDestroy(uiControl(inputdlg[type].win)); uiControlDestroy(uiControl(inputdlg[type].win));
openedmask &= ~(1<<type); openedmask &= ~(1<<type);
if (inputdlg[type].timer) SDL_RemoveTimer(inputdlg[type].timer);
} }
} }