Dialogs.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "Dialogs.h"
  2. static SDL_MessageBoxButtonData buttonDataAbortRetryIgnore[] = {
  3. {
  4. .flags = 0,
  5. .buttonID = IDABORT,
  6. .text = "Abort"
  7. },
  8. {
  9. .flags = 0,
  10. .buttonID = IDRETRY,
  11. .text = "Retry"
  12. },
  13. {
  14. .flags = 0,
  15. .buttonID = IDIGNORE,
  16. .text = "Ignore"
  17. }
  18. };
  19. static SDL_MessageBoxButtonData buttonDataCancelTryContinue[] = {
  20. {
  21. .flags = 0,
  22. .buttonID = IDCANCEL,
  23. .text = "Cancel"
  24. },
  25. {
  26. .flags = 0,
  27. .buttonID = IDTRYAGAIN,
  28. .text = "Try Again"
  29. },
  30. {
  31. .flags = 0,
  32. .buttonID = IDCONTINUE,
  33. .text = "Continue"
  34. }
  35. };
  36. static SDL_MessageBoxButtonData buttonOk[] = {
  37. {
  38. .flags = 0,
  39. .buttonID = IDOK,
  40. .text = "OK"
  41. }
  42. };
  43. static SDL_MessageBoxButtonData buttonOkCancel[] = {
  44. {
  45. .flags = 0,
  46. .buttonID = IDOK,
  47. .text = "OK"
  48. },
  49. {
  50. .flags = 0,
  51. .buttonID = IDCANCEL,
  52. .text = "Cancel"
  53. }
  54. };
  55. static SDL_MessageBoxButtonData buttonRetryCancel[] = {
  56. {
  57. .flags = 0,
  58. .buttonID = IDRETRY,
  59. .text = "Retry"
  60. },
  61. {
  62. .flags = 0,
  63. .buttonID = IDCANCEL,
  64. .text = "Cancel"
  65. }
  66. };
  67. static SDL_MessageBoxButtonData buttonDataYesNo[] = {
  68. {
  69. .flags = 0,
  70. .buttonID = IDYES,
  71. .text = "Yes"
  72. },
  73. {
  74. .flags = 0,
  75. .buttonID = IDNO,
  76. .text = "No"
  77. }
  78. };
  79. static SDL_MessageBoxButtonData buttonDataYesNoCancel[] = {
  80. {
  81. .flags = 0,
  82. .buttonID = IDYES,
  83. .text = "Yes"
  84. },
  85. {
  86. .flags = 0,
  87. .buttonID = IDNO,
  88. .text = "No"
  89. },
  90. {
  91. .flags = 0,
  92. .buttonID = IDCANCEL,
  93. .text = "Cancel"
  94. }
  95. };
  96. int MessageBox(SDL_Window *parent, char const *msg, char const *caption, unsigned int type)
  97. {
  98. int numbuttons;
  99. SDL_MessageBoxButtonData *buttons;
  100. switch (type & MB_MASK_BUTTON)
  101. {
  102. case MB_ABORTRETRYIGNORE:
  103. buttons = buttonDataAbortRetryIgnore;
  104. numbuttons = sizeof(buttonDataAbortRetryIgnore) / sizeof(SDL_MessageBoxButtonData);
  105. break;
  106. case MB_CANCELTRYCONTINUE:
  107. buttons = buttonDataCancelTryContinue;
  108. numbuttons = sizeof(buttonDataCancelTryContinue) / sizeof(SDL_MessageBoxButtonData);
  109. break;
  110. case MB_OK:
  111. buttons = buttonOk;
  112. numbuttons = sizeof(buttonOk) / sizeof(SDL_MessageBoxButtonData);
  113. break;
  114. case MB_OKCANCEL:
  115. buttons = buttonOkCancel;
  116. numbuttons = sizeof(buttonOkCancel) / sizeof(SDL_MessageBoxButtonData);
  117. break;
  118. case MB_RETRYCANCEL:
  119. buttons = buttonRetryCancel;
  120. numbuttons = sizeof(buttonRetryCancel) / sizeof(SDL_MessageBoxButtonData);
  121. break;
  122. case MB_YESNO:
  123. buttons = buttonDataYesNo;
  124. numbuttons = sizeof(buttonDataYesNo) / sizeof(SDL_MessageBoxButtonData);
  125. break;
  126. case MB_YESNOCANCEL:
  127. buttons = buttonDataYesNoCancel;
  128. numbuttons = sizeof(buttonDataYesNoCancel) / sizeof(SDL_MessageBoxButtonData);
  129. break;
  130. }
  131. SDL_MessageBoxData data = {
  132. .flags = type & MB_MASK_ICON,
  133. .window = parent,
  134. .title = caption,
  135. .message = msg,
  136. .numbuttons = numbuttons,
  137. .buttons = buttons,
  138. .colorScheme = NULL
  139. };
  140. int result;
  141. SDL_ShowMessageBox(&data, &result);
  142. return result;
  143. }