| 1 | package SDL2::messagebox 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use SDL2::stdinc; | ||
| 4 | use SDL2::video; | ||
| 5 | enum | ||
| 6 | SDL_MessageBoxFlags => [ | ||
| 7 | [ SDL_MESSAGEBOX_ERROR => 0x00000010 ], | ||
| 8 | [ SDL_MESSAGEBOX_WARNING => 0x00000020 ], | ||
| 9 | [ SDL_MESSAGEBOX_INFORMATION => 0x00000040 ], | ||
| 10 | [ SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT => 0x00000080 ], | ||
| 11 | [ SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT => 0x00000100 ] | ||
| 12 | ], | ||
| 13 | SDL_MessageBoxButtonFlags => [ | ||
| 14 | [ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT => 0x00000001 ], | ||
| 15 | [ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT => 0x00000002 ] | ||
| 16 | ]; | ||
| 17 | |||
| 18 | package SDL2::MessageBoxButtonData { | ||
| 19 | use SDL2::Utils; | ||
| 20 | our $TYPE = has | ||
| 21 | flags => 'uint32', | ||
| 22 | buttonid => 'int', | ||
| 23 | text => 'opaque' # 'string' | ||
| 24 | ; | ||
| 25 | }; | ||
| 26 | |||
| 27 | package SDL2::MessageBoxColor { | ||
| 28 | use SDL2::Utils; | ||
| 29 | our $TYPE = has | ||
| 30 | r => 'uint8', | ||
| 31 | g => 'uint8', | ||
| 32 | b => 'uint8'; | ||
| 33 | }; | ||
| 34 | enum SDL_MessageBoxColorType => [ | ||
| 35 | qw[ | ||
| 36 | SDL_MESSAGEBOX_COLOR_BACKGROUND | ||
| 37 | SDL_MESSAGEBOX_COLOR_TEXT | ||
| 38 | SDL_MESSAGEBOX_COLOR_BUTTON_BORDER | ||
| 39 | SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND | ||
| 40 | SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED | ||
| 41 | SDL_MESSAGEBOX_COLOR_MAX] | ||
| 42 | ]; | ||
| 43 | |||
| 44 | package SDL2::MessageBoxColorScheme { | ||
| 45 | use SDL2::Utils; | ||
| 46 | our $TYPE = has colors => 'opaque' | ||
| 47 | |||
| 48 | #'SDL_MessageBoxColor[' . SDL2::FFI::SDL_MESSAGEBOX_COLOR_MAX() . ']'; | ||
| 49 | }; | ||
| 50 | |||
| 51 | package SDL2::MessageBoxData { | ||
| 52 | use SDL2::Utils; | ||
| 53 | has | ||
| 54 | flags => 'uint32', | ||
| 55 | window => 'SDL_Window', | ||
| 56 | title => 'opaque', # string | ||
| 57 | message => 'opaque', # string | ||
| 58 | numbuttons => 'int', | ||
| 59 | buttons => 'SDL_MessageBoxButtonData', | ||
| 60 | colorScheme => 'SDL_MessageBoxColorScheme'; | ||
| 61 | }; | ||
| 62 | attach messagebox => { | ||
| 63 | SDL_ShowMessageBox => [ [ 'SDL_MessageBoxData', 'int*' ], 'int' ], | ||
| 64 | SDL_ShowSimpleMessageBox => [ [ 'uint32', 'string', 'string', 'SDL_Window' ], 'int' ] | ||
| 65 | }; | ||
| 66 | |||
| 67 | =encoding utf-8 | ||
| 68 | |||
| 69 | =head1 NAME | ||
| 70 | |||
| 71 | SDL2::messagebox - Modal Message Box Support | ||
| 72 | |||
| 73 | =head1 SYNOPSIS | ||
| 74 | |||
| 75 | use SDL2 qw[:messagebox]; | ||
| 76 | |||
| 77 | =head1 DESCRIPTION | ||
| 78 | |||
| 79 | SDL2::messagebox provides functions to display modal message boxes. | ||
| 80 | |||
| 81 | =head1 Functions | ||
| 82 | |||
| 83 | These functions may be imported by name or with the C<:messagebox> tag. | ||
| 84 | |||
| 85 | =head2 C<SDL_ShowMessageBox( ... )> | ||
| 86 | |||
| 87 | Create a modal message box. | ||
| 88 | |||
| 89 | If your needs aren't complex, it might be easier to use L<< | ||
| 90 | C<SDL_ShowSimpleMessageBox( ... )>|/C<SDL_ShowSimpleMessageBox( ... )> >>. | ||
| 91 | |||
| 92 | This function should be called on the thread that created the parent window, or | ||
| 93 | on the main thread if the messagebox has no parent. It will block execution of | ||
| 94 | that thread until the user clicks a button or closes the messagebox. | ||
| 95 | |||
| 96 | This function may be called at any time, even before C<SDL_Init( ... )>. This | ||
| 97 | makes it useful for reporting errors like a failure to create a renderer or | ||
| 98 | OpenGL context. | ||
| 99 | |||
| 100 | On X11, SDL rolls its own dialog box with X11 primitives instead of a formal | ||
| 101 | toolkit like GTK+ or Qt. | ||
| 102 | |||
| 103 | Note that if C<SDL_Init( ... )> would fail because there isn't any available | ||
| 104 | video target, this function is likely to fail for the same reasons. If this is | ||
| 105 | a concern, check the return value from this function and fall back to writing | ||
| 106 | to stderr if you can. | ||
| 107 | |||
| 108 | Expected parameters include: | ||
| 109 | |||
| 110 | =over | ||
| 111 | |||
| 112 | =item C<messageboxdata> - the L<SDL2::MessageBoxData> structure with title, text and other options | ||
| 113 | |||
| 114 | =item C<buttonid> - the pointer to which user id of hit button should be copied | ||
| 115 | |||
| 116 | =back | ||
| 117 | |||
| 118 | Returns C<0> on success or a negative error code on failure; call | ||
| 119 | C<SDL_GetError( )> for more information. | ||
| 120 | |||
| 121 | =head2 C<SDL_ShowSimpleMessageBox( ... )> | ||
| 122 | |||
| 123 | Display a simple modal message box. | ||
| 124 | |||
| 125 | If your needs aren't complex, this function is preferred over L<< | ||
| 126 | C<SDL_ShowMessageBox( ... )>|/C<SDL_ShowMessageBox( ... )> >>. | ||
| 127 | |||
| 128 | C<flags> may be any of the following: | ||
| 129 | |||
| 130 | =over | ||
| 131 | |||
| 132 | =item C<SDL_MESSAGEBOX_ERROR>: error dialog | ||
| 133 | |||
| 134 | =item C<SDL_MESSAGEBOX_WARNING>: warning dialog | ||
| 135 | |||
| 136 | =item C<SDL_MESSAGEBOX_INFORMATION>: informational dialog | ||
| 137 | |||
| 138 | =back | ||
| 139 | |||
| 140 | This function should be called on the thread that created the parent window, or | ||
| 141 | on the main thread if the messagebox has no parent. It will block execution of | ||
| 142 | that thread until the user clicks a button or closes the messagebox. | ||
| 143 | |||
| 144 | This function may be called at any time, even before C<SDL_Init( ... )>. This | ||
| 145 | makes 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 formal | ||
| 149 | toolkit like GTK+ or Qt. | ||
| 150 | |||
| 151 | Note that if C<SDL_Init( ... )> would fail because there isn't any available | ||
| 152 | video target, this function is likely to fail for the same reasons. If this is | ||
| 153 | a concern, check the return value from this function and fall back to writing | ||
| 154 | to stderr if you can. | ||
| 155 | |||
| 156 | Expected parameters include: | ||
| 157 | |||
| 158 | =over | ||
| 159 | |||
| 160 | =item C<flags> - an C<SDL_MessageBoxFlags> value | ||
| 161 | |||
| 162 | =item C<title> - UTF-8 title text | ||
| 163 | |||
| 164 | =item C<message> - UTF-8 message text | ||
| 165 | |||
| 166 | =item C<window> - the parent window, or C<undef> for no parent | ||
| 167 | |||
| 168 | =back | ||
| 169 | |||
| 170 | Returns C<0> on success or a negative error code on failure; call | ||
| 171 | C<SDL_GetError( )> for more information. | ||
| 172 | |||
| 173 | =head1 Defined Variables and Enumerations | ||
| 174 | |||
| 175 | Variables may be imported by name or with the C<:messagebox> tag. Enumerations | ||
| 176 | may be imported with their given tag. | ||
| 177 | |||
| 178 | =head2 C<SDL_MessageBoxFlags> | ||
| 179 | |||
| 180 | L<SDL2::MessageBox> flags. If supported will display warning icon, etc. | ||
| 181 | |||
| 182 | =over | ||
| 183 | |||
| 184 | =item C<SDL_MESSAGEBOX_ERROR> - error dialog | ||
| 185 | |||
| 186 | =item C<SDL_MESSAGEBOX_WARNING> - warning dialog | ||
| 187 | |||
| 188 | =item C<SDL_MESSAGEBOX_INFORMATION> - informational dialog | ||
| 189 | |||
| 190 | =item C<SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT> - buttons placed left to right | ||
| 191 | |||
| 192 | =item C<SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT> - buttons placed right to left | ||
| 193 | |||
| 194 | =back | ||
| 195 | |||
| 196 | =head2 C<SDL_MessageBoxButtonFlags> | ||
| 197 | |||
| 198 | Flags for L<SDL2::MessageBoxButtonData>. | ||
| 199 | |||
| 200 | =over | ||
| 201 | |||
| 202 | =item C<SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT> - Marks the default button when return is hit | ||
| 203 | |||
| 204 | =item C<SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT> - Marks the default button when escape is hit | ||
| 205 | |||
| 206 | =back | ||
| 207 | |||
| 208 | =head2 C<SDL_MessageBoxColorType> | ||
| 209 | |||
| 210 | =over | ||
| 211 | |||
| 212 | =item C<SDL_MESSAGEBOX_COLOR_BACKGROUND> | ||
| 213 | |||
| 214 | =item C<SDL_MESSAGEBOX_COLOR_TEXT> | ||
| 215 | |||
| 216 | =item C<SDL_MESSAGEBOX_COLOR_BUTTON_BORDER> | ||
| 217 | |||
| 218 | =item C<SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND> | ||
| 219 | |||
| 220 | =item C<SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED> | ||
| 221 | |||
| 222 | =item C<SDL_MESSAGEBOX_COLOR_MAX> | ||
| 223 | |||
| 224 | =back | ||
| 225 | |||
| 226 | =head1 LICENSE | ||
| 227 | |||
| 228 | Copyright (C) Sanko Robinson. | ||
| 229 | |||
| 230 | This library is free software; you can redistribute it and/or modify it under | ||
| 231 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 232 | conditions may apply to data transmitted through this module. | ||
| 233 | |||
| 234 | =head1 AUTHOR | ||
| 235 | |||
| 236 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 237 | |||
| 238 | =begin stopwords | ||
| 239 | |||
| 240 | messagebox | ||
| 241 | |||
| 242 | =end stopwords | ||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | }; | ||
| 247 | 1; |