|
| 1 | +{ |
| 2 | + This file is part of: |
| 3 | +
|
| 4 | + SDL3 for Pascal |
| 5 | + (https://github.com/PascalGameDevelopment/SDL3-for-Pascal) |
| 6 | + SPDX-License-Identifier: Zlib |
| 7 | +} |
| 8 | + |
| 9 | +{* |
| 10 | + * # CategoryMessagebox |
| 11 | + * |
| 12 | + * SDL offers a simple message box API, which is useful for simple alerts, |
| 13 | + * such as informing the user when something fatal happens at startup without |
| 14 | + * the need to build a UI for it (or informing the user _before_ your UI is |
| 15 | + * ready). |
| 16 | + * |
| 17 | + * These message boxes are native system dialogs where possible. |
| 18 | + * |
| 19 | + * There is both a customizable function (SDL_ShowMessageBox()) that offers |
| 20 | + * lots of options for what to display and reports on what choice the user |
| 21 | + * made, and also a much-simplified version (SDL_ShowSimpleMessageBox()), |
| 22 | + * merely takes a text message and title, and waits until the user presses a |
| 23 | + * single "OK" UI button. Often, this is all that is necessary. |
| 24 | + } |
| 25 | + |
| 26 | +{* |
| 27 | + * Message box flags. |
| 28 | + * |
| 29 | + * If supported will display warning icon, etc. |
| 30 | + * |
| 31 | + * \since This datatype is available since SDL 3.2.0. |
| 32 | + } |
| 33 | +type |
| 34 | + PPSDL_MessageBoxFlags = ^PSDL_MessageBoxFlags; |
| 35 | + PSDL_MessageBoxFlags = ^TSDL_MessageBoxFlags; |
| 36 | + TSDL_MessageBoxFlags = type cuint32; |
| 37 | +const |
| 38 | + SDL_MESSAGEBOX_ERROR = TSDL_MessageBoxFlags($00000010); {*< error dialog } |
| 39 | + SDL_MESSAGEBOX_WARNING = TSDL_MessageBoxFlags($00000020); {*< warning dialog } |
| 40 | + SDL_MESSAGEBOX_INFORMATION = TSDL_MessageBoxFlags($00000040); {*< informational dialog } |
| 41 | + SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT = TSDL_MessageBoxFlags($00000080); {*< buttons placed left to right } |
| 42 | + SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT = TSDL_MessageBoxFlags($00000100); {*< buttons placed right to left } |
| 43 | + |
| 44 | +{* |
| 45 | + * SDL_MessageBoxButtonData flags. |
| 46 | + * |
| 47 | + * \since This datatype is available since SDL 3.2.0. |
| 48 | + } |
| 49 | +type |
| 50 | + PPSDL_MessageBoxButtonFlags = ^PSDL_MessageBoxButtonFlags; |
| 51 | + PSDL_MessageBoxButtonFlags = ^TSDL_MessageBoxButtonFlags; |
| 52 | + TSDL_MessageBoxButtonFlags = type cuint32; |
| 53 | +const |
| 54 | + SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = TSDL_MessageBoxButtonFlags($00000001); {*< Marks the default button when return is hit } |
| 55 | + SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = TSDL_MessageBoxButtonFlags($00000002); {*< Marks the default button when escape is hit } |
| 56 | + |
| 57 | +{* |
| 58 | + * Individual button data. |
| 59 | + * |
| 60 | + * \since This struct is available since SDL 3.2.0. |
| 61 | + } |
| 62 | +type |
| 63 | + PPSDL_MessageBoxButtonData = ^PSDL_MessageBoxButtonData; |
| 64 | + PSDL_MessageBoxButtonData = ^TSDL_MessageBoxButtonData; |
| 65 | + TSDL_MessageBoxButtonData = record |
| 66 | + flags: TSDL_MessageBoxButtonFlags; |
| 67 | + buttonID: cint; {*< User defined button id (value returned via SDL_ShowMessageBox) } |
| 68 | + text: PAnsiChar; {*< The UTF-8 button text } |
| 69 | + end; |
| 70 | + |
| 71 | +{* |
| 72 | + * RGB value used in a message box color scheme |
| 73 | + * |
| 74 | + * \since This struct is available since SDL 3.2.0. |
| 75 | + } |
| 76 | +type |
| 77 | + PPSDL_MessageBoxColor = ^PSDL_MessageBoxColor; |
| 78 | + PSDL_MessageBoxColor = ^TSDL_MessageBoxColor; |
| 79 | + TSDL_MessageBoxColor = record |
| 80 | + r: cuint8; |
| 81 | + g: cuint8; |
| 82 | + b: cuint8; |
| 83 | + end; |
| 84 | + |
| 85 | +{* |
| 86 | + * An enumeration of indices inside the colors array of |
| 87 | + * SDL_MessageBoxColorScheme. |
| 88 | + } |
| 89 | +type |
| 90 | + PPSDL_MessageBoxColorType = ^PSDL_MessageBoxColorType; |
| 91 | + PSDL_MessageBoxColorType = ^TSDL_MessageBoxColorType; |
| 92 | + TSDL_MessageBoxColorType = type Integer; |
| 93 | +const |
| 94 | + SDL_MESSAGEBOX_COLOR_BACKGROUND = TSDL_MessageBoxColorType(0); |
| 95 | + SDL_MESSAGEBOX_COLOR_TEXT = TSDL_MessageBoxColorType(1); |
| 96 | + SDL_MESSAGEBOX_COLOR_BUTTON_BORDER = TSDL_MessageBoxColorType(2); |
| 97 | + SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND = TSDL_MessageBoxColorType(3); |
| 98 | + SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED = TSDL_MessageBoxColorType(4); |
| 99 | + SDL_MESSAGEBOX_COLOR_COUNT = TSDL_MessageBoxColorType(5); {*< Size of the colors array of SDL_MessageBoxColorScheme. } |
| 100 | + |
| 101 | +{* |
| 102 | + * A set of colors to use for message box dialogs |
| 103 | + * |
| 104 | + * \since This struct is available since SDL 3.2.0. |
| 105 | + } |
| 106 | +type |
| 107 | + PPSDL_MessageBoxColorScheme = ^PSDL_MessageBoxColorScheme; |
| 108 | + PSDL_MessageBoxColorScheme = ^TSDL_MessageBoxColorScheme; |
| 109 | + TSDL_MessageBoxColorScheme = record |
| 110 | + colors: array[0..SDL_MESSAGEBOX_COLOR_COUNT-1] of TSDL_MessageBoxColor; |
| 111 | + end; |
| 112 | + |
| 113 | +{* |
| 114 | + * MessageBox structure containing title, text, window, etc. |
| 115 | + * |
| 116 | + * \since This struct is available since SDL 3.2.0. |
| 117 | + } |
| 118 | +type |
| 119 | + PPSDL_MessageBoxData = ^PSDL_MessageBoxData; |
| 120 | + PSDL_MessageBoxData = ^TSDL_MessageBoxData; |
| 121 | + TSDL_MessageBoxData = record |
| 122 | + flags: TSDL_MessageBoxFlags; |
| 123 | + window: PSDL_Window; {*< Parent window, can be nil } |
| 124 | + title: PAnsiChar; {*< UTF-8 title } |
| 125 | + message: PAnsiChar; {*< UTF-8 message text } |
| 126 | + |
| 127 | + numbuttons: cint; |
| 128 | + buttons: PSDL_MessageBoxButtonData; |
| 129 | + |
| 130 | + colorScheme: PSDL_MessageBoxColorScheme; {*< SDL_MessageBoxColorScheme, can be nil to use system settings } |
| 131 | + end; |
| 132 | + |
| 133 | +{* |
| 134 | + * Create a modal message box. |
| 135 | + * |
| 136 | + * If your needs aren't complex, it might be easier to use |
| 137 | + * SDL_ShowSimpleMessageBox. |
| 138 | + * |
| 139 | + * This function should be called on the thread that created the parent |
| 140 | + * window, or on the main thread if the messagebox has no parent. It will |
| 141 | + * block execution of that thread until the user clicks a button or closes the |
| 142 | + * messagebox. |
| 143 | + * |
| 144 | + * This function may be called at any time, even before SDL_Init(). This makes |
| 145 | + * it useful for reporting errors like a failure to create a renderer or |
| 146 | + * OpenGL context. |
| 147 | + * |
| 148 | + * On X11, SDL rolls its own dialog box with X11 primitives instead of a |
| 149 | + * formal toolkit like GTK+ or Qt. |
| 150 | + * |
| 151 | + * Note that if SDL_Init() would fail because there isn't any available video |
| 152 | + * target, this function is likely to fail for the same reasons. If this is a |
| 153 | + * concern, check the return value from this function and fall back to writing |
| 154 | + * to stderr if you can. |
| 155 | + * |
| 156 | + * \param messageboxdata the SDL_MessageBoxData structure with title, text and |
| 157 | + * other options. |
| 158 | + * \param buttonid the Pointer to which user id of hit button should be |
| 159 | + * copied. |
| 160 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 161 | + * information. |
| 162 | + * |
| 163 | + * \since This function is available since SDL 3.2.0. |
| 164 | + * |
| 165 | + * \sa SDL_ShowSimpleMessageBox |
| 166 | + } |
| 167 | +function SDL_ShowMessageBox(messageboxdata: PSDL_MessageBoxData; buttonid: pcint): cbool; cdecl; |
| 168 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowMessageBox' {$ENDIF} {$ENDIF}; |
| 169 | + |
| 170 | +{* |
| 171 | + * Display a simple modal message box. |
| 172 | + * |
| 173 | + * If your needs aren't complex, this function is preferred over |
| 174 | + * SDL_ShowMessageBox. |
| 175 | + * |
| 176 | + * `flags` may be any of the following: |
| 177 | + * |
| 178 | + * - `SDL_MESSAGEBOX_ERROR`: error dialog |
| 179 | + * - `SDL_MESSAGEBOX_WARNING`: warning dialog |
| 180 | + * - `SDL_MESSAGEBOX_INFORMATION`: informational dialog |
| 181 | + * |
| 182 | + * This function should be called on the thread that created the parent |
| 183 | + * window, or on the main thread if the messagebox has no parent. It will |
| 184 | + * block execution of that thread until the user clicks a button or closes the |
| 185 | + * messagebox. |
| 186 | + * |
| 187 | + * This function may be called at any time, even before SDL_Init(). This makes |
| 188 | + * it useful for reporting errors like a failure to create a renderer or |
| 189 | + * OpenGL context. |
| 190 | + * |
| 191 | + * On X11, SDL rolls its own dialog box with X11 primitives instead of a |
| 192 | + * formal toolkit like GTK+ or Qt. |
| 193 | + * |
| 194 | + * Note that if SDL_Init() would fail because there isn't any available video |
| 195 | + * target, this function is likely to fail for the same reasons. If this is a |
| 196 | + * concern, check the return value from this function and fall back to writing |
| 197 | + * to stderr if you can. |
| 198 | + * |
| 199 | + * \param flags an SDL_MessageBoxFlags value. |
| 200 | + * \param title UTF-8 title text. |
| 201 | + * \param message UTF-8 message text. |
| 202 | + * \param window the parent window, or nil for no parent. |
| 203 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 204 | + * information. |
| 205 | + * |
| 206 | + * \since This function is available since SDL 3.2.0. |
| 207 | + * |
| 208 | + * \sa SDL_ShowMessageBox |
| 209 | + } |
| 210 | +function SDL_ShowSimpleMessageBox(flags: TSDL_MessageBoxFlags; title: PAnsiChar; message: PAnsiChar; window: PSDL_Window): cbool; cdecl; |
| 211 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ShowSimpleMessageBox' {$ENDIF} {$ENDIF}; |
| 212 | + |
0 commit comments