2
0

sdlMsgBox.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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(buttons == MBOk)
  61. return SDL_ShowSimpleMessageBox(0, title, message, window );
  62. SDL_MessageBoxData boxData;
  63. boxData.title = title;
  64. boxData.message = message;
  65. boxData.window = window;
  66. boxData.flags = 0;
  67. boxData.colorScheme = NULL;
  68. boxData.buttons = NULL;
  69. boxData.numbuttons = 0;
  70. int res = MBOk;
  71. switch(buttons)
  72. {
  73. case MBOkCancel:
  74. {
  75. boxData.buttons = &MBOkCancelData[0];
  76. boxData.numbuttons = 2;
  77. break;
  78. }
  79. case MBRetryCancel:
  80. {
  81. boxData.buttons = &MBRetryCancelData[0];
  82. boxData.numbuttons = 2;
  83. break;
  84. }
  85. case MBSaveDontSave:
  86. {
  87. boxData.buttons = &MBSaveDontSaveData[0];
  88. boxData.numbuttons = 2;
  89. break;
  90. }
  91. case MBSaveDontSaveCancel:
  92. {
  93. boxData.buttons = &MBSaveDontSaveCancelData[0];
  94. boxData.numbuttons = 3;
  95. break;
  96. }
  97. case MBAlertAssert:
  98. {
  99. boxData.buttons = &MBAlertAssetData[0];
  100. boxData.numbuttons = 4;
  101. break;
  102. }
  103. default:
  104. {
  105. return MBOk;
  106. }
  107. }
  108. SDL_ShowMessageBox(&boxData, &res);
  109. return res;
  110. }
  111. //--------------------------------------
  112. void Platform::AlertOK(const char *windowTitle, const char *message)
  113. {
  114. SDL_ShowCursor(1);
  115. Platform::messageBox(windowTitle, message, MBOk );
  116. }
  117. //--------------------------------------
  118. bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
  119. {
  120. SDL_ShowCursor(1);
  121. return MROk == Platform::messageBox(windowTitle, message, MBOkCancel );
  122. }
  123. //--------------------------------------
  124. bool Platform::AlertRetry(const char *windowTitle, const char *message)
  125. {
  126. SDL_ShowCursor(1);
  127. return MROk == Platform::messageBox(windowTitle, message, MBRetryCancel );
  128. }
  129. Platform::ALERT_ASSERT_RESULT Platform::AlertAssert(const char *windowTitle, const char *message)
  130. {
  131. SDL_ShowCursor(1);
  132. return (Platform::ALERT_ASSERT_RESULT)Platform::messageBox(windowTitle, message, MBAlertAssert );
  133. }
  134. #endif