sdlMsgBox.cpp

Engine/source/platformSDL/sdlMsgBox.cpp

More...

Detailed Description

  1
  2#include "windowManager/platformWindowMgr.h"
  3#include "windowManager/sdl/sdlWindow.h"
  4
  5#include "SDL.h"
  6
  7namespace
  8{   
  9   SDL_MessageBoxButtonData MBOkCancelData[2], MBRetryCancelData[2], MBSaveDontSaveData[2], MBSaveDontSaveCancelData[3], MBAlertAssetData[4];
 10
 11   bool needInitMsgBox = true;
 12
 13   void initMsgBox_ButtonData()
 14   {
 15      needInitMsgBox = false;
 16
 17      SDL_MessageBoxButtonData MBOkButton;
 18      MBOkButton.text = "Ok";
 19      MBOkButton.buttonid = MROk;
 20      MBOkButton.flags = 0;
 21      
 22      SDL_MessageBoxButtonData MBCancelButton;
 23      MBCancelButton.text = "Cancel";
 24      MBCancelButton.buttonid = MRCancel;
 25      MBCancelButton.flags = 0;
 26      
 27      SDL_MessageBoxButtonData MBRetryButton;
 28      MBRetryButton.text = "Retry";
 29      MBRetryButton.buttonid = MROk;
 30      MBRetryButton.flags = 0;
 31      
 32      SDL_MessageBoxButtonData MBSaveButton;
 33      MBSaveButton.text = "Save";
 34      MBSaveButton.buttonid = MROk;
 35      MBSaveButton.flags = 0;
 36      
 37      SDL_MessageBoxButtonData MBDontSaveButton;
 38      MBDontSaveButton.text = "Don't Save";
 39      MBDontSaveButton.buttonid = MRRetry;
 40      MBDontSaveButton.flags = 0;
 41
 42      MBOkCancelData[0] = MBOkButton;
 43      MBOkCancelData[1] = MBCancelButton;
 44
 45      MBRetryCancelData[0] = MBRetryButton;
 46      MBRetryCancelData[1] = MBCancelButton;
 47
 48      MBSaveDontSaveData[0] = MBSaveButton;
 49      MBSaveDontSaveData[1] = MBDontSaveButton;
 50
 51      MBSaveDontSaveCancelData[0] = MBSaveButton;
 52      MBSaveDontSaveCancelData[1] = MBDontSaveButton;
 53      MBSaveDontSaveCancelData[2] = MBRetryButton;
 54      
 55      MBAlertAssetData[0].text = "Debug";
 56      MBAlertAssetData[0].buttonid = Platform::ALERT_ASSERT_DEBUG;
 57      MBAlertAssetData[0].flags = 0;
 58      
 59      MBAlertAssetData[1].text = "Ignore";
 60      MBAlertAssetData[1].buttonid = Platform::ALERT_ASSERT_IGNORE;
 61      MBAlertAssetData[1].flags = 0;
 62      
 63      MBAlertAssetData[2].text = "Ignore all";
 64      MBAlertAssetData[2].buttonid = Platform::ALERT_ASSERT_IGNORE_ALL;
 65      MBAlertAssetData[2].flags = 0;
 66      
 67      MBAlertAssetData[3].text = "Exit";
 68      MBAlertAssetData[3].buttonid = Platform::ALERT_ASSERT_EXIT;
 69      MBAlertAssetData[3].flags = 0;
 70   }
 71}
 72
 73#ifdef TORQUE_SDL
 74S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon)
 75{
 76   if(needInitMsgBox)
 77      initMsgBox_ButtonData();
 78
 79   SDL_Window *window = WindowManager->getFirstWindow() ? SDL_GetWindowFromID( WindowManager->getFirstWindow()->getWindowId() ) : NULL;
 80
 81   if (window) //release the mouse from the window constaints
 82      SDL_SetWindowGrab(window, SDL_FALSE);
 83
 84   if(buttons == MBOk)
 85      return SDL_ShowSimpleMessageBox(0, title, message,  window );
 86
 87   SDL_MessageBoxData boxData;
 88   boxData.title = title;
 89   boxData.message = message;
 90   boxData.window = window;
 91   boxData.flags = 0;
 92   boxData.colorScheme = NULL;
 93   boxData.buttons = NULL;
 94   boxData.numbuttons = 0;
 95
 96   int res = MBOk;
 97
 98   switch(buttons)
 99   {
100      case MBOkCancel:
101      {
102         boxData.buttons = &MBOkCancelData[0];
103         boxData.numbuttons = 2;
104         break;
105      }
106      case MBRetryCancel:
107      {
108         boxData.buttons = &MBRetryCancelData[0];
109         boxData.numbuttons = 2;
110         break;
111      }
112      case MBSaveDontSave:
113      {
114         boxData.buttons = &MBSaveDontSaveData[0];
115         boxData.numbuttons = 2;
116         break;
117      }
118      case MBSaveDontSaveCancel:
119      {
120         boxData.buttons = &MBSaveDontSaveCancelData[0];
121         boxData.numbuttons = 3;
122         break;
123      }
124      case MBAlertAssert:
125      {
126         boxData.buttons = &MBAlertAssetData[0];
127         boxData.numbuttons = 4;
128         break;
129      }
130      default:
131      {
132         return MBOk;
133      }
134   }
135
136   SDL_ShowMessageBox(&boxData, &res);
137   return res;
138}
139
140//--------------------------------------
141void Platform::AlertOK(const char *windowTitle, const char *message)
142{
143   SDL_ShowCursor(1);
144   Platform::messageBox(windowTitle, message, MBOk );
145}
146
147//--------------------------------------
148bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
149{
150   SDL_ShowCursor(1);
151   return MROk == Platform::messageBox(windowTitle, message, MBOkCancel );
152}
153
154//--------------------------------------
155bool Platform::AlertRetry(const char *windowTitle, const char *message)
156{
157   SDL_ShowCursor(1);
158   return MROk == Platform::messageBox(windowTitle, message, MBRetryCancel );
159}
160
161Platform::ALERT_ASSERT_RESULT Platform::AlertAssert(const char *windowTitle, const char *message)
162{
163   SDL_ShowCursor(1);
164   return (Platform::ALERT_ASSERT_RESULT)Platform::messageBox(windowTitle, message, MBAlertAssert );
165}
166
167#endif
168