sdlMsgBox.cpp 4.6 KB

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