uDialog.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include "Blue.h"
  21. #include "../cyan.h"
  22. extern SDL_Window *sdlWindow;
  23. extern SDL_Surface *sdlShadowSurface;
  24. extern int sdlWindowWidth;
  25. extern int sdlWindowHeight;
  26. extern short rspMsgBox( // Returns RSP_MB_RET_*. See switch statement below.
  27. USHORT usFlags, // MB_BUT/ICO_* flags specifying buttons and icons.
  28. char *pszTitle, // Title for box.
  29. char *pszFrmt, // Format for string.
  30. ...) // Various shit.
  31. {
  32. char szOutput[4096];
  33. va_list varp;
  34. // Get pointer to the arguments.
  35. va_start(varp, pszFrmt);
  36. // Compose string.
  37. SDL_vsnprintf(szOutput, sizeof (szOutput), pszFrmt, varp);
  38. // Done with var arguments.
  39. va_end(varp);
  40. SDL_MessageBoxData data;
  41. SDL_zero(data);
  42. switch (usFlags & RSP_MB_ICN_MASK)
  43. {
  44. case RSP_MB_ICN_STOP: data.flags |= SDL_MESSAGEBOX_ERROR; break;
  45. case RSP_MB_ICN_QUERY: data.flags |= SDL_MESSAGEBOX_INFORMATION; break;
  46. case RSP_MB_ICN_EXCLAIM: data.flags |= SDL_MESSAGEBOX_WARNING; break;
  47. case RSP_MB_ICN_INFO: data.flags |= SDL_MESSAGEBOX_INFORMATION; break;
  48. default: break;
  49. }
  50. data.window = sdlWindow;
  51. data.title = pszTitle;
  52. data.message = szOutput;
  53. SDL_MessageBoxButtonData buttons[3];
  54. SDL_zero(buttons);
  55. switch (usFlags & RSP_MB_BUT_MASK)
  56. {
  57. case RSP_MB_BUT_OK:
  58. data.numbuttons = 1;
  59. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT |
  60. SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  61. buttons[0].buttonid = RSP_MB_RET_OK;
  62. buttons[0].text = "OK";
  63. break;
  64. case RSP_MB_BUT_OKCANCEL:
  65. data.numbuttons = 2;
  66. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
  67. buttons[0].buttonid = RSP_MB_RET_OK;
  68. buttons[0].text = "OK";
  69. buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  70. buttons[1].buttonid = RSP_MB_RET_CANCEL;
  71. buttons[1].text = "Cancel";
  72. break;
  73. case RSP_MB_BUT_ABORTRETRYIGNORE:
  74. data.numbuttons = 3;
  75. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  76. buttons[0].buttonid = RSP_MB_RET_ABORT;
  77. buttons[0].text = "Abort";
  78. buttons[1].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
  79. buttons[1].buttonid = RSP_MB_RET_RETRY;
  80. buttons[1].text = "Retry";
  81. buttons[2].flags = 0;
  82. buttons[2].buttonid = RSP_MB_RET_IGNORE;
  83. buttons[2].text = "Ignore";
  84. break;
  85. case RSP_MB_BUT_YESNOCANCEL:
  86. data.numbuttons = 3;
  87. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
  88. buttons[0].buttonid = RSP_MB_RET_YES;
  89. buttons[0].text = "Yes";
  90. buttons[1].flags = 0;
  91. buttons[1].buttonid = RSP_MB_RET_NO;
  92. buttons[1].text = "No";
  93. buttons[2].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  94. buttons[2].buttonid = RSP_MB_RET_CANCEL;
  95. buttons[2].text = "Cancel";
  96. break;
  97. case RSP_MB_BUT_YESNO:
  98. data.numbuttons = 2;
  99. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
  100. buttons[0].buttonid = RSP_MB_RET_YES;
  101. buttons[0].text = "Yes";
  102. buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  103. buttons[1].buttonid = RSP_MB_RET_NO;
  104. buttons[1].text = "No";
  105. break;
  106. case RSP_MB_BUT_RETRYCANCEL:
  107. data.numbuttons = 2;
  108. buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
  109. buttons[0].buttonid = RSP_MB_RET_RETRY;
  110. buttons[0].text = "Retry";
  111. buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
  112. buttons[1].buttonid = RSP_MB_RET_CANCEL;
  113. buttons[1].text = "Cancel";
  114. break;
  115. default: ASSERT(false); return -1;
  116. }
  117. data.buttons = buttons;
  118. int button = 0;
  119. const int rc = SDL_ShowMessageBox(&data, &button);
  120. return (rc == 0) ? button : -1;
  121. }
  122. extern short rspOpenBox( // Returns 0 if successfull, non-zero otherwise
  123. const char* pszBoxTitle, // In: Title of box
  124. const char* pszDefaultPath, // In: Default directory and file
  125. char* pszSelectedFile, // Out: File that user selected
  126. short sSelectedFileBufSize, // In: Size of buffer pointed to by pszSelectedFile
  127. const char* pszFilter /*= NULL*/) // In: Filename filter or NULL for none
  128. {
  129. fprintf(stderr, "STUBBED: %s:%d\n", __FILE__, __LINE__);
  130. return -1;
  131. }
  132. extern short rspSaveBox( // Returns 0 on success.
  133. const char* pszBoxTitle, // In: Title of box.
  134. const char* pszDefFileName, // In: Default filename.
  135. char* pszChosenFileName, // Out: User's choice.
  136. short sStrSize, // In: Amount of memory pointed to by pszChosenFileName.
  137. const char* pszFilter /*= NULL*/) // In: If not NULL, '.' delimited extension based filename
  138. // filter specification. Ex: ".cpp.h.exe.lib" or "cpp.h.exe.lib"
  139. // Note: Cannot use '.' in filter. Preceding '.' ignored.
  140. {
  141. fprintf(stderr, "STUBBED: %s:%d\n", __FILE__, __LINE__);
  142. return -1;
  143. }
  144. extern void rspSetCursor(
  145. short sCursorID) // In: ID of built-in cursor (use RSP_CURSOR_* macros)
  146. {
  147. fprintf(stderr, "STUBBED: %s:%d\n", __FILE__, __LINE__);
  148. }