Prevent modal dialog from being dismissed immediately.
This commit is contained in:
parent
95cb35d5a1
commit
d2acbefc6d
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "modalDialog.h"
|
||||
|
||||
static int enableTimer;
|
||||
static Widget *ok;
|
||||
static Widget *okCancelOK;
|
||||
static Widget *okCancelCancel;
|
||||
|
@ -30,14 +31,16 @@ void initModalDialog(void)
|
|||
ok = getWidget("ok", "ok");
|
||||
ok->action = NULL;
|
||||
ok->isModal = 1;
|
||||
|
||||
|
||||
okCancelOK = getWidget("ok", "okCancel");
|
||||
okCancelOK->action = NULL;
|
||||
okCancelOK->isModal = 1;
|
||||
|
||||
|
||||
okCancelCancel = getWidget("cancel", "okCancel");
|
||||
okCancelCancel->action = NULL;
|
||||
okCancelCancel->isModal = 1;
|
||||
|
||||
enableTimer = 0;
|
||||
}
|
||||
|
||||
void showOKDialog(void (*callback)(void), const char *format, ...)
|
||||
|
@ -49,12 +52,15 @@ void showOKDialog(void (*callback)(void), const char *format, ...)
|
|||
va_start(args, format);
|
||||
vsprintf(textBuffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
|
||||
STRNCPY(app.modalDialog.message, textBuffer, MAX_DESCRIPTION_LENGTH);
|
||||
|
||||
|
||||
app.modalDialog.type = MD_OK;
|
||||
|
||||
|
||||
ok->action = callback;
|
||||
|
||||
enableTimer = FPS;
|
||||
ok->enabled = okCancelOK = okCancelCancel = 0;
|
||||
}
|
||||
|
||||
void showOKCancelDialog(void (*okCallback)(void), void (*cancelCallback)(void), const char *format, ...)
|
||||
|
@ -66,59 +72,68 @@ void showOKCancelDialog(void (*okCallback)(void), void (*cancelCallback)(void),
|
|||
va_start(args, format);
|
||||
vsprintf(textBuffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
|
||||
STRNCPY(app.modalDialog.message, textBuffer, MAX_DESCRIPTION_LENGTH);
|
||||
|
||||
|
||||
app.modalDialog.type = MD_OK_CANCEL;
|
||||
|
||||
|
||||
okCancelOK->action = okCallback;
|
||||
okCancelCancel->action = cancelCallback;
|
||||
|
||||
enableTimer = FPS;
|
||||
ok->enabled = okCancelOK = okCancelCancel = 0;
|
||||
}
|
||||
|
||||
void doModalDialog(void)
|
||||
{
|
||||
doWidgets();
|
||||
|
||||
|
||||
clearInput();
|
||||
|
||||
enableTimer = MAX(enableTimer - 1, 0);
|
||||
if (!enableTimer)
|
||||
{
|
||||
ok->enabled = okCancelOK = okCancelCancel = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void drawModalDialog(void)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
|
||||
limitTextWidth(700);
|
||||
|
||||
|
||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96);
|
||||
SDL_RenderFillRect(app.renderer, NULL);
|
||||
|
||||
|
||||
r.w = 800;
|
||||
r.h = getWrappedTextHeight(app.modalDialog.message, 24) + 100;
|
||||
r.x = (SCREEN_WIDTH / 2) - (r.w / 2);
|
||||
r.y = (SCREEN_HEIGHT / 2) - (r.h / 2);
|
||||
|
||||
|
||||
ok->rect.y = okCancelOK->rect.y = okCancelCancel->rect.y = r.y + r.h - 50;
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 225);
|
||||
SDL_RenderFillRect(app.renderer, &r);
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 200);
|
||||
SDL_RenderDrawRect(app.renderer, &r);
|
||||
|
||||
|
||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
||||
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, r.y + 10, 24, TA_CENTER, colors.white, app.modalDialog.message);
|
||||
|
||||
|
||||
switch (app.modalDialog.type)
|
||||
{
|
||||
case MD_OK:
|
||||
drawWidgets("ok");
|
||||
break;
|
||||
|
||||
|
||||
case MD_OK_CANCEL:
|
||||
drawWidgets("okCancel");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
limitTextWidth(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue