int MessageBox(GraphicContext *parentCtx, const std::string font, MessageBoxType type, std::string title, std::string caption1, std::string caption2, std::string caption3) { // for passing captions to class std::string captionArray[3]={ caption1, caption2, caption3 }; int captionWidth[3]; memset(captionWidth, 0, sizeof(captionWidth)); Font *fontPtr=Toolkit::getFont(font); // compute number of caption unsigned captionCount; if (!caption3.empty()) { captionCount = 3; captionWidth[2] = fontPtr->getStringWidth(captionArray[2])+40; captionWidth[1] = fontPtr->getStringWidth(captionArray[1])+40; captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40; } else if (!caption2.empty()) { captionCount = 2; captionWidth[1] = fontPtr->getStringWidth(captionArray[1])+40; captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40; } else { captionCount = 1; captionWidth[0] = fontPtr->getStringWidth(captionArray[0])+40; } int totCaptionWidth = captionWidth[0]+captionWidth[1]+captionWidth[2]+(captionCount-1)*20+40; int titleWidth = fontPtr->getStringWidth(title)+20; MessageBoxScreen *mbs = new MessageBoxScreen(parentCtx, font, type, title, titleWidth, totCaptionWidth, captionCount, captionWidth, captionArray); // save screen in a temporary surface parentCtx->setClipRect(); DrawableSurface *background = new DrawableSurface(parentCtx->getW(), parentCtx->getH()); background->drawSurface(0, 0, parentCtx); mbs->dispatchPaint(); SDL_Event event; while(mbs->endValue<0) { Sint32 time = SDL_GetTicks(); while (SDL_PollEvent(&event)) { if (event.type==SDL_QUIT) break; //Manual integration of cmd+q and alt f4 if(event.type == SDL_KEYDOWN) { # ifdef USE_OSX if(event.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_META) { break; } # endif # ifdef USE_WIN32 if(event.key.keysym.sym == SDLK_F4 && SDL_GetModState() & KMOD_ALT) { break; } # endif } mbs->translateAndProcessEvent(&event); } mbs->dispatchPaint(); parentCtx->drawSurface((int)0, (int)0, background); parentCtx->drawSurface(mbs->decX, mbs->decY, mbs->getSurface()); parentCtx->nextFrame(); Sint32 newTime = SDL_GetTicks(); SDL_Delay(std::max(40 - newTime + time, 0)); } int retVal; if (mbs->endValue>=0) retVal=mbs->endValue; else retVal=-1; // clean up delete mbs; // restore screen and destroy temporary surface parentCtx->drawSurface(0, 0, background); delete background; return retVal; }